// ArduinoJson - arduinojson.org // Copyright Benoit Blanchon 2014-2019 // MIT License #include #include TEST_CASE("StaticJsonBuffer::parseArray()") { SECTION("TooSmallBufferForEmptyArray") { StaticJsonBuffer bufferTooSmall; char input[] = "[]"; JsonArray& arr = bufferTooSmall.parseArray(input); REQUIRE_FALSE(arr.success()); } SECTION("BufferOfTheRightSizeForEmptyArray") { StaticJsonBuffer bufferOfRightSize; char input[] = "[]"; JsonArray& arr = bufferOfRightSize.parseArray(input); REQUIRE(arr.success()); } SECTION("TooSmallBufferForArrayWithOneValue") { StaticJsonBuffer bufferTooSmall; char input[] = "[1]"; JsonArray& arr = bufferTooSmall.parseArray(input); REQUIRE_FALSE(arr.success()); } SECTION("BufferOfTheRightSizeForArrayWithOneValue") { StaticJsonBuffer bufferOfRightSize; char input[] = "[1]"; JsonArray& arr = bufferOfRightSize.parseArray(input); REQUIRE(arr.success()); } SECTION("TooSmallBufferForArrayWithNestedObject") { StaticJsonBuffer bufferTooSmall; char input[] = "[{}]"; JsonArray& arr = bufferTooSmall.parseArray(input); REQUIRE_FALSE(arr.success()); } SECTION("BufferOfTheRightSizeForArrayWithNestedObject") { StaticJsonBuffer bufferOfRightSize; char input[] = "[{}]"; JsonArray& arr = bufferOfRightSize.parseArray(input); REQUIRE(arr.success()); } SECTION("CharPtrNull") { REQUIRE_FALSE( StaticJsonBuffer<100>().parseArray(static_cast(0)).success()); } SECTION("ConstCharPtrNull") { REQUIRE_FALSE(StaticJsonBuffer<100>() .parseArray(static_cast(0)) .success()); } SECTION("CopyStringNotSpaces") { StaticJsonBuffer<100> jsonBuffer; jsonBuffer.parseArray(" [ \"1234567\" ] "); REQUIRE(JSON_ARRAY_SIZE(1) + sizeof("1234567") == jsonBuffer.size()); // note we use a string of 8 bytes to be sure that the StaticJsonBuffer // will not insert bytes to enforce alignement } }