diff --git a/extras/tests/Cpp17/string_view.cpp b/extras/tests/Cpp17/string_view.cpp index 7bd96361..31b95e3f 100644 --- a/extras/tests/Cpp17/string_view.cpp +++ b/extras/tests/Cpp17/string_view.cpp @@ -10,7 +10,6 @@ #endif using ArduinoJson::detail::sizeofArray; -using ArduinoJson::detail::sizeofString; TEST_CASE("string_view") { SpyingAllocator spy; @@ -63,10 +62,11 @@ TEST_CASE("string_view") { doc.add(std::string_view("example\0tree", 12)); doc.add(std::string_view("example\0tree and a half", 12)); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(7)) - << AllocatorLog::Allocate(sizeofString(12))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("example")), + Allocate(sizeofString("example tree")), + }); } SECTION("as()") { diff --git a/extras/tests/Helpers/Allocators.hpp b/extras/tests/Helpers/Allocators.hpp index 8bac44ed..ab332c22 100644 --- a/extras/tests/Helpers/Allocators.hpp +++ b/extras/tests/Helpers/Allocators.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -30,63 +31,68 @@ struct FailingAllocator : ArduinoJson::Allocator { } }; +class AllocatorLogEntry { + public: + AllocatorLogEntry(std::string s, size_t n = 1) : str_(s), count_(n) {} + + const std::string& str() const { + return str_; + } + + size_t count() const { + return count_; + } + + AllocatorLogEntry operator*(size_t n) const { + return AllocatorLogEntry(str_, n); + } + + private: + std::string str_; + size_t count_; +}; + +inline AllocatorLogEntry Allocate(size_t s) { + char buffer[32]; + sprintf(buffer, "allocate(%zu)", s); + return AllocatorLogEntry(buffer); +} + +inline AllocatorLogEntry AllocateFail(size_t s) { + char buffer[32]; + sprintf(buffer, "allocate(%zu) -> nullptr", s); + return AllocatorLogEntry(buffer); +} + +inline AllocatorLogEntry Reallocate(size_t s1, size_t s2) { + char buffer[32]; + sprintf(buffer, "reallocate(%zu, %zu)", s1, s2); + return AllocatorLogEntry(buffer); +} + +inline AllocatorLogEntry ReallocateFail(size_t s1, size_t s2) { + char buffer[32]; + sprintf(buffer, "reallocate(%zu, %zu) -> nullptr", s1, s2); + return AllocatorLogEntry(buffer); +} + +inline AllocatorLogEntry Deallocate(size_t s) { + char buffer[32]; + sprintf(buffer, "deallocate(%zu)", s); + return AllocatorLogEntry(buffer); +} + class AllocatorLog { public: - class Entry { - public: - Entry(std::string s, size_t n = 1) : str_(s), count_(n) {} - - const std::string& str() const { - return str_; - } - - size_t count() const { - return count_; - } - - Entry operator*(size_t n) const { - return Entry(str_, n); - } - - private: - std::string str_; - size_t count_; - }; - - static Entry Allocate(size_t s) { - char buffer[32]; - sprintf(buffer, "allocate(%zu)", s); - return Entry(buffer); + AllocatorLog() = default; + AllocatorLog(std::initializer_list list) { + for (auto& entry : list) + append(entry); } - static Entry AllocateFail(size_t s) { - char buffer[32]; - sprintf(buffer, "allocate(%zu) -> nullptr", s); - return Entry(buffer); - } - - static Entry Reallocate(size_t s1, size_t s2) { - char buffer[32]; - sprintf(buffer, "reallocate(%zu, %zu)", s1, s2); - return Entry(buffer); - }; - - static Entry ReallocateFail(size_t s1, size_t s2) { - char buffer[32]; - sprintf(buffer, "reallocate(%zu, %zu) -> nullptr", s1, s2); - return Entry(buffer); - }; - - static Entry Deallocate(size_t s) { - char buffer[32]; - sprintf(buffer, "deallocate(%zu)", s); - return Entry(buffer); - }; - - AllocatorLog& operator<<(const Entry& entry) { + void append(const AllocatorLogEntry& entry) { for (size_t i = 0; i < entry.count(); i++) log_ << entry.str() << "\n"; - return *this; } std::string str() const { @@ -125,12 +131,12 @@ class SpyingAllocator : public ArduinoJson::Allocator { auto block = reinterpret_cast( upstream_->allocate(sizeof(AllocatedBlock) + n - 1)); if (block) { - log_ << AllocatorLog::Allocate(n); + log_.append(Allocate(n)); allocatedBytes_ += n; block->size = n; return block->payload; } else { - log_ << AllocatorLog::AllocateFail(n); + log_.append(AllocateFail(n)); return nullptr; } } @@ -138,7 +144,7 @@ class SpyingAllocator : public ArduinoJson::Allocator { void deallocate(void* p) override { auto block = AllocatedBlock::fromPayload(p); allocatedBytes_ -= block->size; - log_ << AllocatorLog::Deallocate(block ? block->size : 0); + log_.append(Deallocate(block ? block->size : 0)); upstream_->deallocate(block); } @@ -148,12 +154,12 @@ class SpyingAllocator : public ArduinoJson::Allocator { block = reinterpret_cast( upstream_->reallocate(block, sizeof(AllocatedBlock) + n - 1)); if (block) { - log_ << AllocatorLog::Reallocate(oldSize, n); + log_.append(Reallocate(oldSize, n)); block->size = n; allocatedBytes_ += n - oldSize; return block->payload; } else { - log_ << AllocatorLog::ReallocateFail(oldSize, n); + log_.append(ReallocateFail(oldSize, n)); return nullptr; } } @@ -259,3 +265,15 @@ inline size_t sizeofPool( ArduinoJson::detail::SlotCount n = ARDUINOJSON_POOL_CAPACITY) { return ArduinoJson::detail::VariantPool::slotsToBytes(n); } + +inline size_t sizeofStringBuffer(size_t iteration = 1) { + // returns 31, 63, 127, 255, etc. + auto capacity = ArduinoJson::detail::StringBuilder::initialCapacity; + for (size_t i = 1; i < iteration; i++) + capacity = capacity * 2 + 1; + return ArduinoJson::detail::sizeofString(capacity); +} + +inline size_t sizeofString(const char* s) { + return ArduinoJson::detail::sizeofString(strlen(s)); +} diff --git a/extras/tests/JsonArray/add.cpp b/extras/tests/JsonArray/add.cpp index a248dd37..5ef38797 100644 --- a/extras/tests/JsonArray/add.cpp +++ b/extras/tests/JsonArray/add.cpp @@ -8,7 +8,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofArray; -using ArduinoJson::detail::sizeofString; TEST_CASE("JsonArray::add()") { SpyingAllocator spy; @@ -102,49 +101,56 @@ TEST_CASE("JsonArray::add()") { SECTION("should not duplicate const char*") { array.add("world"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("should duplicate char*") { array.add(const_cast("world")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should duplicate std::string") { array.add(std::string("world")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should duplicate serialized(const char*)") { array.add(serialized("{}")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(2))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("{}")), + }); } SECTION("should duplicate serialized(char*)") { array.add(serialized(const_cast("{}"))); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(2))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("{}")), + }); } SECTION("should duplicate serialized(std::string)") { array.add(serialized(std::string("{}"))); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(2))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("{}")), + }); } SECTION("should duplicate serialized(std::string)") { array.add(serialized(std::string("\0XX", 3))); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(3))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString(" XX")), + }); } } diff --git a/extras/tests/JsonArray/clear.cpp b/extras/tests/JsonArray/clear.cpp index 37cd7594..0e3f2970 100644 --- a/extras/tests/JsonArray/clear.cpp +++ b/extras/tests/JsonArray/clear.cpp @@ -39,7 +39,8 @@ TEST_CASE("JsonArray::clear()") { for (int i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++) array.add(i); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } } diff --git a/extras/tests/JsonArray/remove.cpp b/extras/tests/JsonArray/remove.cpp index 8baaa88c..99c5e53b 100644 --- a/extras/tests/JsonArray/remove.cpp +++ b/extras/tests/JsonArray/remove.cpp @@ -105,7 +105,7 @@ TEST_CASE("Removed elements are recycled") { // add one element; it should use the free slot array.add(42); - REQUIRE(spy.log() == AllocatorLog() << AllocatorLog::Allocate( - sizeofPool()) // only one pool - ); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), // only one pool + }); } diff --git a/extras/tests/JsonArray/subscript.cpp b/extras/tests/JsonArray/subscript.cpp index ec90a8fb..530a76a1 100644 --- a/extras/tests/JsonArray/subscript.cpp +++ b/extras/tests/JsonArray/subscript.cpp @@ -9,7 +9,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofArray; -using ArduinoJson::detail::sizeofString; TEST_CASE("JsonArray::operator[]") { SpyingAllocator spy; @@ -118,22 +117,25 @@ TEST_CASE("JsonArray::operator[]") { SECTION("should not duplicate const char*") { array[0] = "world"; - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("should duplicate char*") { array[0] = const_cast("world"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should duplicate std::string") { array[0] = std::string("world"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("array[0].to()") { diff --git a/extras/tests/JsonDeserializer/array.cpp b/extras/tests/JsonDeserializer/array.cpp index 92f44fc3..2c0e4460 100644 --- a/extras/tests/JsonDeserializer/array.cpp +++ b/extras/tests/JsonDeserializer/array.cpp @@ -8,7 +8,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofArray; -using ArduinoJson::detail::sizeofString; TEST_CASE("deserialize JSON array") { SpyingAllocator spy; @@ -254,9 +253,10 @@ TEST_CASE("deserialize JSON array") { JsonArray arr = doc.as(); REQUIRE(arr.size() == 0); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Deallocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Deallocate(sizeofPool()), + }); } } @@ -307,10 +307,11 @@ TEST_CASE("deserialize JSON array under memory constraints") { SECTION("don't store space characters") { deserializeJson(doc, " [ \"1234567\" ] "); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("1234567")), + }); } } diff --git a/extras/tests/JsonDeserializer/filter.cpp b/extras/tests/JsonDeserializer/filter.cpp index 3c847d9f..cc1f2a28 100644 --- a/extras/tests/JsonDeserializer/filter.cpp +++ b/extras/tests/JsonDeserializer/filter.cpp @@ -13,7 +13,6 @@ using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; TEST_CASE("Filtering") { struct TestCase { @@ -49,7 +48,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"abcdefg\":\"hijklmn\"}", - sizeofObject(1) + 2*sizeofString(7) + sizeofObject(1) + sizeofString("abcdefg") + sizeofString("hijklmn") }, { "{\"hello\":\"world\"}", @@ -75,7 +74,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":null}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // Member is a number, but filter wants an array @@ -84,7 +83,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":null}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // Input is an array, but filter wants an object @@ -120,7 +119,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // skip a float @@ -129,7 +128,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // skip false @@ -138,7 +137,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // skip true @@ -147,7 +146,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // skip null @@ -156,7 +155,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip a double-quoted string @@ -165,7 +164,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip a single-quoted string @@ -174,7 +173,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip an empty array @@ -183,7 +182,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip an empty array with spaces in it @@ -192,7 +191,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip an array @@ -201,7 +200,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip an array with spaces in it @@ -210,7 +209,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip an empty object @@ -219,7 +218,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip an empty object with spaces in it @@ -228,7 +227,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // can skip an object @@ -237,7 +236,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // skip an object with spaces in it @@ -246,7 +245,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":42}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { "{\"an_integer\": 0,\"example\":{\"type\":\"int\",\"outcome\":42}}", @@ -254,7 +253,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":{\"outcome\":42}}", - 2 * sizeofObject(1) + 2*sizeofString(7) + 2 * sizeofObject(1) + 2*sizeofString("example") }, { // wildcard @@ -263,7 +262,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":{\"outcome\":42}}", - 2 * sizeofObject(1) + 2*sizeofString(7) + 2 * sizeofObject(1) + 2*sizeofString("example") }, { // exclusion filter (issue #1628) @@ -272,7 +271,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "{\"example\":1}", - sizeofObject(1) + sizeofString(7) + sizeofObject(1) + sizeofString("example") }, { // only the first element of array counts @@ -299,7 +298,7 @@ TEST_CASE("Filtering") { 10, DeserializationError::Ok, "[{\"example\":1},{\"example\":3}]", - sizeofArray(2) + 2 * sizeofObject(1) + sizeofString(7) + sizeofArray(2) + 2 * sizeofObject(1) + sizeofString("example") }, { "[',2,3]", diff --git a/extras/tests/JsonDeserializer/input_types.cpp b/extras/tests/JsonDeserializer/input_types.cpp index 69542ddf..2c57c000 100644 --- a/extras/tests/JsonDeserializer/input_types.cpp +++ b/extras/tests/JsonDeserializer/input_types.cpp @@ -11,7 +11,6 @@ #include "CustomReader.hpp" using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; TEST_CASE("deserializeJson(char*)") { SpyingAllocator spy; @@ -23,14 +22,14 @@ TEST_CASE("deserializeJson(char*)") { REQUIRE(err == DeserializationError::Ok); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(5))); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("world")), + }); } TEST_CASE("deserializeJson(unsigned char*, unsigned int)") { // issue #1897 diff --git a/extras/tests/JsonDeserializer/misc.cpp b/extras/tests/JsonDeserializer/misc.cpp index 950c660c..02e90c3f 100644 --- a/extras/tests/JsonDeserializer/misc.cpp +++ b/extras/tests/JsonDeserializer/misc.cpp @@ -117,8 +117,9 @@ TEST_CASE("deserializeJson(JsonDocument&)") { deserializeJson(doc, "{}"); REQUIRE(doc.is()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Deallocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Deallocate(sizeofPool()), + }); } } diff --git a/extras/tests/JsonDeserializer/object.cpp b/extras/tests/JsonDeserializer/object.cpp index 199b5c4e..eea4a027 100644 --- a/extras/tests/JsonDeserializer/object.cpp +++ b/extras/tests/JsonDeserializer/object.cpp @@ -8,7 +8,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; TEST_CASE("deserialize JSON object") { SpyingAllocator spy; @@ -285,26 +284,19 @@ TEST_CASE("deserialize JSON object") { REQUIRE(err == DeserializationError::Ok); REQUIRE(doc.as() == "{\"a\":2}"); REQUIRE(spy.log() == - AllocatorLog() - // a - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(1)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // b - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(1)) - // c - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(1)) - // string builder - << AllocatorLog::Allocate(sizeofString(31)) - // remove b & c - << AllocatorLog::Deallocate(sizeofString(1)) * 2 - // string builder - << AllocatorLog::Deallocate(sizeofString(31)) - - ); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("a")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("b")), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("c")), + Allocate(sizeofStringBuffer()), + Deallocate(sizeofString("b")), + Deallocate(sizeofString("c")), + Deallocate(sizeofStringBuffer()), + }); } SECTION("Repeated key with zero copy mode") { // issue #1697 @@ -331,22 +323,17 @@ TEST_CASE("deserialize JSON object") { REQUIRE(doc.is()); REQUIRE(obj.size() == 0); - REQUIRE(spy.log() == AllocatorLog() - // string "hello" - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(5)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string "world" - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(5)) - // free pool - << AllocatorLog::Deallocate(sizeofPool()) - // free "hello" and "world" - << AllocatorLog::Deallocate(sizeofString(5)) - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("world")), + Deallocate(sizeofPool()), + Deallocate(sizeofString("hello")), + Deallocate(sizeofString("world")), + }); } SECTION("Issue #1335") { diff --git a/extras/tests/JsonDeserializer/string.cpp b/extras/tests/JsonDeserializer/string.cpp index 2d2d1086..54b92207 100644 --- a/extras/tests/JsonDeserializer/string.cpp +++ b/extras/tests/JsonDeserializer/string.cpp @@ -10,7 +10,6 @@ using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; TEST_CASE("Valid JSON strings value") { struct TestCase { @@ -106,39 +105,43 @@ TEST_CASE("Allocation of the key fails") { SECTION("Quoted string, first member") { REQUIRE(deserializeJson(doc, "{\"example\":1}") == DeserializationError::NoMemory); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::AllocateFail(sizeofString(31))); + REQUIRE(spy.log() == AllocatorLog{ + AllocateFail(sizeofStringBuffer()), + }); } SECTION("Quoted string, second member") { timebomb.setCountdown(3); REQUIRE(deserializeJson(doc, "{\"hello\":1,\"world\"}") == DeserializationError::NoMemory); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::AllocateFail(sizeofString(31))); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("hello")), + Allocate(sizeofPool()), + AllocateFail(sizeofStringBuffer()), + }); } SECTION("Non-Quoted string, first member") { REQUIRE(deserializeJson(doc, "{example:1}") == DeserializationError::NoMemory); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::AllocateFail(sizeofString(31))); + REQUIRE(spy.log() == AllocatorLog{ + AllocateFail(sizeofStringBuffer()), + }); } SECTION("Non-Quoted string, second member") { timebomb.setCountdown(3); REQUIRE(deserializeJson(doc, "{hello:1,world}") == DeserializationError::NoMemory); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::AllocateFail(sizeofString(31))); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("hello")), + Allocate(sizeofPool()), + AllocateFail(sizeofStringBuffer()), + }); } } @@ -149,8 +152,9 @@ TEST_CASE("String allocation fails") { SECTION("Input is const char*") { REQUIRE(deserializeJson(doc, "\"hello\"") == DeserializationError::NoMemory); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::AllocateFail(sizeofString(31))); + REQUIRE(spy.log() == AllocatorLog{ + AllocateFail(sizeofStringBuffer()), + }); } } @@ -160,17 +164,14 @@ TEST_CASE("Deduplicate values") { deserializeJson(doc, "[\"example\",\"example\"]"); CHECK(doc[0].as() == doc[1].as()); - REQUIRE(spy.log() == AllocatorLog() - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder - << AllocatorLog::Allocate(sizeofString(31)) - // string "example" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // string builder - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("example")), + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } TEST_CASE("Deduplicate keys") { @@ -182,15 +183,12 @@ TEST_CASE("Deduplicate keys") { const char* key2 = doc[1].as().begin()->key().c_str(); CHECK(key1 == key2); - REQUIRE(spy.log() == AllocatorLog() - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder - << AllocatorLog::Allocate(sizeofString(31)) - // string "example" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // string builder - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("example")), + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } diff --git a/extras/tests/JsonDocument/ElementProxy.cpp b/extras/tests/JsonDocument/ElementProxy.cpp index 851f750a..d3f276d4 100644 --- a/extras/tests/JsonDocument/ElementProxy.cpp +++ b/extras/tests/JsonDocument/ElementProxy.cpp @@ -6,7 +6,6 @@ #include typedef ArduinoJson::detail::ElementProxy ElementProxy; -using ArduinoJson::detail::sizeofString; TEST_CASE("ElementProxy::add()") { JsonDocument doc; diff --git a/extras/tests/JsonDocument/MemberProxy.cpp b/extras/tests/JsonDocument/MemberProxy.cpp index 98c1415e..68fd62fc 100644 --- a/extras/tests/JsonDocument/MemberProxy.cpp +++ b/extras/tests/JsonDocument/MemberProxy.cpp @@ -12,7 +12,6 @@ using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; typedef ArduinoJson::detail::MemberProxy MemberProxy; @@ -326,9 +325,10 @@ TEST_CASE("Deduplicate keys") { const char* key2 = doc[1].as().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().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().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().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()); REQUIRE(doc.size() == 0); REQUIRE(doc.overflowed() == true); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::AllocateFail(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + AllocateFail(sizeofString("hello")), + }); } } diff --git a/extras/tests/JsonDocument/add.cpp b/extras/tests/JsonDocument/add.cpp index 577a1a12..65c6fc3b 100644 --- a/extras/tests/JsonDocument/add.cpp +++ b/extras/tests/JsonDocument/add.cpp @@ -11,7 +11,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofArray; -using ArduinoJson::detail::sizeofString; TEST_CASE("JsonDocument::add()") { SpyingAllocator spy; @@ -21,16 +20,18 @@ TEST_CASE("JsonDocument::add()") { doc.add(42); REQUIRE(doc.as() == "[42]"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("const char*") { doc.add("hello"); REQUIRE(doc.as() == "[\"hello\"]"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("std::string") { @@ -38,9 +39,10 @@ TEST_CASE("JsonDocument::add()") { doc.add(std::string("example")); CHECK(doc[0].as() == doc[1].as()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(7))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("example")), + }); } SECTION("char*") { @@ -49,9 +51,10 @@ TEST_CASE("JsonDocument::add()") { doc.add(value); CHECK(doc[0].as() == doc[1].as()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(7))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("example")), + }); } SECTION("Arduino String") { @@ -59,9 +62,10 @@ TEST_CASE("JsonDocument::add()") { doc.add(String("example")); CHECK(doc[0].as() == doc[1].as()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(7))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("example")), + }); } SECTION("Flash string") { @@ -69,8 +73,9 @@ TEST_CASE("JsonDocument::add()") { doc.add(F("example")); CHECK(doc[0].as() == doc[1].as()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(7))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("example")), + }); } } diff --git a/extras/tests/JsonDocument/assignment.cpp b/extras/tests/JsonDocument/assignment.cpp index 99acc682..c5bebc5e 100644 --- a/extras/tests/JsonDocument/assignment.cpp +++ b/extras/tests/JsonDocument/assignment.cpp @@ -7,8 +7,6 @@ #include "Allocators.hpp" -using ArduinoJson::detail::sizeofString; - TEST_CASE("JsonDocument assignment") { SpyingAllocator spyingAllocator; @@ -22,11 +20,11 @@ TEST_CASE("JsonDocument assignment") { REQUIRE(doc2.as() == "{\"hello\":\"world\"}"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(5)) // hello - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5)) // world - ); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("Copy assignment reallocates when capacity is smaller") { @@ -38,11 +36,11 @@ TEST_CASE("JsonDocument assignment") { doc2 = doc1; REQUIRE(doc2.as() == "[{\"hello\":\"world\"}]"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5)) // hello - << AllocatorLog::Allocate(sizeofString(5)) // world - ); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("hello")), + Allocate(sizeofString("world")), + }); } SECTION("Copy assignment reallocates when capacity is larger") { @@ -54,11 +52,11 @@ TEST_CASE("JsonDocument assignment") { doc2 = doc1; REQUIRE(doc2.as() == "{\"hello\":\"world\"}"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(5)) // hello - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5)) // world - ); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("Move assign") { @@ -72,14 +70,14 @@ TEST_CASE("JsonDocument assignment") { REQUIRE(doc2.as() == "{\"hello\":\"world\"}"); REQUIRE(doc1.as() == "null"); } - REQUIRE( - spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(5)) // hello - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5)) // world - << AllocatorLog::Deallocate(sizeofString(5)) // hello - << AllocatorLog::Deallocate(sizeofString(5)) // world - << AllocatorLog::Deallocate(sizeofPool())); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + Deallocate(sizeofString("hello")), + Deallocate(sizeofString("world")), + Deallocate(sizeofPool()), + }); } SECTION("Assign from JsonObject") { diff --git a/extras/tests/JsonDocument/constructor.cpp b/extras/tests/JsonDocument/constructor.cpp index 1cc382a6..d8a2acfa 100644 --- a/extras/tests/JsonDocument/constructor.cpp +++ b/extras/tests/JsonDocument/constructor.cpp @@ -8,14 +8,13 @@ #include "Allocators.hpp" using ArduinoJson::detail::addPadding; -using ArduinoJson::detail::sizeofString; TEST_CASE("JsonDocument constructor") { SpyingAllocator spyingAllocator; SECTION("JsonDocument(size_t)") { { JsonDocument doc(&spyingAllocator); } - REQUIRE(spyingAllocator.log() == AllocatorLog()); + REQUIRE(spyingAllocator.log() == AllocatorLog{}); } SECTION("JsonDocument(const JsonDocument&)") { @@ -28,11 +27,12 @@ TEST_CASE("JsonDocument constructor") { REQUIRE(doc1.as() == "The size of this string is 32!!"); REQUIRE(doc2.as() == "The size of this string is 32!!"); } - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } SECTION("JsonDocument(JsonDocument&&)") { @@ -45,9 +45,10 @@ TEST_CASE("JsonDocument constructor") { REQUIRE(doc2.as() == "The size of this string is 32!!"); REQUIRE(doc1.as() == "null"); } - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } SECTION("JsonDocument(JsonObject)") { @@ -58,8 +59,9 @@ TEST_CASE("JsonDocument constructor") { JsonDocument doc2(obj, &spyingAllocator); REQUIRE(doc2.as() == "{\"hello\":\"world\"}"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("Construct from JsonArray") { @@ -70,8 +72,9 @@ TEST_CASE("JsonDocument constructor") { JsonDocument doc2(arr, &spyingAllocator); REQUIRE(doc2.as() == "[\"hello\"]"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("Construct from JsonVariant") { @@ -81,7 +84,8 @@ TEST_CASE("JsonDocument constructor") { JsonDocument doc2(doc1.as(), &spyingAllocator); REQUIRE(doc2.as() == "hello"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + }); } } diff --git a/extras/tests/JsonDocument/shrinkToFit.cpp b/extras/tests/JsonDocument/shrinkToFit.cpp index f9df912a..90dea9d7 100644 --- a/extras/tests/JsonDocument/shrinkToFit.cpp +++ b/extras/tests/JsonDocument/shrinkToFit.cpp @@ -12,7 +12,6 @@ using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; class ArmoredAllocator : public Allocator { public: @@ -48,7 +47,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "null"); - REQUIRE(spyingAllocator.log() == AllocatorLog()); + REQUIRE(spyingAllocator.log() == AllocatorLog{}); } SECTION("empty object") { @@ -57,7 +56,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "{}"); - REQUIRE(spyingAllocator.log() == AllocatorLog()); + REQUIRE(spyingAllocator.log() == AllocatorLog{}); } SECTION("empty array") { @@ -66,7 +65,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "[]"); - REQUIRE(spyingAllocator.log() == AllocatorLog()); + REQUIRE(spyingAllocator.log() == AllocatorLog{}); } SECTION("linked string") { @@ -75,7 +74,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "hello"); - REQUIRE(spyingAllocator.log() == AllocatorLog()); + REQUIRE(spyingAllocator.log() == AllocatorLog{}); } SECTION("owned string") { @@ -85,8 +84,9 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "abcdefg"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(7))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("abcdefg")), + }); } SECTION("raw string") { @@ -95,8 +95,9 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "[{},12]"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(7))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("[{},12]")), + }); } SECTION("linked key") { @@ -105,10 +106,11 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "{\"key\":42}"); - REQUIRE(spyingAllocator.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Reallocate( - sizeofPool(), sizeofObject(1))); + REQUIRE(spyingAllocator.log() == + AllocatorLog{ + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("owned key") { @@ -118,10 +120,11 @@ TEST_CASE("JsonDocument::shrinkToFit()") { REQUIRE(doc.as() == "{\"abcdefg\":42}"); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Reallocate(sizeofPool(), - sizeofObject(1))); + AllocatorLog{ + Allocate(sizeofString("abcdefg")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("linked string in array") { @@ -130,10 +133,11 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "[\"hello\"]"); - REQUIRE(spyingAllocator.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Reallocate( - sizeofPool(), sizeofArray(1))); + REQUIRE(spyingAllocator.log() == + AllocatorLog{ + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofArray(1)), + }); } SECTION("owned string in array") { @@ -143,10 +147,11 @@ TEST_CASE("JsonDocument::shrinkToFit()") { REQUIRE(doc.as() == "[\"abcdefg\"]"); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(7)) - << AllocatorLog::Reallocate(sizeofPool(), - sizeofArray(1))); + AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("abcdefg")), + Reallocate(sizeofPool(), sizeofArray(1)), + }); } SECTION("linked string in object") { @@ -155,10 +160,11 @@ TEST_CASE("JsonDocument::shrinkToFit()") { doc.shrinkToFit(); REQUIRE(doc.as() == "{\"key\":\"hello\"}"); - REQUIRE(spyingAllocator.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Reallocate( - sizeofPool(), sizeofObject(1))); + REQUIRE(spyingAllocator.log() == + AllocatorLog{ + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("owned string in object") { @@ -168,9 +174,10 @@ TEST_CASE("JsonDocument::shrinkToFit()") { REQUIRE(doc.as() == "{\"key\":\"abcdefg\"}"); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(7)) - << AllocatorLog::Reallocate(sizeofPool(), - sizeofPool(1))); + AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("abcdefg")), + Reallocate(sizeofPool(), sizeofPool(1)), + }); } } diff --git a/extras/tests/JsonObject/copy.cpp b/extras/tests/JsonObject/copy.cpp index 795de4a1..959ae31b 100644 --- a/extras/tests/JsonObject/copy.cpp +++ b/extras/tests/JsonObject/copy.cpp @@ -7,8 +7,6 @@ #include "Allocators.hpp" -using ArduinoJson::detail::sizeofString; - TEST_CASE("JsonObject::set()") { SpyingAllocator spy; JsonDocument doc1(&spy); @@ -25,8 +23,9 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == std::string("world")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("copy local string value") { @@ -37,9 +36,10 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == std::string("world")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("copy local key") { @@ -50,9 +50,10 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == std::string("world")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + }); } SECTION("copy string from deserializeJson()") { @@ -63,10 +64,11 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == std::string("world")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("copy string from deserializeMsgPack()") { @@ -77,10 +79,11 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == std::string("world")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should work with JsonObjectConst") { diff --git a/extras/tests/JsonObject/subscript.cpp b/extras/tests/JsonObject/subscript.cpp index 963f8969..9cf518c3 100644 --- a/extras/tests/JsonObject/subscript.cpp +++ b/extras/tests/JsonObject/subscript.cpp @@ -8,7 +8,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; TEST_CASE("JsonObject::operator[]") { SpyingAllocator spy; @@ -106,65 +105,72 @@ TEST_CASE("JsonObject::operator[]") { SECTION("should not duplicate const char*") { obj["hello"] = "world"; - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{Allocate(sizeofPool())}); } SECTION("should duplicate char* value") { obj["hello"] = const_cast("world"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should duplicate char* key") { obj[const_cast("hello")] = "world"; - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + }); } SECTION("should duplicate char* key&value") { obj[const_cast("hello")] = const_cast("world"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should duplicate std::string value") { obj["hello"] = std::string("world"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should duplicate std::string key") { obj[std::string("hello")] = "world"; - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + }); } SECTION("should duplicate std::string key&value") { obj[std::string("hello")] = std::string("world"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + Allocate(sizeofString("world")), + }); } SECTION("should duplicate a non-static JsonString key") { obj[JsonString("hello", JsonString::Copied)] = "world"; - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Allocate(sizeofPool()), + }); } SECTION("should not duplicate a static JsonString key") { obj[JsonString("hello", JsonString::Linked)] = "world"; - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } SECTION("should ignore null key") { diff --git a/extras/tests/JsonSerializer/std_string.cpp b/extras/tests/JsonSerializer/std_string.cpp index 204b5b31..f25deb20 100644 --- a/extras/tests/JsonSerializer/std_string.cpp +++ b/extras/tests/JsonSerializer/std_string.cpp @@ -5,8 +5,6 @@ #include #include -using ArduinoJson::detail::sizeofString; - TEST_CASE("serialize JsonArray to std::string") { JsonDocument doc; JsonArray array = doc.to(); diff --git a/extras/tests/JsonVariant/clear.cpp b/extras/tests/JsonVariant/clear.cpp index b40dd7de..67748041 100644 --- a/extras/tests/JsonVariant/clear.cpp +++ b/extras/tests/JsonVariant/clear.cpp @@ -8,8 +8,6 @@ #include "Allocators.hpp" -using ArduinoJson::detail::sizeofString; - TEST_CASE("JsonVariant::clear()") { SpyingAllocator spy; JsonDocument doc(&spy); @@ -33,8 +31,9 @@ TEST_CASE("JsonVariant::clear()") { var.set(std::string("hello")); var.clear(); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(5)) - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofString("hello")), + Deallocate(sizeofString("hello")), + }); } } diff --git a/extras/tests/JsonVariant/copy.cpp b/extras/tests/JsonVariant/copy.cpp index 585ce726..6131e0d6 100644 --- a/extras/tests/JsonVariant/copy.cpp +++ b/extras/tests/JsonVariant/copy.cpp @@ -6,8 +6,6 @@ #include #include "Allocators.hpp" -using ArduinoJson::detail::sizeofString; - TEST_CASE("JsonVariant::set(JsonVariant)") { KillswitchAllocator killswitch; SpyingAllocator spyingAllocator(&killswitch); @@ -44,7 +42,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); - REQUIRE(spyingAllocator.log() == AllocatorLog()); + REQUIRE(spyingAllocator.log() == AllocatorLog{}); } SECTION("stores char* by copy") { @@ -54,8 +52,9 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString((7)))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello!!")), + }); } SECTION("fails gracefully if string allocation fails") { @@ -67,8 +66,9 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); REQUIRE(doc2.overflowed() == true); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::AllocateFail(sizeofString((7)))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + AllocateFail(sizeofString("hello!!")), + }); } SECTION("stores std::string by copy") { @@ -77,8 +77,9 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString((7)))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello!!")), + }); } SECTION("stores Serialized by copy") { @@ -87,8 +88,9 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString((7)))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello!!")), + }); } SECTION("stores Serialized by copy") { @@ -98,8 +100,9 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString((7)))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello!!")), + }); } SECTION("stores Serialized by copy") { @@ -108,8 +111,9 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString((7)))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofString("hello!!")), + }); } SECTION("fails gracefully if raw string allocation fails") { @@ -120,8 +124,9 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var2.set(var1); REQUIRE(doc2.overflowed() == true); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::AllocateFail(sizeofString((7)))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + AllocateFail(sizeofString("hello!!")), + }); } SECTION("destination is unbound") { diff --git a/extras/tests/JsonVariant/remove.cpp b/extras/tests/JsonVariant/remove.cpp index 830ed6aa..e775f856 100644 --- a/extras/tests/JsonVariant/remove.cpp +++ b/extras/tests/JsonVariant/remove.cpp @@ -9,7 +9,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofArray; -using ArduinoJson::detail::sizeofString; TEST_CASE("JsonVariant::remove(int)") { SpyingAllocator spy; @@ -26,19 +25,21 @@ TEST_CASE("JsonVariant::remove(int)") { spy.clearLog(); var.remove(1); REQUIRE(var.as() == "[\"hello\",\"world\"]"); - REQUIRE(spy.log() == AllocatorLog()); + REQUIRE(spy.log() == AllocatorLog{}); spy.clearLog(); var.remove(1); REQUIRE(var.as() == "[\"hello\"]"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("world")), + }); spy.clearLog(); var.remove(0); REQUIRE(var.as() == "[]"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("hello")), + }); } SECTION("release strings in nested array") { @@ -51,8 +52,9 @@ TEST_CASE("JsonVariant::remove(int)") { var.remove(0); REQUIRE(var.as() == "[]"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("hello")), + }); } } diff --git a/extras/tests/JsonVariant/set.cpp b/extras/tests/JsonVariant/set.cpp index 72381c92..cd51158a 100644 --- a/extras/tests/JsonVariant/set.cpp +++ b/extras/tests/JsonVariant/set.cpp @@ -8,7 +8,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; enum ErrorCode { ERROR_01 = 1, ERROR_10 = 10 }; @@ -186,32 +185,37 @@ TEST_CASE("JsonVariant::set() releases the previous value") { SECTION("int") { v.set(42); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("world")), + }); } SECTION("bool") { v.set(false); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("world")), + }); } SECTION("const char*") { v.set("hello"); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("world")), + }); } SECTION("float") { v.set(1.2); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("world")), + }); } SECTION("Serialized") { v.set(serialized("[]")); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Deallocate(sizeofString(5)) - << AllocatorLog::Allocate(sizeofString(2))); + REQUIRE(spy.log() == AllocatorLog{ + Deallocate(sizeofString("world")), + Allocate(sizeofString("[]")), + }); } } diff --git a/extras/tests/Misc/printable.cpp b/extras/tests/Misc/printable.cpp index 6b66c10f..6e3d5afd 100644 --- a/extras/tests/Misc/printable.cpp +++ b/extras/tests/Misc/printable.cpp @@ -11,7 +11,6 @@ #include "Allocators.hpp" using ArduinoJson::detail::sizeofArray; -using ArduinoJson::detail::sizeofString; struct PrintOneCharacterAtATime { static size_t printStringTo(const std::string& s, Print& p) { @@ -65,10 +64,11 @@ TEST_CASE("Printable") { CHECK(doc.as() == value); CHECK(printable.totalBytesWritten() == 7); CHECK(doc.overflowed() == false); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("example")), + }); } SECTION("Via Print::write(const char* size_t)") { @@ -77,10 +77,11 @@ TEST_CASE("Printable") { CHECK(doc.as() == value); CHECK(printable.totalBytesWritten() == 7); CHECK(doc.overflowed() == false); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("example")), + }); } } @@ -100,8 +101,9 @@ TEST_CASE("Printable") { CHECK(doc.isNull()); CHECK(printable.totalBytesWritten() == 0); CHECK(doc.overflowed() == true); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::AllocateFail(sizeofString(31))); + CHECK(spy.log() == AllocatorLog{ + AllocateFail(sizeofStringBuffer()), + }); } SECTION("Via Print::write(const char*, size_t)") { @@ -113,8 +115,9 @@ TEST_CASE("Printable") { CHECK(doc.isNull()); CHECK(printable.totalBytesWritten() == 0); CHECK(doc.overflowed() == true); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::AllocateFail(sizeofString(31))); + CHECK(spy.log() == AllocatorLog{ + AllocateFail(sizeofStringBuffer()), + }); } } @@ -135,11 +138,12 @@ TEST_CASE("Printable") { CHECK(doc.isNull()); CHECK(printable.totalBytesWritten() == 31); CHECK(doc.overflowed() == true); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::ReallocateFail(sizeofString(31), - sizeofString(63)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + ReallocateFail(sizeofStringBuffer(), sizeofStringBuffer(2)), + Deallocate(sizeofStringBuffer()), + }); } SECTION("Via Print::write(const char*, size_t)") { @@ -151,11 +155,12 @@ TEST_CASE("Printable") { CHECK(doc.isNull()); CHECK(printable.totalBytesWritten() == 31); CHECK(doc.overflowed() == true); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::ReallocateFail(sizeofString(31), - sizeofString(63)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + ReallocateFail(sizeofStringBuffer(), sizeofStringBuffer(2)), + Deallocate(sizeofStringBuffer()), + }); } } @@ -175,12 +180,13 @@ TEST_CASE("Printable") { REQUIRE(doc.size() == 2); CHECK(doc[0] == "Hello World!"); CHECK(doc[1] == "Hello World!"); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(12)) - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("Hello World!")), + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } } diff --git a/extras/tests/MsgPackDeserializer/filter.cpp b/extras/tests/MsgPackDeserializer/filter.cpp index 92af5d16..e2d5fdea 100644 --- a/extras/tests/MsgPackDeserializer/filter.cpp +++ b/extras/tests/MsgPackDeserializer/filter.cpp @@ -29,9 +29,10 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } SECTION("input truncated after inside skipped uint 8") { @@ -40,9 +41,10 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } SECTION("input truncated after before skipped string size") { @@ -50,9 +52,10 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } SECTION("input truncated after before skipped ext size") { @@ -60,9 +63,10 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } SECTION("skip nil") { @@ -72,10 +76,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("reject 0xc1") { @@ -83,9 +88,10 @@ TEST_CASE("deserializeMsgPack() filter") { filterOpt); CHECK(error == DeserializationError::InvalidInput); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Deallocate(sizeofString(31))); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + Deallocate(sizeofStringBuffer()), + }); } SECTION("skip false") { @@ -95,10 +101,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip true") { @@ -108,10 +115,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip positive fixint") { @@ -121,10 +129,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip negative fixint") { @@ -134,10 +143,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip uint 8") { @@ -147,10 +157,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip int 8") { @@ -160,10 +171,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip uint 16") { @@ -173,10 +185,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip int 16") { @@ -186,10 +199,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip uint 32") { @@ -200,10 +214,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip int 32") { @@ -214,10 +229,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip uint 64") { @@ -229,10 +245,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip int 64") { @@ -244,10 +261,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip float 32") { @@ -258,10 +276,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip float 64") { @@ -273,10 +292,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixstr") { @@ -286,10 +306,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip str 8") { @@ -299,10 +320,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip str 16") { @@ -312,10 +334,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip str 32") { @@ -326,10 +349,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip bin 8") { @@ -339,10 +363,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip bin 16") { @@ -352,10 +377,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip bin 32") { @@ -366,10 +392,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixarray") { @@ -379,10 +406,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip array 16") { @@ -393,10 +421,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip array 32") { @@ -410,10 +439,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixmap") { @@ -424,10 +454,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip map 16") { @@ -440,10 +471,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip map 32") { @@ -458,10 +490,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixext 1") { @@ -474,10 +507,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixext 2") { @@ -490,10 +524,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixext 4") { @@ -506,10 +541,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixext 8") { @@ -522,10 +558,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip fixext 16") { @@ -540,10 +577,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip ext 8") { @@ -556,10 +594,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip ext 16") { @@ -572,10 +611,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } SECTION("skip ext 32") { @@ -588,10 +628,11 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofPool()), + }); } } @@ -613,39 +654,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(doc.as() == "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "measure" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); - CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "measure" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("measure")), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("include array 16") { @@ -661,22 +678,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(doc.as() == "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "measure" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("measure")), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("include array 32") { @@ -692,22 +702,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(doc.as() == "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "measure" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("measure")), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip null") { @@ -717,31 +720,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); - CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip false") { @@ -751,18 +736,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip true") { @@ -772,18 +752,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip positive fixint") { @@ -793,18 +768,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip negative fixint") { @@ -814,18 +784,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 8") { @@ -835,18 +800,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 16") { @@ -856,18 +816,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 32") { @@ -878,18 +833,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 64") { @@ -901,18 +851,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 8") { @@ -922,18 +867,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 16") { @@ -943,18 +883,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 32") { @@ -965,18 +900,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 64") { @@ -988,18 +918,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip float 32") { @@ -1010,18 +935,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip float 64") { @@ -1033,18 +953,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip fixstr") { @@ -1054,18 +969,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip str 8") { @@ -1088,18 +998,13 @@ TEST_CASE("deserializeMsgPack() filter") { filterOpt); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip fixmap") { @@ -1110,18 +1015,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip map 16") { @@ -1134,18 +1034,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip map 32") { @@ -1160,18 +1055,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } } } @@ -1199,8 +1089,9 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "[1,2,3]"); - CHECK(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool())); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + }); } } } @@ -1222,21 +1113,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(doc.as() == "{\"onlyobj\":{\"measure\":2},\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyobj" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "measure" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("measure")), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("include map 16") { @@ -1250,21 +1135,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(doc.as() == "{\"onlyobj\":{\"measure\":2},\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyobj" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "measure" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("measure")), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("include map 32") { @@ -1279,21 +1158,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(doc.as() == "{\"onlyobj\":{\"measure\":2},\"include\":42}"); CHECK(spy.log() == - AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyobj" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "measure" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7)) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), sizeofString(7))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("measure")), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip null") { @@ -1302,19 +1175,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip false") { @@ -1323,19 +1191,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip true") { @@ -1344,19 +1207,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip positive fixint") { @@ -1365,19 +1223,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip negative fixint") { @@ -1386,19 +1239,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 8") { @@ -1407,19 +1255,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 16") { @@ -1428,19 +1271,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 32") { @@ -1449,19 +1287,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip uint 64") { @@ -1472,19 +1305,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 8") { @@ -1493,19 +1321,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 16") { @@ -1514,19 +1337,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 32") { @@ -1535,19 +1353,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip int 64") { @@ -1558,19 +1371,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + // string builder's buffer + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip float 32") { @@ -1579,19 +1388,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + // string builder's buffer + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip float 64") { @@ -1602,19 +1407,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + // string builder's buffer + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip fixstr") { @@ -1623,19 +1424,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + // string builder's buffer + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip str 8") { @@ -1657,19 +1454,15 @@ TEST_CASE("deserializeMsgPack() filter") { doc, "\x82\xA7onlyobj\xdb\x00\x00\x00\x05hello\xA7include\x2A", filterOpt); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + // string builder's buffer + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip fixarray") { @@ -1678,19 +1471,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + // string builder's buffer + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip array 16") { @@ -1701,19 +1490,15 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + // string builder's buffer + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } SECTION("skip array 32") { @@ -1725,19 +1510,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == AllocatorLog() - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "onlyarr" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7)) - // pool - << AllocatorLog::Allocate(sizeofPool()) - // string builder's buffer - << AllocatorLog::Allocate(sizeofString(31)) - // string "include" - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(7))); + CHECK(spy.log() == + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("include")), + }); } } diff --git a/extras/tests/ResourceManager/StringBuilder.cpp b/extras/tests/ResourceManager/StringBuilder.cpp index ffb49dfa..98ab2d0c 100644 --- a/extras/tests/ResourceManager/StringBuilder.cpp +++ b/extras/tests/ResourceManager/StringBuilder.cpp @@ -20,12 +20,13 @@ TEST_CASE("StringBuilder") { str.startString(); str.save(); - REQUIRE(resources.size() == sizeofString(0)); + REQUIRE(resources.size() == sizeofString("")); REQUIRE(resources.overflowed() == false); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(0))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + Reallocate(sizeofStringBuffer(), sizeofString("")), + }); } SECTION("Short string fits in first allocation") { @@ -37,29 +38,29 @@ TEST_CASE("StringBuilder") { REQUIRE(str.isValid() == true); REQUIRE(str.str() == "hello"); REQUIRE(resources.overflowed() == false); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(31))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + Allocate(sizeofStringBuffer()), + }); } SECTION("Long string needs reallocation") { StringBuilder str(&resources); + const char* lorem = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " + "eiusmod tempor incididunt ut labore et dolore magna aliqua."; str.startString(); - str.append( - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " - "eiusmod tempor incididunt ut labore et dolore magna aliqua."); + str.append(lorem); REQUIRE(str.isValid() == true); - REQUIRE(str.str() == - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " - "eiusmod tempor incididunt ut labore et dolore magna aliqua."); + REQUIRE(str.str() == lorem); REQUIRE(resources.overflowed() == false); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::Reallocate(sizeofString(31), - sizeofString(63)) - << AllocatorLog::Reallocate(sizeofString(63), - sizeofString(127))); + AllocatorLog{ + Allocate(sizeofStringBuffer(1)), + Reallocate(sizeofStringBuffer(1), sizeofStringBuffer(2)), + Reallocate(sizeofStringBuffer(2), sizeofStringBuffer(3)), + }); } SECTION("Realloc fails") { @@ -72,10 +73,11 @@ TEST_CASE("StringBuilder") { "eiusmod tempor incididunt ut labore et dolore magna aliqua."); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(31)) - << AllocatorLog::ReallocateFail(sizeofString(31), - sizeofString(63)) - << AllocatorLog::Deallocate(sizeofString(31))); + AllocatorLog{ + Allocate(sizeofStringBuffer()), + ReallocateFail(sizeofStringBuffer(), sizeofStringBuffer(2)), + Deallocate(sizeofStringBuffer()), + }); REQUIRE(str.isValid() == false); REQUIRE(resources.overflowed() == true); } @@ -88,8 +90,9 @@ TEST_CASE("StringBuilder") { REQUIRE(str.isValid() == false); REQUIRE(resources.overflowed() == true); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::AllocateFail(sizeofString(31))); + REQUIRE(spyingAllocator.log() == AllocatorLog{ + AllocateFail(sizeofStringBuffer()), + }); } } @@ -113,7 +116,7 @@ TEST_CASE("StringBuilder::save() deduplicates strings") { REQUIRE(s1->references == 2); REQUIRE(s2->references == 1); REQUIRE(s3->references == 2); - REQUIRE(resources.size() == 2 * sizeofString(5)); + REQUIRE(resources.size() == sizeofString("hello") + sizeofString("world")); } SECTION("Requires terminator") { @@ -123,7 +126,8 @@ TEST_CASE("StringBuilder::save() deduplicates strings") { REQUIRE(s2 != s1); REQUIRE(s1->references == 1); REQUIRE(s2->references == 1); - REQUIRE(resources.size() == sizeofString(11) + sizeofString(5)); + REQUIRE(resources.size() == + sizeofString("hello world") + sizeofString("hello")); } SECTION("Don't overrun") { @@ -133,6 +137,7 @@ TEST_CASE("StringBuilder::save() deduplicates strings") { REQUIRE(s2 != s1); REQUIRE(s1->references == 1); REQUIRE(s2->references == 1); - REQUIRE(resources.size() == sizeofString(11) + sizeofString(3)); + REQUIRE(resources.size() == + sizeofString("hello world") + sizeofString("wor")); } } diff --git a/extras/tests/ResourceManager/saveString.cpp b/extras/tests/ResourceManager/saveString.cpp index d64c9147..d57c1a21 100644 --- a/extras/tests/ResourceManager/saveString.cpp +++ b/extras/tests/ResourceManager/saveString.cpp @@ -30,7 +30,7 @@ TEST_CASE("ResourceManager::saveString()") { REQUIRE(b->length == 5); REQUIRE(a->references == 1); REQUIRE(b->references == 1); - REQUIRE(resources.size() == 2 * sizeofString(5)); + REQUIRE(resources.size() == sizeofString("hello") + sizeofString("world")); } SECTION("Deduplicates identical strings") { @@ -39,7 +39,7 @@ TEST_CASE("ResourceManager::saveString()") { REQUIRE(a == b); REQUIRE(a->length == 5); REQUIRE(a->references == 2); - REQUIRE(resources.size() == sizeofString(5)); + REQUIRE(resources.size() == sizeofString("hello")); } SECTION("Deduplicates identical strings that contain NUL") { @@ -48,7 +48,7 @@ TEST_CASE("ResourceManager::saveString()") { REQUIRE(a == b); REQUIRE(a->length == 11); REQUIRE(a->references == 2); - REQUIRE(resources.size() == sizeofString(11)); + REQUIRE(resources.size() == sizeofString("hello world")); } SECTION("Don't stop on first NUL") { @@ -59,7 +59,8 @@ TEST_CASE("ResourceManager::saveString()") { REQUIRE(b->length == 11); REQUIRE(a->references == 1); REQUIRE(b->references == 1); - REQUIRE(resources.size() == sizeofString(5) + sizeofString(11)); + REQUIRE(resources.size() == + sizeofString("hello") + sizeofString("hello world")); } SECTION("Returns NULL when allocation fails") { diff --git a/extras/tests/ResourceManager/shrinkToFit.cpp b/extras/tests/ResourceManager/shrinkToFit.cpp index ed90237c..203944ed 100644 --- a/extras/tests/ResourceManager/shrinkToFit.cpp +++ b/extras/tests/ResourceManager/shrinkToFit.cpp @@ -17,7 +17,7 @@ TEST_CASE("ResourceManager::shrinkToFit()") { SECTION("empty") { resources.shrinkToFit(); - REQUIRE(spyingAllocator.log() == AllocatorLog()); + REQUIRE(spyingAllocator.log() == AllocatorLog{}); } SECTION("only one pool") { @@ -26,9 +26,10 @@ TEST_CASE("ResourceManager::shrinkToFit()") { resources.shrinkToFit(); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Reallocate(sizeofPool(), - sizeof(VariantSlot))); + AllocatorLog{ + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeof(VariantSlot)), + }); } SECTION("more pools than initial count") { @@ -37,20 +38,20 @@ TEST_CASE("ResourceManager::shrinkToFit()") { i++) resources.allocSlot(); REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofPool()) * - ARDUINOJSON_INITIAL_POOL_COUNT - << AllocatorLog::Allocate(sizeofPoolList( - ARDUINOJSON_INITIAL_POOL_COUNT * 2)) - << AllocatorLog::Allocate(sizeofPool())); + AllocatorLog{ + Allocate(sizeofPool()) * ARDUINOJSON_INITIAL_POOL_COUNT, + Allocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2)), + Allocate(sizeofPool()), + }); spyingAllocator.clearLog(); resources.shrinkToFit(); REQUIRE(spyingAllocator.log() == - AllocatorLog() - << AllocatorLog::Reallocate(sizeofPool(), sizeof(VariantSlot)) - << AllocatorLog::Reallocate( - sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2), - sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT + 1))); + AllocatorLog{ + Reallocate(sizeofPool(), sizeof(VariantSlot)), + Reallocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2), + sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT + 1)), + }); } } diff --git a/extras/tests/ResourceManager/swap.cpp b/extras/tests/ResourceManager/swap.cpp index 311f0580..7fa00827 100644 --- a/extras/tests/ResourceManager/swap.cpp +++ b/extras/tests/ResourceManager/swap.cpp @@ -31,8 +31,9 @@ TEST_CASE("ResourceManager::swap()") { REQUIRE(a1->data() == b.getSlot(a1.id())->data()); REQUIRE(b1->data() == a.getSlot(b1.id())->data()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) * 2); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()) * 2, + }); } SECTION("Only left using preallocated pool list") { @@ -48,12 +49,12 @@ TEST_CASE("ResourceManager::swap()") { REQUIRE(a1->data() == b.getSlot(a1.id())->data()); REQUIRE(b1->data() == a.getSlot(b1.id())->data()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) * - (ARDUINOJSON_INITIAL_POOL_COUNT + 1) - << AllocatorLog::Allocate(sizeofPoolList( - ARDUINOJSON_INITIAL_POOL_COUNT * 2)) - << AllocatorLog::Allocate(sizeofPool())); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofPool()) * (ARDUINOJSON_INITIAL_POOL_COUNT + 1), + Allocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2)), + Allocate(sizeofPool()), + }); } SECTION("Only right using preallocated pool list") { @@ -69,12 +70,12 @@ TEST_CASE("ResourceManager::swap()") { REQUIRE(a1->data() == b.getSlot(a1.id())->data()); REQUIRE(b1->data() == a.getSlot(b1.id())->data()); - REQUIRE(spy.log() == AllocatorLog() - << AllocatorLog::Allocate(sizeofPool()) * - ARDUINOJSON_INITIAL_POOL_COUNT - << AllocatorLog::Allocate(sizeofPoolList( - ARDUINOJSON_INITIAL_POOL_COUNT * 2)) - << AllocatorLog::Allocate(sizeofPool()) * 2); + REQUIRE(spy.log() == + AllocatorLog{ + Allocate(sizeofPool()) * ARDUINOJSON_INITIAL_POOL_COUNT, + Allocate(sizeofPoolList(ARDUINOJSON_INITIAL_POOL_COUNT * 2)), + Allocate(sizeofPool()) * 2, + }); } SECTION("None is using preallocated pool list") {