forked from bblanchon/ArduinoJson
Add a stub for DynamicJsonDocument
This commit is contained in:
@ -15,6 +15,7 @@ if(MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(DeprecatedTests
|
add_executable(DeprecatedTests
|
||||||
|
DynamicJsonDocument.cpp
|
||||||
StaticJsonDocument.cpp
|
StaticJsonDocument.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
37
extras/tests/Deprecated/DynamicJsonDocument.cpp
Normal file
37
extras/tests/Deprecated/DynamicJsonDocument.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// 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("DynamicJsonDocument") {
|
||||||
|
SECTION("is a JsonDocument") {
|
||||||
|
REQUIRE(is_base_of<JsonDocument, DynamicJsonDocument>::value == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserialize / serialize") {
|
||||||
|
DynamicJsonDocument doc(256);
|
||||||
|
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||||
|
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("copy") {
|
||||||
|
DynamicJsonDocument doc(256);
|
||||||
|
doc["hello"] = "world";
|
||||||
|
auto copy = doc;
|
||||||
|
REQUIRE(copy.as<std::string>() == "{\"hello\":\"world\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("capacity") {
|
||||||
|
DynamicJsonDocument doc(256);
|
||||||
|
REQUIRE(doc.capacity() == 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("garbageCollect()") {
|
||||||
|
DynamicJsonDocument doc(256);
|
||||||
|
doc.garbageCollect();
|
||||||
|
}
|
||||||
|
}
|
@ -42,4 +42,20 @@ class ARDUINOJSON_DEPRECATED("use JsonDocument instead") StaticJsonDocument
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// DEPRECATED: use JsonDocument instead
|
||||||
|
class ARDUINOJSON_DEPRECATED("use JsonDocument instead") DynamicJsonDocument
|
||||||
|
: public JsonDocument {
|
||||||
|
public:
|
||||||
|
DynamicJsonDocument(size_t capacity) : _capacity(capacity) {}
|
||||||
|
|
||||||
|
size_t capacity() const {
|
||||||
|
return _capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void garbageCollect() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t _capacity;
|
||||||
|
};
|
||||||
|
|
||||||
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
ARDUINOJSON_END_PUBLIC_NAMESPACE
|
||||||
|
Reference in New Issue
Block a user