2017-01-06 21:07:34 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2017
|
2014-11-06 10:24:37 +01:00
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
2017-03-25 22:05:06 +01:00
|
|
|
// https://bblanchon.github.io/ArduinoJson/
|
2016-01-07 22:35:12 +01:00
|
|
|
// If you like this project, please add a star!
|
2014-11-06 10:24:37 +01:00
|
|
|
|
2014-11-11 16:54:46 +01:00
|
|
|
#include <ArduinoJson.h>
|
2017-04-18 18:22:24 +02:00
|
|
|
#include <catch.hpp>
|
2014-11-06 10:24:37 +01:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
bool tryParseArray(const char *json, uint8_t nestingLimit) {
|
|
|
|
DynamicJsonBuffer buffer;
|
|
|
|
return buffer.parseArray(json, nestingLimit).success();
|
|
|
|
}
|
2014-11-06 10:24:37 +01:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
bool tryParseObject(const char *json, uint8_t nestingLimit) {
|
|
|
|
DynamicJsonBuffer buffer;
|
|
|
|
return buffer.parseObject(json, nestingLimit).success();
|
|
|
|
}
|
2014-11-06 10:24:37 +01:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
TEST_CASE("JsonParser nestingLimit") {
|
|
|
|
SECTION("ParseArrayWithNestingLimit0") {
|
|
|
|
REQUIRE(true == tryParseArray("[]", 0));
|
|
|
|
REQUIRE(false == tryParseArray("[[]]", 0));
|
2014-11-06 10:24:37 +01:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("ParseArrayWithNestingLimit1") {
|
|
|
|
REQUIRE(true == tryParseArray("[[]]", 1));
|
|
|
|
REQUIRE(false == tryParseArray("[[[]]]", 1));
|
2014-11-06 10:24:37 +01:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("ParseArrayWithNestingLimit2") {
|
|
|
|
REQUIRE(true == tryParseArray("[[[]]]", 2));
|
|
|
|
REQUIRE(false == tryParseArray("[[[[]]]]", 2));
|
2014-11-06 10:24:37 +01:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("ParseObjectWithNestingLimit0") {
|
|
|
|
REQUIRE(true == tryParseObject("{}", 0));
|
|
|
|
REQUIRE(false == tryParseObject("{\"key\":{}}", 0));
|
2014-11-06 10:24:37 +01:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("ParseObjectWithNestingLimit1") {
|
|
|
|
REQUIRE(true == tryParseObject("{\"key\":{}}", 1));
|
|
|
|
REQUIRE(false == tryParseObject("{\"key\":{\"key\":{}}}", 1));
|
2014-11-06 10:24:37 +01:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("ParseObjectWithNestingLimit2") {
|
|
|
|
REQUIRE(true == tryParseObject("{\"key\":{\"key\":{}}}", 2));
|
|
|
|
REQUIRE(false == tryParseObject("{\"key\":{\"key\":{\"key\":{}}}}", 2));
|
|
|
|
}
|
2014-11-06 10:24:37 +01:00
|
|
|
}
|