Tests: use a consistent naming convention for allocators

This commit is contained in:
Benoit Blanchon
2023-07-25 14:53:54 +02:00
parent 7a76da3bc7
commit 30ec507989
25 changed files with 698 additions and 698 deletions

View File

@ -315,8 +315,8 @@ TEST_CASE("MemberProxy::createNestedObject(key)") {
}
TEST_CASE("Deduplicate keys") {
SpyingAllocator allocator;
JsonDocument doc(&allocator);
SpyingAllocator spy;
JsonDocument doc(&spy);
SECTION("std::string") {
doc[0][std::string("example")] = 1;
@ -326,9 +326,9 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
SECTION("char*") {
@ -340,9 +340,9 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
SECTION("Arduino String") {
@ -353,9 +353,9 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
SECTION("Flash string") {
@ -366,9 +366,9 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
}

View File

@ -14,23 +14,23 @@ using ArduinoJson::detail::sizeofArray;
using ArduinoJson::detail::sizeofString;
TEST_CASE("JsonDocument::add()") {
SpyingAllocator allocator;
JsonDocument doc(&allocator);
SpyingAllocator spy;
JsonDocument doc(&spy);
SECTION("integer") {
doc.add(42);
REQUIRE(doc.as<std::string>() == "[42]");
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool()));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool()));
}
SECTION("const char*") {
doc.add("hello");
REQUIRE(doc.as<std::string>() == "[\"hello\"]");
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool()));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool()));
}
SECTION("std::string") {
@ -38,9 +38,9 @@ TEST_CASE("JsonDocument::add()") {
doc.add(std::string("example"));
CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
SECTION("char*") {
@ -49,9 +49,9 @@ TEST_CASE("JsonDocument::add()") {
doc.add(value);
CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
SECTION("Arduino String") {
@ -59,9 +59,9 @@ TEST_CASE("JsonDocument::add()") {
doc.add(String("example"));
CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
SECTION("Flash string") {
@ -69,8 +69,8 @@ TEST_CASE("JsonDocument::add()") {
doc.add(F("example"));
CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
REQUIRE(allocator.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
}
}

View File

@ -8,75 +8,75 @@
#include "Allocators.hpp"
TEST_CASE("JsonDocument::overflowed()") {
TimebombAllocator allocator(10);
JsonDocument doc(&allocator);
TimebombAllocator timebomb(10);
JsonDocument doc(&timebomb);
SECTION("returns false on a fresh object") {
allocator.setCountdown(0);
timebomb.setCountdown(0);
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed insertion") {
allocator.setCountdown(0);
timebomb.setCountdown(0);
doc.add(0);
CHECK(doc.overflowed() == true);
}
SECTION("returns false after successful insertion") {
allocator.setCountdown(2);
timebomb.setCountdown(2);
doc.add(0);
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed string copy") {
allocator.setCountdown(0);
timebomb.setCountdown(0);
doc.add(std::string("example"));
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful string copy") {
allocator.setCountdown(3);
timebomb.setCountdown(3);
doc.add(std::string("example"));
CHECK(doc.overflowed() == false);
}
SECTION("returns true after a failed member add") {
allocator.setCountdown(0);
timebomb.setCountdown(0);
doc["example"] = true;
CHECK(doc.overflowed() == true);
}
SECTION("returns true after a failed deserialization") {
allocator.setCountdown(0);
timebomb.setCountdown(0);
deserializeJson(doc, "[1, 2]");
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful deserialization") {
allocator.setCountdown(3);
timebomb.setCountdown(3);
deserializeJson(doc, "[\"example\"]");
CHECK(doc.overflowed() == false);
}
SECTION("returns false after clear()") {
allocator.setCountdown(0);
timebomb.setCountdown(0);
doc.add(0);
doc.clear();
CHECK(doc.overflowed() == false);
}
SECTION("remains false after shrinkToFit()") {
allocator.setCountdown(2);
timebomb.setCountdown(2);
doc.add(0);
allocator.setCountdown(2);
timebomb.setCountdown(2);
doc.shrinkToFit();
CHECK(doc.overflowed() == false);
}
SECTION("remains true after shrinkToFit()") {
allocator.setCountdown(0);
timebomb.setCountdown(0);
doc.add(0);
allocator.setCountdown(2);
timebomb.setCountdown(2);
doc.shrinkToFit();
CHECK(doc.overflowed() == true);
}