2 #include "ntp_stdlib.h"
3 #include "ntp_calendar.h"
6 #include "sockaddrtest.h"
9 void test_IPv4AddressOnly(void) {
10 const char *str = "192.0.2.1";
14 expected.sa4.sin_family = AF_INET;
15 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
16 SET_PORT(&expected, NTP_PORT);
18 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
19 TEST_ASSERT_TRUE(IsEqual(expected, actual));
22 void test_IPv4AddressWithPort(void) {
23 const char *str = "192.0.2.2:2000";
27 expected.sa4.sin_family = AF_INET;
28 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.2");
29 SET_PORT(&expected, 2000);
31 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
32 TEST_ASSERT_TRUE(IsEqual(expected, actual));
35 void test_IPv6AddressOnly(void) {
36 const struct in6_addr address = {
37 0x20, 0x01, 0x0d, 0xb8,
38 0x85, 0xa3, 0x08, 0xd3,
39 0x13, 0x19, 0x8a, 0x2e,
40 0x03, 0x70, 0x73, 0x34
43 const char *str = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
47 expected.sa6.sin6_family = AF_INET6;
48 expected.sa6.sin6_addr = address;
49 SET_PORT(&expected, NTP_PORT);
51 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
52 TEST_ASSERT_TRUE(IsEqual(expected, actual));
55 void test_IPv6AddressWithPort(void) {
56 const struct in6_addr address = {
57 0x20, 0x01, 0x0d, 0xb8,
58 0x85, 0xa3, 0x08, 0xd3,
59 0x13, 0x19, 0x8a, 0x2e,
60 0x03, 0x70, 0x73, 0x34
63 const char *str = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334]:3000";
67 expected.sa6.sin6_family = AF_INET6;
68 expected.sa6.sin6_addr = address;
69 SET_PORT(&expected, 3000);
71 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
72 TEST_ASSERT_TRUE(IsEqual(expected, actual));
75 void test_IllegalAddress(void) {
76 const char *str = "192.0.2.270:2000";
79 TEST_ASSERT_FALSE(decodenetnum(str, &actual));
82 void test_IllegalCharInPort(void) {
83 /* An illegal port does not make the decodenetnum fail, but instead
84 * makes it use the standard port.
86 const char *str = "192.0.2.1:a700";
90 expected.sa4.sin_family = AF_INET;
91 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
92 SET_PORT(&expected, NTP_PORT);
94 TEST_ASSERT_TRUE(decodenetnum(str, &actual));
95 TEST_ASSERT_TRUE(IsEqual(expected, actual));