Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b3119a9

Browse files
committedDec 31, 2020
Use == for string comparison in tests
This replaces assertions that previously checked the return value of strcmp or compareTo, giving the testing framework a bit more information on the actual comparison happening, so it can show the actual strings it compares (instead of just the strcmp or compareTo return value). This changes errors like: REQUIRE( strcmp(str.c_str(), "ABC") == 0 ) with expansion: 220 == 0 into: REQUIRE( str == "ABC" ); with expansion: "XYZ" equals: "ABC" These changes were done using the following commands: sed -i 's/REQUIRE(strcmp(\([^,]*\).c_str(), \([^,]*\).c_str()) == 0)/REQUIRE(\1 == \2)/g' * sed -i 's/REQUIRE(strcmp(\([^,]*\).c_str(), \([^,]*\)) == 0)/REQUIRE(\1 == \2)/g' * sed -i 's/REQUIRE(\([^.]*\).compareTo(\([^)]*\)) == 0)/REQUIRE(\1 == \2)/g' test_String.cpp test_characterAccessFunc.cpp test_operators.cpp test_substring.cpp Note that test_compareTo.cpp was excluded, since that actually needs to test compareTo. Additionally, two more lines were changed manually (one where the Arduino string and cstr were reversed, one where compareTo needed to return non-zero). Also note that this relies on the operator == defined by String itself, but since that is subject of its own tests, this should be ok to use in other tests.
1 parent 1e5f7a3 commit b3119a9

10 files changed

+67
-67
lines changed
 

‎test/src/String/test_String.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,82 +22,82 @@ TEST_CASE ("Testing String(const char *) constructor()", "[String-Ctor-01]")
2222
{
2323
char const CSTR[] = "Hello Arduino String Class";
2424
arduino::String str(CSTR);
25-
REQUIRE(strcmp(CSTR, str.c_str()) == 0);
25+
REQUIRE(str == CSTR);
2626
}
2727

2828
TEST_CASE ("Testing String(const String &) constructor()", "[String-Ctor-02]")
2929
{
3030
arduino::String str1("Hello Arduino String class"),
3131
str2(str1);
32-
REQUIRE(strcmp(str1.c_str(), str2.c_str()) == 0);
32+
REQUIRE(str1 == str2);
3333
}
3434

3535
TEST_CASE ("Testing String(const __FlashStringHelper) constructor()", "[String-Ctor-03]")
3636
{
3737
#undef F
3838
#define F(string_literal) (reinterpret_cast<const arduino::__FlashStringHelper *>(PSTR(string_literal)))
3939
arduino::String str1(F("Hello"));
40-
REQUIRE(str1.compareTo("Hello") == 0);
40+
REQUIRE(str1 == "Hello");
4141
}
4242

4343
TEST_CASE ("Testing String(char) constructor()", "[String-Ctor-04]")
4444
{
4545
char const ch = 'A';
4646
arduino::String str(ch);
47-
REQUIRE(strcmp(str.c_str(), "A") == 0);
47+
REQUIRE(str == "A");
4848
}
4949

5050
TEST_CASE ("Testing String(unsigned char, unsigned char base = 10) constructor()", "[String-Ctor-05]")
5151
{
5252
unsigned char const val = 1;
5353
arduino::String str(val);
54-
REQUIRE(strcmp(str.c_str(), "1") == 0);
54+
REQUIRE(str == "1");
5555
}
5656

5757
TEST_CASE ("Testing String(int, unsigned char base = 10) constructor()", "[String-Ctor-06]")
5858
{
5959
int const val = -1;
6060
arduino::String str(val);
61-
REQUIRE(strcmp(str.c_str(), "-1") == 0);
61+
REQUIRE(str == "-1");
6262
}
6363

6464
TEST_CASE ("Testing String(unsigned int, unsigned char base = 10) constructor()", "[String-Ctor-07]")
6565
{
6666
unsigned int const val = 1;
6767
arduino::String str(val);
68-
REQUIRE(strcmp(str.c_str(), "1") == 0);
68+
REQUIRE(str == "1");
6969
}
7070

7171
TEST_CASE ("Testing String(long, unsigned char base = 10) constructor()", "[String-Ctor-08]")
7272
{
7373
long const val = -1;
7474
arduino::String str(val);
75-
REQUIRE(strcmp(str.c_str(), "-1") == 0);
75+
REQUIRE(str == "-1");
7676
}
7777

