diff --git a/tests/Makefile b/tests/Makefile index 9ff441b..aae1740 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,7 +1,7 @@ CC = gcc TEST = test -OBJS = test.o base32.o base64.o read.o dns.o encoding.o login.o user.o fw_query.o -SRCOBJS = ../src/base32.o ../src/base64.o ../src/read.o ../src/dns.o ../src/encoding.o ../src/login.o ../src/md5.o ../src/user.o ../src/fw_query.o +OBJS = test.o base32.o base64.o common.o read.o dns.o encoding.o login.o user.o fw_query.o +SRCOBJS = ../src/base32.o ../src/base64.o ../src/common.o ../src/read.o ../src/dns.o ../src/encoding.o ../src/login.o ../src/md5.o ../src/user.o ../src/fw_query.o OS = `uname | tr "a-z" "A-Z"` diff --git a/tests/common.c b/tests/common.c new file mode 100644 index 0000000..ff1531c --- /dev/null +++ b/tests/common.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +START_TEST(test_parse_format_ipv4) +{ + char *host = "192.168.2.10"; + char *formatted; + struct sockaddr_storage addr; + struct sockaddr_in *v4addr; + int addr_len; + + addr_len = get_addr(host, 53, AF_INET, 0, &addr); + fail_unless(addr_len == sizeof(struct sockaddr_in)); + + v4addr = (struct sockaddr_in *) &addr; + fail_unless(v4addr->sin_addr.s_addr == htonl(0xc0a8020a)); + fail_unless(v4addr->sin_port == htons(53)); + + formatted = format_addr(&addr, addr_len); + fail_if(strcmp(host, formatted)); +} +END_TEST + +START_TEST(test_parse_format_ipv4_listen_all) +{ + char *host = "0.0.0.0"; + char *formatted; + struct sockaddr_storage addr; + struct sockaddr_in *v4addr; + int addr_len; + + addr_len = get_addr(NULL, 53, AF_INET, AI_PASSIVE, &addr); + fail_unless(addr_len == sizeof(struct sockaddr_in)); + + v4addr = (struct sockaddr_in *) &addr; + fail_unless(v4addr->sin_addr.s_addr == htonl(0x00000000)); + fail_unless(v4addr->sin_port == htons(53)); + + formatted = format_addr(&addr, addr_len); + fail_if(strcmp(host, formatted)); +} +END_TEST + +TCase * +test_common_create_tests() +{ + TCase *tc; + + tc = tcase_create("Common"); + tcase_add_test(tc, test_parse_format_ipv4); + tcase_add_test(tc, test_parse_format_ipv4_listen_all); + return tc; +} diff --git a/tests/test.c b/tests/test.c index 5bee9d2..e897cc2 100644 --- a/tests/test.c +++ b/tests/test.c @@ -38,6 +38,9 @@ main() test = test_base64_create_tests(); suite_add_tcase(iodine, test); + test = test_common_create_tests(); + suite_add_tcase(iodine, test); + test = test_dns_create_tests(); suite_add_tcase(iodine, test); diff --git a/tests/test.h b/tests/test.h index 1022a9e..0701886 100644 --- a/tests/test.h +++ b/tests/test.h @@ -19,6 +19,7 @@ TCase *test_base32_create_tests(); TCase *test_base64_create_tests(); +TCase *test_common_create_tests(); TCase *test_dns_create_tests(); TCase *test_encoding_create_tests(); TCase *test_read_create_tests();