3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
8 #include "sockaddrtest.h"
12 void test_ClassBAddress(void);
13 void test_ClassCAddress(void);
14 void test_ClassAAddress(void);
15 void test_IPv6Address(void);
28 test_ClassBAddress(void)
30 sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT);
31 sockaddr_u expected = CreateSockaddr4("172.16.0.0", NTP_PORT);
33 sockaddr_u* actual = netof(&input);
35 TEST_ASSERT_TRUE(actual != NULL);
36 TEST_ASSERT_TRUE(IsEqual(expected, *actual));
42 test_ClassCAddress(void)
44 sockaddr_u input = CreateSockaddr4("192.0.2.255", NTP_PORT);
45 sockaddr_u expected = CreateSockaddr4("192.0.2.0", NTP_PORT);
47 sockaddr_u* actual = netof(&input);
49 TEST_ASSERT_TRUE(actual != NULL);
50 TEST_ASSERT_TRUE(IsEqual(expected, *actual));
57 test_ClassAAddress(void)
59 /* Class A addresses are assumed to be classless,
60 * thus the same address should be returned.
62 sockaddr_u input = CreateSockaddr4("10.20.30.40", NTP_PORT);
63 sockaddr_u expected = CreateSockaddr4("10.20.30.40", NTP_PORT);
65 sockaddr_u* actual = netof(&input);
67 TEST_ASSERT_TRUE(actual != NULL);
68 TEST_ASSERT_TRUE(IsEqual(expected, *actual));
74 test_IPv6Address(void)
76 /* IPv6 addresses are assumed to have 64-bit host- and 64-bit network parts. */
77 const struct in6_addr input_address = { { {
78 0x20, 0x01, 0x0d, 0xb8,
79 0x85, 0xa3, 0x08, 0xd3,
80 0x13, 0x19, 0x8a, 0x2e,
81 0x03, 0x70, 0x73, 0x34
82 } } }; // 2001:0db8:85a3:08d3:1319:8a2e:0370:7334
84 const struct in6_addr expected_address = { { {
85 0x20, 0x01, 0x0d, 0xb8,
86 0x85, 0xa3, 0x08, 0xd3,
87 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00
89 } } }; // 2001:0db8:85a3:08d3:0000:0000:0000:0000
92 input.sa6.sin6_family = AF_INET6;
93 input.sa6.sin6_addr = input_address;
94 SET_PORT(&input, 3000);
97 expected.sa6.sin6_family = AF_INET6;
98 expected.sa6.sin6_addr = expected_address;
99 SET_PORT(&expected, 3000);
101 sockaddr_u* actual = netof(&input);
103 TEST_ASSERT_TRUE(actual != NULL);
104 TEST_ASSERT_TRUE(IsEqual(expected, *actual));