7878
TEST_CASE ("Testing String(unsigned long, unsigned char base = 10) constructor()", "[String-Ctor-09]")
7979
{
8080
unsigned long const val = 1;
8181
arduino::String str(val);
82-
REQUIRE(strcmp(str.c_str(), "1") == 0);
82+
REQUIRE(str == "1");
8383
}
8484

8585
TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-10]")
8686
{
8787
WHEN ("String::String (some float value)")
8888
{
8989
arduino::String str(1.234f);
90-
REQUIRE(strcmp(str.c_str(), "1.23") == 0);
90+
REQUIRE(str == "1.23");
9191
}
9292
WHEN ("String::String (FLT_MAX)")
9393
{
9494
arduino::String str(FLT_MAX);
95-
REQUIRE(strcmp(str.c_str(), "340282346638528859811704183484516925440.00") == 0);
95+
REQUIRE(str == "340282346638528859811704183484516925440.00");
9696
}
9797
WHEN ("String::String (-FLT_MAX)")
9898
{
9999
arduino::String str(-FLT_MAX);
100-
REQUIRE(strcmp(str.c_str(), "-340282346638528859811704183484516925440.00") == 0);
100+
REQUIRE(str == "-340282346638528859811704183484516925440.00");
101101
}
102102
}
103103

@@ -106,17 +106,17 @@ TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor(
106106
WHEN ("String::String (some double value)")
107107
{
108108
arduino::String str(5.678);
109-
REQUIRE(strcmp(str.c_str(), "5.68") == 0);
109+
REQUIRE(str == "5.68");
110110
}
111111
WHEN ("String::String (DBL_MAX)")
112112
{
113113
arduino::String str(DBL_MAX);
114-
REQUIRE(strcmp(str.c_str(), "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00") == 0);
114+
REQUIRE(str == "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00");
115115
}
116116
WHEN ("String::String (-DBL_MAX)")
117117
{
118118
arduino::String str(-DBL_MAX);
119-
REQUIRE(strcmp(str.c_str(), "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00") == 0);
119+
REQUIRE(str == "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00");
120120
}
121121
}
122122

@@ -135,28 +135,28 @@ TEST_CASE ("Testing String(StringSumHelper &&) constructor()", "[String-Ctor-13]
135135
arduino::String str("Hello");
136136
char const ch = '!';
137137
arduino::String str1(static_cast<arduino::StringSumHelper&&>(str+ch));
138-
REQUIRE(str1.compareTo("Hello!") == 0);
138+
REQUIRE(str1 == "Hello!");
139139
}
140140

141141
TEST_CASE ("Testing String(String &&) constructor()", "[String-Ctor-14]")
142142
{
143143
arduino::String str("Hello");
144144
arduino::String str1(static_cast<arduino::String&&>(str));
145-
REQUIRE(str1.compareTo("Hello") == 0);
145+
REQUIRE(str1 == "Hello");
146146
}
147147

148148
TEST_CASE ("Testing String(String &&) with move(String &rhs) from smaller to larger buffer", "[String-Ctor-15]")
149149
{
150150
arduino::String str("Hello");
151151
arduino::String str1("Arduino");
152152
str1 = static_cast<arduino::String&&>(str);
153-
REQUIRE(str1.compareTo("Hello") == 0);
153+
REQUIRE(str1 == "Hello");
154154
}
155155

156156
TEST_CASE ("Testing String(String &&) with move(String &rhs) from larger to smaller buffer", "[String-Ctor-16]")
157157
{
158158
arduino::String str("Hello");
159159
arduino::String str1("Arduino");
160160
str = static_cast<arduino::String&&>(str1);
161-
REQUIRE(str.compareTo("Arduino") == 0);
161+
REQUIRE(str == "Arduino");
162162
}

‎test/src/String/test_characterAccessFunc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TEST_CASE ("Testing String::setCharAt(unsigned int, char )", "[String-setCharAt-
2626
{
2727
arduino::String str1("Hello");
2828
str1.setCharAt(1, 'a');
29-
REQUIRE(str1.compareTo("Hallo") == 0);
29+
REQUIRE(str1 == "Hallo");
3030
}
3131

3232
TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)", "[String-getBytes-02]")

