Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3119a9

Browse files
Use == for string comparison in tests
This replaces assertions that previously checked the return value ofstrcmp or compareTo, giving the testing framework a bit more informationon the actual comparison happening, so it can show the actual stringsit compares (instead of just the strcmp or compareTo return value).This changes errors like: REQUIRE( strcmp(str.c_str(), "ABC") == 0 ) with expansion: 220 == 0into: 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.cppNote that test_compareTo.cpp was excluded, since that actually needs totest compareTo.Additionally, two more lines were changed manually (one where theArduino string and cstr were reversed, one where compareTo needed toreturn 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 usein other tests.
1 parent1e5f7a3 commitb3119a9

File tree

10 files changed

+67
-67
lines changed

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
charconst CSTR[] ="Hello Arduino String Class";
2424
arduino::Stringstr(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::Stringstr1("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
#defineF(string_literal) (reinterpret_cast<const arduino::__FlashStringHelper *>(PSTR(string_literal)))
3939
arduino::Stringstr1(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
charconst ch ='A';
4646
arduino::Stringstr(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
unsignedcharconst val =1;
5353
arduino::Stringstr(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
intconst val = -1;
6060
arduino::Stringstr(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
unsignedintconst val =1;
6767
arduino::Stringstr(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
longconst val = -1;
7474
arduino::Stringstr(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
unsignedlongconst val =1;
8181
arduino::Stringstr(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::Stringstr(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::Stringstr(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::Stringstr(-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::Stringstr(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::Stringstr(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::Stringstr(-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::Stringstr("Hello");
136136
charconst ch ='!';
137137
arduino::Stringstr1(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::Stringstr("Hello");
144144
arduino::Stringstr1(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::Stringstr("Hello");
151151
arduino::Stringstr1("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::Stringstr("Hello");
159159
arduino::Stringstr1("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::Stringstr1("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::Stringstr1("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::Stringstr("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::Stringstr("Hello");
3636
charconst 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::Stringstr("Hello");
4444
unsignedcharconst 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::Stringstr("Hello");
5252
intconst 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::Stringstr("Hello");
6060
unsignedintconst 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::Stringstr("Hello");
6868
longconst 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::Stringstr("Hello");
7676
unsignedlongconst 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::Stringstr("Hello");
8484
floatconst 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::Stringstr("Hello");
9292
doubleconst 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
#defineF(string_literal) (reinterpret_cast<const arduino::__FlashStringHelper *>(PSTR(string_literal)))
101101
arduino::Stringstr1("Hello");
102102
REQUIRE(str1.concat(F(" Arduino")) ==1);
103-
REQUIRE(strcmp(str1.c_str(),"Hello Arduino") ==0);
103+
REQUIRE(str1 =="Hello Arduino");
104104
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp