From 54a9a143f0e013eed28d049243709abf4cc6e5f2 Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Mon, 23 Nov 2015 14:01:25 +0100 Subject: [PATCH] tests: Test asn1_u32_to_bitstring and asn1bitstr_to_u32 --- src/tests/Makefile | 2 +- src/tests/test-helpers.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/tests/Makefile b/src/tests/Makefile index 4722d2d2..e6536c05 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -5,5 +5,5 @@ PKG_LDFLAGS:=$(shell pkg-config --libs libosmocore libosmovty libosmogsm libasn1 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 b2998417..b82e909f 100644 --- a/src/tests/test-helpers.c +++ b/src/tests/test-helpers.c @@ -33,12 +33,14 @@ void *talloc_asn1_ctx; 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 @@ int main(int argc, char **argv) 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; }