mirror of
https://github.com/yarrick/iodine.git
synced 2024-12-26 15:03:31 +02:00
Add some tests for get_addr/format_addr
IPv4 only for now for compatibility with old machines
This commit is contained in:
parent
540d3795a9
commit
d57aebacdc
4 changed files with 61 additions and 2 deletions
|
@ -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"`
|
||||
|
||||
|
|
55
tests/common.c
Normal file
55
tests/common.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <check.h>
|
||||
#include <common.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
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;
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue