invalid_input.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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("Invalid JSON input") {
  8. const char* testCases[] = {"'\\u'", "'\\u000g'", "'\\u000'", "'\\u000G'",
  9. "'\\u000/'", "\\x1234", "6a9", "1,",
  10. "nulL", "tru3", "fals3", "2]",
  11. "3}"};
  12. const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
  13. DynamicJsonDocument doc(4096);
  14. for (size_t i = 0; i < testCount; i++) {
  15. const char* input = testCases[i];
  16. CAPTURE(input);
  17. REQUIRE(deserializeJson(doc, input) == DeserializationError::InvalidInput);
  18. }
  19. }
  20. TEST_CASE("Invalid JSON input that should pass") {
  21. const char* testCases[] = {
  22. "'\\ud83d'", // leading surrogate without a trailing surrogate
  23. "'\\udda4'", // trailing surrogate without a leading surrogate
  24. "'\\ud83d\\ud83d'", // two leading surrogates
  25. };
  26. const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
  27. DynamicJsonDocument doc(4096);
  28. for (size_t i = 0; i < testCount; i++) {
  29. const char* input = testCases[i];
  30. CAPTURE(input);
  31. REQUIRE(deserializeJson(doc, input) == DeserializationError::Ok);
  32. }
  33. }