Store the strings in the heap

This commit is contained in:
Benoit Blanchon
2023-04-11 10:03:47 +02:00
parent 7c0fa7c276
commit d8f3058efa
27 changed files with 434 additions and 377 deletions

View File

@ -5,8 +5,9 @@
#include <ArduinoJson.h>
#include <catch.hpp>
#include "Allocators.hpp"
using ArduinoJson::detail::sizeofArray;
using ArduinoJson::detail::sizeofString;
TEST_CASE("JsonDocument::overflowed()") {
SECTION("returns false on a fresh object") {
@ -27,13 +28,15 @@ TEST_CASE("JsonDocument::overflowed()") {
}
SECTION("returns true after a failed string copy") {
JsonDocument doc(sizeofArray(1));
ControllableAllocator allocator;
JsonDocument doc(sizeofArray(1), &allocator);
allocator.disable();
doc.add(std::string("example"));
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful string copy") {
JsonDocument doc(sizeofArray(1) + sizeofString(7));
JsonDocument doc(sizeofArray(1));
doc.add(std::string("example"));
CHECK(doc.overflowed() == false);
}
@ -46,12 +49,12 @@ TEST_CASE("JsonDocument::overflowed()") {
SECTION("returns true after a failed deserialization") {
JsonDocument doc(sizeofArray(1));
deserializeJson(doc, "[\"example\"]");
deserializeJson(doc, "[1, 2]");
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful deserialization") {
JsonDocument doc(sizeofArray(1) + sizeofString(7));
JsonDocument doc(sizeofArray(1));
deserializeJson(doc, "[\"example\"]");
CHECK(doc.overflowed() == false);
}