Skip to content

Commit 3f868e7

Browse files
committed
Adding ests for all 'IPAddress' ctors
1 parent d1dda97 commit 3f868e7

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

test/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(TEST_SRCS
2828
src/Common/test_makeWord.cpp
2929
src/Common/test_max.cpp
3030
src/Common/test_min.cpp
31+
src/IPAddress/test_IPAddress.cpp
3132
src/Print/test_clearWriteError.cpp
3233
src/Print/test_getWriteError.cpp
3334
src/Print/test_print.cpp
@@ -50,6 +51,7 @@ set(TEST_SRCS
5051

5152
set(TEST_DUT_SRCS
5253
../api/Common.cpp
54+
../api/IPAddress.cpp
5355
../api/String.cpp
5456
../api/Print.cpp
5557
)

test/src/IPAddress/test_IPAddress.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <IPAddress.h>
12+
13+
/**************************************************************************************
14+
* TEST CODE
15+
**************************************************************************************/
16+
17+
TEST_CASE ("Testing IPAddress() default constructor()", "[IPAddress-Ctor-01]")
18+
{
19+
arduino::IPAddress ip;
20+
REQUIRE(ip[0] == 0);
21+
REQUIRE(ip[1] == 0);
22+
REQUIRE(ip[2] == 0);
23+
REQUIRE(ip[3] == 0);
24+
}
25+
26+
TEST_CASE ("Testing IPAddress(o,o,o,o) constructor", "[IPAddress-Ctor-02]")
27+
{
28+
arduino::IPAddress ip(129,168,1,2);
29+
REQUIRE(ip[0] == 129);
30+
REQUIRE(ip[1] == 168);
31+
REQUIRE(ip[2] == 1);
32+
REQUIRE(ip[3] == 2);
33+
}
34+
35+
TEST_CASE ("Testing IPAddress(a) constructor", "[IPAddress-Ctor-03]")
36+
{
37+
arduino::IPAddress ip(129 | (168 << 8) | (1 << 16) | (2 << 24));
38+
REQUIRE(ip[0] == 129);
39+
REQUIRE(ip[1] == 168);
40+
REQUIRE(ip[2] == 1);
41+
REQUIRE(ip[3] == 2);
42+
}
43+
44+
TEST_CASE ("Testing IPAddress(a *) constructor", "[IPAddress-Ctor-04]")
45+
{
46+
uint8_t const ip_addr_array[] = {129,168,1,2};
47+
48+
arduino::IPAddress ip(ip_addr_array);
49+
REQUIRE(ip[0] == 129);
50+
REQUIRE(ip[1] == 168);
51+
REQUIRE(ip[2] == 1);
52+
REQUIRE(ip[3] == 2);
53+
}

0 commit comments

Comments
 (0)