1212
1313#include < String.h>
1414
15+ #include " StringPrinter.h"
16+
1517/* *************************************************************************************
1618 * TEST CODE
1719 **************************************************************************************/
@@ -20,82 +22,82 @@ TEST_CASE ("Testing String(const char *) constructor()", "[String-Ctor-01]")
2022{
2123char const CSTR[] =" Hello Arduino String Class" ;
2224 arduino::Stringstr (CSTR);
23- REQUIRE (strcmp (CSTR, str. c_str ()) ==0 );
25+ REQUIRE (str ==CSTR );
2426}
2527
2628TEST_CASE (" Testing String(const String &) constructor()" ," [String-Ctor-02]" )
2729{
2830 arduino::Stringstr1 (" Hello Arduino String class" ),
2931str2 (str1);
30- REQUIRE (strcmp ( str1. c_str (), str2. c_str ()) ==0 );
32+ REQUIRE (str1 ==str2 );
3133}
3234
3335TEST_CASE (" Testing String(const __FlashStringHelper) constructor()" ," [String-Ctor-03]" )
3436{
3537#undef F
3638#define F (string_literal ) (reinterpret_cast <const arduino::__FlashStringHelper *>(PSTR(string_literal)))
3739 arduino::Stringstr1 (F (" Hello" ));
38- REQUIRE (str1. compareTo ( " Hello " ) ==0 );
40+ REQUIRE (str1 ==" Hello " );
3941}
4042
4143TEST_CASE (" Testing String(char) constructor()" ," [String-Ctor-04]" )
4244{
4345char const ch =' A' ;
4446 arduino::Stringstr (ch);
45- REQUIRE (strcmp ( str. c_str (), " A " ) ==0 );
47+ REQUIRE (str ==" A " );
4648}
4749
4850TEST_CASE (" Testing String(unsigned char, unsigned char base = 10) constructor()" ," [String-Ctor-05]" )
4951{
5052unsigned char const val =1 ;
5153 arduino::Stringstr (val);
52- REQUIRE (strcmp ( str. c_str (), " 1 " ) ==0 );
54+ REQUIRE (str ==" 1 " );
5355}
5456
5557TEST_CASE (" Testing String(int, unsigned char base = 10) constructor()" ," [String-Ctor-06]" )
5658{
5759int const val = -1 ;
5860 arduino::Stringstr (val);
59- REQUIRE (strcmp ( str. c_str (), " -1" ) == 0 );
61+ REQUIRE (str == " -1" );
6062}
6163
6264TEST_CASE (" Testing String(unsigned int, unsigned char base = 10) constructor()" ," [String-Ctor-07]" )
6365{
6466unsigned int const val =1 ;
6567 arduino::Stringstr (val);
66- REQUIRE (strcmp ( str. c_str (), " 1 " ) ==0 );
68+ REQUIRE (str ==" 1 " );
6769}
6870
6971TEST_CASE (" Testing String(long, unsigned char base = 10) constructor()" ," [String-Ctor-08]" )
7072{
7173long const val = -1 ;
7274 arduino::Stringstr (val);
73- REQUIRE (strcmp ( str. c_str (), " -1" ) == 0 );
75+ REQUIRE (str == " -1" );
7476}
7577
7678TEST_CASE (" Testing String(unsigned long, unsigned char base = 10) constructor()" ," [String-Ctor-09]" )
7779{
7880unsigned long const val =1 ;
7981 arduino::Stringstr (val);
80- REQUIRE (strcmp ( str. c_str (), " 1 " ) ==0 );
82+ REQUIRE (str ==" 1 " );
8183}
8284
8385TEST_CASE (" Testing String(float, unsigned char decimalPlaces = 2) constructor()" ," [String-Ctor-10]" )
8486{
8587WHEN (" String::String (some float value)" )
8688 {
8789 arduino::Stringstr (1 .234f );
88- REQUIRE (strcmp ( str. c_str (), " 1.23" ) == 0 );
90+ REQUIRE (str == " 1.23" );
8991 }
9092WHEN (" String::String (FLT_MAX)" )
9193 {
9294 arduino::Stringstr (FLT_MAX);
93- REQUIRE (strcmp ( str. c_str (), " 340282346638528859811704183484516925440.00" ) == 0 );
95+ REQUIRE (str == " 340282346638528859811704183484516925440.00" );
9496 }
9597WHEN (" String::String (-FLT_MAX)" )
9698 {
9799 arduino::Stringstr (-FLT_MAX);
98- REQUIRE (strcmp ( str. c_str (), " -340282346638528859811704183484516925440.00" ) == 0 );
100+ REQUIRE (str == " -340282346638528859811704183484516925440.00" );
99101 }
100102}
101103
@@ -104,17 +106,17 @@ TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor(
104106WHEN (" String::String (some double value)" )
105107 {
106108 arduino::Stringstr (5.678 );
107- REQUIRE (strcmp ( str. c_str (), " 5.68" ) == 0 );
109+ REQUIRE (str == " 5.68" );
108110 }
109111WHEN (" String::String (DBL_MAX)" )
110112 {
111113 arduino::Stringstr (DBL_MAX);
112- REQUIRE (strcmp ( str. c_str (), " 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00" ) == 0 );
114+ REQUIRE (str == " 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00" );
113115 }
114116WHEN (" String::String (-DBL_MAX)" )
115117 {
116118 arduino::Stringstr (-DBL_MAX);
117- REQUIRE (strcmp ( str. c_str (), " -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00" ) == 0 );
119+ REQUIRE (str == " -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00" );
118120 }
119121}
120122
@@ -125,36 +127,36 @@ TEST_CASE ("Testing String(const __FlashStringHelper) constructor() with invalid
125127char *buffer =NULL ;
126128
127129 arduino::Stringstr1 (F (buffer));
128- REQUIRE (str1. compareTo ( " Hello " ) == 0 );
130+ REQUIRE_FALSE (str1);
129131}
130132
131133TEST_CASE (" Testing String(StringSumHelper &&) constructor()" ," [String-Ctor-13]" )
132134{
133135 arduino::Stringstr (" Hello" );
134136char const ch =' !' ;
135137 arduino::Stringstr1 (static_cast <arduino::StringSumHelper&&>(str+ch));
136- REQUIRE (str1. compareTo ( " Hello! " ) ==0 );
138+ REQUIRE (str1 ==" Hello! " );
137139}
138140
139141TEST_CASE (" Testing String(String &&) constructor()" ," [String-Ctor-14]" )
140142{
141143 arduino::Stringstr (" Hello" );
142144 arduino::Stringstr1 (static_cast <arduino::String&&>(str));
143- REQUIRE (str1. compareTo ( " Hello " ) ==0 );
145+ REQUIRE (str1 ==" Hello " );
144146}
145147
146148TEST_CASE (" Testing String(String &&) with move(String &rhs) from smaller to larger buffer" ," [String-Ctor-15]" )
147149{
148150 arduino::Stringstr (" Hello" );
149151 arduino::Stringstr1 (" Arduino" );
150152 str1 =static_cast <arduino::String&&>(str);
151- REQUIRE (str1. compareTo ( " Hello " ) ==0 );
153+ REQUIRE (str1 ==" Hello " );
152154}
153155
154156TEST_CASE (" Testing String(String &&) with move(String &rhs) from larger to smaller buffer" ," [String-Ctor-16]" )
155157{
156158 arduino::Stringstr (" Hello" );
157159 arduino::Stringstr1 (" Arduino" );
158160 str =static_cast <arduino::String&&>(str1);
159- REQUIRE (str1. compareTo ( " Arduino " ) ==0 );
161+ REQUIRE (str ==" Arduino " );
160162}