Remove createNestedArray() and createNestedObject()

This commit is contained in:
Benoit Blanchon
2023-08-09 11:31:29 +02:00
parent cdc1262127
commit 7f459adc4b
37 changed files with 99 additions and 547 deletions

View File

@ -7,8 +7,6 @@ add_executable(JsonObjectTests
compare.cpp
containsKey.cpp
copy.cpp
createNestedArray.cpp
createNestedObject.cpp
equals.cpp
invalid.cpp
isNull.cpp

View File

@ -43,12 +43,12 @@ TEST_CASE("Compare JsonObject with JsonObject") {
}
SECTION("Compare with identical object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello";
object1["c"][0] = false;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello";
object2["c"][0] = false;
@ -62,12 +62,12 @@ TEST_CASE("Compare JsonObject with JsonObject") {
}
SECTION("Compare with different object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello1";
object1["c"][0] = false;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello2";
object2["c"][0] = false;
@ -107,12 +107,12 @@ TEST_CASE("Compare JsonObject with JsonVariant") {
}
SECTION("Compare with identical object") {
JsonObject object = doc.createNestedObject();
JsonObject object = doc.add<JsonObject>();
object["a"] = 1;
object["b"] = "hello";
object["c"][0] = false;
JsonVariant variant = doc.createNestedObject();
JsonVariant variant = doc.add<JsonObject>();
variant["a"] = 1;
variant["b"] = "hello";
variant["c"][0] = false;
@ -133,12 +133,12 @@ TEST_CASE("Compare JsonObject with JsonVariant") {
}
SECTION("Compare with different object") {
JsonObject object = doc.createNestedObject();
JsonObject object = doc.add<JsonObject>();
object["a"] = 1;
object["b"] = "hello1";
object["c"][0] = false;
JsonVariant variant = doc.createNestedObject();
JsonVariant variant = doc.add<JsonObject>();
variant["a"] = 1;
variant["b"] = "hello2";
variant["c"][0] = false;
@ -199,12 +199,12 @@ TEST_CASE("Compare JsonObject with JsonVariantConst") {
}
SECTION("Compare with identical object") {
JsonObject object = doc.createNestedObject();
JsonObject object = doc.add<JsonObject>();
object["a"] = 1;
object["b"] = "hello";
object["c"][0] = false;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello";
object2["c"][0] = false;
@ -226,12 +226,12 @@ TEST_CASE("Compare JsonObject with JsonVariantConst") {
}
SECTION("Compare with different object") {
JsonObject object = doc.createNestedObject();
JsonObject object = doc.add<JsonObject>();
object["a"] = 1;
object["b"] = "hello1";
object["c"][0] = false;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello2";
object2["c"][0] = false;
@ -292,12 +292,12 @@ TEST_CASE("Compare JsonObject with JsonObjectConst") {
}
SECTION("Compare with identical object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello";
object1["c"][0] = false;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello";
object2["c"][0] = false;
@ -319,12 +319,12 @@ TEST_CASE("Compare JsonObject with JsonObjectConst") {
}
SECTION("Compare with different object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello1";
object1["c"][0] = false;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello2";
object2["c"][0] = false;
@ -387,13 +387,13 @@ TEST_CASE("Compare JsonObjectConst with JsonObjectConst") {
}
SECTION("Compare with identical object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello";
object1["c"][0] = false;
JsonObjectConst carray1 = object1;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello";
object2["c"][0] = false;
@ -408,13 +408,13 @@ TEST_CASE("Compare JsonObjectConst with JsonObjectConst") {
}
SECTION("Compare with different object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello1";
object1["c"][0] = false;
JsonObjectConst carray1 = object1;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello2";
object2["c"][0] = false;
@ -455,13 +455,13 @@ TEST_CASE("Compare JsonObjectConst with JsonVariant") {
}
SECTION("Compare with identical object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello";
object1["c"][0] = false;
JsonObjectConst carray1 = object1;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello";
object2["c"][0] = false;
@ -483,13 +483,13 @@ TEST_CASE("Compare JsonObjectConst with JsonVariant") {
}
SECTION("Compare with different object") {
JsonObject object1 = doc.createNestedObject();
JsonObject object1 = doc.add<JsonObject>();
object1["a"] = 1;
object1["b"] = "hello1";
object1["c"][0] = false;
JsonObjectConst carray1 = object1;
JsonObject object2 = doc.createNestedObject();
JsonObject object2 = doc.add<JsonObject>();
object2["a"] = 1;
object2["b"] = "hello2";
object2["c"][0] = false;

View File

@ -1,27 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonObject::createNestedArray()") {
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
SECTION("key is a const char*") {
JsonArray arr = obj.createNestedArray("hello");
REQUIRE(arr.isNull() == false);
}
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("key is a VLA") {
size_t i = 16;
char vla[i];
strcpy(vla, "hello");
JsonArray arr = obj.createNestedArray(vla);
REQUIRE(arr.isNull() == false);
}
#endif
}

View File

@ -1,25 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonObject::createNestedObject()") {
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
SECTION("key is a const char*") {
obj.createNestedObject("hello");
}
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("key is a VLA") {
size_t i = 16;
char vla[i];
strcpy(vla, "hello");
obj.createNestedObject(vla);
}
#endif
}

View File

@ -19,14 +19,6 @@ TEST_CASE("JsonObject::invalid()") {
REQUIRE(0 == obj.size());
}
SECTION("CreateNestedArrayFails") {
REQUIRE(obj.createNestedArray("hello").isNull());
}
SECTION("CreateNestedObjectFails") {
REQUIRE(obj.createNestedObject("world").isNull());
}
SECTION("serialize to 'null'") {
char buffer[32];
serializeJson(obj, buffer, sizeof(buffer));

View File

@ -24,12 +24,12 @@ TEST_CASE("JsonObject::nesting()") {
}
SECTION("returns 2 with nested array") {
obj.createNestedArray("nested");
obj["nested"].to<JsonArray>();
REQUIRE(obj.nesting() == 2);
}
SECTION("returns 2 with nested object") {
obj.createNestedObject("nested");
obj["nested"].to<JsonObject>();
REQUIRE(obj.nesting() == 2);
}
}

View File

@ -32,26 +32,6 @@ TEST_CASE("std::string") {
REQUIRE(std::string("value") == obj[std::string("key")]);
}
SECTION("createNestedObject()") {
JsonObject obj = doc.to<JsonObject>();
std::string key = "key";
char json[64];
obj.createNestedObject(key);
eraseString(key);
serializeJson(doc, json, sizeof(json));
REQUIRE(std::string("{\"key\":{}}") == json);
}
SECTION("createNestedArray()") {
JsonObject obj = doc.to<JsonObject>();
std::string key = "key";
char json[64];
obj.createNestedArray(key);
eraseString(key);
serializeJson(doc, json, sizeof(json));
REQUIRE(std::string("{\"key\":[]}") == json);
}
SECTION("containsKey()") {
char json[] = "{\"key\":\"value\"}";
deserializeJson(doc, json);

View File

@ -245,7 +245,7 @@ TEST_CASE("JsonObject::operator[]") {
#endif
SECTION("chain") {
obj.createNestedObject("hello")["world"] = 123;
obj["hello"]["world"] = 123;
REQUIRE(123 == obj["hello"]["world"].as<int>());
REQUIRE(true == obj["hello"]["world"].is<int>());