deserializationErrors.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. static void check(const char* input, MsgPackError expected,
  7. uint8_t nestingLimit = 10) {
  8. DynamicJsonVariant variant;
  9. MsgPackError error = deserializeMsgPack(variant, input, nestingLimit);
  10. REQUIRE(error == expected);
  11. }
  12. TEST_CASE("Errors returned by deserializeMsgPack()") {
  13. SECTION("unsupported") {
  14. check("\xc4", MsgPackError::NotSupported); // bin 8
  15. check("\xc5", MsgPackError::NotSupported); // bin 16
  16. check("\xc6", MsgPackError::NotSupported); // bin 32
  17. check("\xc7", MsgPackError::NotSupported); // ext 8
  18. check("\xc8", MsgPackError::NotSupported); // ext 16
  19. check("\xc9", MsgPackError::NotSupported); // ext 32
  20. check("\xd4", MsgPackError::NotSupported); // fixext 1
  21. check("\xd5", MsgPackError::NotSupported); // fixext 2
  22. check("\xd6", MsgPackError::NotSupported); // fixext 4
  23. check("\xd7", MsgPackError::NotSupported); // fixext 8
  24. check("\xd8", MsgPackError::NotSupported); // fixext 16
  25. }
  26. SECTION("unsupported in array") {
  27. check("\x91\xc4", MsgPackError::NotSupported);
  28. }
  29. SECTION("unsupported in map") {
  30. check("\x81\xc4\x00\xA1H", MsgPackError::NotSupported);
  31. check("\x81\xA1H\xc4\x00", MsgPackError::NotSupported);
  32. }
  33. SECTION("integer as key") {
  34. check("\x81\x01\xA1H", MsgPackError::NotSupported);
  35. }
  36. SECTION("object too deep") {
  37. check("\x80", MsgPackError::TooDeep, 0); // {}
  38. check("\x80", MsgPackError::Ok, 1); // {}
  39. check("\x81\xA1H\x80", MsgPackError::TooDeep, 1); // {H:{}}
  40. check("\x81\xA1H\x80", MsgPackError::Ok, 2); // {H:{}}
  41. }
  42. SECTION("array too deep") {
  43. check("\x90", MsgPackError::TooDeep, 0); // []
  44. check("\x90", MsgPackError::Ok, 1); // []
  45. check("\x91\x90", MsgPackError::TooDeep, 1); // [[]]
  46. check("\x91\x90", MsgPackError::Ok, 2); // [[]]
  47. }
  48. }