invalid_input.cpp 1019 B

12345678910111213141516171819202122232425262728293031323334
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  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'",
  9. "'\\u000G'", "'\\u000/'", "\\x1234"};
  10. const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
  11. DynamicJsonDocument doc(4096);
  12. for (size_t i = 0; i < testCount; i++) {
  13. const char* input = testCases[i];
  14. CAPTURE(input);
  15. REQUIRE(deserializeJson(doc, input) == DeserializationError::InvalidInput);
  16. }
  17. }
  18. TEST_CASE("Invalid JSON input that should pass") {
  19. const char* testCases[] = {"nulL", "tru3", "fals3"};
  20. const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
  21. DynamicJsonDocument doc(4096);
  22. for (size_t i = 0; i < testCount; i++) {
  23. const char* input = testCases[i];
  24. CAPTURE(input);
  25. REQUIRE(deserializeJson(doc, input) == DeserializationError::Ok);
  26. }
  27. }