mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-31 11:17:34 +02:00
Fix resource manager tests
This commit is contained in:
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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{
|
||||
|
Reference in New Issue
Block a user