forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_compareTo.cpp
102 lines (82 loc) · 2.29 KB
/
test_compareTo.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
#include "StringPrinter.h"
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]")
{
WHEN ("Strings are equal")
{
arduino::String str1("Hello"), str2("Hello");
REQUIRE(str1.compareTo(str2) == 0);
}
WHEN ("str2 is empty")
{
arduino::String str1("Hello"), str2;
REQUIRE(str1.compareTo(str2) > 0);
}
WHEN ("str1 is empty")
{
arduino::String str1, str2("Hello");
REQUIRE(str1.compareTo(str2) < 0);
}
}
TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]")
{
WHEN ("Strings are equal")
{
arduino::String str("Hello");
REQUIRE(str.compareTo("Hello") == 0);
}
WHEN ("Passed string is empty")
{
arduino::String str("Hello");
REQUIRE(str.compareTo("") > 0);
}
WHEN ("Passed string is compared with empty string")
{
arduino::String str;
REQUIRE(str.compareTo("") == 0);
}
}
TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String-compareTo-03]")
{
WHEN ("First string has a valid buffer")
{
char *buffer = NULL;
arduino::String str("Hello");
REQUIRE(str.compareTo(buffer) != 0);
}
WHEN ("First string does NOT have a valid buffer")
{
char *buffer1 = NULL;
char *buffer2 = NULL;
arduino::String str(buffer1);
REQUIRE(str.compareTo(buffer2) == 0);
}
}
TEST_CASE ("Testing String::compareTo(const String &) with empty buffer", "[String-compareTo-04]")
{
WHEN ("First string has a valid buffer")
{
char *buffer = NULL;
arduino::String str1("Hello");
arduino::String str2(buffer);
REQUIRE(str1.compareTo(str2) != 0);
}
WHEN ("First string does NOT have a valid buffer")
{
char *buffer1 = NULL;
char *buffer2 = NULL;
arduino::String str1(buffer1);
arduino::String str2(buffer2);
REQUIRE(str1.compareTo(str2) == 0);
}
}