forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_fromString.cpp
60 lines (47 loc) · 1.76 KB
/
test_fromString.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
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
#include <IPAddress.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Extract valid IP address 'fromString(const char *)'", "[IPAddress-fromString-01]")
{
arduino::IPAddress ip;
REQUIRE(ip.fromString("129.168.1.2") == true);
REQUIRE(ip[0] == 129);
REQUIRE(ip[1] == 168);
REQUIRE(ip[2] == 1);
REQUIRE(ip[3] == 2);
}
TEST_CASE ("Extract valid IP address 'fromString(const String &)'", "[IPAddress-fromString-02]")
{
arduino::IPAddress ip;
arduino::String const ip_addr_str("129.168.1.2");
REQUIRE(ip.fromString(ip_addr_str) == true);
REQUIRE(ip[0] == 129);
REQUIRE(ip[1] == 168);
REQUIRE(ip[2] == 1);
REQUIRE(ip[3] == 2);
}
TEST_CASE ("Extract invalid IP address 'fromString(const char *)'", "[IPAddress-fromString-03]")
{
arduino::IPAddress ip;
REQUIRE(ip.fromString("") == false);
REQUIRE(ip.fromString("1") == false);
REQUIRE(ip.fromString("1.") == false);
REQUIRE(ip.fromString("1.1") == false);
REQUIRE(ip.fromString("1.1.") == false);
REQUIRE(ip.fromString("1.1.1") == false);
REQUIRE(ip.fromString("1.1.1.") == false);
REQUIRE(ip.fromString("...") == false);
REQUIRE(ip.fromString("256.1.1.1") == false);
REQUIRE(ip.fromString("a.1.1.1") == false);
REQUIRE(ip.fromString("-.1.1.1") == false);
REQUIRE(ip.fromString("-1.1.1.1") == false);
}