‎test/src/String/test_concat.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,78 +20,78 @@ TEST_CASE ("Testing String::concat(const String &)", "[String-concat-01]")
2020
{
2121
arduino::String str1("Hello "), str2("Arduino!");
2222
REQUIRE(str1.concat(str2) == 1);
23-
REQUIRE(strcmp(str1.c_str(), "Hello Arduino!") == 0);
23+
REQUIRE(str1 == "Hello Arduino!");
2424
}
2525

2626
TEST_CASE ("Testing String::concat(const char *)", "[String-concat-02]")
2727
{
2828
arduino::String str("Hello ");
2929
REQUIRE(str.concat("Arduino!") == 1);
30-
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
30+
REQUIRE(str == "Hello Arduino!");
3131
}
3232

3333
TEST_CASE ("Testing String::concat(char)", "[String-concat-03]")
3434
{
3535
arduino::String str("Hello ");
3636
char const c = 'A';
3737
REQUIRE(str.concat(c) == 1);
38-
REQUIRE(strcmp(str.c_str(), "Hello A") == 0);
38+
REQUIRE(str == "Hello A");
3939
}
4040

4141
TEST_CASE ("Testing String::concat(unsigned char)", "[String-concat-04]")
4242
{
4343
arduino::String str("Hello ");
4444
unsigned char const c = 'A';
4545
REQUIRE(str.concat(c) == 1);
46-
REQUIRE(strcmp(str.c_str(), "Hello 65") == 0); /* ASCII['A'] = 65 */
46+
REQUIRE(str == "Hello 65"); /* ASCII['A'] = 65 */
4747
}
4848

4949
TEST_CASE ("Testing String::concat(int)", "[String-concat-05]")
5050
{
5151
arduino::String str("Hello ");
5252
int const num = -1;
5353
REQUIRE(str.concat(num) == 1);
54-
REQUIRE(strcmp(str.c_str(), "Hello -1") == 0);
54+
REQUIRE(str == "Hello -1");
5555
}
5656

5757
TEST_CASE ("Testing String::concat(unsigned int)", "[String-concat-06]")
5858
{
5959
arduino::String str("Hello ");
6060
unsigned int const num = 1;
6161
REQUIRE(str.concat(num) == 1);
62-
REQUIRE(strcmp(str.c_str(), "Hello 1") == 0);
62+
REQUIRE(str == "Hello 1");
6363
}
6464

6565
TEST_CASE ("Testing String::concat(long)", "[String-concat-07]")
6666
{
6767
arduino::String str("Hello ");
6868
long const num = -1;
6969
REQUIRE(str.concat(num) == 1);
70-
REQUIRE(strcmp(str.c_str(), "Hello -1") == 0);
70+
REQUIRE(str == "Hello -1");
7171
}
7272

7373
TEST_CASE ("Testing String::concat(unsigned long)", "[String-concat-08]")
7474
{
7575
arduino::String str("Hello ");
7676
unsigned long const num = 1;
7777
REQUIRE(str.concat(num) == 1);
78-
REQUIRE(strcmp(str.c_str(), "Hello 1") == 0);
78+
REQUIRE(str == "Hello 1");
7979
}
8080

8181
TEST_CASE ("Testing String::concat(float)", "[String-concat-09]")
8282
{
8383
arduino::String str("Hello ");
8484
float const num = 1.234f;
8585
REQUIRE(str.concat(num) == 1);
86-
REQUIRE(strcmp(str.c_str(), "Hello 1.23") == 0);
86+
REQUIRE(str == "Hello 1.23");
8787
}
8888

8989
TEST_CASE ("Testing String::concat(double)", "[String-concat-10]")
9090
{
9191
arduino::String str("Hello ");
9292
double const num = 5.678;
9393
REQUIRE(str.concat(num) == 1);
94-
REQUIRE(strcmp(str.c_str(), "Hello 5.68") == 0);
94+
REQUIRE(str == "Hello 5.68");
9595
}
9696

9797
TEST_CASE ("Testing String::concat(const __FlashStringHelper *)", "[String-concat-11]")
@@ -100,5 +100,5 @@ TEST_CASE ("Testing String::concat(const __FlashStringHelper *)", "[String-conca
100100
#define F(string_literal) (reinterpret_cast<const arduino::__FlashStringHelper *>(PSTR(string_literal)))
101101
arduino::String str1("Hello");
102102
REQUIRE(str1.concat(F(" Arduino")) == 1);
103-
REQUIRE(strcmp(str1.c_str(), "Hello Arduino") == 0);
103+
REQUIRE(str1 == "Hello Arduino");
104104
}

