tests: Test asn1_u32_to_bitstring and asn1bitstr_to_u32
diff --git a/src/tests/Makefile b/src/tests/Makefile
index 4722d2d..e6536c0 100644
--- a/src/tests/Makefile
+++ b/src/tests/Makefile
@@ -5,5 +5,5 @@
CFLAGS:=-g -Wall $(PKG_INCLUDES) -I..
LDFLAGS:=$(PKG_LDFLAGS)
-test-helpers: ../iu_helpers.o test-helpers.c
+test-helpers: ../iu_helpers.o ../asn1helpers.o test-helpers.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
diff --git a/src/tests/test-helpers.c b/src/tests/test-helpers.c
index b299841..b82e909 100644
--- a/src/tests/test-helpers.c
+++ b/src/tests/test-helpers.c
@@ -33,12 +33,14 @@
const uint8_t imsi_encoded[] = { 0x10, 0x32, 0x54, 0x76, 0xF8 };
const char imsi_decoded[] = "012345678";
-int main(int argc, char **argv)
+void test_iu_helpers(void)
{
char outstr[32];
uint8_t outbuf[16];
int rc;
+ printf("Testing Iu helper functions\n");
+
printf("pre-encoded: %s\n", osmo_hexdump_nospc(imsi_encoded,
sizeof(imsi_encoded)));
rc = decode_iu_bcd(outstr, sizeof(outstr), imsi_encoded,
@@ -51,6 +53,35 @@
ASSERT(rc >= 0);
printf("re-encoded: %s\n", osmo_hexdump_nospc(outbuf, rc));
ASSERT(!memcmp(outbuf, imsi_encoded, sizeof(imsi_encoded)));
+}
+
+uint32_t val1 = 0xdeadbeef;
+
+void test_asn1_helpers(void)
+{
+ BIT_STRING_t enc;
+ uint32_t res;
+
+ printf("Testing asn.1 helper functions\n");
+
+ printf("Encoding 0x%x to asn.1 bitstring\n", val1);
+ asn1_u32_to_bitstring(&enc, &val1);
+
+ ASSERT(enc.buf == (uint8_t *) &val1);
+ ASSERT(enc.size == sizeof(uint32_t));
+ ASSERT(enc.bits_unused == 0);
+
+ res = asn1bitstr_to_u32(&enc);
+
+ printf("Decoding back to uint32_t: 0x%x\n", res);
+ ASSERT(res == val1);
+
+}
+
+int main(int argc, char **argv)
+{
+ test_iu_helpers();
+ test_asn1_helpers();
return 0;
}