Extracted VariantData and CollectionData classes

This commit is contained in:
Benoit Blanchon
2018-12-07 09:16:58 +01:00
parent 1ad97ebf85
commit b77b203935
45 changed files with 1129 additions and 1007 deletions

View File

@ -11,48 +11,48 @@ char buffer[4096];
TEST_CASE("MemoryPool::capacity()") {
const size_t capacity = 64;
MemoryPool memoryPool(buffer, capacity);
REQUIRE(capacity == memoryPool.capacity());
MemoryPool pool(buffer, capacity);
REQUIRE(capacity == pool.capacity());
}
TEST_CASE("MemoryPool::size()") {
MemoryPool memoryPool(buffer, sizeof(buffer));
MemoryPool pool(buffer, sizeof(buffer));
SECTION("Initial size is 0") {
REQUIRE(0 == memoryPool.size());
REQUIRE(0 == pool.size());
}
SECTION("size() == capacity() after allocExpandableString()") {
memoryPool.allocExpandableString();
REQUIRE(memoryPool.size() == memoryPool.capacity());
pool.allocExpandableString();
REQUIRE(pool.size() == pool.capacity());
}
SECTION("Decreases after freezeString()") {
StringSlot a = memoryPool.allocExpandableString();
memoryPool.freezeString(a, 1);
REQUIRE(memoryPool.size() == JSON_STRING_SIZE(1));
StringSlot a = pool.allocExpandableString();
pool.freezeString(a, 1);
REQUIRE(pool.size() == JSON_STRING_SIZE(1));
StringSlot b = memoryPool.allocExpandableString();
memoryPool.freezeString(b, 1);
REQUIRE(memoryPool.size() == 2 * JSON_STRING_SIZE(1));
StringSlot b = pool.allocExpandableString();
pool.freezeString(b, 1);
REQUIRE(pool.size() == 2 * JSON_STRING_SIZE(1));
}
SECTION("Increases after allocFrozenString()") {
memoryPool.allocFrozenString(0);
REQUIRE(memoryPool.size() == JSON_STRING_SIZE(0));
pool.allocFrozenString(0);
REQUIRE(pool.size() == JSON_STRING_SIZE(0));
memoryPool.allocFrozenString(0);
REQUIRE(memoryPool.size() == 2 * JSON_STRING_SIZE(0));
pool.allocFrozenString(0);
REQUIRE(pool.size() == 2 * JSON_STRING_SIZE(0));
}
SECTION("Doesn't grow when memory pool is full") {
const size_t variantCount = sizeof(buffer) / sizeof(VariantSlot);
for (size_t i = 0; i < variantCount; i++) memoryPool.allocVariant();
size_t size = memoryPool.size();
for (size_t i = 0; i < variantCount; i++) pool.allocVariant();
size_t size = pool.size();
memoryPool.allocVariant();
pool.allocVariant();
REQUIRE(size == memoryPool.size());
REQUIRE(size == pool.size());
}
}