‎test/src/String/test_operators.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,77 +21,77 @@ TEST_CASE ("Testing String::operator + (const StringSumHelper, const String)", "
2121
arduino::String str1("Hello ");
2222
arduino::String str2("Arduino");
2323
arduino::String str("Hello Arduino");
24-
REQUIRE(str.compareTo(str1+str2) == 0);
24+
REQUIRE(str == str1+str2);
2525
}
2626

2727
TEST_CASE ("Testing String::operator + (const StringSumHelper, const char *)", "[String-operator+-02]")
2828
{
2929
arduino::String str1("Hello ");
3030
arduino::String str("Hello Arduino");
31-
REQUIRE(str.compareTo(str1+"Arduino") == 0);
31+
REQUIRE(str == str1+"Arduino");
3232
}
3333

3434
TEST_CASE ("Testing String::operator + (const StringSumHelper, char)", "[String-operator+-03]")
3535
{
3636
arduino::String str1("Hello");
3737
char ch='!';
3838
arduino::String str("Hello!");
39-
REQUIRE(str.compareTo(str1+ch) == 0);
39+
REQUIRE(str == str1+ch);
4040
}
4141

4242
TEST_CASE ("Testing String::operator + (const StringSumHelper, unsigned char)", "[String-operator+-04]")
4343
{
4444
arduino::String str1("Hello ");
4545
unsigned char ch='A';
4646
arduino::String str("Hello 65"); /* ASCII['A'] = 65 */
47-
REQUIRE(str.compareTo(str1+ch) == 0);
47+
REQUIRE(str == str1+ch);
4848
}
4949

5050
TEST_CASE ("Testing String::operator + (const StringSumHelper, int)", "[String-operator+-05]")
5151
{
5252
arduino::String str1("Hello ");
5353
arduino::String str("Hello 1");
54-
REQUIRE(str.compareTo(str1+1) == 0);
54+
REQUIRE(str == str1+1);
5555
}
5656

5757
TEST_CASE ("Testing String::operator + (unsigned int)", "[String-operator+-06]")
5858
{
5959
arduino::String str1("Hello ");
6060
unsigned int const num = 1;
6161
arduino::String str("Hello 1");
62-
REQUIRE(str.compareTo(str1+num) == 0);
62+
REQUIRE(str == str1+num);
6363
}
6464

6565
TEST_CASE ("Testing String::operator + (long)", "[String-operator+-07]")
6666
{
6767
arduino::String str1("Hello ");
6868
long const num = -1;
6969
arduino::String str("Hello -1");
70-
REQUIRE(str.compareTo(str1+num) == 0);
70+
REQUIRE(str == str1+num);
7171
}
7272

7373
TEST_CASE ("Testing String::operator + (unsigned long)", "[String-operator+-08]")
7474
{
7575
arduino::String str1("Hello ");
7676
unsigned long const num = 1;
7777
arduino::String str("Hello 1");
78-
REQUIRE(str.compareTo(str1+num) == 0);
78+
REQUIRE(str == str1+num);
7979
}
8080

8181
TEST_CASE ("Testing String::operator + (float)", "[String-operator+-09]")
8282
{
8383
arduino::String str1("Hello ");
8484
float const num = 1.234f;
8585
arduino::String str("Hello 1.23");
86-
REQUIRE(str.compareTo(str1+num) == 0);
86+
REQUIRE(str == str1+num);
8787
}
8888

8989
TEST_CASE ("Testing String::operator + (double)", "[String-operator+-10]")
9090
{
9191
arduino::String str1("Hello ");
9292
double const num = 5.678;
9393
arduino::String str("Hello 5.68");
94-
REQUIRE(str.compareTo(str1+num) == 0);
94+
REQUIRE(str == str1+num);
9595
}
9696

9797
TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String-operator+-11]")
@@ -100,14 +100,14 @@ TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String-
100100
#define F(string_literal) (reinterpret_cast<const arduino::__FlashStringHelper *>(PSTR(string_literal)))
101101
arduino::String str1("Hello ");
102102
arduino::String str("Hello Arduino");
103-
REQUIRE(str.compareTo(str1+F("Arduino")) == 0);
103+
REQUIRE(str == str1+F("Arduino"));
104104
}
105105

