1+ /*
2+ * Copyright (c) 2020 Arduino. All rights reserved.
3+ */
4+
5+ /* *************************************************************************************
6+ * INCLUDE
7+ **************************************************************************************/
8+
9+ #include < catch.hpp>
10+
11+ #include < String.h>
12+
13+ /* *************************************************************************************
14+ * TEST CODE
15+ **************************************************************************************/
16+
17+ TEST_CASE (" Testing String::operator + (const StringSumHelper, const String)" , " [String-operator+-01]" )
18+ {
19+ arduino::String str1 (" Hello " );
20+ arduino::String str2 (" Arduino" );
21+ arduino::String str (" Hello Arduino" );
22+ REQUIRE (str.compareTo (str1+str2) == 0 );
23+ }
24+
25+ TEST_CASE (" Testing String::operator + (const StringSumHelper, const char *)" , " [String-operator+-02]" )
26+ {
27+ arduino::String str1 (" Hello " );
28+ arduino::String str (" Hello Arduino" );
29+ REQUIRE (str.compareTo (str1+" Arduino" ) == 0 );
30+ }
31+
32+ TEST_CASE (" Testing String::operator + (const StringSumHelper, char)" , " [String-operator+-03]" )
33+ {
34+ arduino::String str1 (" Hello" );
35+ char ch=' !' ;
36+ arduino::String str (" Hello!" );
37+ REQUIRE (str.compareTo (str1+ch) == 0 );
38+ }
39+
40+ TEST_CASE (" Testing String::operator + (const StringSumHelper, unsigned char)" , " [String-operator+-04]" )
41+ {
42+ arduino::String str1 (" Hello " );
43+ unsigned char ch=' A' ;
44+ arduino::String str (" Hello 65" ); /* ASCII['A'] = 65 */
45+ REQUIRE (str.compareTo (str1+ch) == 0 );
46+ }
47+
48+ TEST_CASE (" Testing String::operator + (const StringSumHelper, int)" , " [String-operator+-05]" )
49+ {
50+ arduino::String str1 (" Hello " );
51+ arduino::String str (" Hello 1" );
52+ REQUIRE (str.compareTo (str1+1 ) == 0 );
53+ }
54+
55+ TEST_CASE (" Testing String::operator + (unsigned int)" , " [String-operator+-06]" )
56+ {
57+ arduino::String str1 (" Hello " );
58+ unsigned int const num = 1 ;
59+ arduino::String str (" Hello 1" );
60+ REQUIRE (str.compareTo (str1+num) == 0 );
61+ }
62+
63+ TEST_CASE (" Testing String::operator + (long)" , " [String-operator+-07]" )
64+ {
65+ arduino::String str1 (" Hello " );
66+ long const num = -1 ;
67+ arduino::String str (" Hello -1" );
68+ REQUIRE (str.compareTo (str1+num) == 0 );
69+ }
70+
71+ TEST_CASE (" Testing String::operator + (unsigned long)" , " [String-operator+-08]" )
72+ {
73+ arduino::String str1 (" Hello " );
74+ unsigned long const num = 1 ;
75+ arduino::String str (" Hello 1" );
76+ REQUIRE (str.compareTo (str1+num) == 0 );
77+ }
78+
79+ TEST_CASE (" Testing String::operator + (float)" , " [String-operator+-09]" )
80+ {
81+ arduino::String str1 (" Hello " );
82+ float const num = 1 .234f ;
83+ arduino::String str (" Hello 1.23" );
84+ REQUIRE (str.compareTo (str1+num) == 0 );
85+ }
86+
87+ TEST_CASE (" Testing String::operator + (double)" , " [String-operator+-10]" )
88+ {
89+ arduino::String str1 (" Hello " );
90+ double const num = 5.678 ;
91+ arduino::String str (" Hello 5.68" );
92+ REQUIRE (str.compareTo (str1+num) == 0 );
93+ }
94+
95+ TEST_CASE (" Testing String::operator + (const __FlashStringHelper *)" , " [String-operator+-11]" )
96+ {
97+ #undef F
98+ #define F (string_literal ) (reinterpret_cast <const arduino::__FlashStringHelper *>(PSTR(string_literal)))
99+ arduino::String str1 (" Hello " );
100+ arduino::String str (" Hello Arduino" );
101+ REQUIRE (str.compareTo (str1+F (" Arduino" )) == 0 );
102+ }
0 commit comments