From 5995389b0ffab644adbdb2f305ce502cb87f928d Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 7 May 2015 09:29:36 +0200 Subject: [PATCH] tests: added ipv6-prefix unit test --- tests/Makefile.am | 7 +++- tests/ipv6-prefix.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 tests/ipv6-prefix.c diff --git a/tests/Makefile.am b/tests/Makefile.am index c5dd7d53..175e2aa8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,7 +20,7 @@ dist_check_SCRIPTS = test-pass test-pass-cert test-cert test-iroute test-pass-sc test-cookie-invalidation -ipv4_prefix_CPPFLAGS = \ +AM_CPPFLAGS = \ -I$(top_srcdir)/src/ \ -I$(top_builddir)/src/ \ -I$(top_srcdir)/gl/ \ @@ -28,7 +28,10 @@ ipv4_prefix_CPPFLAGS = \ ipv4_prefix_SOURCES = ../src/common.c ../src/common.h ipv4-prefix.c ipv4_prefix_LDADD = ../gl/libgnu.a $(LIBTALLOC_LIBS) -check_PROGRAMS = ipv4-prefix +ipv6_prefix_SOURCES = ../src/common.c ../src/common.h ipv6-prefix.c +ipv6_prefix_LDADD = ../gl/libgnu.a $(LIBTALLOC_LIBS) + +check_PROGRAMS = ipv4-prefix ipv6-prefix TESTS = test-pass test-pass-cert test-cert test-iroute test-pass-script \ test-multi-cookie full-test test-group-pass test-pass-group-cert \ diff --git a/tests/ipv6-prefix.c b/tests/ipv6-prefix.c new file mode 100644 index 00000000..35beeb18 --- /dev/null +++ b/tests/ipv6-prefix.c @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "../src/common.h" + +int main() +{ + char *p; + char str[MAX_IP_STR]; + + p = ipv6_prefix_to_mask(str, 128); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 127); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 97); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffff:ffff:ffff:8000:0") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 96); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffff:ffff:ffff::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 95); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffff:ffff:fffe::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 67); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffff:e000::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 64); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffff::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 59); + if (p == NULL || strcmp(p, "ffff:ffff:ffff:ffe0::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 48); + if (p == NULL || strcmp(p, "ffff:ffff:ffff::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 32); + if (p == NULL || strcmp(p, "ffff:ffff::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + p = ipv6_prefix_to_mask(str, 12); + if (p == NULL || strcmp(p, "fff0::") != 0) { + fprintf(stderr, "error in %d: %s\n", __LINE__, p); + exit(1); + } + + return 0; +}