invalid_input.cpp 1.1 KB

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