-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_IPAddress6.cpp
87 lines (77 loc) · 2.34 KB
/
test_IPAddress6.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
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <api/IPAddress.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing IPAddress(type) constructor()", "[IPAddress6-Ctor-01]")
{
arduino::IPAddress ip (arduino::IPType::IPv6);
REQUIRE(ip.type() == arduino::IPType::IPv6);
REQUIRE(ip[0] == 0);
REQUIRE(ip[1] == 0);
REQUIRE(ip[2] == 0);
REQUIRE(ip[3] == 0);
REQUIRE(ip[4] == 0);
REQUIRE(ip[5] == 0);
REQUIRE(ip[6] == 0);
REQUIRE(ip[7] == 0);
REQUIRE(ip[8] == 0);
REQUIRE(ip[9] == 0);
REQUIRE(ip[10] == 0);
REQUIRE(ip[11] == 0);
REQUIRE(ip[12] == 0);
REQUIRE(ip[13] == 0);
REQUIRE(ip[14] == 0);
REQUIRE(ip[15] == 0);
}
TEST_CASE ("Testing IPAddress(o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o) constructor", "[IPAddress-Ctor6-02]")
{
arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc);
REQUIRE(ip.type() == arduino::IPType::IPv6);
REQUIRE(ip[0] == 0x20);
REQUIRE(ip[1] == 0x01);
REQUIRE(ip[2] == 0xd);
REQUIRE(ip[3] == 0xb8);
REQUIRE(ip[4] == 1);
REQUIRE(ip[5] == 2);
REQUIRE(ip[6] == 3);
REQUIRE(ip[7] == 4);
REQUIRE(ip[8] == 5);
REQUIRE(ip[9] == 6);
REQUIRE(ip[10] == 7);
REQUIRE(ip[11] == 8);
REQUIRE(ip[12] == 9);
REQUIRE(ip[13] == 0xa);
REQUIRE(ip[14] == 0xb);
REQUIRE(ip[15] == 0xc);
}
TEST_CASE ("Testing IPAddress(type, a *) constructor", "[IPAddress6-Ctor-03]")
{
uint8_t const ip_addr_array[] = {0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc};
arduino::IPAddress ip(arduino::IPType::IPv6, ip_addr_array);
REQUIRE(ip.type() == arduino::IPType::IPv6);
REQUIRE(ip[0] == 0x20);
REQUIRE(ip[1] == 0x01);
REQUIRE(ip[2] == 0xd);
REQUIRE(ip[3] == 0xb8);
REQUIRE(ip[4] == 1);
REQUIRE(ip[5] == 2);
REQUIRE(ip[6] == 3);
REQUIRE(ip[7] == 4);
REQUIRE(ip[8] == 5);
REQUIRE(ip[9] == 6);
REQUIRE(ip[10] == 7);
REQUIRE(ip[11] == 8);
REQUIRE(ip[12] == 9);
REQUIRE(ip[13] == 0xa);
REQUIRE(ip[14] == 0xb);
REQUIRE(ip[15] == 0xc);
}