summaryrefslogtreecommitdiffstats
path: root/tests/utils
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-06-02 15:52:06 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2015-06-02 15:52:06 +0200
commitf558ed4bb9c0f00997b8f97c2b251a574c1a64c4 (patch)
tree16524d63b63a4c5496a9bc6412c3a9862367cc36 /tests/utils
parent91ff17c9ef7dd4a29bb13d6b9995100ffc65b72a (diff)
ipa: Properly parse LV stream of a ID_GET request
For some reason the structure is closer to be a LV (length and value). The value is actually a tag but it is counted inside the length. Introduce an overload of the parse function to provide an offset for the length. This will be taken from the returned length.
Diffstat (limited to 'tests/utils')
-rw-r--r--tests/utils/utils_test.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c
index b21b074b..1a79baa3 100644
--- a/tests/utils/utils_test.c
+++ b/tests/utils/utils_test.c
@@ -20,6 +20,9 @@
*
*/
+#include <osmocom/gsm/ipa.h>
+
+#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <stdio.h>
@@ -40,8 +43,66 @@ static void hexdump_test(void)
printf("%s\n", osmo_hexdump_nospc(data, ARRAY_SIZE(data)));
}
+static void test_idtag_parsing(void)
+{
+ struct tlv_parsed tvp;
+ int rc;
+
+ static uint8_t data[] = {
+ 0x01, 0x08,
+ 0x01, 0x07,
+ 0x01, 0x02,
+ 0x01, 0x03,
+ 0x01, 0x04,
+ 0x01, 0x05,
+ 0x01, 0x01,
+ 0x01, 0x00,
+ 0x11, 0x23, 0x4e, 0x6a, 0x28, 0xd2, 0xa2, 0x53, 0x3a, 0x2a, 0x82, 0xa7, 0x7a, 0xef, 0x29, 0xd4, 0x44, 0x30,
+ 0x11, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
+ rc = ipa_ccm_idtag_parse_off(&tvp, data, sizeof(data), 1);
+ OSMO_ASSERT(rc == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 8));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 8) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 7));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 7) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 2));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 2) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 3));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 3) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 4));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 4) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 5));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 5) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 1));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 1) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 0));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 0) == 0);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 0x23));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 0x23) == 16);
+
+ OSMO_ASSERT(TLVP_PRESENT(&tvp, 0x24));
+ OSMO_ASSERT(TLVP_LEN(&tvp, 0x24) == 16);
+
+ OSMO_ASSERT(!TLVP_PRESENT(&tvp, 0x25));
+}
+
int main(int argc, char **argv)
{
+ static const struct log_info log_info = {};
+ log_init(&log_info, NULL);
+
hexdump_test();
+ test_idtag_parsing();
return 0;
}