misc.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2025, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include "Allocators.hpp"
  7. using ArduinoJson::detail::sizeofArray;
  8. TEST_CASE("deserializeJson() misc cases") {
  9. SpyingAllocator spy;
  10. JsonDocument doc(&spy);
  11. SECTION("null") {
  12. DeserializationError err = deserializeJson(doc, "null");
  13. REQUIRE(err == DeserializationError::Ok);
  14. REQUIRE(doc.is<float>() == false);
  15. }
  16. SECTION("true") {
  17. DeserializationError err = deserializeJson(doc, "true");
  18. REQUIRE(err == DeserializationError::Ok);
  19. REQUIRE(doc.is<bool>());
  20. REQUIRE(doc.as<bool>() == true);
  21. }
  22. SECTION("false") {
  23. DeserializationError err = deserializeJson(doc, "false");
  24. REQUIRE(err == DeserializationError::Ok);
  25. REQUIRE(doc.is<bool>());
  26. REQUIRE(doc.as<bool>() == false);
  27. }
  28. SECTION("Should clear the JsonVariant") {
  29. deserializeJson(doc, "[1,2,3]");
  30. spy.clearLog();
  31. deserializeJson(doc, "{}");
  32. REQUIRE(doc.is<JsonObject>());
  33. REQUIRE(spy.log() == AllocatorLog{
  34. Deallocate(sizeofArray(3)),
  35. });
  36. }
  37. }