From 386105be90f2eb364e4878f3cba9d9c2b3daf471 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Fri, 23 Aug 2024 15:27:46 +0200 Subject: [PATCH] Allocate slot before key --- extras/tests/JsonDocument/MemberProxy.cpp | 2 +- extras/tests/JsonDocument/assignment.cpp | 6 +++--- extras/tests/JsonDocument/shrinkToFit.cpp | 2 +- extras/tests/JsonObject/set.cpp | 6 +++--- extras/tests/JsonObject/subscript.cpp | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/extras/tests/JsonDocument/MemberProxy.cpp b/extras/tests/JsonDocument/MemberProxy.cpp index bb6acdfc..8361377c 100644 --- a/extras/tests/JsonDocument/MemberProxy.cpp +++ b/extras/tests/JsonDocument/MemberProxy.cpp @@ -358,7 +358,7 @@ TEST_CASE("MemberProxy under memory constraints") { REQUIRE(doc.size() == 0); REQUIRE(doc.overflowed() == true); REQUIRE(spy.log() == AllocatorLog{ - AllocateFail(sizeofString("hello")), + AllocateFail(sizeofPool()), }); } } diff --git a/extras/tests/JsonDocument/assignment.cpp b/extras/tests/JsonDocument/assignment.cpp index 42cef3e5..58a83913 100644 --- a/extras/tests/JsonDocument/assignment.cpp +++ b/extras/tests/JsonDocument/assignment.cpp @@ -22,8 +22,8 @@ TEST_CASE("JsonDocument assignment") { REQUIRE(doc2.as() == "{\"hello\":\"world\"}"); REQUIRE(spyingAllocator.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), Allocate(sizeofString("world")), }); } @@ -54,8 +54,8 @@ TEST_CASE("JsonDocument assignment") { REQUIRE(doc2.as() == "{\"hello\":\"world\"}"); REQUIRE(spyingAllocator.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), Allocate(sizeofString("world")), }); } @@ -72,8 +72,8 @@ TEST_CASE("JsonDocument assignment") { REQUIRE(doc1.as() == "null"); } REQUIRE(spyingAllocator.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), Allocate(sizeofString("world")), Deallocate(sizeofString("hello")), Deallocate(sizeofString("world")), diff --git a/extras/tests/JsonDocument/shrinkToFit.cpp b/extras/tests/JsonDocument/shrinkToFit.cpp index 1d431401..98656db9 100644 --- a/extras/tests/JsonDocument/shrinkToFit.cpp +++ b/extras/tests/JsonDocument/shrinkToFit.cpp @@ -122,8 +122,8 @@ TEST_CASE("JsonDocument::shrinkToFit()") { REQUIRE(doc.as() == "{\"abcdefg\":42}"); REQUIRE(spyingAllocator.log() == AllocatorLog{ - Allocate(sizeofString("abcdefg")), Allocate(sizeofPool()), + Allocate(sizeofString("abcdefg")), Reallocate(sizeofPool(), sizeofObject(1)), }); } diff --git a/extras/tests/JsonObject/set.cpp b/extras/tests/JsonObject/set.cpp index f80f8a82..bad06742 100644 --- a/extras/tests/JsonObject/set.cpp +++ b/extras/tests/JsonObject/set.cpp @@ -52,8 +52,8 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), }); } @@ -66,8 +66,8 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), Allocate(sizeofString("world")), }); } @@ -81,8 +81,8 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == true); REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), Allocate(sizeofString("world")), }); } diff --git a/extras/tests/JsonObject/subscript.cpp b/extras/tests/JsonObject/subscript.cpp index 775d149f..1a5ceb7a 100644 --- a/extras/tests/JsonObject/subscript.cpp +++ b/extras/tests/JsonObject/subscript.cpp @@ -118,16 +118,16 @@ TEST_CASE("JsonObject::operator[]") { SECTION("should duplicate char* key") { obj[const_cast("hello")] = "world"; REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), }); } SECTION("should duplicate char* key&value") { obj[const_cast("hello")] = const_cast("world"); REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), Allocate(sizeofString("world")), }); } @@ -143,16 +143,16 @@ TEST_CASE("JsonObject::operator[]") { SECTION("should duplicate std::string key") { obj["hello"_s] = "world"; REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), }); } SECTION("should duplicate std::string key&value") { obj["hello"_s] = "world"_s; REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), Allocate(sizeofString("world")), }); } @@ -160,8 +160,8 @@ TEST_CASE("JsonObject::operator[]") { SECTION("should duplicate a non-static JsonString key") { obj[JsonString("hello", JsonString::Copied)] = "world"; REQUIRE(spy.log() == AllocatorLog{ - Allocate(sizeofString("hello")), Allocate(sizeofPool()), + Allocate(sizeofString("hello")), }); }