string_length_size_1.cpp 1.5 KB

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