containsKey.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <stdint.h>
  6. #include <catch.hpp>
  7. static const char* null = 0;
  8. TEST_CASE("JsonVariant::containsKey()") {
  9. DynamicJsonDocument doc(4096);
  10. JsonVariant var = doc.to<JsonVariant>();
  11. SECTION("containsKey(const char*)") {
  12. var["hello"] = "world";
  13. REQUIRE(var.containsKey("hello") == true);
  14. REQUIRE(var.containsKey("world") == false);
  15. }
  16. SECTION("containsKey(std::string)") {
  17. var["hello"] = "world";
  18. REQUIRE(var.containsKey(std::string("hello")) == true);
  19. REQUIRE(var.containsKey(std::string("world")) == false);
  20. }
  21. SECTION("linked object") {
  22. StaticJsonDocument<128> doc2;
  23. doc2["hello"] = "world";
  24. var.link(doc2);
  25. CHECK(var.containsKey("hello") == true);
  26. CHECK(var.containsKey("world") == false);
  27. }
  28. }
  29. TEST_CASE("JsonVariantConst::containsKey()") {
  30. DynamicJsonDocument doc(4096);
  31. doc["hello"] = "world";
  32. JsonVariantConst cvar = doc.as<JsonVariant>();
  33. SECTION("containsKey(const char*) returns true") {
  34. REQUIRE(cvar.containsKey("hello") == true);
  35. REQUIRE(cvar.containsKey("world") == false);
  36. }
  37. SECTION("containsKey(std::string) returns true") {
  38. REQUIRE(cvar.containsKey(std::string("hello")) == true);
  39. REQUIRE(cvar.containsKey(std::string("world")) == false);
  40. }
  41. }