DynamicJsonDocument.cpp 896 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using ArduinoJson::detail::is_base_of;
  7. TEST_CASE("DynamicJsonDocument") {
  8. SECTION("is a JsonDocument") {
  9. REQUIRE(is_base_of<JsonDocument, DynamicJsonDocument>::value == true);
  10. }
  11. SECTION("deserialize / serialize") {
  12. DynamicJsonDocument doc(256);
  13. deserializeJson(doc, "{\"hello\":\"world\"}");
  14. REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
  15. }
  16. SECTION("copy") {
  17. DynamicJsonDocument doc(256);
  18. doc["hello"] = "world";
  19. auto copy = doc;
  20. REQUIRE(copy.as<std::string>() == "{\"hello\":\"world\"}");
  21. }
  22. SECTION("capacity") {
  23. DynamicJsonDocument doc(256);
  24. REQUIRE(doc.capacity() == 256);
  25. }
  26. SECTION("garbageCollect()") {
  27. DynamicJsonDocument doc(256);
  28. doc.garbageCollect();
  29. }
  30. }