Files

38 lines
898 B
C++
Raw Permalink Normal View History

2023-08-09 18:02:31 +02:00
// ArduinoJson - https://arduinojson.org
2025-02-24 15:18:26 +01:00
// Copyright © 2014-2025, Benoit BLANCHON
2023-08-09 18:02:31 +02:00
// MIT License
#include <ArduinoJson.h>
2026-07-06 15:12:32 +02:00
#include <doctest.h>
2023-08-09 18:02:31 +02:00
using ArduinoJson::detail::is_base_of;
TEST_CASE("DynamicJsonDocument") {
2026-07-06 15:12:32 +02:00
SUBCASE("is a JsonDocument") {
REQUIRE((is_base_of<JsonDocument, DynamicJsonDocument>::value == true));
2023-08-09 18:02:31 +02:00
}
2026-07-06 15:12:32 +02:00
SUBCASE("deserialize / serialize") {
2023-08-09 18:02:31 +02:00
DynamicJsonDocument doc(256);
deserializeJson(doc, "{\"hello\":\"world\"}");
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
}
2026-07-06 15:12:32 +02:00
SUBCASE("copy") {
2023-08-09 18:02:31 +02:00
DynamicJsonDocument doc(256);
doc["hello"] = "world";
auto copy = doc;
REQUIRE(copy.as<std::string>() == "{\"hello\":\"world\"}");
}
2026-07-06 15:12:32 +02:00
SUBCASE("capacity") {
2023-08-09 18:02:31 +02:00
DynamicJsonDocument doc(256);
REQUIRE(doc.capacity() == 256);
}
2026-07-06 15:12:32 +02:00
SUBCASE("garbageCollect()") {
2023-08-09 18:02:31 +02:00
DynamicJsonDocument doc(256);
doc.garbageCollect();
}
}