2017-11-07 20:42:50 +01:00
|
|
|
// ArduinoJson - arduinojson.org
|
2018-01-05 09:20:01 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2018
|
2016-11-06 17:48:32 +01:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
2017-04-18 18:22:24 +02:00
|
|
|
#include <catch.hpp>
|
2016-11-06 17:48:32 +01:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
using namespace Catch::Matchers;
|
2016-11-06 17:48:32 +01:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
TEST_CASE("JsonObject::get()") {
|
2018-04-17 21:27:45 +02:00
|
|
|
DynamicJsonDocument doc;
|
2018-07-02 09:35:21 +02:00
|
|
|
JsonObject obj = doc.to<JsonObject>();
|
2016-11-06 17:48:32 +01:00
|
|
|
|
2018-08-22 14:37:17 +02:00
|
|
|
SECTION("get<const char*>(const char*)") {
|
2017-04-18 18:22:24 +02:00
|
|
|
obj.set("hello", "world");
|
|
|
|
const char* value = obj.get<const char*>("hello");
|
|
|
|
REQUIRE_THAT(value, Equals("world"));
|
|
|
|
}
|
2018-08-22 14:37:17 +02:00
|
|
|
|
|
|
|
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
|
|
|
SECTION("get<const char*>(VLA)") {
|
|
|
|
obj.set("hello", "world");
|
|
|
|
int i = 16;
|
|
|
|
char vla[i];
|
|
|
|
strcpy(vla, "hello");
|
|
|
|
|
|
|
|
REQUIRE(std::string("world") == obj.get<char*>(vla));
|
|
|
|
}
|
|
|
|
#endif
|
2018-10-12 12:00:27 +02:00
|
|
|
|
|
|
|
SECTION("works on JsonObjectConst") {
|
|
|
|
obj.set("hello", "world");
|
|
|
|
const char* value =
|
|
|
|
static_cast<JsonObjectConst>(obj).get<const char*>("hello");
|
|
|
|
REQUIRE_THAT(value, Equals("world"));
|
|
|
|
}
|
2016-11-06 17:48:32 +01:00
|
|
|
}
|