forked from bblanchon/ArduinoJson
Add a stub for StaticJsonDocument
This commit is contained in:
@ -12,6 +12,7 @@ link_libraries(ArduinoJson catch)
|
|||||||
include_directories(Helpers)
|
include_directories(Helpers)
|
||||||
add_subdirectory(Cpp17)
|
add_subdirectory(Cpp17)
|
||||||
add_subdirectory(Cpp20)
|
add_subdirectory(Cpp20)
|
||||||
|
add_subdirectory(Deprecated)
|
||||||
add_subdirectory(FailingBuilds)
|
add_subdirectory(FailingBuilds)
|
||||||
add_subdirectory(IntegrationTests)
|
add_subdirectory(IntegrationTests)
|
||||||
add_subdirectory(JsonArray)
|
add_subdirectory(JsonArray)
|
||||||
|
26
extras/tests/Deprecated/CMakeLists.txt
Normal file
26
extras/tests/Deprecated/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# ArduinoJson - https://arduinojson.org
|
||||||
|
# Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||||
|
add_compile_options(
|
||||||
|
-Wno-deprecated-declarations
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
add_compile_options(
|
||||||
|
/wd4996
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(DeprecatedTests
|
||||||
|
StaticJsonDocument.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(Deprecated DeprecatedTests)
|
||||||
|
|
||||||
|
set_tests_properties(Deprecated
|
||||||
|
PROPERTIES
|
||||||
|
LABELS "Catch"
|
||||||
|
)
|
32
extras/tests/Deprecated/StaticJsonDocument.cpp
Normal file
32
extras/tests/Deprecated/StaticJsonDocument.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// ArduinoJson - https://arduinojson.org
|
||||||
|
// Copyright © 2014-2023, Benoit BLANCHON
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
using ArduinoJson::detail::is_base_of;
|
||||||
|
|
||||||
|
TEST_CASE("StaticJsonDocument") {
|
||||||
|
SECTION("is a JsonDocument") {
|
||||||
|
REQUIRE(is_base_of<JsonDocument, StaticJsonDocument<256>>::value == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserialize / serialize") {
|
||||||
|
StaticJsonDocument<256> doc;
|
||||||
|
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||||
|
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("copy") {
|
||||||
|
StaticJsonDocument<256> doc;
|
||||||
|
doc["hello"] = "world";
|
||||||
|
auto copy = doc;
|
||||||
|
REQUIRE(copy.as<std::string>() == "{\"hello\":\"world\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("capacity") {
|
||||||
|
StaticJsonDocument<256> doc;
|
||||||
|
REQUIRE(doc.capacity() == 256);
|
||||||
|
}
|
||||||
|
}
|
@ -9,16 +9,32 @@
|
|||||||
# define FORCE_INLINE // __forceinline causes C4714 when returning std::string
|
# define FORCE_INLINE // __forceinline causes C4714 when returning std::string
|
||||||
# define NO_INLINE __declspec(noinline)
|
# define NO_INLINE __declspec(noinline)
|
||||||
|
|
||||||
|
# ifndef ARDUINOJSON_DEPRECATED
|
||||||
|
# define ARDUINOJSON_DEPRECATED(msg) __declspec(deprecated(msg))
|
||||||
|
# endif
|
||||||
|
|
||||||
#elif defined(__GNUC__) // GCC or Clang
|
#elif defined(__GNUC__) // GCC or Clang
|
||||||
|
|
||||||
# define FORCE_INLINE __attribute__((always_inline))
|
# define FORCE_INLINE __attribute__((always_inline))
|
||||||
# define NO_INLINE __attribute__((noinline))
|
# define NO_INLINE __attribute__((noinline))
|
||||||
|
|
||||||
|
# ifndef ARDUINOJSON_DEPRECATED
|
||||||
|
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
|
||||||
|
# define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated(msg)))
|
||||||
|
# else
|
||||||
|
# define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated))
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
#else // Other compilers
|
#else // Other compilers
|
||||||
|
|
||||||
# define FORCE_INLINE
|
# define FORCE_INLINE
|
||||||
# define NO_INLINE
|
# define NO_INLINE
|
||||||
|
|
||||||
|
# ifndef ARDUINOJSON_DEPRECATED
|
||||||
|
# define ARDUINOJSON_DEPRECATED(msg)
|
||||||
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__has_attribute)
|
#if defined(__has_attribute)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
//
|
//
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
#include <ArduinoJson/Namespace.hpp>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
|
|
||||||
#define ARDUINOJSON_PRAGMA(x) _Pragma(#x)
|
#define ARDUINOJSON_PRAGMA(x) _Pragma(#x)
|
||||||
@ -23,3 +25,21 @@
|
|||||||
#define ARDUINOJSON_NAMESPACE _Pragma ("GCC warning \"ARDUINOJSON_NAMESPACE is deprecated, use ArduinoJson instead\"") ArduinoJson
|
#define ARDUINOJSON_NAMESPACE _Pragma ("GCC warning \"ARDUINOJSON_NAMESPACE is deprecated, use ArduinoJson instead\"") ArduinoJson
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
|
||||||
|
|
||||||
|
// DEPRECATED: use JsonDocument instead
|
||||||
|
template <size_t N>
|
||||||
|
class ARDUINOJSON_DEPRECATED("use JsonDocument instead") StaticJsonDocument
|
||||||
|
: public JsonDocument {
|
||||||
|
public:
|
||||||
|
using JsonDocument::JsonDocument;
|
||||||
|
|
||||||
|
size_t capacity() const {
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||||
|
Reference in New Issue
Block a user