diff --git a/CHANGELOG.md b/CHANGELOG.md index f46577aa..b88a6d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Removed `JsonArray::is(i)` and `JsonArray::set(i,v)` +* Removed `JsonObject::is(k)` and `JsonObject::set(k,v)` +* Replaced `T JsonArray::get(i)` with `JsonVariant JsonArray::get(i)` +* Replaced `T JsonObject::get(k)` with `JsonVariant JsonObject::get(k)` + v6.5.0-beta (2018-10-13) ----------- diff --git a/src/ArduinoJson/JsonArray.hpp b/src/ArduinoJson/JsonArray.hpp index a4b73ea8..12a909ef 100644 --- a/src/ArduinoJson/JsonArray.hpp +++ b/src/ArduinoJson/JsonArray.hpp @@ -191,15 +191,8 @@ class JsonArray : public JsonArrayProxy, public Visitable { } // Gets the value at the specified index. - template - FORCE_INLINE typename JsonVariantAs::type get(size_t index) const { - return get_impl(index).as(); - } - - // Check the type of the value at specified index. - template - FORCE_INLINE bool is(size_t index) const { - return get_impl(index).is(); + FORCE_INLINE JsonVariant get(size_t index) const { + return JsonVariant(_memoryPool, arrayGet(_data, index)); } // Removes element at specified position. @@ -212,25 +205,6 @@ class JsonArray : public JsonArrayProxy, public Visitable { arrayRemove(_data, index); } - // Sets the value at specified index. - // - // bool add(size_t index, const TValue&); - // TValue = bool, long, int, short, float, double, serialized, JsonVariant, - // std::string, String, JsonArray, JsonObject - template - FORCE_INLINE bool set(size_t index, const T& value) const { - if (!_data) return false; - return get_impl(index).set(value); - } - // - // bool add(size_t index, TValue); - // TValue = char*, const char*, const FlashStringHelper* - template - FORCE_INLINE bool set(size_t index, T* value) const { - if (!_data) return false; - return get_impl(index).set(value); - } - template FORCE_INLINE void accept(Visitor& visitor) const { JsonArrayConst(_data).accept(visitor); @@ -242,10 +216,6 @@ class JsonArray : public JsonArrayProxy, public Visitable { return add().set(value); } - FORCE_INLINE JsonVariant get_impl(size_t index) const { - return JsonVariant(_memoryPool, arrayGet(_data, index)); - } - MemoryPool* _memoryPool; }; } // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/JsonArraySubscript.hpp b/src/ArduinoJson/JsonArraySubscript.hpp index 59677011..acfa1cdf 100644 --- a/src/ArduinoJson/JsonArraySubscript.hpp +++ b/src/ArduinoJson/JsonArraySubscript.hpp @@ -90,7 +90,7 @@ class JsonArraySubscript : public JsonVariantBase, private: FORCE_INLINE JsonVariant get_impl() const { - return _array.get(_index); + return _array.get(_index); } JsonArray _array; diff --git a/src/ArduinoJson/JsonObject.hpp b/src/ArduinoJson/JsonObject.hpp index a7f3fa0d..9c0737ad 100644 --- a/src/ArduinoJson/JsonObject.hpp +++ b/src/ArduinoJson/JsonObject.hpp @@ -80,18 +80,18 @@ class JsonObjectConst : public JsonObjectProxy, // TKey = const std::string&, const String& // TValue = bool, char, long, int, short, float, double, // std::string, String, JsonArrayConst, JsonObjectConst - template - FORCE_INLINE typename JsonVariantAs::type get(const TKey& key) const { - return get_impl(makeString(key)).template as(); + template + FORCE_INLINE JsonVariantConst get(const TKey& key) const { + return get_impl(makeString(key)); } // // TValue get(TKey) const; // TKey = char*, const char*, const FlashStringHelper* // TValue = bool, char, long, int, short, float, double, // std::string, String, JsonArrayConst, JsonObjectConst - template - FORCE_INLINE typename JsonVariantAs::type get(TKey* key) const { - return get_impl(makeString(key)).template as(); + template + FORCE_INLINE JsonVariantConst get(TKey* key) const { + return get_impl(makeString(key)); } // @@ -191,39 +191,18 @@ class JsonObject : public JsonObjectProxy, public Visitable { // TKey = const std::string&, const String& // TValue = bool, char, long, int, short, float, double, // std::string, String, JsonArray, JsonObject - template - FORCE_INLINE typename JsonVariantAs::type get(const TKey& key) const { - return get_impl(makeString(key)).template as(); + template + FORCE_INLINE JsonVariant get(const TKey& key) const { + return get_impl(makeString(key)); } // // TValue get(TKey) const; // TKey = char*, const char*, const FlashStringHelper* // TValue = bool, char, long, int, short, float, double, // std::string, String, JsonArray, JsonObject - template - FORCE_INLINE typename JsonVariantAs::type get(TKey* key) const { - return get_impl(makeString(key)).template as(); - } - - // Checks the type of the value associated with the specified key. - // - // - // bool is(TKey) const; - // TKey = const std::string&, const String& - // TValue = bool, char, long, int, short, float, double, - // std::string, String, JsonArray, JsonObject - template - FORCE_INLINE bool is(const TKey& key) const { - return get_impl(makeString(key)).template is(); - } - // - // bool is(TKey) const; - // TKey = char*, const char*, const FlashStringHelper* - // TValue = bool, char, long, int, short, float, double, - // std::string, String, JsonArray, JsonObject - template - FORCE_INLINE bool is(TKey* key) const { - return get_impl(makeString(key)).template is(); + template + FORCE_INLINE JsonVariant get(TKey* key) const { + return get_impl(makeString(key)); } // Gets or sets the value associated with the specified key. @@ -267,42 +246,6 @@ class JsonObject : public JsonObjectProxy, public Visitable { remove_impl(makeString(key)); } - // Sets the specified key with the specified value. - // - // bool set(TKey, TValue); - // TKey = const std::string&, const String& - // TValue = bool, long, int, short, float, double, serialized, JsonVariant, - // std::string, String, JsonArray, JsonObject - template - FORCE_INLINE bool set(const TKey& key, const TValue& value) const { - return set(key).set(value); - } - // - // bool set(TKey, TValue); - // TKey = const std::string&, const String& - // TValue = char*, const char*, const FlashStringHelper* - template - FORCE_INLINE bool set(const TKey& key, TValue* value) const { - return set(key).set(value); - } - // - // bool set(TKey, const TValue&); - // TKey = char*, const char*, const FlashStringHelper* - // TValue = bool, long, int, short, float, double, serialized, JsonVariant, - // std::string, String, JsonArray, JsonObject - template - FORCE_INLINE bool set(TKey* key, const TValue& value) const { - return set(key).set(value); - } - // - // bool set(TKey, TValue); - // TKey = char*, const char*, const FlashStringHelper* - // TValue = char*, const char*, const FlashStringHelper* - template - FORCE_INLINE bool set(TKey* key, TValue* value) const { - return set(key).set(value); - } - template FORCE_INLINE JsonVariant set(TKey* key) const { return set_impl(makeString(key)); diff --git a/src/ArduinoJson/JsonObjectSubscript.hpp b/src/ArduinoJson/JsonObjectSubscript.hpp index e4d3cea8..ad557be1 100644 --- a/src/ArduinoJson/JsonObjectSubscript.hpp +++ b/src/ArduinoJson/JsonObjectSubscript.hpp @@ -99,7 +99,7 @@ class JsonObjectSubscript private: FORCE_INLINE JsonVariant get_impl() const { - return _object.get(_key); + return _object.get(_key); } FORCE_INLINE JsonVariant set_impl() const { diff --git a/test/JsonArray/CMakeLists.txt b/test/JsonArray/CMakeLists.txt index ae3342da..069dd1ce 100644 --- a/test/JsonArray/CMakeLists.txt +++ b/test/JsonArray/CMakeLists.txt @@ -11,7 +11,6 @@ add_executable(JsonArrayTests isNull.cpp iterator.cpp remove.cpp - set.cpp size.cpp std_string.cpp subscript.cpp diff --git a/test/JsonArray/set.cpp b/test/JsonArray/set.cpp deleted file mode 100644 index 50466db6..00000000 --- a/test/JsonArray/set.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#include -#include - -using namespace Catch::Matchers; - -TEST_CASE("JsonArray::set()") { - DynamicJsonDocument doc; - JsonArray array = doc.to(); - array.add(0); - - SECTION("int") { - array.set(0, 123); - REQUIRE(123 == array[0].as()); - REQUIRE(array[0].is()); - REQUIRE_FALSE(array[0].is()); - } - - SECTION("double") { - array.set(0, 123.45); - REQUIRE(123.45 == array[0].as()); - REQUIRE(array[0].is()); - REQUIRE_FALSE(array[0].is()); - } - - SECTION("bool") { - array.set(0, true); - REQUIRE(true == array[0].as()); - REQUIRE(array[0].is()); - REQUIRE_FALSE(array[0].is()); - } - - SECTION("const char*") { - array.set(0, "hello"); - REQUIRE_THAT(array[0].as(), Equals("hello")); - REQUIRE(array[0].is()); - REQUIRE_FALSE(array[0].is()); - } - -#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(); - - array.set(0, arr); - - REQUIRE(arr == array[0].as()); - REQUIRE(array[0].is()); - REQUIRE_FALSE(array[0].is()); - } - - SECTION("nested object") { - DynamicJsonDocument doc2; - JsonObject obj = doc2.to(); - - array.set(0, obj); - - REQUIRE(obj == array[0].as()); - REQUIRE(array[0].is()); - REQUIRE_FALSE(array[0].is()); - } - - SECTION("array subscript") { - DynamicJsonDocument doc2; - JsonArray arr = doc2.to(); - arr.add("hello"); - - array.set(0, arr[0]); - - REQUIRE_THAT(array[0].as(), Equals("hello")); - } - - SECTION("object subscript") { - DynamicJsonDocument doc2; - JsonObject obj = doc2.to(); - obj["x"] = "hello"; - - array.set(0, obj["x"]); - - REQUIRE_THAT(array[0].as(), 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("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()); - } -} diff --git a/test/JsonArray/size.cpp b/test/JsonArray/size.cpp index 3d9b1139..1a3ec655 100644 --- a/test/JsonArray/size.cpp +++ b/test/JsonArray/size.cpp @@ -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()); diff --git a/test/JsonArray/std_string.cpp b/test/JsonArray/std_string.cpp index ac355436..adb98745 100644 --- a/test/JsonArray/std_string.cpp +++ b/test/JsonArray/std_string.cpp @@ -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"); diff --git a/test/JsonObject/CMakeLists.txt b/test/JsonObject/CMakeLists.txt index 13e59189..dde3a3f7 100644 --- a/test/JsonObject/CMakeLists.txt +++ b/test/JsonObject/CMakeLists.txt @@ -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 diff --git a/test/JsonObject/containsKey.cpp b/test/JsonObject/containsKey.cpp index a423a31d..2bacfa23 100644 --- a/test/JsonObject/containsKey.cpp +++ b/test/JsonObject/containsKey.cpp @@ -8,7 +8,7 @@ TEST_CASE("JsonObject::containsKey()") { DynamicJsonDocument doc; JsonObject obj = doc.to(); - obj.set("hello", 42); + obj["hello"] = 42; SECTION("returns true only if key is present") { REQUIRE(false == obj.containsKey("world")); diff --git a/test/JsonObject/get.cpp b/test/JsonObject/get.cpp deleted file mode 100644 index 3f954274..00000000 --- a/test/JsonObject/get.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#include -#include - -using namespace Catch::Matchers; - -TEST_CASE("JsonObject::get()") { - DynamicJsonDocument doc; - JsonObject obj = doc.to(); - - SECTION("get(const char*)") { - obj.set("hello", "world"); - const char* value = obj.get("hello"); - REQUIRE_THAT(value, Equals("world")); - } - -#ifdef HAS_VARIABLE_LENGTH_ARRAY - SECTION("get(VLA)") { - obj.set("hello", "world"); - int i = 16; - char vla[i]; - strcpy(vla, "hello"); - - REQUIRE(std::string("world") == obj.get(vla)); - } -#endif - - SECTION("works on JsonObjectConst") { - obj.set("hello", "world"); - const char* value = - static_cast(obj).get("hello"); - REQUIRE_THAT(value, Equals("world")); - } -} diff --git a/test/JsonObject/invalid.cpp b/test/JsonObject/invalid.cpp index b3b8490e..cc0349d0 100644 --- a/test/JsonObject/invalid.cpp +++ b/test/JsonObject/invalid.cpp @@ -15,7 +15,7 @@ TEST_CASE("JsonObject::invalid()") { } SECTION("AddFails") { - obj.set("hello", "world"); + obj["hello"] = "world"; REQUIRE(0 == obj.size()); } diff --git a/test/JsonObject/is.cpp b/test/JsonObject/is.cpp deleted file mode 100644 index eef4a441..00000000 --- a/test/JsonObject/is.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#include -#include - -TEST_CASE("JsonObject::is()") { - DynamicJsonDocument doc; - JsonObject obj = doc.to(); - obj["int"] = 42; - obj["str"] = "hello"; - - SECTION("is(const char*)") { - REQUIRE(true == obj.is("int")); - REQUIRE(false == obj.is("str")); - } - -#if HAS_VARIABLE_LENGTH_ARRAY - SECTION("is(VLA)") { - int i = 16; - char vla[i]; - strcpy(vla, "int"); - - REQUIRE(true == obj.is(vla)); - } -#endif -} diff --git a/test/JsonObject/set.cpp b/test/JsonObject/set.cpp deleted file mode 100644 index d8d84ff6..00000000 --- a/test/JsonObject/set.cpp +++ /dev/null @@ -1,174 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2018 -// MIT License - -#include -#include -#include - -TEST_CASE("JsonObject::set()") { - DynamicJsonDocument doc; - JsonObject obj = doc.to(); - - SECTION("int") { - obj.set("hello", 123); - - REQUIRE(123 == obj["hello"].as()); - REQUIRE(obj["hello"].is()); - REQUIRE_FALSE(obj["hello"].is()); - } - - SECTION("double") { - obj.set("hello", 123.45); - - REQUIRE(123.45 == obj["hello"].as()); - REQUIRE(obj["hello"].is()); - REQUIRE_FALSE(obj["hello"].is()); - } - - SECTION("bool") { - obj.set("hello", true); - - REQUIRE(obj["hello"].as()); - REQUIRE(obj["hello"].is()); - REQUIRE_FALSE(obj["hello"].is()); - } - - SECTION("const char*") { - obj.set("hello", "h3110"); - - REQUIRE(std::string("h3110") == obj["hello"].as()); - REQUIRE(obj["hello"].is()); - REQUIRE_FALSE(obj["hello"].is()); - } - -#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(); - - obj.set("hello", arr); - - REQUIRE(arr == obj["hello"].as()); - REQUIRE(obj["hello"].is()); - REQUIRE_FALSE(obj["hello"].is()); - } - - SECTION("nested object") { - DynamicJsonDocument doc2; - JsonObject obj2 = doc2.to(); - - obj.set("hello", obj2); - - REQUIRE(obj2 == obj["hello"].as()); - REQUIRE(obj["hello"].is()); - REQUIRE_FALSE(obj["hello"].is()); - } - - SECTION("array subscript") { - DynamicJsonDocument doc2; - JsonArray arr = doc2.to(); - arr.add(42); - - obj.set("a", arr[0]); - - REQUIRE(42 == obj["a"]); - } - - SECTION("object subscript") { - DynamicJsonDocument doc2; - JsonObject obj2 = doc2.to(); - obj2.set("x", 42); - - obj.set("a", obj2["x"]); - - REQUIRE(42 == obj["a"]); - } - - SECTION("returns true when allocation succeeds") { - StaticJsonDocument doc2; - JsonObject obj2 = doc2.to(); - - REQUIRE(true == obj2.set(std::string("hello"), std::string("world"))); - } - - SECTION("returns false when allocation fails") { - StaticJsonDocument doc2; - JsonObject obj2 = doc2.to(); - - 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("world")); - const size_t expectedSize = JSON_OBJECT_SIZE(1) + 6; - REQUIRE(expectedSize == doc.memoryUsage()); - } - - SECTION("should duplicate char* key") { - obj.set(const_cast("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("hello"), const_cast("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()); - } -} diff --git a/test/JsonObject/size.cpp b/test/JsonObject/size.cpp index 3e19459f..8ec27493 100644 --- a/test/JsonObject/size.cpp +++ b/test/JsonObject/size.cpp @@ -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()); } diff --git a/test/JsonObject/std_string.cpp b/test/JsonObject/std_string.cpp index de106739..41e7c179 100644 --- a/test/JsonObject/std_string.cpp +++ b/test/JsonObject/std_string.cpp @@ -31,70 +31,6 @@ TEST_CASE("std::string") { REQUIRE(std::string("value") == obj[std::string("key")]); } - SECTION("set(key)") { - JsonObject obj = doc.to(); - std::string key("hello"); - obj.set(key, "world"); - eraseString(key); - REQUIRE(std::string("world") == obj["hello"]); - } - - SECTION("set(value)") { - JsonObject obj = doc.to(); - std::string value("world"); - obj.set("hello", value); - eraseString(value); - REQUIRE(std::string("world") == obj["hello"]); - } - - SECTION("set(key,value)") { - JsonObject obj = doc.to(); - 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(); - DynamicJsonDocument doc2; - JsonArray arr = doc2.to(); - arr.add("world"); - - obj.set(std::string("hello"), arr[0]); - - REQUIRE(std::string("world") == obj["hello"]); - } - - SECTION("set(JsonObjectSubscript)") { - JsonObject obj = doc.to(); - DynamicJsonDocument doc2; - JsonObject obj2 = doc2.to(); - obj2.set("x", "world"); - - obj.set(std::string("hello"), obj2["x"]); - - REQUIRE(std::string("world") == obj["hello"]); - } - - SECTION("get()") { - char json[] = "{\"key\":\"value\"}"; - deserializeJson(doc, json); - JsonObject obj = doc.as(); - - REQUIRE(std::string("value") == obj.get(std::string("key"))); - } - - SECTION("is()") { - char json[] = "{\"key\":\"value\"}"; - deserializeJson(doc, json); - JsonObject obj = doc.as(); - - REQUIRE(true == obj.is(std::string("key"))); - } - SECTION("createNestedObject()") { JsonObject obj = doc.to(); std::string key = "key"; diff --git a/test/JsonObject/subscript.cpp b/test/JsonObject/subscript.cpp index 47ec20d5..1b0753b3 100644 --- a/test/JsonObject/subscript.cpp +++ b/test/JsonObject/subscript.cpp @@ -86,7 +86,7 @@ TEST_CASE("JsonObject::operator[]") { SECTION("object subscript") { DynamicJsonDocument doc2; JsonObject obj2 = doc2.to(); - obj2.set("x", 42); + obj2["x"] = 42; obj["a"] = obj2["x"]; diff --git a/test/JsonSerializer/JsonObject.cpp b/test/JsonSerializer/JsonObject.cpp index 42451080..90d9a73e 100644 --- a/test/JsonSerializer/JsonObject.cpp +++ b/test/JsonSerializer/JsonObject.cpp @@ -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(0); - obj.set("b", static_cast(0)); + obj["b"] = static_cast(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(); - obj.set("c", c.to()); + obj["c"] = c.to(); check(obj, "{\"a\":[],\"b\":[],\"c\":[]}"); } @@ -109,7 +109,7 @@ TEST_CASE("serializeJson(JsonObject)") { obj.createNestedObject("a"); obj["b"] = b.to(); - obj.set("c", c.to()); + obj["c"] = c.to(); check(obj, "{\"a\":{},\"b\":{},\"c\":{}}"); } diff --git a/test/Misc/unsigned_char.cpp b/test/Misc/unsigned_char.cpp index c65611cd..b1a76ab8 100644 --- a/test/Misc/unsigned_char.cpp +++ b/test/Misc/unsigned_char.cpp @@ -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(); - REQUIRE(std::string("world") == obj.get(key)); - } - - SECTION("set() key") { - unsigned char key[] = "hello"; - - DynamicJsonDocument doc; - JsonObject obj = doc.to(); - obj.set(key, "world"); - - REQUIRE(std::string("world") == obj["hello"]); - } - - SECTION("set() value") { - unsigned char value[] = "world"; - - DynamicJsonDocument doc; - JsonObject obj = doc.to(); - obj.set("hello", value); - - REQUIRE(std::string("world") == obj["hello"]); - } - - SECTION("set() key&value") { - unsigned char key[] = "world"; - - DynamicJsonDocument doc; - JsonObject obj = doc.to(); - 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(); - - REQUIRE(true == obj.is(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(); - arr.add("hello"); - arr.set(0, value); - - REQUIRE(std::string("world") == arr[0]); - } } SECTION("JsonArraySubscript") {