incomplete_input.cpp 980 B

1234567891011121314151617181920212223242526272829
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #define ARDUINOJSON_DECODE_UNICODE 1
  5. #include <ArduinoJson.h>
  6. #include <catch.hpp>
  7. TEST_CASE("Truncated JSON input") {
  8. const char* testCases[] = {"\"hello", "\'hello", "'\\u", "'\\u00", "'\\u000",
  9. // false
  10. "f", "fa", "fal", "fals",
  11. // true
  12. "t", "tr", "tru",
  13. // null
  14. "n", "nu", "nul",
  15. // object
  16. "{", "{a", "{a:", "{a:1", "{a:1,", "{a:1,"};
  17. const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
  18. DynamicJsonDocument doc(4096);
  19. for (size_t i = 0; i < testCount; i++) {
  20. const char* input = testCases[i];
  21. CAPTURE(input);
  22. REQUIRE(deserializeJson(doc, input) ==
  23. DeserializationError::IncompleteInput);
  24. }
  25. }