notSupported.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. static void checkMsgPackDocument(const char* input, size_t inputSize,
  7. const char* expectedJson) {
  8. DynamicJsonDocument doc(4096);
  9. DeserializationError error = deserializeMsgPack(doc, input, inputSize);
  10. REQUIRE(error == DeserializationError::Ok);
  11. std::string actualJson;
  12. serializeJson(doc, actualJson);
  13. REQUIRE(actualJson == expectedJson);
  14. }
  15. static void checkMsgPackError(const char* input, size_t inputSize,
  16. DeserializationError expectedError) {
  17. DynamicJsonDocument doc(4096);
  18. DeserializationError error = deserializeMsgPack(doc, input, inputSize);
  19. REQUIRE(error == expectedError);
  20. }
  21. TEST_CASE("deserializeMsgPack() return NotSupported") {
  22. SECTION("bin 8") {
  23. checkMsgPackDocument("\x92\xc4\x01X\x2A", 5, "[null,42]");
  24. }
  25. SECTION("bin 16") {
  26. checkMsgPackDocument("\x92\xc5\x00\x01X\x2A", 6, "[null,42]");
  27. }
  28. SECTION("bin 32") {
  29. checkMsgPackDocument("\x92\xc6\x00\x00\x00\x01X\x2A", 8, "[null,42]");
  30. }
  31. SECTION("ext 8") {
  32. checkMsgPackDocument("\x92\xc7\x01\x01\x01\x2A", 6, "[null,42]");
  33. }
  34. SECTION("ext 16") {
  35. checkMsgPackDocument("\x92\xc8\x00\x01\x01\x01\x2A", 7, "[null,42]");
  36. }
  37. SECTION("ext 32") {
  38. checkMsgPackDocument("\x92\xc9\x00\x00\x00\x01\x01\x01\x2A", 9,
  39. "[null,42]");
  40. }
  41. SECTION("fixext 1") {
  42. checkMsgPackDocument("\x92\xd4\x01\x01\x2A", 5, "[null,42]");
  43. }
  44. SECTION("fixext 2") {
  45. checkMsgPackDocument("\x92\xd5\x01\x01\x02\x2A", 6, "[null,42]");
  46. }
  47. SECTION("fixext 4") {
  48. checkMsgPackDocument("\x92\xd6\x01\x01\x02\x03\x04\x2A", 8, "[null,42]");
  49. }
  50. SECTION("fixext 8") {
  51. checkMsgPackDocument("\x92\xd7\x01\x01\x02\x03\x04\x05\x06\x07\x08\x2A", 12,
  52. "[null,42]");
  53. }
  54. SECTION("fixext 16") {
  55. checkMsgPackDocument(
  56. "\x92\xd8\x01\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E"
  57. "\x0F\x10\x2A",
  58. 20, "[null,42]");
  59. }
  60. SECTION("integer as key") {
  61. checkMsgPackError("\x81\x01\xA1H", 3, DeserializationError::InvalidInput);
  62. }
  63. }