containsKey.cpp 765 B

123456789101112131415161718192021222324252627282930313233343536
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonObject::containsKey()") {
  7. DynamicJsonDocument doc;
  8. JsonObject obj = doc.to<JsonObject>();
  9. obj.set("hello", 42);
  10. SECTION("returns false if key not present") {
  11. REQUIRE(false == obj.containsKey("world"));
  12. }
  13. SECTION("returns true if key present") {
  14. REQUIRE(true == obj.containsKey("hello"));
  15. }
  16. SECTION("returns false after remove()") {
  17. obj.remove("hello");
  18. REQUIRE(false == obj.containsKey("hello"));
  19. }
  20. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  21. SECTION("key is a VLA") {
  22. int i = 16;
  23. char vla[i];
  24. strcpy(vla, "hello");
  25. REQUIRE(true == obj.containsKey(vla));
  26. }
  27. #endif
  28. }