mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 20:12:16 +02:00
Add ARDUINOJSON_STRING_LENGTH_SIZE
to the namespace name
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
ArduinoJson: change log
|
ArduinoJson: change log
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
* Add `ARDUINOJSON_STRING_LENGTH_SIZE` to the namespace name
|
||||||
|
|
||||||
v7.0.4 (2024-03-12)
|
v7.0.4 (2024-03-12)
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -15,6 +15,9 @@ add_executable(MixedConfigurationTests
|
|||||||
enable_nan_1.cpp
|
enable_nan_1.cpp
|
||||||
enable_progmem_1.cpp
|
enable_progmem_1.cpp
|
||||||
issue1707.cpp
|
issue1707.cpp
|
||||||
|
string_length_size_1.cpp
|
||||||
|
string_length_size_2.cpp
|
||||||
|
string_length_size_4.cpp
|
||||||
use_double_0.cpp
|
use_double_0.cpp
|
||||||
use_double_1.cpp
|
use_double_1.cpp
|
||||||
use_long_long_0.cpp
|
use_long_long_0.cpp
|
||||||
|
56
extras/tests/MixedConfiguration/string_length_size_1.cpp
Normal file
56
extras/tests/MixedConfiguration/string_length_size_1.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#define ARDUINOJSON_STRING_LENGTH_SIZE 1
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 1") {
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
SECTION("set() returns true if string has 255 characters") {
|
||||||
|
auto result = doc.set(std::string(255, '?'));
|
||||||
|
|
||||||
|
REQUIRE(result == true);
|
||||||
|
REQUIRE(doc.overflowed() == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("set() returns false if string has 256 characters") {
|
||||||
|
auto result = doc.set(std::string(256, '?'));
|
||||||
|
|
||||||
|
REQUIRE(result == false);
|
||||||
|
REQUIRE(doc.overflowed() == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeJson() returns Ok if string has 255 characters") {
|
||||||
|
auto input = "\"" + std::string(255, '?') + "\"";
|
||||||
|
|
||||||
|
auto err = deserializeJson(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeJson() returns NoMemory if string has 256 characters") {
|
||||||
|
auto input = "\"" + std::string(256, '?') + "\"";
|
||||||
|
|
||||||
|
auto err = deserializeJson(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::NoMemory);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeMsgPack() returns Ok of string has 255 characters") {
|
||||||
|
auto input = "\xd9\xff" + std::string(255, '?');
|
||||||
|
|
||||||
|
auto err = deserializeMsgPack(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION(
|
||||||
|
"deserializeMsgPack() returns NoMemory of string has 256 characters") {
|
||||||
|
auto input = std::string("\xda\x01\x00", 3) + std::string(256, '?');
|
||||||
|
|
||||||
|
auto err = deserializeMsgPack(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::NoMemory);
|
||||||
|
}
|
||||||
|
}
|
57
extras/tests/MixedConfiguration/string_length_size_2.cpp
Normal file
57
extras/tests/MixedConfiguration/string_length_size_2.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#define ARDUINOJSON_STRING_LENGTH_SIZE 2
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 2") {
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
SECTION("set() returns true if string has 65535 characters") {
|
||||||
|
auto result = doc.set(std::string(65535, '?'));
|
||||||
|
|
||||||
|
REQUIRE(result == true);
|
||||||
|
REQUIRE(doc.overflowed() == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("set() returns false if string has 65536 characters") {
|
||||||
|
auto result = doc.set(std::string(65536, '?'));
|
||||||
|
|
||||||
|
REQUIRE(result == false);
|
||||||
|
REQUIRE(doc.overflowed() == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeJson() returns Ok if string has 65535 characters") {
|
||||||
|
auto input = "\"" + std::string(65535, '?') + "\"";
|
||||||
|
|
||||||
|
auto err = deserializeJson(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeJson() returns NoMemory if string has 65536 characters") {
|
||||||
|
auto input = "\"" + std::string(65536, '?') + "\"";
|
||||||
|
|
||||||
|
auto err = deserializeJson(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::NoMemory);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeMsgPack() returns Ok of string has 65535 characters") {
|
||||||
|
auto input = "\xda\xff\xff" + std::string(65535, '?');
|
||||||
|
|
||||||
|
auto err = deserializeMsgPack(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION(
|
||||||
|
"deserializeMsgPack() returns NoMemory of string has 65536 characters") {
|
||||||
|
auto input =
|
||||||
|
std::string("\xdb\x00\x01\x00\x00", 5) + std::string(65536, '?');
|
||||||
|
|
||||||
|
auto err = deserializeMsgPack(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::NoMemory);
|
||||||
|
}
|
||||||
|
}
|
32
extras/tests/MixedConfiguration/string_length_size_4.cpp
Normal file
32
extras/tests/MixedConfiguration/string_length_size_4.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#define ARDUINOJSON_STRING_LENGTH_SIZE 4
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 4") {
|
||||||
|
JsonDocument doc;
|
||||||
|
|
||||||
|
SECTION("set() returns true if string has 65536 characters") {
|
||||||
|
auto result = doc.set(std::string(65536, '?'));
|
||||||
|
|
||||||
|
REQUIRE(result == true);
|
||||||
|
REQUIRE(doc.overflowed() == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeJson() returns Ok if string has 65536 characters") {
|
||||||
|
auto input = "\"" + std::string(65536, '?') + "\"";
|
||||||
|
|
||||||
|
auto err = deserializeJson(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("deserializeMsgPack() returns Ok of string has 65536 characters") {
|
||||||
|
auto input = "\xda\xff\xff" + std::string(65536, '?');
|
||||||
|
|
||||||
|
auto err = deserializeMsgPack(doc, input);
|
||||||
|
|
||||||
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
|
}
|
||||||
|
}
|
@ -10,16 +10,16 @@
|
|||||||
|
|
||||||
#ifndef ARDUINOJSON_VERSION_NAMESPACE
|
#ifndef ARDUINOJSON_VERSION_NAMESPACE
|
||||||
|
|
||||||
# define ARDUINOJSON_VERSION_NAMESPACE \
|
# define ARDUINOJSON_VERSION_NAMESPACE \
|
||||||
ARDUINOJSON_CONCAT4(ARDUINOJSON_VERSION_MACRO, \
|
ARDUINOJSON_CONCAT5( \
|
||||||
ARDUINOJSON_BIN2ALPHA(ARDUINOJSON_ENABLE_PROGMEM, \
|
ARDUINOJSON_VERSION_MACRO, \
|
||||||
ARDUINOJSON_USE_LONG_LONG, \
|
ARDUINOJSON_BIN2ALPHA(ARDUINOJSON_ENABLE_PROGMEM, \
|
||||||
ARDUINOJSON_USE_DOUBLE, 1), \
|
ARDUINOJSON_USE_LONG_LONG, \
|
||||||
ARDUINOJSON_BIN2ALPHA(ARDUINOJSON_ENABLE_NAN, \
|
ARDUINOJSON_USE_DOUBLE, 1), \
|
||||||
ARDUINOJSON_ENABLE_INFINITY, \
|
ARDUINOJSON_BIN2ALPHA( \
|
||||||
ARDUINOJSON_ENABLE_COMMENTS, \
|
ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \
|
||||||
ARDUINOJSON_DECODE_UNICODE), \
|
ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE), \
|
||||||
ARDUINOJSON_SLOT_ID_SIZE)
|
ARDUINOJSON_SLOT_ID_SIZE, ARDUINOJSON_STRING_LENGTH_SIZE)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -6,8 +6,12 @@
|
|||||||
|
|
||||||
#define ARDUINOJSON_CONCAT_(A, B) A##B
|
#define ARDUINOJSON_CONCAT_(A, B) A##B
|
||||||
#define ARDUINOJSON_CONCAT2(A, B) ARDUINOJSON_CONCAT_(A, B)
|
#define ARDUINOJSON_CONCAT2(A, B) ARDUINOJSON_CONCAT_(A, B)
|
||||||
|
#define ARDUINOJSON_CONCAT3(A, B, C) \
|
||||||
|
ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT2(A, B), C)
|
||||||
#define ARDUINOJSON_CONCAT4(A, B, C, D) \
|
#define ARDUINOJSON_CONCAT4(A, B, C, D) \
|
||||||
ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT2(A, B), ARDUINOJSON_CONCAT2(C, D))
|
ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT3(A, B, C), D)
|
||||||
|
#define ARDUINOJSON_CONCAT5(A, B, C, D, E) \
|
||||||
|
ARDUINOJSON_CONCAT2(ARDUINOJSON_CONCAT4(A, B, C, D), E)
|
||||||
|
|
||||||
#define ARDUINOJSON_BIN2ALPHA_0000() A
|
#define ARDUINOJSON_BIN2ALPHA_0000() A
|
||||||
#define ARDUINOJSON_BIN2ALPHA_0001() B
|
#define ARDUINOJSON_BIN2ALPHA_0001() B
|
||||||
|
Reference in New Issue
Block a user