File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed
Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff 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_fromString.cpp
3132 src/IPAddress/test_IPAddress.cpp
3233 src/Print/test_clearWriteError.cpp
3334 src/Print/test_getWriteError.cpp
Original file line number Diff line number Diff line change 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 IP address 'fromString(const char *)'" , " [IPAddress-fromString-01]" )
19+ {
20+ arduino::IPAddress ip;
21+
22+ REQUIRE (ip.fromString (" 129.168.1.2" ) == true );
23+
24+ REQUIRE (ip[0 ] == 129 );
25+ REQUIRE (ip[1 ] == 168 );
26+ REQUIRE (ip[2 ] == 1 );
27+ REQUIRE (ip[3 ] == 2 );
28+ }
29+
30+ TEST_CASE (" Extract valid IP address 'fromString(const String &)'" , " [IPAddress-fromString-02]" )
31+ {
32+ arduino::IPAddress ip;
33+
34+ arduino::String const ip_addr_str (" 129.168.1.2" );
35+
36+ REQUIRE (ip.fromString (ip_addr_str) == true );
37+
38+ REQUIRE (ip[0 ] == 129 );
39+ REQUIRE (ip[1 ] == 168 );
40+ REQUIRE (ip[2 ] == 1 );
41+ REQUIRE (ip[3 ] == 2 );
42+ }
43+
44+
45+ TEST_CASE (" Extract invalid IP address 'fromString(const char *)'" , " [IPAddress-fromString-03]" )
46+ {
47+ arduino::IPAddress ip;
48+
49+ REQUIRE (ip.fromString (" " ) == false );
50+ REQUIRE (ip.fromString (" 1" ) == false );
51+ REQUIRE (ip.fromString (" 1." ) == false );
52+ REQUIRE (ip.fromString (" 1.1" ) == false );
53+ REQUIRE (ip.fromString (" 1.1." ) == false );
54+ REQUIRE (ip.fromString (" 1.1.1" ) == false );
55+ REQUIRE (ip.fromString (" 1.1.1." ) == false );
56+ REQUIRE (ip.fromString (" 256.1.1.1" ) == false );
57+ REQUIRE (ip.fromString (" a.1.1.1" ) == false );
58+ REQUIRE (ip.fromString (" -.1.1.1" ) == false );
59+ REQUIRE (ip.fromString (" -1.1.1.1" ) == false );
60+ }
You can’t perform that action at this time.
0 commit comments