string_length_size_2.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #define ARDUINOJSON_STRING_LENGTH_SIZE 2
  2. #include <ArduinoJson.h>
  3. #include <catch.hpp>
  4. #include <string>
  5. TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 2") {
  6. JsonDocument doc;
  7. SECTION("set() returns true if string has 65535 characters") {
  8. auto result = doc.set(std::string(65535, '?'));
  9. REQUIRE(result == true);
  10. REQUIRE(doc.overflowed() == false);
  11. }
  12. SECTION("set() returns false if string has 65536 characters") {
  13. auto result = doc.set(std::string(65536, '?'));
  14. REQUIRE(result == false);
  15. REQUIRE(doc.overflowed() == true);
  16. }
  17. SECTION("deserializeJson() returns Ok if string has 65535 characters") {
  18. auto input = "\"" + std::string(65535, '?') + "\"";
  19. auto err = deserializeJson(doc, input);
  20. REQUIRE(err == DeserializationError::Ok);
  21. }
  22. SECTION("deserializeJson() returns NoMemory if string has 65536 characters") {
  23. auto input = "\"" + std::string(65536, '?') + "\"";
  24. auto err = deserializeJson(doc, input);
  25. REQUIRE(err == DeserializationError::NoMemory);
  26. }
  27. SECTION("deserializeMsgPack() returns Ok of string has 65535 characters") {
  28. auto input = "\xda\xff\xff" + std::string(65535, '?');
  29. auto err = deserializeMsgPack(doc, input);
  30. REQUIRE(err == DeserializationError::Ok);
  31. }
  32. SECTION(
  33. "deserializeMsgPack() returns NoMemory of string has 65536 characters") {
  34. auto input =
  35. std::string("\xdb\x00\x01\x00\x00", 5) + std::string(65536, '?');
  36. auto err = deserializeMsgPack(doc, input);
  37. REQUIRE(err == DeserializationError::NoMemory);
  38. }
  39. }