Skip to content

Commit 1a4a7f8

Browse files
committed
Add testcases for IPAddress::toString()
1 parent 1b7ef0d commit 1a4a7f8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Diff for: test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(TEST_SRCS
2929
src/Common/test_map.cpp
3030
src/Common/test_max.cpp
3131
src/Common/test_min.cpp
32+
src/IPAddress/test_toString.cpp
3233
src/IPAddress/test_fromString.cpp
3334
src/IPAddress/test_fromString6.cpp
3435
src/IPAddress/test_IPAddress.cpp

Diff for: test/src/IPAddress/test_toString.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <String.h>
12+
#include <IPAddress.h>
13+
14+
/**************************************************************************************
15+
* TEST CODE
16+
**************************************************************************************/
17+
18+
TEST_CASE ("Extract valid string from IPv4address", "[IPAddress-toString-01]")
19+
{
20+
arduino::IPAddress ip(129,168,1,2);
21+
22+
REQUIRE(ip.toString().equals("129.168.1.2") == true);
23+
}
24+
25+
TEST_CASE ("Extract valid ipv6 string from IPv6address", "[IPAddress-toString-02]")
26+
{
27+
arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc);
28+
29+
REQUIRE(ip.toString().equals("2001:0db8:0102:0304:0506:0708:090a:0b0c") == true);
30+
}
31+
32+
TEST_CASE ("Extract 0.0.0.0 string from uninitialized IP address", "[IPAddress-toString-03]")
33+
{
34+
arduino::IPAddress ip;
35+
36+
REQUIRE(ip.toString().equals("0.0.0.0") == true);
37+
}

0 commit comments

Comments
 (0)