Replaced JsonDocument::nestingLimit with a param to deserializeJson()

This commit is contained in:
Benoit Blanchon
2019-01-19 14:45:16 +01:00
parent 30b94493bb
commit e633292df1
11 changed files with 249 additions and 98 deletions

View File

@ -78,7 +78,6 @@ TEST_CASE("DynamicJsonDocument copies") {
SECTION("Copy constructor") {
DynamicJsonDocument doc1(1234);
deserializeJson(doc1, "{\"hello\":\"world\"}");
doc1.nestingLimit = 42;
DynamicJsonDocument doc2 = doc1;
@ -86,14 +85,12 @@ TEST_CASE("DynamicJsonDocument copies") {
serializeJson(doc2, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc2.nestingLimit == 42);
REQUIRE(doc2.capacity() == doc1.capacity());
}
SECTION("Copy assignment preserves the buffer when capacity is sufficient") {
DynamicJsonDocument doc1(1234);
deserializeJson(doc1, "{\"hello\":\"world\"}");
doc1.nestingLimit = 42;
DynamicJsonDocument doc2(doc1.capacity());
doc2 = doc1;
@ -101,14 +98,12 @@ TEST_CASE("DynamicJsonDocument copies") {
std::string json;
serializeJson(doc2, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc2.nestingLimit == 42);
REQUIRE(doc2.capacity() == doc1.capacity());
}
SECTION("Copy assignment realloc the buffer when capacity is insufficient") {
DynamicJsonDocument doc1(1234);
deserializeJson(doc1, "{\"hello\":\"world\"}");
doc1.nestingLimit = 42;
DynamicJsonDocument doc2(8);
REQUIRE(doc2.capacity() < doc1.memoryUsage());
@ -118,20 +113,17 @@ TEST_CASE("DynamicJsonDocument copies") {
std::string json;
serializeJson(doc2, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc2.nestingLimit == 42);
}
SECTION("Construct from StaticJsonDocument") {
StaticJsonDocument<200> sdoc;
deserializeJson(sdoc, "{\"hello\":\"world\"}");
sdoc.nestingLimit = 42;
DynamicJsonDocument ddoc = sdoc;
std::string json;
serializeJson(ddoc, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(ddoc.nestingLimit == 42);
REQUIRE(ddoc.capacity() == sdoc.capacity());
}
@ -141,13 +133,11 @@ TEST_CASE("DynamicJsonDocument copies") {
StaticJsonDocument<200> sdoc;
deserializeJson(sdoc, "{\"hello\":\"world\"}");
sdoc.nestingLimit = 42;
ddoc = sdoc;
std::string json;
serializeJson(ddoc, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(ddoc.nestingLimit == 42);
}
}

View File

@ -33,27 +33,23 @@ TEST_CASE("StaticJsonDocument") {
StaticJsonDocument<200> doc1, doc2;
doc1.to<JsonVariant>().set(666);
deserializeJson(doc2, "{\"hello\":\"world\"}");
doc2.nestingLimit = 42;
doc1 = doc2;
std::string json;
serializeJson(doc1, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc1.nestingLimit == 42);
}
SECTION("Copy constructor") {
StaticJsonDocument<200> doc1;
deserializeJson(doc1, "{\"hello\":\"world\"}");
doc1.nestingLimit = 42;
StaticJsonDocument<200> doc2 = doc1;
std::string json;
serializeJson(doc2, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc2.nestingLimit == 42);
}
SECTION("Assign from StaticJsonDocument of different capacity") {
@ -61,14 +57,12 @@ TEST_CASE("StaticJsonDocument") {
StaticJsonDocument<300> doc2;
doc1.to<JsonVariant>().set(666);
deserializeJson(doc2, "{\"hello\":\"world\"}");
doc2.nestingLimit = 42;
doc1 = doc2;
std::string json;
serializeJson(doc1, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc1.nestingLimit == 42);
}
SECTION("Assign from DynamicJsonDocument") {
@ -76,39 +70,33 @@ TEST_CASE("StaticJsonDocument") {
DynamicJsonDocument doc2(4096);
doc1.to<JsonVariant>().set(666);
deserializeJson(doc2, "{\"hello\":\"world\"}");
doc2.nestingLimit = 42;
doc1 = doc2;
std::string json;
serializeJson(doc1, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc1.nestingLimit == 42);
}
SECTION("Construct from StaticJsonDocument of different size") {
StaticJsonDocument<300> doc2;
deserializeJson(doc2, "{\"hello\":\"world\"}");
doc2.nestingLimit = 42;
StaticJsonDocument<200> doc1 = doc2;
std::string json;
serializeJson(doc1, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc1.nestingLimit == 42);
}
SECTION("Construct from DynamicJsonDocument") {
DynamicJsonDocument doc2(4096);
deserializeJson(doc2, "{\"hello\":\"world\"}");
doc2.nestingLimit = 42;
StaticJsonDocument<200> doc1 = doc2;
std::string json;
serializeJson(doc1, json);
REQUIRE(json == "{\"hello\":\"world\"}");
REQUIRE(doc1.nestingLimit == 42);
}
}