Tasmota/lib-before-5.9.1f/ArduinoJson/test/JsonParser_NestingLimit_Tests.cpp
arendst 299bed1c05 v5.9.1f - Update libraries and a fix
5.9.1f
 * Upgrade library ArduinoJson to 5.11.2
 * Upgrade library
IRRemoteEsp8266 to 2.2.1 + 2 commits but tweaked some protocols to keep
code usage small
 * Upgrade library NeoPixelBus to 2.2.9
 * Upgrade
library OneWire to 2.3.3 + 6 commits
 * Formalize library PubSubClient
to 2.6 + 9 commits and additional delay
 * Add optional ADS1115 driver
as alternative for unsupported I2Cdevlib in esp8266-core 2.4.0-rc2
 *
Fix wrong response name for command HlwISet (#1214)
2017-11-19 18:02:03 +01:00

86 lines
2.1 KiB
C++

// Copyright Benoit Blanchon 2014-2017
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
#include <ArduinoJson.h>
#include <gtest/gtest.h>
class JsonParser_NestingLimit_Tests : public testing::Test {
protected:
void whenNestingLimitIs(uint8_t nestingLimit) {
_nestingLimit = nestingLimit;
}
void parseArrayMustFail(const char *json) {
ASSERT_FALSE(tryParseArray(json));
}
void parseArrayMustSucceed(const char *json) {
ASSERT_TRUE(tryParseArray(json));
}
void parseObjectMustFail(const char *json) {
ASSERT_FALSE(tryParseObject(json));
}
void parseObjectMustSucceed(const char *json) {
ASSERT_TRUE(tryParseObject(json));
}
private:
bool tryParseArray(const char *json) {
DynamicJsonBuffer buffer;
char s[256];
strcpy(s, json);
return buffer.parseArray(s, _nestingLimit).success();
}
bool tryParseObject(const char *json) {
DynamicJsonBuffer buffer;
char s[256];
strcpy(s, json);
return buffer.parseObject(s, _nestingLimit).success();
}
uint8_t _nestingLimit;
};
TEST_F(JsonParser_NestingLimit_Tests, ParseArrayWithNestingLimit0) {
whenNestingLimitIs(0);
parseArrayMustSucceed("[]");
parseArrayMustFail("[[]]");
}
TEST_F(JsonParser_NestingLimit_Tests, ParseArrayWithNestingLimit1) {
whenNestingLimitIs(1);
parseArrayMustSucceed("[[]]");
parseArrayMustFail("[[[]]]");
}
TEST_F(JsonParser_NestingLimit_Tests, ParseArrayWithNestingLimit2) {
whenNestingLimitIs(2);
parseArrayMustSucceed("[[[]]]");
parseArrayMustFail("[[[[]]]]");
}
TEST_F(JsonParser_NestingLimit_Tests, ParseObjectWithNestingLimit0) {
whenNestingLimitIs(0);
parseObjectMustSucceed("{}");
parseObjectMustFail("{\"key\":{}}");
}
TEST_F(JsonParser_NestingLimit_Tests, ParseObjectWithNestingLimit1) {
whenNestingLimitIs(1);
parseObjectMustSucceed("{\"key\":{}}");
parseObjectMustFail("{\"key\":{\"key\":{}}}");
}
TEST_F(JsonParser_NestingLimit_Tests, ParseObjectWithNestingLimit2) {
whenNestingLimitIs(2);
parseObjectMustSucceed("{\"key\":{\"key\":{}}}");
parseObjectMustFail("{\"key\":{\"key\":{\"key\":{}}}}");
}