diff --git a/src/tests/Makefile b/src/tests/Makefile new file mode 100644 index 00000000..4722d2d2 --- /dev/null +++ b/src/tests/Makefile @@ -0,0 +1,9 @@ + +PKG_INCLUDES:=$(shell pkg-config --cflags libosmocore libosmovty libosmogsm libasn1c) +PKG_LDFLAGS:=$(shell pkg-config --libs libosmocore libosmovty libosmogsm libasn1c) + +CFLAGS:=-g -Wall $(PKG_INCLUDES) -I.. +LDFLAGS:=$(PKG_LDFLAGS) + +test-helpers: ../iu_helpers.o test-helpers.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ diff --git a/src/tests/test-helpers.c b/src/tests/test-helpers.c new file mode 100644 index 00000000..e23f017d --- /dev/null +++ b/src/tests/test-helpers.c @@ -0,0 +1,35 @@ +#include "iu_helpers.h" +#include "asn1helpers.h" + +#include +#define ASSERT(x) assert(x) + +#include + +void *talloc_asn1_ctx; + +/* use odd number of digits */ +const uint8_t imsi_encoded[] = { 0x10, 0x32, 0x54, 0x76, 0xF8 }; +const char imsi_decoded[] = "012345678"; + +int main(int argc, char **argv) +{ + char outstr[32]; + uint8_t outbuf[16]; + int rc; + + printf("pre-encoded: %s\n", osmo_hexdump_nospc(imsi_encoded, + sizeof(imsi_encoded))); + rc = decode_iu_bcd(outstr, sizeof(outstr), imsi_encoded, + sizeof(imsi_encoded)); + ASSERT(rc >= 0); + printf("decoded: %s\n", outstr); + ASSERT(!strcmp(outstr, imsi_decoded)); + + rc = encode_iu_imsi(outbuf, sizeof(outbuf), imsi_decoded); + ASSERT(rc >= 0); + printf("re-encoded: %s\n", osmo_hexdump_nospc(outbuf, rc)); + ASSERT(!memcmp(outbuf, imsi_encoded, sizeof(imsi_encoded))); + + return 0; +}