Fix resource manager tests

This commit is contained in:
Benoit Blanchon
2025-06-26 15:18:46 +02:00
parent be1e33f5ff
commit 242d3f2f35
2 changed files with 23 additions and 21 deletions

View File

@@ -21,8 +21,8 @@ TEST_CASE("StringBuffer") {
strcpy(ptr, "hi!"); strcpy(ptr, "hi!");
sb.save(&variant); sb.save(&variant);
REQUIRE(variant.type() == VariantType::TinyString); REQUIRE(variant.type == VariantType::TinyString);
REQUIRE(variant.asString(&resources) == "hi!"); REQUIRE(VariantImpl(&variant, &resources).asString() == "hi!");
} }
SECTION("Tiny string can't contain NUL") { SECTION("Tiny string can't contain NUL") {
@@ -30,9 +30,9 @@ TEST_CASE("StringBuffer") {
memcpy(ptr, "a\0b", 3); memcpy(ptr, "a\0b", 3);
sb.save(&variant); 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.size() == 3);
REQUIRE(str.c_str()[0] == 'a'); REQUIRE(str.c_str()[0] == 'a');
REQUIRE(str.c_str()[1] == 0); REQUIRE(str.c_str()[1] == 0);
@@ -44,7 +44,7 @@ TEST_CASE("StringBuffer") {
strcpy(ptr, "alfa"); strcpy(ptr, "alfa");
sb.save(&variant); sb.save(&variant);
REQUIRE(variant.type() == VariantType::OwnedString); REQUIRE(variant.type == VariantType::OwnedString);
REQUIRE(variant.asString(&resources) == "alfa"); REQUIRE(VariantImpl(&variant, &resources).asString() == "alfa");
} }
} }

View File

@@ -26,7 +26,7 @@ TEST_CASE("StringBuilder") {
REQUIRE(spyingAllocator.log() == AllocatorLog{ REQUIRE(spyingAllocator.log() == AllocatorLog{
Allocate(sizeofStringBuffer()), Allocate(sizeofStringBuffer()),
}); });
REQUIRE(data.type() == VariantType::TinyString); REQUIRE(data.type == VariantType::TinyString);
} }
SECTION("Tiny string") { SECTION("Tiny string") {
@@ -45,8 +45,8 @@ TEST_CASE("StringBuilder") {
str.save(&data); str.save(&data);
REQUIRE(resources.overflowed() == false); REQUIRE(resources.overflowed() == false);
REQUIRE(data.type() == VariantType::TinyString); REQUIRE(data.type == VariantType::TinyString);
REQUIRE(data.asString(&resources) == "url"); REQUIRE(VariantImpl(&data, &resources).asString() == "url");
} }
SECTION("Short string fits in first allocation") { SECTION("Short string fits in first allocation") {
@@ -134,10 +134,10 @@ TEST_CASE("StringBuilder::save() deduplicates strings") {
auto s2 = saveString(builder, "world"); auto s2 = saveString(builder, "world");
auto s3 = saveString(builder, "hello"); auto s3 = saveString(builder, "hello");
REQUIRE(s1.asString(&resources) == "hello"); REQUIRE(VariantImpl(&s1, &resources).asString() == "hello");
REQUIRE(s2.asString(&resources) == "world"); REQUIRE(VariantImpl(&s2, &resources).asString() == "world");
REQUIRE(+s1.asString(&resources).c_str() == REQUIRE(+VariantImpl(&s1, &resources).asString().c_str() ==
+s3.asString(&resources).c_str()); // same address +VariantImpl(&s3, &resources).asString().c_str()); // same address
REQUIRE(spy.log() == REQUIRE(spy.log() ==
AllocatorLog{ AllocatorLog{
@@ -153,10 +153,11 @@ TEST_CASE("StringBuilder::save() deduplicates strings") {
auto s1 = saveString(builder, "hello world"); auto s1 = saveString(builder, "hello world");
auto s2 = saveString(builder, "hello"); auto s2 = saveString(builder, "hello");
REQUIRE(s1.asString(&resources) == "hello world"); REQUIRE(VariantImpl(&s1, &resources).asString() == "hello world");
REQUIRE(s2.asString(&resources) == "hello"); REQUIRE(VariantImpl(&s2, &resources).asString() == "hello");
REQUIRE(+s2.asString(&resources).c_str() != REQUIRE(
+s1.asString(&resources).c_str()); // different address +VariantImpl(&s1, &resources).asString().c_str() !=
+VariantImpl(&s2, &resources).asString().c_str()); // different address
REQUIRE(spy.log() == REQUIRE(spy.log() ==
AllocatorLog{ AllocatorLog{
@@ -171,10 +172,11 @@ TEST_CASE("StringBuilder::save() deduplicates strings") {
auto s1 = saveString(builder, "hello world"); auto s1 = saveString(builder, "hello world");
auto s2 = saveString(builder, "worl"); auto s2 = saveString(builder, "worl");
REQUIRE(s1.asString(&resources) == "hello world"); REQUIRE(VariantImpl(&s1, &resources).asString() == "hello world");
REQUIRE(s2.asString(&resources) == "worl"); REQUIRE(VariantImpl(&s2, &resources).asString() == "worl");
REQUIRE(s2.asString(&resources).c_str() != REQUIRE(
s1.asString(&resources).c_str()); // different address VariantImpl(&s1, &resources).asString().c_str() !=
VariantImpl(&s2, &resources).asString().c_str()); // different address
REQUIRE(spy.log() == REQUIRE(spy.log() ==
AllocatorLog{ AllocatorLog{