2017-11-07 20:42:50 +01:00
|
|
|
// ArduinoJson - arduinojson.org
|
2023-03-16 17:50:34 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2023
|
2015-04-27 15:57:40 +02:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
2017-04-18 18:22:24 +02:00
|
|
|
#include <catch.hpp>
|
|
|
|
TEST_CASE("StaticJsonBuffer::parseObject()") {
|
|
|
|
SECTION("TooSmallBufferForEmptyObject") {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(0) - 1> bufferTooSmall;
|
|
|
|
char input[] = "{}";
|
|
|
|
JsonObject& obj = bufferTooSmall.parseObject(input);
|
|
|
|
REQUIRE_FALSE(obj.success());
|
2016-06-22 21:41:19 +02:00
|
|
|
}
|
2015-04-27 15:57:40 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("BufferOfTheRightSizeForEmptyObject") {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(0)> bufferOfRightSize;
|
|
|
|
char input[] = "{}";
|
|
|
|
JsonObject& obj = bufferOfRightSize.parseObject(input);
|
|
|
|
REQUIRE(obj.success());
|
2016-06-22 21:41:19 +02:00
|
|
|
}
|
2015-04-27 15:57:40 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("TooSmallBufferForObjectWithOneValue") {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(1) - 1> bufferTooSmall;
|
|
|
|
char input[] = "{\"a\":1}";
|
|
|
|
JsonObject& obj = bufferTooSmall.parseObject(input);
|
|
|
|
REQUIRE_FALSE(obj.success());
|
2015-04-27 15:57:40 +02:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("BufferOfTheRightSizeForObjectWithOneValue") {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(1)> bufferOfRightSize;
|
|
|
|
char input[] = "{\"a\":1}";
|
|
|
|
JsonObject& obj = bufferOfRightSize.parseObject(input);
|
|
|
|
REQUIRE(obj.success());
|
2015-04-27 15:57:40 +02:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("TooSmallBufferForObjectWithNestedObject") {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0) - 1>
|
|
|
|
bufferTooSmall;
|
|
|
|
char input[] = "{\"a\":[]}";
|
|
|
|
JsonObject& obj = bufferTooSmall.parseObject(input);
|
|
|
|
REQUIRE_FALSE(obj.success());
|
|
|
|
}
|
2015-04-27 15:57:40 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("BufferOfTheRightSizeForObjectWithNestedObject") {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(1) + JSON_ARRAY_SIZE(0)>
|
|
|
|
bufferOfRightSize;
|
|
|
|
char input[] = "{\"a\":[]}";
|
|
|
|
JsonObject& obj = bufferOfRightSize.parseObject(input);
|
|
|
|
REQUIRE(obj.success());
|
|
|
|
}
|
2015-08-29 22:51:17 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("CharPtrNull") {
|
|
|
|
REQUIRE_FALSE(
|
|
|
|
StaticJsonBuffer<100>().parseObject(static_cast<char*>(0)).success());
|
|
|
|
}
|
2015-08-29 22:51:17 +02:00
|
|
|
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("ConstCharPtrNull") {
|
|
|
|
REQUIRE_FALSE(StaticJsonBuffer<100>()
|
|
|
|
.parseObject(static_cast<const char*>(0))
|
|
|
|
.success());
|
|
|
|
}
|
2015-08-29 22:51:17 +02:00
|
|
|
}
|