mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Don't use JsonBuffer to create or parse objects and arrays.
* Added DynamicJsonArray and StaticJsonArray * Added DynamicJsonObject and StaticJsonObject * Added DynamicJsonVariant and StaticJsonVariant * Added deserializeJson() * Removed JsonBuffer::parseArray(), parseObject() and parse() * Removed JsonBuffer::createArray() and createObject()
This commit is contained in:
48
test/JsonParser/nestingLimit.cpp
Normal file
48
test/JsonParser/nestingLimit.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
bool tryParseArray(const char *json, uint8_t nestingLimit) {
|
||||
DynamicJsonArray array;
|
||||
return deserializeJson(array, json, nestingLimit);
|
||||
}
|
||||
|
||||
bool tryParseObject(const char *json, uint8_t nestingLimit) {
|
||||
DynamicJsonObject obj;
|
||||
return deserializeJson(obj, json, nestingLimit);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonParser nestingLimit") {
|
||||
SECTION("ParseArrayWithNestingLimit0") {
|
||||
REQUIRE(true == tryParseArray("[]", 0));
|
||||
REQUIRE(false == tryParseArray("[[]]", 0));
|
||||
}
|
||||
|
||||
SECTION("ParseArrayWithNestingLimit1") {
|
||||
REQUIRE(true == tryParseArray("[[]]", 1));
|
||||
REQUIRE(false == tryParseArray("[[[]]]", 1));
|
||||
}
|
||||
|
||||
SECTION("ParseArrayWithNestingLimit2") {
|
||||
REQUIRE(true == tryParseArray("[[[]]]", 2));
|
||||
REQUIRE(false == tryParseArray("[[[[]]]]", 2));
|
||||
}
|
||||
|
||||
SECTION("ParseObjectWithNestingLimit0") {
|
||||
REQUIRE(true == tryParseObject("{}", 0));
|
||||
REQUIRE(false == tryParseObject("{\"key\":{}}", 0));
|
||||
}
|
||||
|
||||
SECTION("ParseObjectWithNestingLimit1") {
|
||||
REQUIRE(true == tryParseObject("{\"key\":{}}", 1));
|
||||
REQUIRE(false == tryParseObject("{\"key\":{\"key\":{}}}", 1));
|
||||
}
|
||||
|
||||
SECTION("ParseObjectWithNestingLimit2") {
|
||||
REQUIRE(true == tryParseObject("{\"key\":{\"key\":{}}}", 2));
|
||||
REQUIRE(false == tryParseObject("{\"key\":{\"key\":{\"key\":{}}}}", 2));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user