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

38 lines
892 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>
using namespace Catch::Matchers;
TEST_CASE("JsonObject::get()") {
DynamicJsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
2018-11-13 14:50:48 +00:00
SECTION("get<const char*>(const char*)") {
2018-11-03 20:21:33 +00:00
obj.set("hello", "world");
const char* value = obj.get<const char*>("hello");
REQUIRE_THAT(value, Equals("world"));
}
2018-11-13 14:50:48 +00: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
SECTION("works on JsonObjectConst") {
obj.set("hello", "world");
const char* value =
static_cast<JsonObjectConst>(obj).get<const char*>("hello");
REQUIRE_THAT(value, Equals("world"));
}
2018-11-03 20:21:33 +00:00
}