diff --git a/api/String.cpp b/api/String.cpp index 37812418..6f14ae13 100644 --- a/api/String.cpp +++ b/api/String.cpp @@ -462,7 +462,7 @@ int String::compareTo(const String &s) const int String::compareTo(const char *cstr) const { if (!buffer || !cstr) { - if (cstr && !*cstr) return 0 - *(unsigned char *)cstr; + if (cstr && *cstr) return 0 - *(unsigned char *)cstr; if (buffer && len > 0) return *(unsigned char *)buffer; return 0; } diff --git a/test/src/String/StringPrinter.h b/test/src/String/StringPrinter.h new file mode 100644 index 00000000..f338a902 --- /dev/null +++ b/test/src/String/StringPrinter.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace Catch { + /** + * Template specialization that makes sure Catch can properly print + * Arduino Strings when used in comparisons directly. + * + * Note that without this, String objects are printed as 0 and 1, + * because they are implicitly convertible to StringIfHelperType, + * which is a dummy pointer. + */ + template<> + struct StringMaker { + static std::string convert(const arduino::String& str) { + if (str) + return ::Catch::Detail::stringify(std::string(str.c_str(), str.length())); + else + return "{invalid String}"; + } + }; +} // namespace Catch diff --git a/test/src/String/test_String.cpp b/test/src/String/test_String.cpp index 8ff44c0f..461f2d08 100644 --- a/test/src/String/test_String.cpp +++ b/test/src/String/test_String.cpp @@ -12,6 +12,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -20,14 +22,14 @@ TEST_CASE ("Testing String(const char *) constructor()", "[String-Ctor-01]") { char const CSTR[] = "Hello Arduino String Class"; arduino::String str(CSTR); - REQUIRE(strcmp(CSTR, str.c_str()) == 0); + REQUIRE(str == CSTR); } TEST_CASE ("Testing String(const String &) constructor()", "[String-Ctor-02]") { arduino::String str1("Hello Arduino String class"), str2(str1); - REQUIRE(strcmp(str1.c_str(), str2.c_str()) == 0); + REQUIRE(str1 == str2); } TEST_CASE ("Testing String(const __FlashStringHelper) constructor()", "[String-Ctor-03]") @@ -35,49 +37,49 @@ TEST_CASE ("Testing String(const __FlashStringHelper) constructor()", "[String-C #undef F #define F(string_literal) (reinterpret_cast(PSTR(string_literal))) arduino::String str1(F("Hello")); - REQUIRE(str1.compareTo("Hello") == 0); + REQUIRE(str1 == "Hello"); } TEST_CASE ("Testing String(char) constructor()", "[String-Ctor-04]") { char const ch = 'A'; arduino::String str(ch); - REQUIRE(strcmp(str.c_str(), "A") == 0); + REQUIRE(str == "A"); } TEST_CASE ("Testing String(unsigned char, unsigned char base = 10) constructor()", "[String-Ctor-05]") { unsigned char const val = 1; arduino::String str(val); - REQUIRE(strcmp(str.c_str(), "1") == 0); + REQUIRE(str == "1"); } TEST_CASE ("Testing String(int, unsigned char base = 10) constructor()", "[String-Ctor-06]") { int const val = -1; arduino::String str(val); - REQUIRE(strcmp(str.c_str(), "-1") == 0); + REQUIRE(str == "-1"); } TEST_CASE ("Testing String(unsigned int, unsigned char base = 10) constructor()", "[String-Ctor-07]") { unsigned int const val = 1; arduino::String str(val); - REQUIRE(strcmp(str.c_str(), "1") == 0); + REQUIRE(str == "1"); } TEST_CASE ("Testing String(long, unsigned char base = 10) constructor()", "[String-Ctor-08]") { long const val = -1; arduino::String str(val); - REQUIRE(strcmp(str.c_str(), "-1") == 0); + REQUIRE(str == "-1"); } TEST_CASE ("Testing String(unsigned long, unsigned char base = 10) constructor()", "[String-Ctor-09]") { unsigned long const val = 1; arduino::String str(val); - REQUIRE(strcmp(str.c_str(), "1") == 0); + REQUIRE(str == "1"); } TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-10]") @@ -85,17 +87,17 @@ TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor() WHEN ("String::String (some float value)") { arduino::String str(1.234f); - REQUIRE(strcmp(str.c_str(), "1.23") == 0); + REQUIRE(str == "1.23"); } WHEN ("String::String (FLT_MAX)") { arduino::String str(FLT_MAX); - REQUIRE(strcmp(str.c_str(), "340282346638528859811704183484516925440.00") == 0); + REQUIRE(str == "340282346638528859811704183484516925440.00"); } WHEN ("String::String (-FLT_MAX)") { arduino::String str(-FLT_MAX); - REQUIRE(strcmp(str.c_str(), "-340282346638528859811704183484516925440.00") == 0); + REQUIRE(str == "-340282346638528859811704183484516925440.00"); } } @@ -104,17 +106,17 @@ TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor( WHEN ("String::String (some double value)") { arduino::String str(5.678); - REQUIRE(strcmp(str.c_str(), "5.68") == 0); + REQUIRE(str == "5.68"); } WHEN ("String::String (DBL_MAX)") { arduino::String str(DBL_MAX); - REQUIRE(strcmp(str.c_str(), "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00") == 0); + REQUIRE(str == "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); } WHEN ("String::String (-DBL_MAX)") { arduino::String str(-DBL_MAX); - REQUIRE(strcmp(str.c_str(), "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00") == 0); + REQUIRE(str == "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); } } @@ -125,7 +127,7 @@ TEST_CASE ("Testing String(const __FlashStringHelper) constructor() with invalid char *buffer = NULL; arduino::String str1(F(buffer)); - REQUIRE(str1.compareTo("Hello") == 0); + REQUIRE_FALSE(str1); } TEST_CASE ("Testing String(StringSumHelper &&) constructor()", "[String-Ctor-13]") @@ -133,14 +135,14 @@ TEST_CASE ("Testing String(StringSumHelper &&) constructor()", "[String-Ctor-13] arduino::String str("Hello"); char const ch = '!'; arduino::String str1(static_cast(str+ch)); - REQUIRE(str1.compareTo("Hello!") == 0); + REQUIRE(str1 == "Hello!"); } TEST_CASE ("Testing String(String &&) constructor()", "[String-Ctor-14]") { arduino::String str("Hello"); arduino::String str1(static_cast(str)); - REQUIRE(str1.compareTo("Hello") == 0); + REQUIRE(str1 == "Hello"); } TEST_CASE ("Testing String(String &&) with move(String &rhs) from smaller to larger buffer", "[String-Ctor-15]") @@ -148,7 +150,7 @@ TEST_CASE ("Testing String(String &&) with move(String &rhs) from smaller to lar arduino::String str("Hello"); arduino::String str1("Arduino"); str1 = static_cast(str); - REQUIRE(str1.compareTo("Hello") == 0); + REQUIRE(str1 == "Hello"); } TEST_CASE ("Testing String(String &&) with move(String &rhs) from larger to smaller buffer", "[String-Ctor-16]") @@ -156,5 +158,5 @@ TEST_CASE ("Testing String(String &&) with move(String &rhs) from larger to smal arduino::String str("Hello"); arduino::String str1("Arduino"); str = static_cast(str1); - REQUIRE(str1.compareTo("Arduino") == 0); + REQUIRE(str == "Arduino"); } diff --git a/test/src/String/test_characterAccessFunc.cpp b/test/src/String/test_characterAccessFunc.cpp index 24b78d86..329cca43 100644 --- a/test/src/String/test_characterAccessFunc.cpp +++ b/test/src/String/test_characterAccessFunc.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -24,7 +26,7 @@ TEST_CASE ("Testing String::setCharAt(unsigned int, char )", "[String-setCharAt- { arduino::String str1("Hello"); str1.setCharAt(1, 'a'); - REQUIRE(str1.compareTo("Hallo") == 0); + REQUIRE(str1 == "Hallo"); } TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)", "[String-getBytes-02]") diff --git a/test/src/String/test_compareTo.cpp b/test/src/String/test_compareTo.cpp index cce07ec3..9aef1ee7 100644 --- a/test/src/String/test_compareTo.cpp +++ b/test/src/String/test_compareTo.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ diff --git a/test/src/String/test_comparisonFunc.cpp b/test/src/String/test_comparisonFunc.cpp index 281ba8d7..89a7f3be 100644 --- a/test/src/String/test_comparisonFunc.cpp +++ b/test/src/String/test_comparisonFunc.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -20,24 +22,72 @@ TEST_CASE ("Testing String::equals(const String &) with exit status PASS", "[Str REQUIRE(str1.equals(str2) == 1); } +TEST_CASE ("Testing String::operator==(const String &) with exit status PASS", "[String-equals-01]") +{ + arduino::String str1("Hello"), str2("Hello"); + REQUIRE(str1 == str2); +} + +TEST_CASE ("Testing String::operator!=(const String &) with exit status FAIL", "[String-equals-01]") +{ + arduino::String str1("Hello"), str2("Hello"); + REQUIRE_FALSE(str1 != str2); +} + TEST_CASE ("Testing String::equals(const String &) with exit status FAIL", "[String-equals-02]") { arduino::String str1("Hello"), str2("World"); REQUIRE(str1.equals(str2) == 0); } +TEST_CASE ("Testing String::operator==(const String &) with exit status FAIL", "[String-equals-02]") +{ + arduino::String str1("Hello"), str2("World"); + REQUIRE_FALSE(str1 == str2); +} + +TEST_CASE ("Testing String::operator !=(const String &) with exit status PASS", "[String-equals-02]") +{ + arduino::String str1("Hello"), str2("World"); + REQUIRE(str1 != str2); +} + TEST_CASE ("Testing String::equals(const char *) with exit status PASS", "[String-equals-03]") { arduino::String str1("Hello"); REQUIRE(str1.equals("Hello") == 1); } +TEST_CASE ("Testing String::operator ==(const char *) with exit status PASS", "[String-equals-03]") +{ + arduino::String str1("Hello"); + REQUIRE(str1 == "Hello"); +} + +TEST_CASE ("Testing String::operator !=(const char *) with exit status FAIL", "[String-equals-03]") +{ + arduino::String str1("Hello"); + REQUIRE_FALSE(str1 != "Hello"); +} + TEST_CASE ("Testing String::equals(const char *) with exit status FAIL", "[String-equals-04]") { arduino::String str1("Hello"); REQUIRE(str1.equals("World") == 0); } +TEST_CASE ("Testing String::operator ==(const char *) with exit status FAIL", "[String-equals-04]") +{ + arduino::String str1("Hello"); + REQUIRE_FALSE(str1 == "World"); +} + +TEST_CASE ("Testing String::operator !=(const char *) with exit status PASS", "[String-equals-04]") +{ + arduino::String str1("Hello"); + REQUIRE(str1 != "World"); +} + TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with NON-empty string", "[String-equalsIgnoreCase-05]") { arduino::String str1("Hello"), str2("Hello"); @@ -104,4 +154,4 @@ TEST_CASE ("Testing String::endsWith(const String &)", "[String-endsWith-10]") arduino::String str2("Helo"); REQUIRE(str1.endsWith(str2) == 0); } -} \ No newline at end of file +} diff --git a/test/src/String/test_concat.cpp b/test/src/String/test_concat.cpp index b3f48960..b7390b64 100644 --- a/test/src/String/test_concat.cpp +++ b/test/src/String/test_concat.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -18,14 +20,14 @@ TEST_CASE ("Testing String::concat(const String &)", "[String-concat-01]") { arduino::String str1("Hello "), str2("Arduino!"); REQUIRE(str1.concat(str2) == 1); - REQUIRE(strcmp(str1.c_str(), "Hello Arduino!") == 0); + REQUIRE(str1 == "Hello Arduino!"); } TEST_CASE ("Testing String::concat(const char *)", "[String-concat-02]") { arduino::String str("Hello "); REQUIRE(str.concat("Arduino!") == 1); - REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); + REQUIRE(str == "Hello Arduino!"); } TEST_CASE ("Testing String::concat(char)", "[String-concat-03]") @@ -33,7 +35,7 @@ TEST_CASE ("Testing String::concat(char)", "[String-concat-03]") arduino::String str("Hello "); char const c = 'A'; REQUIRE(str.concat(c) == 1); - REQUIRE(strcmp(str.c_str(), "Hello A") == 0); + REQUIRE(str == "Hello A"); } TEST_CASE ("Testing String::concat(unsigned char)", "[String-concat-04]") @@ -41,7 +43,7 @@ TEST_CASE ("Testing String::concat(unsigned char)", "[String-concat-04]") arduino::String str("Hello "); unsigned char const c = 'A'; REQUIRE(str.concat(c) == 1); - REQUIRE(strcmp(str.c_str(), "Hello 65") == 0); /* ASCII['A'] = 65 */ + REQUIRE(str == "Hello 65"); /* ASCII['A'] = 65 */ } TEST_CASE ("Testing String::concat(int)", "[String-concat-05]") @@ -49,7 +51,7 @@ TEST_CASE ("Testing String::concat(int)", "[String-concat-05]") arduino::String str("Hello "); int const num = -1; REQUIRE(str.concat(num) == 1); - REQUIRE(strcmp(str.c_str(), "Hello -1") == 0); + REQUIRE(str == "Hello -1"); } TEST_CASE ("Testing String::concat(unsigned int)", "[String-concat-06]") @@ -57,7 +59,7 @@ TEST_CASE ("Testing String::concat(unsigned int)", "[String-concat-06]") arduino::String str("Hello "); unsigned int const num = 1; REQUIRE(str.concat(num) == 1); - REQUIRE(strcmp(str.c_str(), "Hello 1") == 0); + REQUIRE(str == "Hello 1"); } TEST_CASE ("Testing String::concat(long)", "[String-concat-07]") @@ -65,7 +67,7 @@ TEST_CASE ("Testing String::concat(long)", "[String-concat-07]") arduino::String str("Hello "); long const num = -1; REQUIRE(str.concat(num) == 1); - REQUIRE(strcmp(str.c_str(), "Hello -1") == 0); + REQUIRE(str == "Hello -1"); } TEST_CASE ("Testing String::concat(unsigned long)", "[String-concat-08]") @@ -73,7 +75,7 @@ TEST_CASE ("Testing String::concat(unsigned long)", "[String-concat-08]") arduino::String str("Hello "); unsigned long const num = 1; REQUIRE(str.concat(num) == 1); - REQUIRE(strcmp(str.c_str(), "Hello 1") == 0); + REQUIRE(str == "Hello 1"); } TEST_CASE ("Testing String::concat(float)", "[String-concat-09]") @@ -81,7 +83,7 @@ TEST_CASE ("Testing String::concat(float)", "[String-concat-09]") arduino::String str("Hello "); float const num = 1.234f; REQUIRE(str.concat(num) == 1); - REQUIRE(strcmp(str.c_str(), "Hello 1.23") == 0); + REQUIRE(str == "Hello 1.23"); } TEST_CASE ("Testing String::concat(double)", "[String-concat-10]") @@ -89,7 +91,7 @@ TEST_CASE ("Testing String::concat(double)", "[String-concat-10]") arduino::String str("Hello "); double const num = 5.678; REQUIRE(str.concat(num) == 1); - REQUIRE(strcmp(str.c_str(), "Hello 5.68") == 0); + REQUIRE(str == "Hello 5.68"); } TEST_CASE ("Testing String::concat(const __FlashStringHelper *)", "[String-concat-11]") @@ -98,5 +100,5 @@ TEST_CASE ("Testing String::concat(const __FlashStringHelper *)", "[String-conca #define F(string_literal) (reinterpret_cast(PSTR(string_literal))) arduino::String str1("Hello"); REQUIRE(str1.concat(F(" Arduino")) == 1); - REQUIRE(strcmp(str1.c_str(), "Hello Arduino") == 0); -} \ No newline at end of file + REQUIRE(str1 == "Hello Arduino"); +} diff --git a/test/src/String/test_indexOf.cpp b/test/src/String/test_indexOf.cpp index c0c06d88..bcaf65ef 100644 --- a/test/src/String/test_indexOf.cpp +++ b/test/src/String/test_indexOf.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ diff --git a/test/src/String/test_lastIndexOf.cpp b/test/src/String/test_lastIndexOf.cpp index bee7276e..2ae95f54 100644 --- a/test/src/String/test_lastIndexOf.cpp +++ b/test/src/String/test_lastIndexOf.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ diff --git a/test/src/String/test_length.cpp b/test/src/String/test_length.cpp index 7cb493a9..3b47faed 100644 --- a/test/src/String/test_length.cpp +++ b/test/src/String/test_length.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ diff --git a/test/src/String/test_operators.cpp b/test/src/String/test_operators.cpp index f0851fbf..67cb39be 100644 --- a/test/src/String/test_operators.cpp +++ b/test/src/String/test_operators.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -19,14 +21,14 @@ TEST_CASE ("Testing String::operator + (const StringSumHelper, const String)", " arduino::String str1("Hello "); arduino::String str2("Arduino"); arduino::String str("Hello Arduino"); - REQUIRE(str.compareTo(str1+str2) == 0); + REQUIRE(str == str1+str2); } 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); + REQUIRE(str == str1+"Arduino"); } TEST_CASE ("Testing String::operator + (const StringSumHelper, char)", "[String-operator+-03]") @@ -34,7 +36,7 @@ TEST_CASE ("Testing String::operator + (const StringSumHelper, char)", "[String- arduino::String str1("Hello"); char ch='!'; arduino::String str("Hello!"); - REQUIRE(str.compareTo(str1+ch) == 0); + REQUIRE(str == str1+ch); } TEST_CASE ("Testing String::operator + (const StringSumHelper, unsigned char)", "[String-operator+-04]") @@ -42,14 +44,14 @@ TEST_CASE ("Testing String::operator + (const StringSumHelper, unsigned char)", arduino::String str1("Hello "); unsigned char ch='A'; arduino::String str("Hello 65"); /* ASCII['A'] = 65 */ - REQUIRE(str.compareTo(str1+ch) == 0); + REQUIRE(str == str1+ch); } 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); + REQUIRE(str == str1+1); } TEST_CASE ("Testing String::operator + (unsigned int)", "[String-operator+-06]") @@ -57,7 +59,7 @@ 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); + REQUIRE(str == str1+num); } TEST_CASE ("Testing String::operator + (long)", "[String-operator+-07]") @@ -65,7 +67,7 @@ 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); + REQUIRE(str == str1+num); } TEST_CASE ("Testing String::operator + (unsigned long)", "[String-operator+-08]") @@ -73,7 +75,7 @@ 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); + REQUIRE(str == str1+num); } TEST_CASE ("Testing String::operator + (float)", "[String-operator+-09]") @@ -81,7 +83,7 @@ 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); + REQUIRE(str == str1+num); } TEST_CASE ("Testing String::operator + (double)", "[String-operator+-10]") @@ -89,7 +91,7 @@ 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); + REQUIRE(str == str1+num); } TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String-operator+-11]") @@ -98,14 +100,14 @@ TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String- #define F(string_literal) (reinterpret_cast(PSTR(string_literal))) arduino::String str1("Hello "); arduino::String str("Hello Arduino"); - REQUIRE(str.compareTo(str1+F("Arduino")) == 0); + REQUIRE(str == str1+F("Arduino")); } 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); + REQUIRE(str == "Hello Arduino"); } TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of second string", "[String-operator+-13]") @@ -116,15 +118,23 @@ TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of arduino::String str2(buffer2); str1 = str2; - REQUIRE(str1.compareTo(str2) == 0); + REQUIRE(str1 == str2); +} + +TEST_CASE ("Testing & String::operator = (const char *) with NULL does not leave string unchanged", "[String-operator+-14]") +{ + char *buffer = NULL; + arduino::String str("Hello"); + str = buffer; + REQUIRE(str != "Hello"); } -TEST_CASE ("Testing & String::operator = (const char *)", "[String-operator+-14]") +TEST_CASE ("Testing & String::operator = (const char *) with NULL produces invalid string", "[String-operator+-14]") { char *buffer = NULL; arduino::String str("Hello"); str = buffer; - REQUIRE(str.compareTo("Hello") == 0); + REQUIRE_FALSE(str); } TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of first string", "[String-operator+-15]") @@ -135,7 +145,7 @@ TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of arduino::String str2("Hello"); str1 = str2; - REQUIRE(str1.compareTo(str2) == 0); + REQUIRE(str1 == str2); } TEST_CASE ("Testing & String::operator = (String &&)", "[String-operator+-16]") @@ -143,7 +153,7 @@ TEST_CASE ("Testing & String::operator = (String &&)", "[String-operator+-16]") arduino::String str("Hello"); arduino::String str1("Arduino"); str1 = static_cast(str); - REQUIRE(str1.compareTo("Hello") == 0); + REQUIRE(str1 == "Hello"); } TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operator+-17]") @@ -152,5 +162,5 @@ TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operato char const ch = '!'; arduino::String str1("Arduino"); str1 = static_cast(str+ch); - REQUIRE(str1.compareTo("Hello!") == 0); -} \ No newline at end of file + REQUIRE(str1 == "Hello!"); +} diff --git a/test/src/String/test_remove.cpp b/test/src/String/test_remove.cpp index e7f364c8..e8c19536 100644 --- a/test/src/String/test_remove.cpp +++ b/test/src/String/test_remove.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -25,14 +27,14 @@ TEST_CASE ("Testing String::remove(index) when index is > string length", "[Stri { arduino::String str("Hello Arduino!"); str.remove(100); - REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); + REQUIRE(str == "Hello Arduino!"); } TEST_CASE ("Testing String::remove(index) when index is < string length", "[String-remove-03]") { arduino::String str("Hello Arduino!"); str.remove(5); - REQUIRE(strcmp(str.c_str(), "Hello") == 0); + REQUIRE(str == "Hello"); } TEST_CASE ("Testing String::remove(index,count) when string is empty", "[String-remove-04]") @@ -46,19 +48,19 @@ TEST_CASE ("Testing String::remove(index,count) when index is > string length", { arduino::String str("Hello Arduino!"); str.remove(100, 10); - REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); + REQUIRE(str == "Hello Arduino!"); } TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is > remaining length", "[String-remove-06]") { arduino::String str("Hello Arduino!"); str.remove(5, 100); - REQUIRE(strcmp(str.c_str(), "Hello") == 0); + REQUIRE(str == "Hello"); } TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is < remaining length", "[String-remove-07]") { arduino::String str("Hello Arduino!"); str.remove(5, 1); - REQUIRE(strcmp(str.c_str(), "HelloArduino!") == 0); + REQUIRE(str == "HelloArduino!"); } diff --git a/test/src/String/test_replace.cpp b/test/src/String/test_replace.cpp index 72a5a495..62fd5e8f 100644 --- a/test/src/String/test_replace.cpp +++ b/test/src/String/test_replace.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -25,7 +27,7 @@ TEST_CASE ("Testing String::replace(char, char) when string contains elements != { arduino::String str("Hello Arduino!"); str.replace('Z', '0'); - REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); + REQUIRE(str == "Hello Arduino!"); } TEST_CASE ("Testing String::replace(char, char) when string contains elements = 'find'", "[String-replace-03]") @@ -34,33 +36,33 @@ TEST_CASE ("Testing String::replace(char, char) when string contains elements = str.replace('o', '0'); str.replace('e', '3'); str.replace('i', '1'); - REQUIRE(strcmp(str.c_str(), "H3ll0 Ardu1n0!") == 0); + REQUIRE(str == "H3ll0 Ardu1n0!"); } TEST_CASE ("Testing String::replace(String, String) when string does not constain subtr 'find'", "[String-replace-04]") { arduino::String str("Hello Arduino!"); str.replace(arduino::String("Zulu"), arduino::String("11")); - REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); + REQUIRE(str == "Hello Arduino!"); } TEST_CASE ("Testing String::replace(String, String) when string constains subtr 'find'", "[String-replace-05]") { arduino::String str("Hello Arduino!"); str.replace(arduino::String("ll"), arduino::String("11")); - REQUIRE(strcmp(str.c_str(), "He11o Arduino!") == 0); + REQUIRE(str == "He11o Arduino!"); } TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace'", "[String-replace-06]") { arduino::String str("Hello Arduino!"); str.replace(arduino::String("llo"), arduino::String("11")); - REQUIRE(strcmp(str.c_str(), "He11 Arduino!") == 0); + REQUIRE(str == "He11 Arduino!"); } TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace'", "[String-replace-07]") { arduino::String str("Hello Arduino!"); str.replace(arduino::String("ll"), arduino::String("111")); - REQUIRE(strcmp(str.c_str(), "He111o Arduino!") == 0); + REQUIRE(str == "He111o Arduino!"); } diff --git a/test/src/String/test_substring.cpp b/test/src/String/test_substring.cpp index 9a17abff..8fa43086 100644 --- a/test/src/String/test_substring.cpp +++ b/test/src/String/test_substring.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -26,13 +28,13 @@ TEST_CASE ("Testing String::substring(unsigned int, unsigned int)", "[String-sub { arduino::String str1("Hello"); arduino::String str2("ello"); - REQUIRE(str2.compareTo(str1.substring(1,9)) == 0); + REQUIRE(str2 == str1.substring(1,9)); } WHEN ("left higher than right") { arduino::String str1("Hello"); arduino::String str2("ello"); - REQUIRE(str2.compareTo(str1.substring(9,1)) == 0); + REQUIRE(str2 == str1.substring(9,1)); } -} \ No newline at end of file +} diff --git a/test/src/String/test_toDouble.cpp b/test/src/String/test_toDouble.cpp index e57b128e..246f25d4 100644 --- a/test/src/String/test_toDouble.cpp +++ b/test/src/String/test_toDouble.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ diff --git a/test/src/String/test_toFloat.cpp b/test/src/String/test_toFloat.cpp index b7ad7af3..afef02c5 100644 --- a/test/src/String/test_toFloat.cpp +++ b/test/src/String/test_toFloat.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ diff --git a/test/src/String/test_toInt.cpp b/test/src/String/test_toInt.cpp index 65c2404a..43397b76 100644 --- a/test/src/String/test_toInt.cpp +++ b/test/src/String/test_toInt.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ diff --git a/test/src/String/test_toLowerCase.cpp b/test/src/String/test_toLowerCase.cpp index 2508c3f8..1ff81e91 100644 --- a/test/src/String/test_toLowerCase.cpp +++ b/test/src/String/test_toLowerCase.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -18,5 +20,5 @@ TEST_CASE ("Testing String::toLowerCase", "[String-toLowerCase-01]") { arduino::String str("HELLO ARDUINO"); str.toLowerCase(); - REQUIRE(strcmp(str.c_str(), "hello arduino") == 0); + REQUIRE(str == "hello arduino"); } diff --git a/test/src/String/test_toUpperCase.cpp b/test/src/String/test_toUpperCase.cpp index 83121a40..b8ae6aaf 100644 --- a/test/src/String/test_toUpperCase.cpp +++ b/test/src/String/test_toUpperCase.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -18,5 +20,5 @@ TEST_CASE ("Testing String::toUpperCase", "[String-toUpperCase-01]") { arduino::String str("hello arduino"); str.toUpperCase(); - REQUIRE(strcmp(str.c_str(), "HELLO ARDUINO") == 0); + REQUIRE(str == "HELLO ARDUINO"); } diff --git a/test/src/String/test_trim.cpp b/test/src/String/test_trim.cpp index 114cf10b..0328e3fc 100644 --- a/test/src/String/test_trim.cpp +++ b/test/src/String/test_trim.cpp @@ -10,6 +10,8 @@ #include +#include "StringPrinter.h" + /************************************************************************************** * TEST CODE **************************************************************************************/ @@ -18,26 +20,26 @@ TEST_CASE ("Testing String::trim with space at the beginning", "[String-trim-01] { arduino::String str(" hello"); str.trim(); - REQUIRE(strcmp(str.c_str(), "hello") == 0); + REQUIRE(str == "hello"); } TEST_CASE ("Testing String::trim with space at the end", "[String-trim-02]") { arduino::String str("hello "); str.trim(); - REQUIRE(strcmp(str.c_str(), "hello") == 0); + REQUIRE(str == "hello"); } TEST_CASE ("Testing String::trim with space at both beginng and end", "[String-trim-03]") { arduino::String str(" hello "); str.trim(); - REQUIRE(strcmp(str.c_str(), "hello") == 0); + REQUIRE(str == "hello"); } TEST_CASE ("Testing String::trim with space in the middle", "[String-trim-04]") { arduino::String str("Hello Arduino!"); str.trim(); - REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); + REQUIRE(str == "Hello Arduino!"); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy