Skip to content

Commit 242d3f2

Browse files
committed
Fix resource manager tests
1 parent be1e33f commit 242d3f2

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

extras/tests/ResourceManager/StringBuffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ TEST_CASE("StringBuffer") {
2121
strcpy(ptr, "hi!");
2222
sb.save(&variant);
2323

24-
REQUIRE(variant.type() == VariantType::TinyString);
25-
REQUIRE(variant.asString(&resources) == "hi!");
24+
REQUIRE(variant.type == VariantType::TinyString);
25+
REQUIRE(VariantImpl(&variant, &resources).asString() == "hi!");
2626
}
2727

2828
SECTION("Tiny string can't contain NUL") {
2929
auto ptr = sb.reserve(3);
3030
memcpy(ptr, "a\0b", 3);
3131
sb.save(&variant);
3232

33-
REQUIRE(variant.type() == VariantType::OwnedString);
33+
REQUIRE(variant.type == VariantType::OwnedString);
3434

35-
auto str = variant.asString(&resources);
35+
auto str = VariantImpl(&variant, &resources).asString();
3636
REQUIRE(str.size() == 3);
3737
REQUIRE(str.c_str()[0] == 'a');
3838
REQUIRE(str.c_str()[1] == 0);
@@ -44,7 +44,7 @@ TEST_CASE("StringBuffer") {
4444
strcpy(ptr, "alfa");
4545
sb.save(&variant);
4646

47-
REQUIRE(variant.type() == VariantType::OwnedString);
48-
REQUIRE(variant.asString(&resources) == "alfa");
47+
REQUIRE(variant.type == VariantType::OwnedString);
48+
REQUIRE(VariantImpl(&variant, &resources).asString() == "alfa");
4949
}
5050
}

extras/tests/ResourceManager/StringBuilder.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TEST_CASE("StringBuilder") {
2626
REQUIRE(spyingAllocator.log() == AllocatorLog{
2727
Allocate(sizeofStringBuffer()),
2828
});
29-
REQUIRE(data.type() == VariantType::TinyString);
29+
REQUIRE(data.type == VariantType::TinyString);
3030
}
3131

3232
SECTION("Tiny string") {
@@ -45,8 +45,8 @@ TEST_CASE("StringBuilder") {
4545
str.save(&data);
4646

4747
REQUIRE(resources.overflowed() == false);
48-
REQUIRE(data.type() == VariantType::TinyString);
49-
REQUIRE(data.asString(&resources) == "url");
48+
REQUIRE(data.type == VariantType::TinyString);
49+
REQUIRE(VariantImpl(&data, &resources).asString() == "url");
5050
}
5151

5252
SECTION("Short string fits in first allocation") {
@@ -134,10 +134,10 @@ TEST_CASE("StringBuilder::save() deduplicates strings") {
134134
auto s2 = saveString(builder, "world");
135135
auto s3 = saveString(builder, "hello");
136136

137-
REQUIRE(s1.asString(&resources) == "hello");
138-
REQUIRE(s2.asString(&resources) == "world");
139-
REQUIRE(+s1.asString(&resources).c_str() ==
140-
+s3.asString(&resources).c_str()); // same address
137+
REQUIRE(VariantImpl(&s1, &resources).asString() == "hello");
138+
REQUIRE(VariantImpl(&s2, &resources).asString() == "world");
139+
REQUIRE(+VariantImpl(&s1, &resources).asString().c_str() ==
140+
+VariantImpl(&s3, &resources).asString().c_str()); // same address
141141

142142
REQUIRE(spy.log() ==
143143
AllocatorLog{
@@ -153,10 +153,11 @@ TEST_CASE("StringBuilder::save() deduplicates strings") {
153153
auto s1 = saveString(builder, "hello world");
154154
auto s2 = saveString(builder, "hello");
155155

156-
REQUIRE(s1.asString(&resources) == "hello world");
157-
REQUIRE(s2.asString(&resources) == "hello");
158-
REQUIRE(+s2.asString(&resources).c_str() !=
159-
+s1.asString(&resources).c_str()); // different address
156+
REQUIRE(VariantImpl(&s1, &resources).asString() == "hello world");
157+
REQUIRE(VariantImpl(&s2, &resources).asString() == "hello");
158+
REQUIRE(
159+
+VariantImpl(&s1, &resources).asString().c_str() !=
160+
+VariantImpl(&s2, &resources).asString().c_str()); // different address
160161

161162
REQUIRE(spy.log() ==
162163
AllocatorLog{
@@ -171,10 +172,11 @@ TEST_CASE("StringBuilder::save() deduplicates strings") {
171172
auto s1 = saveString(builder, "hello world");
172173
auto s2 = saveString(builder, "worl");
173174

174-
REQUIRE(s1.asString(&resources) == "hello world");
175-
REQUIRE(s2.asString(&resources) == "worl");
176-
REQUIRE(s2.asString(&resources).c_str() !=
177-
s1.asString(&resources).c_str()); // different address
175+
REQUIRE(VariantImpl(&s1, &resources).asString() == "hello world");
176+
REQUIRE(VariantImpl(&s2, &resources).asString() == "worl");
177+
REQUIRE(
178+
VariantImpl(&s1, &resources).asString().c_str() !=
179+
VariantImpl(&s2, &resources).asString().c_str()); // different address
178180

179181
REQUIRE(spy.log() ==
180182
AllocatorLog{

0 commit comments

Comments
 (0)