Files
ArduinoJson/extras/tests/MixedConfiguration/string_length_size_2.cpp

97 lines
2.5 KiB
C++
Raw Normal View History

#define ARDUINOJSON_STRING_LENGTH_SIZE 2
#include <ArduinoJson.h>
#include <catch.hpp>
#include <string>
TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 2") {
JsonDocument doc;
2024-06-06 18:26:16 +02:00
SECTION("set(std::string)") {
SECTION("returns true if len <= 65535") {
auto result = doc.set(std::string(65535, '?'));
2024-06-06 18:26:16 +02:00
REQUIRE(result == true);
REQUIRE(doc.overflowed() == false);
}
2024-06-06 18:26:16 +02:00
SECTION("returns false if len >= 65536") {
auto result = doc.set(std::string(65536, '?'));
2024-06-06 18:26:16 +02:00
REQUIRE(result == false);
REQUIRE(doc.overflowed() == true);
}
}
2024-06-06 18:26:16 +02:00
SECTION("set(MsgPackBinary)") {
SECTION("returns true if size <= 65532") {
auto str = std::string(65532, '?');
auto result = doc.set(MsgPackBinary(str.data(), str.size()));
2024-06-06 18:26:16 +02:00
REQUIRE(result == true);
REQUIRE(doc.overflowed() == false);
}
2024-06-06 18:26:16 +02:00
SECTION("returns false if size >= 65533") {
auto str = std::string(65533, '?');
auto result = doc.set(MsgPackBinary(str.data(), str.size()));
2024-06-06 18:26:16 +02:00
REQUIRE(result == false);
REQUIRE(doc.overflowed() == true);
}
}
2024-06-06 18:26:16 +02:00
SECTION("deserializeJson()") {
SECTION("returns Ok if string length <= 65535") {
auto input = "\"" + std::string(65535, '?') + "\"";
2024-06-06 18:26:16 +02:00
auto err = deserializeJson(doc, input);
2024-06-06 18:26:16 +02:00
REQUIRE(err == DeserializationError::Ok);
}
2024-06-06 18:26:16 +02:00
SECTION("returns NoMemory if string length >= 65536") {
auto input = "\"" + std::string(65536, '?') + "\"";
2024-06-06 18:26:16 +02:00
auto err = deserializeJson(doc, input);
2024-06-06 18:26:16 +02:00
REQUIRE(err == DeserializationError::NoMemory);
}
}
2024-06-06 18:26:16 +02:00
SECTION("deserializeMsgPack()") {
SECTION("returns Ok if string length <= 65535") {
auto input = "\xda\xff\xff" + std::string(65535, '?');
2024-06-06 18:26:16 +02:00
auto err = deserializeMsgPack(doc, input);
2024-06-06 18:26:16 +02:00
REQUIRE(err == DeserializationError::Ok);
}
2024-06-06 18:26:16 +02:00
SECTION("returns NoMemory if string length >= 65536") {
auto input =
std::string("\xdb\x00\x01\x00\x00", 5) + std::string(65536, '?');
2024-06-06 18:26:16 +02:00
auto err = deserializeMsgPack(doc, input);
2024-06-06 18:26:16 +02:00
REQUIRE(err == DeserializationError::NoMemory);
}
2024-06-06 18:26:16 +02:00
SECTION("returns Ok if binary size <= 65532") {
auto input = "\xc5\xff\xfc" + std::string(65532, '?');
2024-06-06 18:26:16 +02:00
auto err = deserializeMsgPack(doc, input);
2024-06-06 18:26:16 +02:00
REQUIRE(err == DeserializationError::Ok);
}
2024-06-06 18:26:16 +02:00
SECTION("returns NoMemory if binary size >= 65534") {
auto input = "\xc5\xff\xfd" + std::string(65534, '?');
2024-06-06 18:26:16 +02:00
auto err = deserializeMsgPack(doc, input);
2024-06-06 18:26:16 +02:00
REQUIRE(err == DeserializationError::NoMemory);
}
}
}