arduino/libraries/ArduinoJson/test/JsonObject/containsKey.cpp

40 lines
896 B
C++
Raw Normal View History

2018-11-03 20:21:33 +00:00
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2018
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonObject::containsKey()") {
DynamicJsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
2018-11-13 14:50:48 +00:00
obj.set("hello", 42);
2018-11-03 20:21:33 +00:00
2018-11-13 14:50:48 +00:00
SECTION("returns true only if key is present") {
2018-11-03 20:21:33 +00:00
REQUIRE(false == obj.containsKey("world"));
2018-11-13 14:50:48 +00:00
REQUIRE(true == obj.containsKey("hello"));
2018-11-03 20:21:33 +00:00
}
2018-11-13 14:50:48 +00:00
SECTION("works with JsonObjectConst") {
JsonObjectConst cobj = obj;
REQUIRE(false == cobj.containsKey("world"));
REQUIRE(true == cobj.containsKey("hello"));
2018-11-03 20:21:33 +00:00
}
2018-11-13 14:50:48 +00:00
SECTION("returns false after remove()") {
2018-11-03 20:21:33 +00:00
obj.remove("hello");
REQUIRE(false == obj.containsKey("hello"));
}
2018-11-13 14:50:48 +00:00
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("key is a VLA") {
int i = 16;
char vla[i];
strcpy(vla, "hello");
REQUIRE(true == obj.containsKey(vla));
}
#endif
2018-11-03 20:21:33 +00:00
}