diff options
Diffstat (limited to 'tests/types/TypesTest.cpp')
-rw-r--r-- | tests/types/TypesTest.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/types/TypesTest.cpp b/tests/types/TypesTest.cpp new file mode 100644 index 00000000..235ba974 --- /dev/null +++ b/tests/types/TypesTest.cpp @@ -0,0 +1,93 @@ +/* + * TypesTest.cpp Test the primitive data types + * + * Copyright (C) 2013 by Holger Hans Peter Freyther + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +#include "bts.h" +#include "tbf.h" +#include "gprs_debug.h" + +extern "C" { +#include <osmocom/core/application.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/utils.h> +} + +void *tall_pcu_ctx; +int16_t spoof_mnc = 0, spoof_mcc = 0; + +static void test_llc(void) +{ + { + uint8_t data[LLC_MAX_LEN] = {1, 2, 3, 4, }; + uint8_t out; + gprs_llc llc; + llc.init(); + + OSMO_ASSERT(llc.chunk_size() == 0); + OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN); + OSMO_ASSERT(llc.frame_length() == 0); + + llc.put_frame(data, 2); + OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 2); + OSMO_ASSERT(llc.frame_length() == 2); + OSMO_ASSERT(llc.chunk_size() == 2); + OSMO_ASSERT(llc.frame[0] == 1); + OSMO_ASSERT(llc.frame[1] == 2); + + llc.append_frame(&data[3], 1); + OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 3); + OSMO_ASSERT(llc.frame_length() == 3); + OSMO_ASSERT(llc.chunk_size() == 3); + + /* consume two bytes */ + llc.consume(&out, 1); + OSMO_ASSERT(llc.remaining_space() == LLC_MAX_LEN - 3); + OSMO_ASSERT(llc.frame_length() == 3); + OSMO_ASSERT(llc.chunk_size() == 2); + + /* check that the bytes are as we expected */ + OSMO_ASSERT(llc.frame[0] == 1); + OSMO_ASSERT(llc.frame[1] == 2); + OSMO_ASSERT(llc.frame[2] == 4); + + /* now fill the frame */ + llc.append_frame(data, llc.remaining_space() - 1); + OSMO_ASSERT(llc.fits_in_current_frame(1)); + OSMO_ASSERT(!llc.fits_in_current_frame(2)); + } +} + +int main(int argc, char **argv) +{ + printf("Making some basic type testing.\n"); + test_llc(); + return EXIT_SUCCESS; +} + +/* + * stubs that should not be reached + */ +extern "C" { +void l1if_pdch_req() { abort(); } +void l1if_connect_pdch() { abort(); } +void l1if_close_pdch() { abort(); } +void l1if_open_pdch() { abort(); } +} |