106106
TEST_CASE ("Testing & String::operator = (StringSumHelper &&rval)", "[String-operator+-12]")
107107
{
108108
arduino::String str1("Hello ");
109109
arduino::String str = (str1+"Arduino");
110-
REQUIRE(str.compareTo("Hello Arduino") == 0);
110+
REQUIRE(str == "Hello Arduino");
111111
}
112112

113113
TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of second string", "[String-operator+-13]")
@@ -118,7 +118,7 @@ TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of
118118
arduino::String str2(buffer2);
119119

120120
str1 = str2;
121-
REQUIRE(str1.compareTo(str2) == 0);
121+
REQUIRE(str1 == str2);
122122
}
123123

124124
TEST_CASE ("Testing & String::operator = (const char *)", "[String-operator+-14]")
@@ -127,7 +127,7 @@ TEST_CASE ("Testing & String::operator = (const char *)", "[String-operator+-14]
127127
arduino::String str("Hello");
128128
str = buffer;
129129
CHECK_FALSE(str);
130-
REQUIRE(str.compareTo("Hello") != 0);
130+
REQUIRE(str != "Hello");
131131
}
132132

133133
TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of first string", "[String-operator+-15]")
@@ -138,15 +138,15 @@ TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of
138138
arduino::String str2("Hello");
139139

140140
str1 = str2;
141-
REQUIRE(str1.compareTo(str2) == 0);
141+
REQUIRE(str1 == str2);
142142
}
143143

144144
TEST_CASE ("Testing & String::operator = (String &&)", "[String-operator+-16]")
145145
{
146146
arduino::String str("Hello");
147147
arduino::String str1("Arduino");
148148
str1 = static_cast<arduino::String&&>(str);
149-
REQUIRE(str1.compareTo("Hello") == 0);
149+
REQUIRE(str1 == "Hello");
150150
}
151151

152152
TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operator+-17]")
@@ -155,5 +155,5 @@ TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operato
155155
char const ch = '!';
156156
arduino::String str1("Arduino");
157157
str1 = static_cast<arduino::StringSumHelper&&>(str+ch);
158-
REQUIRE(str1.compareTo("Hello!") == 0);
158+
REQUIRE(str1 == "Hello!");
159159
}

