diff --git a/extras/tests/MixedConfiguration/progmem_emulation.hpp b/extras/tests/Helpers/progmem_emulation.hpp similarity index 100% rename from extras/tests/MixedConfiguration/progmem_emulation.hpp rename to extras/tests/Helpers/progmem_emulation.hpp diff --git a/extras/tests/Misc/StringAdapters.cpp b/extras/tests/Misc/StringAdapters.cpp index ff4ee191..8e6fb6e5 100644 --- a/extras/tests/Misc/StringAdapters.cpp +++ b/extras/tests/Misc/StringAdapters.cpp @@ -2,9 +2,14 @@ // Copyright Benoit Blanchon 2014-2020 // MIT License -#include -#include #include "custom_string.hpp" +#include "progmem_emulation.hpp" + +#include +#include +#include + +#include using namespace ARDUINOJSON_NAMESPACE; @@ -17,6 +22,8 @@ TEST_CASE("ConstRamStringAdapter") { REQUIRE(adapter.equals(NULL)); REQUIRE_FALSE(adapter.equals("charlie")); + + REQUIRE(adapter.size() == 0); } SECTION("non-null") { @@ -29,6 +36,36 @@ TEST_CASE("ConstRamStringAdapter") { REQUIRE(adapter.equals("bravo")); REQUIRE_FALSE(adapter.equals("charlie")); + + REQUIRE(adapter.size() == 5); + } +} + +TEST_CASE("FlashStringAdapter") { + SECTION("null") { + FlashStringAdapter adapter(NULL); + + REQUIRE(adapter.compare("bravo") < 0); + REQUIRE(adapter.compare(NULL) == 0); + + REQUIRE(adapter.equals(NULL)); + REQUIRE_FALSE(adapter.equals("charlie")); + + REQUIRE(adapter.size() == 0); + } + + SECTION("non-null") { + FlashStringAdapter adapter = adaptString(F("bravo")); + + REQUIRE(adapter.compare(NULL) > 0); + REQUIRE(adapter.compare("alpha") > 0); + REQUIRE(adapter.compare("bravo") == 0); + REQUIRE(adapter.compare("charlie") < 0); + + REQUIRE(adapter.equals("bravo")); + REQUIRE_FALSE(adapter.equals("charlie")); + + REQUIRE(adapter.size() == 5); } } @@ -43,6 +80,8 @@ TEST_CASE("std::string") { REQUIRE(adapter.equals("bravo")); REQUIRE_FALSE(adapter.equals("charlie")); + + REQUIRE(adapter.size() == 5); } TEST_CASE("custom_string") { @@ -56,6 +95,8 @@ TEST_CASE("custom_string") { REQUIRE(adapter.equals("bravo")); REQUIRE_FALSE(adapter.equals("charlie")); + + REQUIRE(adapter.size() == 5); } TEST_CASE("IsString") { @@ -70,4 +111,8 @@ TEST_CASE("IsString") { SECTION("custom_string") { REQUIRE(IsString::value == true); } + + SECTION("const __FlashStringHelper*") { + REQUIRE(IsString::value == true); + } } diff --git a/extras/tests/Misc/custom_string.hpp b/extras/tests/Misc/custom_string.hpp index 2bbbd2f3..8ba892b0 100644 --- a/extras/tests/Misc/custom_string.hpp +++ b/extras/tests/Misc/custom_string.hpp @@ -6,8 +6,6 @@ #include -using namespace ARDUINOJSON_NAMESPACE; - struct custom_char_traits : std::char_traits {}; struct custom_allocator : std::allocator {}; typedef std::basic_string diff --git a/src/ArduinoJson/Polyfills/pgmspace.hpp b/src/ArduinoJson/Polyfills/pgmspace.hpp index 85997188..ffeffd18 100644 --- a/src/ArduinoJson/Polyfills/pgmspace.hpp +++ b/src/ArduinoJson/Polyfills/pgmspace.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include namespace ARDUINOJSON_NAMESPACE { // Wraps a const char* so that the our functions are picked only if the @@ -18,6 +19,7 @@ struct pgm_p { #ifndef strlen_P inline size_t strlen_P(ARDUINOJSON_NAMESPACE::pgm_p s) { const char* p = s.address; + ARDUINOJSON_ASSERT(p != NULL); while (pgm_read_byte(p)) p++; return size_t(p - s.address); } @@ -27,6 +29,8 @@ inline size_t strlen_P(ARDUINOJSON_NAMESPACE::pgm_p s) { inline int strncmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) { const char* s1 = a; const char* s2 = b.address; + ARDUINOJSON_ASSERT(s1 != NULL); + ARDUINOJSON_ASSERT(s2 != NULL); while (n-- > 0) { char c1 = *s1++; char c2 = static_cast(pgm_read_byte(s2++)); @@ -45,6 +49,8 @@ inline int strncmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) { inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) { const char* s1 = a; const char* s2 = b.address; + ARDUINOJSON_ASSERT(s1 != NULL); + ARDUINOJSON_ASSERT(s2 != NULL); for (;;) { char c1 = *s1++; char c2 = static_cast(pgm_read_byte(s2++)); @@ -62,6 +68,8 @@ inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) { inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) { uint8_t* d = reinterpret_cast(dst); const char* s = src.address; + ARDUINOJSON_ASSERT(d != NULL); + ARDUINOJSON_ASSERT(s != NULL); while (n-- > 0) { *d++ = pgm_read_byte(s++); } diff --git a/src/ArduinoJson/Polyfills/safe_strcmp.hpp b/src/ArduinoJson/Polyfills/safe_strcmp.hpp index 2c5f7d89..135f4957 100644 --- a/src/ArduinoJson/Polyfills/safe_strcmp.hpp +++ b/src/ArduinoJson/Polyfills/safe_strcmp.hpp @@ -6,6 +6,8 @@ #include +#include // int8_t + namespace ARDUINOJSON_NAMESPACE { inline int8_t safe_strcmp(const char* a, const char* b) { diff --git a/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp b/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp index ac7bbdc3..c2e39d84 100644 --- a/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp +++ b/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace ARDUINOJSON_NAMESPACE { diff --git a/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp b/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp index 407f584d..7cc95390 100644 --- a/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp +++ b/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp @@ -8,6 +8,7 @@ #include // strcmp #include +#include #include namespace ARDUINOJSON_NAMESPACE { diff --git a/src/ArduinoJson/Strings/FlashStringAdapter.hpp b/src/ArduinoJson/Strings/FlashStringAdapter.hpp index 328f040f..673a2b31 100644 --- a/src/ArduinoJson/Strings/FlashStringAdapter.hpp +++ b/src/ArduinoJson/Strings/FlashStringAdapter.hpp @@ -4,7 +4,9 @@ #pragma once +#include #include +#include #include namespace ARDUINOJSON_NAMESPACE { diff --git a/src/ArduinoJson/Strings/IsString.hpp b/src/ArduinoJson/Strings/IsString.hpp new file mode 100644 index 00000000..18cbea85 --- /dev/null +++ b/src/ArduinoJson/Strings/IsString.hpp @@ -0,0 +1,18 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { +template +struct IsString : false_type {}; + +template +struct IsString : IsString {}; + +template +struct IsString : IsString {}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Strings/RamStringAdapter.hpp b/src/ArduinoJson/Strings/RamStringAdapter.hpp index 05db2e84..9a80c0aa 100644 --- a/src/ArduinoJson/Strings/RamStringAdapter.hpp +++ b/src/ArduinoJson/Strings/RamStringAdapter.hpp @@ -4,7 +4,9 @@ #pragma once +#include #include +#include #include namespace ARDUINOJSON_NAMESPACE { diff --git a/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp b/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp index 41a6cf6d..2d77b390 100644 --- a/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp +++ b/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include namespace ARDUINOJSON_NAMESPACE { diff --git a/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp b/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp index 911f4af6..c54769fe 100644 --- a/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp +++ b/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include // strcmp diff --git a/src/ArduinoJson/Strings/StlStringAdapter.hpp b/src/ArduinoJson/Strings/StlStringAdapter.hpp index defec413..c5eef2be 100644 --- a/src/ArduinoJson/Strings/StlStringAdapter.hpp +++ b/src/ArduinoJson/Strings/StlStringAdapter.hpp @@ -4,7 +4,9 @@ #pragma once +#include #include +#include #include #include diff --git a/src/ArduinoJson/Strings/String.hpp b/src/ArduinoJson/Strings/String.hpp index 95e4f79a..c6f16baf 100644 --- a/src/ArduinoJson/Strings/String.hpp +++ b/src/ArduinoJson/Strings/String.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include namespace ARDUINOJSON_NAMESPACE { diff --git a/src/ArduinoJson/Strings/StringAdapters.hpp b/src/ArduinoJson/Strings/StringAdapters.hpp index db9f9e48..30b45d04 100644 --- a/src/ArduinoJson/Strings/StringAdapters.hpp +++ b/src/ArduinoJson/Strings/StringAdapters.hpp @@ -4,20 +4,6 @@ #pragma once -#include -#include - -namespace ARDUINOJSON_NAMESPACE { -template -struct IsString : false_type {}; - -template -struct IsString : IsString {}; - -template -struct IsString : IsString {}; -} // namespace ARDUINOJSON_NAMESPACE - #include #include #include