Create more memory pools as needed (resolves #1074)

This commit is contained in:
Benoit Blanchon
2023-07-17 14:39:57 +02:00
parent 65c67d317a
commit 42b2840009
22 changed files with 396 additions and 312 deletions

View File

@ -10,80 +10,81 @@
using ArduinoJson::detail::sizeofArray;
TEST_CASE("JsonDocument::overflowed()") {
TimebombAllocator allocator(10);
JsonDocument doc(0, &allocator);
SECTION("returns false on a fresh object") {
JsonDocument doc(0);
allocator.setCountdown(0);
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed insertion") {
JsonDocument doc(0);
allocator.setCountdown(0);
doc.add(0);
CHECK(doc.overflowed() == true);
}
SECTION("returns false after successful insertion") {
JsonDocument doc(sizeofArray(1));
allocator.setCountdown(2);
doc.add(0);
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed string copy") {
ControllableAllocator allocator;
JsonDocument doc(sizeofArray(1), &allocator);
allocator.disable();
allocator.setCountdown(0);
doc.add(std::string("example"));
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful string copy") {
JsonDocument doc(sizeofArray(1));
allocator.setCountdown(3);
doc.add(std::string("example"));
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed member add") {
JsonDocument doc(1);
allocator.setCountdown(0);
doc["example"] = true;
CHECK(doc.overflowed() == true);
}
SECTION("returns true after a failed deserialization") {
JsonDocument doc(sizeofArray(1));
allocator.setCountdown(1);
deserializeJson(doc, "[1, 2]");
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful deserialization") {
JsonDocument doc(sizeofArray(1));
allocator.setCountdown(4);
deserializeJson(doc, "[\"example\"]");
CHECK(doc.overflowed() == false);
}
SECTION("returns false after clear()") {
JsonDocument doc(0);
allocator.setCountdown(0);
doc.add(0);
doc.clear();
CHECK(doc.overflowed() == false);
}
SECTION("remains false after shrinkToFit()") {
JsonDocument doc(sizeofArray(1));
allocator.setCountdown(2);
doc.add(0);
allocator.setCountdown(2);
doc.shrinkToFit();
CHECK(doc.overflowed() == false);
}
SECTION("remains true after shrinkToFit()") {
JsonDocument doc(sizeofArray(1));
doc.add(0);
allocator.setCountdown(0);
doc.add(0);
allocator.setCountdown(2);
doc.shrinkToFit();
CHECK(doc.overflowed() == true);
}
SECTION("return false after garbageCollect()") {
JsonDocument doc(sizeofArray(1));
doc.add(0);
allocator.setCountdown(0);
doc.add(0);
doc.garbageCollect();
CHECK(doc.overflowed() == false);