‎test/src/String/test_remove.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ TEST_CASE ("Testing String::remove(index) when index is > string length", "[Stri
2727
{
2828
arduino::String str("Hello Arduino!");
2929
str.remove(100);
30-
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
30+
REQUIRE(str == "Hello Arduino!");
3131
}
3232

3333
TEST_CASE ("Testing String::remove(index) when index is < string length", "[String-remove-03]")
3434
{
3535
arduino::String str("Hello Arduino!");
3636
str.remove(5);
37-
REQUIRE(strcmp(str.c_str(), "Hello") == 0);
37+
REQUIRE(str == "Hello");
3838
}
3939

4040
TEST_CASE ("Testing String::remove(index,count) when string is empty", "[String-remove-04]")
@@ -48,19 +48,19 @@ TEST_CASE ("Testing String::remove(index,count) when index is > string length",
4848
{
4949
arduino::String str("Hello Arduino!");
5050
str.remove(100, 10);
51-
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
51+
REQUIRE(str == "Hello Arduino!");
5252
}
5353

5454
TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is > remaining length", "[String-remove-06]")
5555
{
5656
arduino::String str("Hello Arduino!");
5757
str.remove(5, 100);
58-
REQUIRE(strcmp(str.c_str(), "Hello") == 0);
58+
REQUIRE(str == "Hello");
5959
}
6060

6161
TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is < remaining length", "[String-remove-07]")
6262
{
6363
arduino::String str("Hello Arduino!");
6464
str.remove(5, 1);
65-
REQUIRE(strcmp(str.c_str(), "HelloArduino!") == 0);
65+
REQUIRE(str == "HelloArduino!");
6666
}

‎test/src/String/test_replace.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TEST_CASE ("Testing String::replace(char, char) when string contains elements !=
2727
{
2828
arduino::String str("Hello Arduino!");
2929
str.replace('Z', '0');
30-
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
30+
REQUIRE(str == "Hello Arduino!");
3131
}
3232

3333
TEST_CASE ("Testing String::replace(char, char) when string contains elements = 'find'", "[String-replace-03]")
@@ -36,33 +36,33 @@ TEST_CASE ("Testing String::replace(char, char) when string contains elements =
3636
str.replace('o', '0');
3737
str.replace('e', '3');
3838
str.replace('i', '1');
39-
REQUIRE(strcmp(str.c_str(), "H3ll0 Ardu1n0!") == 0);
39+
REQUIRE(str == "H3ll0 Ardu1n0!");
4040
}
4141

4242
TEST_CASE ("Testing String::replace(String, String) when string does not constain subtr 'find'", "[String-replace-04]")
4343
{
4444
arduino::String str("Hello Arduino!");
4545
str.replace(arduino::String("Zulu"), arduino::String("11"));
46-
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
46+
REQUIRE(str == "Hello Arduino!");
4747
}
4848

4949
TEST_CASE ("Testing String::replace(String, String) when string constains subtr 'find'", "[String-replace-05]")
5050
{
5151
arduino::String str("Hello Arduino!");
5252
str.replace(arduino::String("ll"), arduino::String("11"));
53-
REQUIRE(strcmp(str.c_str(), "He11o Arduino!") == 0);
53+
REQUIRE(str == "He11o Arduino!");
5454
}
5555

5656
TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace'", "[String-replace-06]")
5757
{
5858
arduino::String str("Hello Arduino!");
5959
str.replace(arduino::String("llo"), arduino::String("11"));
60-
REQUIRE(strcmp(str.c_str(), "He11 Arduino!") == 0);
60+
REQUIRE(str == "He11 Arduino!");
6161
}
6262

6363
TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace'", "[String-replace-07]")
6464
{
6565
arduino::String str("Hello Arduino!");
6666
str.replace(arduino::String("ll"), arduino::String("111"));
67-
REQUIRE(strcmp(str.c_str(), "He111o Arduino!") == 0);
67+
REQUIRE(str == "He111o Arduino!");
6868
}

‎test/src/String/test_substring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ TEST_CASE ("Testing String::substring(unsigned int, unsigned int)", "[String-sub
2828
{
2929
arduino::String str1("Hello");
3030
arduino::String str2("ello");
31-
REQUIRE(str2.compareTo(str1.substring(1,9)) == 0);
31+
REQUIRE(str2 == str1.substring(1,9));
3232
}
3333

3434
WHEN ("left higher than right")
3535
{
3636
arduino::String str1("Hello");
3737
arduino::String str2("ello");
38-
REQUIRE(str2.compareTo(str1.substring(9,1)) == 0);
38+
REQUIRE(str2 == str1.substring(9,1));
3939
}
4040
}

‎test/src/String/test_toLowerCase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ TEST_CASE ("Testing String::toLowerCase", "[String-toLowerCase-01]")
2020
{
2121
arduino::String str("HELLO ARDUINO");
2222
str.toLowerCase();
23-
REQUIRE(strcmp(str.c_str(), "hello arduino") == 0);
23+
REQUIRE(str == "hello arduino");
2424
}

‎test/src/String/test_toUpperCase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ TEST_CASE ("Testing String::toUpperCase", "[String-toUpperCase-01]")
2020
{
2121
arduino::String str("hello arduino");
2222
str.toUpperCase();
23-
REQUIRE(strcmp(str.c_str(), "HELLO ARDUINO") == 0);
23+
REQUIRE(str == "HELLO ARDUINO");
2424
}

‎test/src/String/test_trim.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ TEST_CASE ("Testing String::trim with space at the beginning", "[String-trim-01]
2020
{
2121
arduino::String str(" hello");
2222
str.trim();
23-
REQUIRE(strcmp(str.c_str(), "hello") == 0);
23+
REQUIRE(str == "hello");
2424
}
2525

2626
TEST_CASE ("Testing String::trim with space at the end", "[String-trim-02]")
2727
{
2828
arduino::String str("hello ");
2929
str.trim();
30-
REQUIRE(strcmp(str.c_str(), "hello") == 0);
30+
REQUIRE(str == "hello");
3131
}
3232

3333
TEST_CASE ("Testing String::trim with space at both beginng and end", "[String-trim-03]")
3434
{
3535
arduino::String str(" hello ");
3636
str.trim();
37-
REQUIRE(strcmp(str.c_str(), "hello") == 0);
37+
REQUIRE(str == "hello");
3838
}
3939

4040
TEST_CASE ("Testing String::trim with space in the middle", "[String-trim-04]")
4141
{
4242
arduino::String str("Hello Arduino!");
4343
str.trim();
44-
REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0);
44+
REQUIRE(str == "Hello Arduino!");
4545
}

0 commit comments

Comments
 (0)
Please sign in to comment.