From 242d3f2f351a74d3f6ff49e5d506aec450803a13 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 26 Jun 2025 15:18:46 +0200 Subject: [PATCH] Fix resource manager tests --- extras/tests/ResourceManager/StringBuffer.cpp | 12 +++---- .../tests/ResourceManager/StringBuilder.cpp | 32 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/extras/tests/ResourceManager/StringBuffer.cpp b/extras/tests/ResourceManager/StringBuffer.cpp index b39b60e7..dcf7d512 100644 --- a/extras/tests/ResourceManager/StringBuffer.cpp +++ b/extras/tests/ResourceManager/StringBuffer.cpp @@ -21,8 +21,8 @@ TEST_CASE("StringBuffer") { strcpy(ptr, "hi!"); sb.save(&variant); - REQUIRE(variant.type() == VariantType::TinyString); - REQUIRE(variant.asString(&resources) == "hi!"); + REQUIRE(variant.type == VariantType::TinyString); + REQUIRE(VariantImpl(&variant, &resources).asString() == "hi!"); } SECTION("Tiny string can't contain NUL") { @@ -30,9 +30,9 @@ TEST_CASE("StringBuffer") { memcpy(ptr, "a\0b", 3); sb.save(&variant); - REQUIRE(variant.type() == VariantType::OwnedString); + REQUIRE(variant.type == VariantType::OwnedString); - auto str = variant.asString(&resources); + auto str = VariantImpl(&variant, &resources).asString(); REQUIRE(str.size() == 3); REQUIRE(str.c_str()[0] == 'a'); REQUIRE(str.c_str()[1] == 0); @@ -44,7 +44,7 @@ TEST_CASE("StringBuffer") { strcpy(ptr, "alfa"); sb.save(&variant); - REQUIRE(variant.type() == VariantType::OwnedString); - REQUIRE(variant.asString(&resources) == "alfa"); + REQUIRE(variant.type == VariantType::OwnedString); + REQUIRE(VariantImpl(&variant, &resources).asString() == "alfa"); } } diff --git a/extras/tests/ResourceManager/StringBuilder.cpp b/extras/tests/ResourceManager/StringBuilder.cpp index ec3c2ab4..9398c43b 100644 --- a/extras/tests/ResourceManager/StringBuilder.cpp +++ b/extras/tests/ResourceManager/StringBuilder.cpp @@ -26,7 +26,7 @@ TEST_CASE("StringBuilder") { REQUIRE(spyingAllocator.log() == AllocatorLog{ Allocate(sizeofStringBuffer()), }); - REQUIRE(data.type() == VariantType::TinyString); + REQUIRE(data.type == VariantType::TinyString); } SECTION("Tiny string") { @@ -45,8 +45,8 @@ TEST_CASE("StringBuilder") { str.save(&data); REQUIRE(resources.overflowed() == false); - REQUIRE(data.type() == VariantType::TinyString); - REQUIRE(data.asString(&resources) == "url"); + REQUIRE(data.type == VariantType::TinyString); + REQUIRE(VariantImpl(&data, &resources).asString() == "url"); } SECTION("Short string fits in first allocation") { @@ -134,10 +134,10 @@ TEST_CASE("StringBuilder::save() deduplicates strings") { auto s2 = saveString(builder, "world"); auto s3 = saveString(builder, "hello"); - REQUIRE(s1.asString(&resources) == "hello"); - REQUIRE(s2.asString(&resources) == "world"); - REQUIRE(+s1.asString(&resources).c_str() == - +s3.asString(&resources).c_str()); // same address + REQUIRE(VariantImpl(&s1, &resources).asString() == "hello"); + REQUIRE(VariantImpl(&s2, &resources).asString() == "world"); + REQUIRE(+VariantImpl(&s1, &resources).asString().c_str() == + +VariantImpl(&s3, &resources).asString().c_str()); // same address REQUIRE(spy.log() == AllocatorLog{ @@ -153,10 +153,11 @@ TEST_CASE("StringBuilder::save() deduplicates strings") { auto s1 = saveString(builder, "hello world"); auto s2 = saveString(builder, "hello"); - REQUIRE(s1.asString(&resources) == "hello world"); - REQUIRE(s2.asString(&resources) == "hello"); - REQUIRE(+s2.asString(&resources).c_str() != - +s1.asString(&resources).c_str()); // different address + REQUIRE(VariantImpl(&s1, &resources).asString() == "hello world"); + REQUIRE(VariantImpl(&s2, &resources).asString() == "hello"); + REQUIRE( + +VariantImpl(&s1, &resources).asString().c_str() != + +VariantImpl(&s2, &resources).asString().c_str()); // different address REQUIRE(spy.log() == AllocatorLog{ @@ -171,10 +172,11 @@ TEST_CASE("StringBuilder::save() deduplicates strings") { auto s1 = saveString(builder, "hello world"); auto s2 = saveString(builder, "worl"); - REQUIRE(s1.asString(&resources) == "hello world"); - REQUIRE(s2.asString(&resources) == "worl"); - REQUIRE(s2.asString(&resources).c_str() != - s1.asString(&resources).c_str()); // different address + REQUIRE(VariantImpl(&s1, &resources).asString() == "hello world"); + REQUIRE(VariantImpl(&s2, &resources).asString() == "worl"); + REQUIRE( + VariantImpl(&s1, &resources).asString().c_str() != + VariantImpl(&s2, &resources).asString().c_str()); // different address REQUIRE(spy.log() == AllocatorLog{