-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathtest_operators.cpp
156 lines (131 loc) · 4.49 KB
/
test_operators.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing String::operator + (const StringSumHelper, const String)", "[String-operator+-01]")
{
arduino::String str1("Hello ");
arduino::String str2("Arduino");
arduino::String str("Hello Arduino");
REQUIRE(str.compareTo(str1+str2) == 0);
}
TEST_CASE ("Testing String::operator + (const StringSumHelper, const char *)", "[String-operator+-02]")
{
arduino::String str1("Hello ");
arduino::String str("Hello Arduino");
REQUIRE(str.compareTo(str1+"Arduino") == 0);
}
TEST_CASE ("Testing String::operator + (const StringSumHelper, char)", "[String-operator+-03]")
{
arduino::String str1("Hello");
char ch='!';
arduino::String str("Hello!");
REQUIRE(str.compareTo(str1+ch) == 0);
}
TEST_CASE ("Testing String::operator + (const StringSumHelper, unsigned char)", "[String-operator+-04]")
{
arduino::String str1("Hello ");
unsigned char ch='A';
arduino::String str("Hello 65"); /* ASCII['A'] = 65 */
REQUIRE(str.compareTo(str1+ch) == 0);
}
TEST_CASE ("Testing String::operator + (const StringSumHelper, int)", "[String-operator+-05]")
{
arduino::String str1("Hello ");
arduino::String str("Hello 1");
REQUIRE(str.compareTo(str1+1) == 0);
}
TEST_CASE ("Testing String::operator + (unsigned int)", "[String-operator+-06]")
{
arduino::String str1("Hello ");
unsigned int const num = 1;
arduino::String str("Hello 1");
REQUIRE(str.compareTo(str1+num) == 0);
}
TEST_CASE ("Testing String::operator + (long)", "[String-operator+-07]")
{
arduino::String str1("Hello ");
long const num = -1;
arduino::String str("Hello -1");
REQUIRE(str.compareTo(str1+num) == 0);
}
TEST_CASE ("Testing String::operator + (unsigned long)", "[String-operator+-08]")
{
arduino::String str1("Hello ");
unsigned long const num = 1;
arduino::String str("Hello 1");
REQUIRE(str.compareTo(str1+num) == 0);
}
TEST_CASE ("Testing String::operator + (float)", "[String-operator+-09]")
{
arduino::String str1("Hello ");
float const num = 1.234f;
arduino::String str("Hello 1.23");
REQUIRE(str.compareTo(str1+num) == 0);
}
TEST_CASE ("Testing String::operator + (double)", "[String-operator+-10]")
{
arduino::String str1("Hello ");
double const num = 5.678;
arduino::String str("Hello 5.68");
REQUIRE(str.compareTo(str1+num) == 0);
}
TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String-operator+-11]")
{
#undef F
#define F(string_literal) (reinterpret_cast<const arduino::__FlashStringHelper *>(PSTR(string_literal)))
arduino::String str1("Hello ");
arduino::String str("Hello Arduino");
REQUIRE(str.compareTo(str1+F("Arduino")) == 0);
}
TEST_CASE ("Testing & String::operator = (StringSumHelper &&rval)", "[String-operator+-12]")
{
arduino::String str1("Hello ");
arduino::String str = (str1+"Arduino");
REQUIRE(str.compareTo("Hello Arduino") == 0);
}
TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of second string", "[String-operator+-13]")
{
arduino::String str1("Hello");
char *buffer2 = NULL;
arduino::String str2(buffer2);
str1 = str2;
REQUIRE(str1.compareTo(str2) == 0);
}
TEST_CASE ("Testing & String::operator = (const char *)", "[String-operator+-14]")
{
char *buffer = NULL;
arduino::String str("Hello");
str = buffer;
REQUIRE(str.compareTo("Hello") == 0);
}
TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of first string", "[String-operator+-15]")
{
char *buffer1 = NULL;
arduino::String str1(buffer1);
arduino::String str2("Hello");
str1 = str2;
REQUIRE(str1.compareTo(str2) == 0);
}
TEST_CASE ("Testing & String::operator = (String &&)", "[String-operator+-16]")
{
arduino::String str("Hello");
arduino::String str1("Arduino");
str1 = static_cast<arduino::String&&>(str);
REQUIRE(str1.compareTo("Hello") == 0);
}
TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operator+-17]")
{
arduino::String str("Hello");
char const ch = '!';
arduino::String str1("Arduino");
str1 = static_cast<arduino::StringSumHelper&&>(str+ch);
REQUIRE(str1.compareTo("Hello!") == 0);
}