-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathtest_printTo6.cpp
139 lines (98 loc) · 3.19 KB
/
test_printTo6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <api/IPAddress.h>
#include <PrintMock.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Print IPv6", "[IPAddress-printTo6-01]")
{
PrintMock mock;
arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc);
mock.print(ip);
REQUIRE(mock._str == "2001:db8:102:304:506:708:90a:b0c");
}
TEST_CASE ("Print IPv6 any", "[IPAddress-printTo6-02]")
{
PrintMock mock;
arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
mock.print(ip);
REQUIRE(mock._str == "::");
}
TEST_CASE ("Print IPv6 localhost", "[IPAddress-printTo6-03]")
{
PrintMock mock;
arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1);
mock.print(ip);
REQUIRE(mock._str == "::1");
}
TEST_CASE ("Print IPv6 different length segments", "[IPAddress-printTo6-04]")
{
PrintMock mock;
arduino::IPAddress const ip(0xab,0xcd, 0x0e,0xf1, 0x00,0x23, 0,0, 0x00,0x04, 0,0, 0,0, 0,0);
mock.print(ip);
REQUIRE(mock._str == "abcd:ef1:23:0:4::");
}
TEST_CASE ("Print IPv6 zero longest run end", "[IPAddress-printTo6-05]")
{
PrintMock mock;
arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,2, 0,0, 0,0, 0,0);
mock.print(ip);
REQUIRE(mock._str == "0:1:0:0:2::");
}
TEST_CASE ("Print IPv6 zero longest run mid", "[IPAddress-printTo6-06]")
{
PrintMock mock;
arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,0, 0,2, 0,0, 0,0);
mock.print(ip);
REQUIRE(mock._str == "0:1::2:0:0");
}
TEST_CASE ("Print IPv6 start zero", "[IPAddress-printTo6-07]")
{
PrintMock mock;
arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,8);
mock.print(ip);
REQUIRE(mock._str == "0:2:3:4:5:6:7:8");
}
TEST_CASE ("Print IPv6 ending zero", "[IPAddress-printTo6-08]")
{
PrintMock mock;
arduino::IPAddress const ip(0,1, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0);
mock.print(ip);
REQUIRE(mock._str == "1:2:3:4:5:6:7:0");
}
TEST_CASE ("Print IPv6 start two zero", "[IPAddress-printTo6-09]")
{
PrintMock mock;
arduino::IPAddress const ip(0,0, 0,0, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0);
mock.print(ip);
REQUIRE(mock._str == "::3:4:5:6:7:0");
}
TEST_CASE ("Print IPv6 ending two zero", "[IPAddress-printTo6-10]")
{
PrintMock mock;
arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,0, 0,0);
mock.print(ip);
REQUIRE(mock._str == "0:2:3:4:5:6::");
}
TEST_CASE ("Print IPv6 first out of same length", "[IPAddress-printTo6-11]")
{
PrintMock mock;
arduino::IPAddress const ip(0,1, 0,0, 0,0, 0,4, 0,5, 0,0, 0,0, 0,8);
mock.print(ip);
REQUIRE(mock._str == "1::4:5:0:0:8");
}
TEST_CASE ("Print IPv6 single zeros not compressed", "[IPAddress-printTo6-12]")
{
PrintMock mock;
arduino::IPAddress const ip(0,1, 0,0, 0,3, 0,0, 0,5, 0,0, 0,7, 0,8);
mock.print(ip);
REQUIRE(mock._str == "1:0:3:0:5:0:7:8");
}