issue1120.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <ArduinoJson.h>
  2. #include <catch.hpp>
  3. TEST_CASE("Issue #1120") {
  4. StaticJsonDocument<500> doc;
  5. constexpr char str[] =
  6. "{\"contents\":[{\"module\":\"Packet\"},{\"module\":\"Analog\"}]}";
  7. deserializeJson(doc, str);
  8. SECTION("MemberProxy<std::string>::isNull()") {
  9. SECTION("returns false") {
  10. auto value = doc[std::string("contents")];
  11. CHECK(value.isNull() == false);
  12. }
  13. SECTION("returns true") {
  14. auto value = doc[std::string("zontents")];
  15. CHECK(value.isNull() == true);
  16. }
  17. }
  18. SECTION("ElementProxy<MemberProxy<const char*> >::isNull()") {
  19. SECTION("returns false") { // Issue #1120
  20. auto value = doc["contents"][1];
  21. CHECK(value.isNull() == false);
  22. }
  23. SECTION("returns true") {
  24. auto value = doc["contents"][2];
  25. CHECK(value.isNull() == true);
  26. }
  27. }
  28. SECTION("MemberProxy<ElementProxy<MemberProxy>, const char*>::isNull()") {
  29. SECTION("returns false") {
  30. auto value = doc["contents"][1]["module"];
  31. CHECK(value.isNull() == false);
  32. }
  33. SECTION("returns true") {
  34. auto value = doc["contents"][1]["zodule"];
  35. CHECK(value.isNull() == true);
  36. }
  37. }
  38. SECTION("MemberProxy<ElementProxy<MemberProxy>, std::string>::isNull()") {
  39. SECTION("returns false") {
  40. auto value = doc["contents"][1][std::string("module")];
  41. CHECK(value.isNull() == false);
  42. }
  43. SECTION("returns true") {
  44. auto value = doc["contents"][1][std::string("zodule")];
  45. CHECK(value.isNull() == true);
  46. }
  47. }
  48. }