2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2023-02-16 11:45:01 +01:00
|
|
|
// Copyright © 2014-2023, Benoit BLANCHON
|
2019-02-18 16:18:11 +01:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#define ARDUINOJSON_DECODE_UNICODE 1
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
TEST_CASE("Truncated JSON input") {
|
2023-07-27 14:31:56 +02:00
|
|
|
const char* testCases[] = {
|
|
|
|
// strings
|
|
|
|
"\"\\",
|
|
|
|
"\"hello",
|
|
|
|
"\'hello",
|
|
|
|
// unicode
|
|
|
|
"'\\u",
|
|
|
|
"'\\u00",
|
|
|
|
"'\\u000",
|
|
|
|
// false
|
|
|
|
"f",
|
|
|
|
"fa",
|
|
|
|
"fal",
|
|
|
|
"fals",
|
|
|
|
// true
|
|
|
|
"t",
|
|
|
|
"tr",
|
|
|
|
"tru",
|
|
|
|
// null
|
|
|
|
"n",
|
|
|
|
"nu",
|
|
|
|
"nul",
|
|
|
|
// object
|
|
|
|
"{",
|
|
|
|
"{a",
|
|
|
|
"{a:",
|
|
|
|
"{a:1",
|
|
|
|
"{a:1,",
|
|
|
|
"{a:1,",
|
|
|
|
};
|
2019-02-18 16:18:11 +01:00
|
|
|
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
|
|
|
|
|
2023-07-17 18:15:13 +02:00
|
|
|
JsonDocument doc;
|
2019-02-18 16:18:11 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < testCount; i++) {
|
|
|
|
const char* input = testCases[i];
|
|
|
|
CAPTURE(input);
|
|
|
|
REQUIRE(deserializeJson(doc, input) ==
|
|
|
|
DeserializationError::IncompleteInput);
|
|
|
|
}
|
|
|
|
}
|