forked from bblanchon/ArduinoJson
Removed JsonArray::is<T>(i)
and JsonArray::set(i,v)
Removed `JsonObject::is<T>(k)` and `JsonObject::set(k,v)` Replaced `T JsonArray::get<T>(i)` with `JsonVariant JsonArray::get(i)` Replaced `T JsonObject::get<T>(k)` with `JsonVariant JsonObject::get(k)`
This commit is contained in:
@ -11,7 +11,6 @@ add_executable(JsonArrayTests
|
||||
isNull.cpp
|
||||
iterator.cpp
|
||||
remove.cpp
|
||||
set.cpp
|
||||
size.cpp
|
||||
std_string.cpp
|
||||
subscript.cpp
|
||||
|
@ -1,115 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace Catch::Matchers;
|
||||
|
||||
TEST_CASE("JsonArray::set()") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
array.add(0);
|
||||
|
||||
SECTION("int") {
|
||||
array.set(0, 123);
|
||||
REQUIRE(123 == array[0].as<int>());
|
||||
REQUIRE(array[0].is<int>());
|
||||
REQUIRE_FALSE(array[0].is<bool>());
|
||||
}
|
||||
|
||||
SECTION("double") {
|
||||
array.set(0, 123.45);
|
||||
REQUIRE(123.45 == array[0].as<double>());
|
||||
REQUIRE(array[0].is<double>());
|
||||
REQUIRE_FALSE(array[0].is<int>());
|
||||
}
|
||||
|
||||
SECTION("bool") {
|
||||
array.set(0, true);
|
||||
REQUIRE(true == array[0].as<bool>());
|
||||
REQUIRE(array[0].is<bool>());
|
||||
REQUIRE_FALSE(array[0].is<int>());
|
||||
}
|
||||
|
||||
SECTION("const char*") {
|
||||
array.set(0, "hello");
|
||||
REQUIRE_THAT(array[0].as<const char*>(), Equals("hello"));
|
||||
REQUIRE(array[0].is<const char*>());
|
||||
REQUIRE_FALSE(array[0].is<int>());
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("set()") {
|
||||
int i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
array.add("hello");
|
||||
array.set(0, vla);
|
||||
|
||||
REQUIRE(std::string("world") == array[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("nested array") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
|
||||
array.set(0, arr);
|
||||
|
||||
REQUIRE(arr == array[0].as<JsonArray>());
|
||||
REQUIRE(array[0].is<JsonArray>());
|
||||
REQUIRE_FALSE(array[0].is<int>());
|
||||
}
|
||||
|
||||
SECTION("nested object") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject obj = doc2.to<JsonObject>();
|
||||
|
||||
array.set(0, obj);
|
||||
|
||||
REQUIRE(obj == array[0].as<JsonObject>());
|
||||
REQUIRE(array[0].is<JsonObject>());
|
||||
REQUIRE_FALSE(array[0].is<int>());
|
||||
}
|
||||
|
||||
SECTION("array subscript") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
arr.add("hello");
|
||||
|
||||
array.set(0, arr[0]);
|
||||
|
||||
REQUIRE_THAT(array[0].as<char*>(), Equals("hello"));
|
||||
}
|
||||
|
||||
SECTION("object subscript") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject obj = doc2.to<JsonObject>();
|
||||
obj["x"] = "hello";
|
||||
|
||||
array.set(0, obj["x"]);
|
||||
|
||||
REQUIRE_THAT(array[0].as<char*>(), Equals("hello"));
|
||||
}
|
||||
|
||||
SECTION("should not duplicate const char*") {
|
||||
array.set(0, "world");
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate char*") {
|
||||
array.set(0, const_cast<char*>("world"));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate std::string") {
|
||||
array.set(0, std::string("world"));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
}
|
@ -21,15 +21,7 @@ TEST_CASE("JsonArray::size()") {
|
||||
REQUIRE(2U == array.size());
|
||||
}
|
||||
|
||||
SECTION("remains the same after set()") {
|
||||
array.add("hello");
|
||||
REQUIRE(1U == array.size());
|
||||
|
||||
array.set(0, "hello");
|
||||
REQUIRE(1U == array.size());
|
||||
}
|
||||
|
||||
SECTION("remains the same after assigment") {
|
||||
SECTION("remains the same after replacing an element") {
|
||||
array.add("hello");
|
||||
REQUIRE(1U == array.size());
|
||||
|
||||
|
@ -21,14 +21,6 @@ TEST_CASE("std::string") {
|
||||
REQUIRE(std::string("hello") == array[0]);
|
||||
}
|
||||
|
||||
SECTION("set()") {
|
||||
std::string value("world");
|
||||
array.add("hello");
|
||||
array.set(0, value);
|
||||
eraseString(value);
|
||||
REQUIRE(std::string("world") == array[0]);
|
||||
}
|
||||
|
||||
SECTION("operator[]") {
|
||||
std::string value("world");
|
||||
array.add("hello");
|
||||
|
@ -8,13 +8,10 @@ add_executable(JsonObjectTests
|
||||
createNestedArray.cpp
|
||||
createNestedObject.cpp
|
||||
equals.cpp
|
||||
get.cpp
|
||||
invalid.cpp
|
||||
is.cpp
|
||||
isNull.cpp
|
||||
iterator.cpp
|
||||
remove.cpp
|
||||
set.cpp
|
||||
size.cpp
|
||||
std_string.cpp
|
||||
subscript.cpp
|
||||
|
@ -8,7 +8,7 @@
|
||||
TEST_CASE("JsonObject::containsKey()") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.set("hello", 42);
|
||||
obj["hello"] = 42;
|
||||
|
||||
SECTION("returns true only if key is present") {
|
||||
REQUIRE(false == obj.containsKey("world"));
|
||||
|
@ -1,37 +0,0 @@
|
||||
// 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>();
|
||||
|
||||
SECTION("get<const char*>(const char*)") {
|
||||
obj.set("hello", "world");
|
||||
const char* value = obj.get<const char*>("hello");
|
||||
REQUIRE_THAT(value, Equals("world"));
|
||||
}
|
||||
|
||||
#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"));
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ TEST_CASE("JsonObject::invalid()") {
|
||||
}
|
||||
|
||||
SECTION("AddFails") {
|
||||
obj.set("hello", "world");
|
||||
obj["hello"] = "world";
|
||||
REQUIRE(0 == obj.size());
|
||||
}
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonObject::is<T>()") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj["int"] = 42;
|
||||
obj["str"] = "hello";
|
||||
|
||||
SECTION("is<int>(const char*)") {
|
||||
REQUIRE(true == obj.is<int>("int"));
|
||||
REQUIRE(false == obj.is<int>("str"));
|
||||
}
|
||||
|
||||
#if HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("is<T>(VLA)") {
|
||||
int i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "int");
|
||||
|
||||
REQUIRE(true == obj.is<int>(vla));
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("JsonObject::set()") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
|
||||
SECTION("int") {
|
||||
obj.set("hello", 123);
|
||||
|
||||
REQUIRE(123 == obj["hello"].as<int>());
|
||||
REQUIRE(obj["hello"].is<int>());
|
||||
REQUIRE_FALSE(obj["hello"].is<bool>());
|
||||
}
|
||||
|
||||
SECTION("double") {
|
||||
obj.set("hello", 123.45);
|
||||
|
||||
REQUIRE(123.45 == obj["hello"].as<double>());
|
||||
REQUIRE(obj["hello"].is<double>());
|
||||
REQUIRE_FALSE(obj["hello"].is<bool>());
|
||||
}
|
||||
|
||||
SECTION("bool") {
|
||||
obj.set("hello", true);
|
||||
|
||||
REQUIRE(obj["hello"].as<bool>());
|
||||
REQUIRE(obj["hello"].is<bool>());
|
||||
REQUIRE_FALSE(obj["hello"].is<long>());
|
||||
}
|
||||
|
||||
SECTION("const char*") {
|
||||
obj.set("hello", "h3110");
|
||||
|
||||
REQUIRE(std::string("h3110") == obj["hello"].as<const char*>());
|
||||
REQUIRE(obj["hello"].is<const char*>());
|
||||
REQUIRE_FALSE(obj["hello"].is<long>());
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("key is a VLA") {
|
||||
int i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
obj.set(vla, "world");
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("value is a VLA") {
|
||||
int i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
obj.set("hello", vla);
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("key and value are VLAs") {
|
||||
int i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "world");
|
||||
|
||||
obj.set(vla, vla);
|
||||
|
||||
REQUIRE(std::string("world") == obj["world"]);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("nested array") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
|
||||
obj.set("hello", arr);
|
||||
|
||||
REQUIRE(arr == obj["hello"].as<JsonArray>());
|
||||
REQUIRE(obj["hello"].is<JsonArray>());
|
||||
REQUIRE_FALSE(obj["hello"].is<JsonObject>());
|
||||
}
|
||||
|
||||
SECTION("nested object") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
|
||||
obj.set("hello", obj2);
|
||||
|
||||
REQUIRE(obj2 == obj["hello"].as<JsonObject>());
|
||||
REQUIRE(obj["hello"].is<JsonObject>());
|
||||
REQUIRE_FALSE(obj["hello"].is<JsonArray>());
|
||||
}
|
||||
|
||||
SECTION("array subscript") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
arr.add(42);
|
||||
|
||||
obj.set("a", arr[0]);
|
||||
|
||||
REQUIRE(42 == obj["a"]);
|
||||
}
|
||||
|
||||
SECTION("object subscript") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
obj2.set("x", 42);
|
||||
|
||||
obj.set("a", obj2["x"]);
|
||||
|
||||
REQUIRE(42 == obj["a"]);
|
||||
}
|
||||
|
||||
SECTION("returns true when allocation succeeds") {
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(1) + 15> doc2;
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
|
||||
REQUIRE(true == obj2.set(std::string("hello"), std::string("world")));
|
||||
}
|
||||
|
||||
SECTION("returns false when allocation fails") {
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(1) + 10> doc2;
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
|
||||
REQUIRE(false == obj2.set(std::string("hello"), std::string("world")));
|
||||
}
|
||||
|
||||
SECTION("should not duplicate const char*") {
|
||||
obj.set("hello", "world");
|
||||
const size_t expectedSize = JSON_OBJECT_SIZE(1);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate char* value") {
|
||||
obj.set("hello", const_cast<char*>("world"));
|
||||
const size_t expectedSize = JSON_OBJECT_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate char* key") {
|
||||
obj.set(const_cast<char*>("hello"), "world");
|
||||
const size_t expectedSize = JSON_OBJECT_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate char* key&value") {
|
||||
obj.set(const_cast<char*>("hello"), const_cast<char*>("world"));
|
||||
const size_t expectedSize = JSON_OBJECT_SIZE(1) + 12;
|
||||
REQUIRE(expectedSize <= doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate std::string value") {
|
||||
obj.set("hello", std::string("world"));
|
||||
const size_t expectedSize = JSON_OBJECT_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate std::string key") {
|
||||
obj.set(std::string("hello"), "world");
|
||||
const size_t expectedSize = JSON_OBJECT_SIZE(1) + 6;
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate std::string key&value") {
|
||||
obj.set(std::string("hello"), std::string("world"));
|
||||
const size_t expectedSize = JSON_OBJECT_SIZE(1) + 12;
|
||||
REQUIRE(expectedSize <= doc.memoryUsage());
|
||||
}
|
||||
}
|
@ -15,12 +15,12 @@ TEST_CASE("JsonObject::size()") {
|
||||
}
|
||||
|
||||
SECTION("increases when values are added") {
|
||||
obj.set("hello", 42);
|
||||
obj["hello"] = 42;
|
||||
REQUIRE(1 == obj.size());
|
||||
}
|
||||
|
||||
SECTION("decreases when values are removed") {
|
||||
obj.set("hello", 42);
|
||||
obj["hello"] = 42;
|
||||
obj.remove("hello");
|
||||
REQUIRE(0 == obj.size());
|
||||
}
|
||||
|
@ -31,70 +31,6 @@ TEST_CASE("std::string") {
|
||||
REQUIRE(std::string("value") == obj[std::string("key")]);
|
||||
}
|
||||
|
||||
SECTION("set(key)") {
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
std::string key("hello");
|
||||
obj.set(key, "world");
|
||||
eraseString(key);
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set(value)") {
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
std::string value("world");
|
||||
obj.set("hello", value);
|
||||
eraseString(value);
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set(key,value)") {
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
std::string key("hello");
|
||||
std::string value("world");
|
||||
obj.set(key, value);
|
||||
eraseString(key);
|
||||
eraseString(value);
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set(JsonArraySubscript)") {
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
DynamicJsonDocument doc2;
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
arr.add("world");
|
||||
|
||||
obj.set(std::string("hello"), arr[0]);
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set(JsonObjectSubscript)") {
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
obj2.set("x", "world");
|
||||
|
||||
obj.set(std::string("hello"), obj2["x"]);
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("get<T>()") {
|
||||
char json[] = "{\"key\":\"value\"}";
|
||||
deserializeJson(doc, json);
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(std::string("value") == obj.get<const char *>(std::string("key")));
|
||||
}
|
||||
|
||||
SECTION("is<T>()") {
|
||||
char json[] = "{\"key\":\"value\"}";
|
||||
deserializeJson(doc, json);
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(true == obj.is<const char *>(std::string("key")));
|
||||
}
|
||||
|
||||
SECTION("createNestedObject()") {
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
std::string key = "key";
|
||||
|
@ -86,7 +86,7 @@ TEST_CASE("JsonObject::operator[]") {
|
||||
SECTION("object subscript") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
obj2.set("x", 42);
|
||||
obj2["x"] = 42;
|
||||
|
||||
obj["a"] = obj2["x"];
|
||||
|
||||
|
@ -26,7 +26,7 @@ TEST_CASE("serializeJson(JsonObject)") {
|
||||
|
||||
SECTION("TwoStrings") {
|
||||
obj["key1"] = "value1";
|
||||
obj.set("key2", "value2");
|
||||
obj["key2"] = "value2";
|
||||
|
||||
check(obj, "{\"key1\":\"value1\",\"key2\":\"value2\"}");
|
||||
}
|
||||
@ -64,31 +64,31 @@ TEST_CASE("serializeJson(JsonObject)") {
|
||||
|
||||
SECTION("TwoIntegers") {
|
||||
obj["a"] = 1;
|
||||
obj.set("b", 2);
|
||||
obj["b"] = 2;
|
||||
check(obj, "{\"a\":1,\"b\":2}");
|
||||
}
|
||||
|
||||
SECTION("serialized(const char*)") {
|
||||
obj["a"] = serialized("[1,2]");
|
||||
obj.set("b", serialized("[4,5]"));
|
||||
obj["b"] = serialized("[4,5]");
|
||||
check(obj, "{\"a\":[1,2],\"b\":[4,5]}");
|
||||
}
|
||||
|
||||
SECTION("Two doubles") {
|
||||
obj["a"] = 12.34;
|
||||
obj.set("b", 56.78);
|
||||
obj["b"] = 56.78;
|
||||
check(obj, "{\"a\":12.34,\"b\":56.78}");
|
||||
}
|
||||
|
||||
SECTION("TwoNull") {
|
||||
obj["a"] = static_cast<char *>(0);
|
||||
obj.set("b", static_cast<char *>(0));
|
||||
obj["b"] = static_cast<char *>(0);
|
||||
check(obj, "{\"a\":null,\"b\":null}");
|
||||
}
|
||||
|
||||
SECTION("TwoBooleans") {
|
||||
obj["a"] = true;
|
||||
obj.set("b", false);
|
||||
obj["b"] = false;
|
||||
check(obj, "{\"a\":true,\"b\":false}");
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ TEST_CASE("serializeJson(JsonObject)") {
|
||||
|
||||
obj.createNestedArray("a");
|
||||
obj["b"] = b.to<JsonArray>();
|
||||
obj.set("c", c.to<JsonArray>());
|
||||
obj["c"] = c.to<JsonArray>();
|
||||
|
||||
check(obj, "{\"a\":[],\"b\":[],\"c\":[]}");
|
||||
}
|
||||
@ -109,7 +109,7 @@ TEST_CASE("serializeJson(JsonObject)") {
|
||||
|
||||
obj.createNestedObject("a");
|
||||
obj["b"] = b.to<JsonObject>();
|
||||
obj.set("c", c.to<JsonObject>());
|
||||
obj["c"] = c.to<JsonObject>();
|
||||
|
||||
check(obj, "{\"a\":{},\"b\":{},\"c\":{}}");
|
||||
}
|
||||
|
@ -110,45 +110,6 @@ TEST_CASE("unsigned char[]") {
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("get()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc;
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
REQUIRE(std::string("world") == obj.get<char*>(key));
|
||||
}
|
||||
|
||||
SECTION("set() key") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.set(key, "world");
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set() value") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.set("hello", value);
|
||||
|
||||
REQUIRE(std::string("world") == obj["hello"]);
|
||||
}
|
||||
|
||||
SECTION("set() key&value") {
|
||||
unsigned char key[] = "world";
|
||||
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj.set(key, key);
|
||||
|
||||
REQUIRE(std::string("world") == obj["world"]);
|
||||
}
|
||||
|
||||
SECTION("containsKey()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
@ -169,16 +130,6 @@ TEST_CASE("unsigned char[]") {
|
||||
REQUIRE(0 == obj.size());
|
||||
}
|
||||
|
||||
SECTION("is()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
DynamicJsonDocument doc;
|
||||
deserializeJson(doc, "{\"hello\":42}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(true == obj.is<int>(key));
|
||||
}
|
||||
|
||||
SECTION("createNestedArray()") {
|
||||
unsigned char key[] = "hello";
|
||||
|
||||
@ -228,17 +179,6 @@ TEST_CASE("unsigned char[]") {
|
||||
|
||||
REQUIRE(std::string("world") == arr[0]);
|
||||
}
|
||||
|
||||
SECTION("set()") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonDocument doc;
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
arr.add("hello");
|
||||
arr.set(0, value);
|
||||
|
||||
REQUIRE(std::string("world") == arr[0]);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("JsonArraySubscript") {
|
||||
|
Reference in New Issue
Block a user