Add more tests with VLAs

This commit is contained in:
Benoit Blanchon
2024-11-08 09:37:49 +01:00
parent 1110d62128
commit 31253dbe13
7 changed files with 160 additions and 2 deletions
+18
View File
@@ -79,6 +79,24 @@ TEST_CASE("JsonDocument::add(T)") {
Allocate(sizeofString("example")),
});
}
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("VLA") {
size_t i = 16;
char vla[i];
strcpy(vla, "example");
doc.add(vla);
doc.add(vla);
CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
REQUIRE("example"_s == doc[0]);
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("example")),
});
}
#endif
}
TEST_CASE("JsonDocument::add<T>()") {