2017-11-07 20:42:50 +01:00
|
|
|
// ArduinoJson - arduinojson.org
|
2020-01-09 15:48:38 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2020
|
2015-09-28 22:14:50 +02:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
2017-04-18 18:22:24 +02:00
|
|
|
#include <catch.hpp>
|
2015-09-28 22:14:50 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
TEST_CASE("JsonObject::containsKey()") {
|
2019-01-14 10:32:19 +01:00
|
|
|
DynamicJsonDocument doc(4096);
|
2018-07-02 09:35:21 +02:00
|
|
|
JsonObject obj = doc.to<JsonObject>();
|
2018-10-18 14:51:02 +02:00
|
|
|
obj["hello"] = 42;
|
2015-09-28 22:14:50 +02:00
|
|
|
|
2018-10-12 12:00:27 +02:00
|
|
|
SECTION("returns true only if key is present") {
|
2018-04-17 21:27:45 +02:00
|
|
|
REQUIRE(false == obj.containsKey("world"));
|
2018-10-12 12:00:27 +02:00
|
|
|
REQUIRE(true == obj.containsKey("hello"));
|
2017-04-18 18:22:24 +02:00
|
|
|
}
|
2015-09-28 22:14:50 +02:00
|
|
|
|
2018-10-12 12:00:27 +02:00
|
|
|
SECTION("works with JsonObjectConst") {
|
|
|
|
JsonObjectConst cobj = obj;
|
|
|
|
REQUIRE(false == cobj.containsKey("world"));
|
|
|
|
REQUIRE(true == cobj.containsKey("hello"));
|
2017-04-18 18:22:24 +02:00
|
|
|
}
|
2015-09-28 22:14:50 +02:00
|
|
|
|
2018-08-22 14:37:17 +02:00
|
|
|
SECTION("returns false after remove()") {
|
2018-04-17 21:27:45 +02:00
|
|
|
obj.remove("hello");
|
2015-09-28 22:14:50 +02:00
|
|
|
|
2018-04-17 21:27:45 +02:00
|
|
|
REQUIRE(false == obj.containsKey("hello"));
|
2017-04-18 18:22:24 +02:00
|
|
|
}
|
2018-08-22 14:37:17 +02: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
|
2015-09-28 22:14:50 +02:00
|
|
|
}
|