diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-10-12 20:01:54 +0800 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-10-13 11:09:30 +0200 |
commit | adabfb2f4e6b7e50376c9fd3ca47d4d4b9bd8337 (patch) | |
tree | 9dcb90f8a55b5651919f08125754ff229099bf7c | |
parent | 336972cb622caf96aa7e1cbf35e5fbcc58b19285 (diff) |
add Unit test for lib/in46_addr.c code
Change-Id: Id032c330405e5dca8ecfc0970d128341ed75c675
-rw-r--r-- | tests/lib/Makefile.am | 14 | ||||
-rw-r--r-- | tests/lib/in46a_test.c | 93 | ||||
-rw-r--r-- | tests/testsuite.at | 6 |
3 files changed, 111 insertions, 2 deletions
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 70d35b7..2366072 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -1,6 +1,7 @@ -EXTRA_DIST = ippool_test.ok ippool_test.err +EXTRA_DIST = ippool_test.ok ippool_test.err \ + in46a_test.ok -noinst_PROGRAMS = ippool_test +noinst_PROGRAMS = ippool_test in46a_test ippool_test_SOURCES = \ ippool_test.c \ @@ -10,3 +11,12 @@ ippool_test_LDADD = \ $(top_builddir)/lib/libmisc.a \ $(LIBOSMOCORE_LIBS) \ $(NULL) + +in46a_test_SOURCES = \ + in46a_test.c \ + $(NULL) + +in46a_test_LDADD = \ + $(top_builddir)/lib/libmisc.a \ + $(LIBOSMOCORE_LIBS) \ + $(NULL) diff --git a/tests/lib/in46a_test.c b/tests/lib/in46a_test.c new file mode 100644 index 0000000..b075610 --- /dev/null +++ b/tests/lib/in46a_test.c @@ -0,0 +1,93 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <time.h> + +#include <osmocom/core/utils.h> +#include <osmocom/core/application.h> +#include <osmocom/core/logging.h> + +#include "../../lib/in46_addr.h" +#include "../../lib/syserr.h" + +static void test_in46a_to_af(void) +{ + struct in46_addr ia; + + printf("Testing in46a_to_af()\n"); + + ia.len = 4; + OSMO_ASSERT(in46a_to_af(&ia) == AF_INET); + ia.len = 8; + OSMO_ASSERT(in46a_to_af(&ia) == AF_INET6); + ia.len = 16; + OSMO_ASSERT(in46a_to_af(&ia) == AF_INET6); +} + +static void test_in46a_to_sas(void) +{ + struct in46_addr ia; + struct sockaddr_storage ss; + + printf("Testing in46a_to_sas()\n"); + + //FIXME; + OSMO_ASSERT(in46a_to_sas(&ss, &ia)); +} + +static void test_in46a_ntop(void) +{ + struct in46_addr ia; + char buf[256]; + const char *res; + + printf("Testing in46a_ntop()\n"); + + res = in46a_ntop(NULL, buf, sizeof(buf)); + OSMO_ASSERT(res && !strcmp(res, "UNDEFINED")); + printf("res = %s\n", res); + + ia.len = 0; + res = in46a_ntop(&ia, buf, sizeof(buf)); + printf("res = %s\n", res); + OSMO_ASSERT(res && !strcmp(res, "UNDEFINED")); + + ia.len = 4; + ia.v4.s_addr = htonl(0x01020304); + res = in46a_ntop(&ia, buf, sizeof(buf)); + OSMO_ASSERT(res && !strcmp(res, "1.2.3.4")); + printf("res = %s\n", res); + + /* FIXME: ipv6 */ +} + +static void test_in46p_ntoa(void) +{ + const struct in46_prefix ip46 = { + .prefixlen = 24, + .addr = { + .len = 4, + .v4.s_addr = htonl(0x10203000), + }, + }; + printf("in46p_ntoa() returns %s\n", in46p_ntoa(&ip46)); +} + +static void test_in46a_eua(void) +{ + +} + +int main(int argc, char **argv) +{ + osmo_init_logging(&log_info); + log_set_use_color(osmo_stderr_target, 0); + log_set_print_filename(osmo_stderr_target, 0); + + srand(time(NULL)); + + test_in46a_to_af(); + test_in46a_ntop(); + test_in46p_ntoa(); +} diff --git a/tests/testsuite.at b/tests/testsuite.at index a10152f..0a69ee7 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -7,3 +7,9 @@ cat $abs_srcdir/lib/ippool_test.ok > expout cat $abs_srcdir/lib/ippool_test.err > experr AT_CHECK([$abs_top_builddir/tests/lib/ippool_test], [], [expout], [experr]) AT_CLEANUP + +AT_SETUP([in46al]) +AT_KEYWORDS([in46al]) +cat $abs_srcdir/lib/in46a_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/lib/in46a_test], [], [expout], []) +AT_CLEANUP |