summaryrefslogtreecommitdiffstats
path: root/openbsc/tests
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-12-11 12:05:29 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-12-23 15:10:24 +0100
commit697a534ed64e76de3cfb8b558e40d081f70b31ff (patch)
tree10748cc45a5f35f422c853e9bf87e022daefc113 /openbsc/tests
parentdcfd456640b6e15f15c94f175eb145220b96ee1a (diff)
gprs: Add gprs_shift_tlv function
This function is similar to gprs_match_tlv with the exception, that the tag is not compared but returned in *tag instead. Sponsored-by: On-Waves ehf
Diffstat (limited to 'openbsc/tests')
-rw-r--r--openbsc/tests/gprs/gprs_test.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/openbsc/tests/gprs/gprs_test.c b/openbsc/tests/gprs/gprs_test.c
index 5bc207343..1b20db147 100644
--- a/openbsc/tests/gprs/gprs_test.c
+++ b/openbsc/tests/gprs/gprs_test.c
@@ -139,20 +139,33 @@ static void test_gsm_03_03_apn(void)
}
/* TODO: Move tlv testing to libosmocore */
-static void check_tlv_match(uint8_t **data, size_t *data_len,
- uint8_t tag, size_t exp_len, const uint8_t *exp_val)
+static void check_tlv_parse(uint8_t **data, size_t *data_len,
+ uint8_t exp_tag, size_t exp_len, const uint8_t *exp_val)
{
uint8_t *value;
size_t value_len;
+ uint8_t tag;
int rc;
+ uint8_t *saved_data = *data;
+ size_t saved_data_len = *data_len;
- rc = gprs_match_tlv(data, data_len, tag ^ 1, NULL, NULL);
+ rc = gprs_match_tlv(data, data_len, exp_tag ^ 1, NULL, NULL);
OSMO_ASSERT(rc == 0);
- rc = gprs_match_tlv(data, data_len, tag, &value, &value_len);
+ rc = gprs_match_tlv(data, data_len, exp_tag, &value, &value_len);
OSMO_ASSERT(rc == (int)value_len + 2);
OSMO_ASSERT(value_len == exp_len);
OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0);
+
+ /* restore data/data_len */
+ *data = saved_data;
+ *data_len = saved_data_len;
+
+ rc = gprs_shift_tlv(data, data_len, &tag, &value, &value_len);
+ OSMO_ASSERT(rc == (int)value_len + 2);
+ OSMO_ASSERT(tag == exp_tag);
+ OSMO_ASSERT(value_len == exp_len);
+ OSMO_ASSERT(memcmp(value, exp_val, exp_len) == 0);
}
static void check_tv_fixed_match(uint8_t **data, size_t *data_len,
@@ -340,7 +353,7 @@ static void test_tlv_shift_functions()
OSMO_ASSERT(data_len <= sizeof(buf));
for (i = 0; i < iterations; i++) {
- check_tlv_match(&data, &data_len, tag, len, test_data);
+ check_tlv_parse(&data, &data_len, tag, len, test_data);
check_tv_fixed_match(&data, &data_len, tag, len, test_data);
check_v_fixed_shift(&data, &data_len, len, test_data);
check_lv_shift(&data, &data_len, len, test_data);