diff options
Diffstat (limited to 'tests/libntp/socktoa.c')
-rw-r--r-- | tests/libntp/socktoa.c | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/tests/libntp/socktoa.c b/tests/libntp/socktoa.c index 537df1e44407..6661fa553c89 100644 --- a/tests/libntp/socktoa.c +++ b/tests/libntp/socktoa.c @@ -4,18 +4,32 @@ #include "ntp_calendar.h" #include "unity.h" - #include "sockaddrtest.h" -void test_IPv4AddressWithPort(void) { +void test_IPv4AddressWithPort(void); +//#ifdef ISC_PLATFORM_HAVEIPV6 +void test_IPv6AddressWithPort(void); +void test_IgnoreIPv6Fields(void); +//#endif /* ISC_PLATFORM_HAVEIPV6 */ +void test_ScopedIPv6AddressWithPort(void); +void test_HashEqual(void); +void test_HashNotEqual(void); + +void +test_IPv4AddressWithPort(void) { sockaddr_u input = CreateSockaddr4("192.0.2.10", 123); TEST_ASSERT_EQUAL_STRING("192.0.2.10", socktoa(&input)); TEST_ASSERT_EQUAL_STRING("192.0.2.10:123", sockporttoa(&input)); } -void test_IPv6AddressWithPort(void) { + +void +test_IPv6AddressWithPort(void) { + +#ifdef ISC_PLATFORM_WANTIPV6 + const struct in6_addr address = { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x08, 0xd3, @@ -36,10 +50,18 @@ void test_IPv6AddressWithPort(void) { TEST_ASSERT_EQUAL_STRING(expected, socktoa(&input)); TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input)); + +#else + TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping."); + +#endif /* ISC_PLATFORM_HAVEIPV6 */ + } + +void +test_ScopedIPv6AddressWithPort(void) { #ifdef ISC_PLATFORM_HAVESCOPEID -void test_ScopedIPv6AddressWithPort(void) { const struct in6_addr address = { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -61,10 +83,13 @@ void test_ScopedIPv6AddressWithPort(void) { TEST_ASSERT_EQUAL_STRING(expected, socktoa(&input)); TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input)); +#else + TEST_IGNORE_MESSAGE("Skipping because ISC_PLATFORM does not have Scope ID"); +#endif } -#endif /* ISC_PLATFORM_HAVESCOPEID */ -void test_HashEqual(void) { +void +test_HashEqual(void) { sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123); sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123); @@ -72,20 +97,22 @@ void test_HashEqual(void) { TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2)); } -void test_HashNotEqual(void) { +void +test_HashNotEqual(void) { /* These two addresses should not generate the same hash. */ sockaddr_u input1 = CreateSockaddr4("192.0.2.1", 123); sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123); TEST_ASSERT_FALSE(IsEqual(input1, input2)); - //TODO : EXPECT_NE(sock_hash(&input1), sock_hash(&input2)); - //Damir's suggestion below: TEST_ASSERT_FALSE(sock_hash(&input1) == sock_hash(&input2)); - //NOTE: sock_hash returns u_short, so you can compare it with == - //for complex structures you have to write an additional function like bool compare(a,b) } -void test_IgnoreIPv6Fields(void) { + +void +test_IgnoreIPv6Fields(void) { + +#ifdef ISC_PLATFORM_WANTIPV6 + const struct in6_addr address = { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x08, 0xd3, @@ -106,4 +133,9 @@ void test_IgnoreIPv6Fields(void) { SET_PORT(&input2, NTP_PORT); TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2)); + +#else + TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping."); +#endif /* ISC_PLATFORM_HAVEIPV6 */ } + |