nestingLimit.cpp 964 B

12345678910111213141516171819202122232425262728293031
  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, uint8_t limit) {
  7. DynamicJsonDocument doc;
  8. doc.nestingLimit = limit;
  9. MsgPackError error = deserializeMsgPack(doc, input);
  10. REQUIRE(error == expected);
  11. }
  12. TEST_CASE("Errors returned by deserializeMsgPack()") {
  13. SECTION("object too deep") {
  14. check("\x80", MsgPackError::TooDeep, 0); // {}
  15. check("\x80", MsgPackError::Ok, 1); // {}
  16. check("\x81\xA1H\x80", MsgPackError::TooDeep, 1); // {H:{}}
  17. check("\x81\xA1H\x80", MsgPackError::Ok, 2); // {H:{}}
  18. }
  19. SECTION("array too deep") {
  20. check("\x90", MsgPackError::TooDeep, 0); // []
  21. check("\x90", MsgPackError::Ok, 1); // []
  22. check("\x91\x90", MsgPackError::TooDeep, 1); // [[]]
  23. check("\x91\x90", MsgPackError::Ok, 2); // [[]]
  24. }
  25. }