Tests: make allocator assertions more readable

This commit is contained in:
Benoit Blanchon
2023-07-26 06:06:38 +02:00
parent 30ec507989
commit 9a11d98117
31 changed files with 1127 additions and 1287 deletions

View File

@ -12,7 +12,6 @@
using ArduinoJson::detail::sizeofArray;
using ArduinoJson::detail::sizeofObject;
using ArduinoJson::detail::sizeofString;
typedef ArduinoJson::detail::MemberProxy<JsonDocument&, const char*>
MemberProxy;
@ -326,9 +325,10 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("example")),
});
}
SECTION("char*") {
@ -340,9 +340,10 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("example")),
});
}
SECTION("Arduino String") {
@ -353,9 +354,10 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("example")),
});
}
SECTION("Flash string") {
@ -366,9 +368,10 @@ TEST_CASE("Deduplicate keys") {
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
CHECK(key1 == key2);
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Allocate(sizeofString(7)));
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("example")),
});
}
}
@ -385,7 +388,8 @@ TEST_CASE("MemberProxy under memory constraints") {
REQUIRE(doc.is<JsonObject>());
REQUIRE(doc.size() == 0);
REQUIRE(doc.overflowed() == true);
REQUIRE(spy.log() == AllocatorLog()
<< AllocatorLog::AllocateFail(sizeofString(5)));
REQUIRE(spy.log() == AllocatorLog{
AllocateFail(sizeofString("hello")),
});
}
}