Skip to content

Commit

Permalink
Improve tests for StringPool
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Nov 4, 2024
1 parent b9f4a95 commit 1bf84c1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/src/tests/tests.stringpool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <gtest/gtest.h>

#define IN_TESTS
#include <zasm/core/stringpool.hpp>

namespace zasm::tests
Expand Down Expand Up @@ -87,4 +89,38 @@ namespace zasm::tests
ASSERT_EQ(pool.getRefCount(id5), 1);
}

TEST(StringPoolTests, TestManyStrings)
{
StringPool pool;

std::vector<StringPool::Id> ids;

constexpr auto kTestSize = 1'000'000;
for (auto i = 0U; i < kTestSize; i++)
{
std::string str = std::string("hello") + std::to_string(i);

const auto id = pool.aquire(str);
ASSERT_NE(id, StringPool::Id::Invalid);
ASSERT_EQ(pool.getLength(id), str.size());
ASSERT_EQ(pool.getRefCount(id), 1);

const auto* cstr = pool.get(id);
ASSERT_NE(cstr, nullptr);
ASSERT_EQ(strcmp(cstr, str.c_str()), 0);

ids.push_back(id);
}

// Validate that the contents still match.
for (auto i = 0U; i < kTestSize; i++)
{
std::string str = std::string("hello") + std::to_string(i);

const auto* cstr = pool.get(ids[i]);
ASSERT_NE(cstr, nullptr);
ASSERT_EQ(strcmp(cstr, str.c_str()), 0);
}
}

} // namespace zasm::tests

0 comments on commit 1bf84c1

Please sign in to comment.