1 //===---------- string_pool_test.cpp - Unit tests for StringPool ----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "string_pool.h"
10 #include "gtest/gtest.h"
12 using namespace orc_rt
;
16 TEST(StringPool
, UniquingAndComparisons
) {
18 auto P1
= SP
.intern("hello");
22 auto P2
= SP
.intern(S
);
24 auto P3
= SP
.intern("goodbye");
26 EXPECT_EQ(P1
, P2
) << "Failed to unique entries";
27 EXPECT_NE(P1
, P3
) << "Unequal pooled strings comparing equal";
29 // We want to test that less-than comparison of PooledStringPtrs compiles,
30 // however we can't test the actual result as this is a pointer comparison and
31 // PooledStringPtr doesn't expose the underlying address of the string.
35 TEST(StringPool
, Dereference
) {
37 auto Foo
= SP
.intern("foo");
38 EXPECT_EQ(*Foo
, "foo") << "Equality on dereferenced string failed";
41 TEST(StringPool
, ClearDeadEntries
) {
44 auto P1
= SP
.intern("s1");
45 SP
.clearDeadEntries();
46 EXPECT_FALSE(SP
.empty()) << "\"s1\" entry in pool should still be retained";
48 SP
.clearDeadEntries();
49 EXPECT_TRUE(SP
.empty()) << "pool should be empty";
52 TEST(StringPool
, NullPtr
) {
53 // Make sure that we can default construct and then destroy a null
58 TEST(StringPool
, Hashable
) {
60 PooledStringPtr P1
= SP
.intern("s1");
62 EXPECT_NE(std::hash
<PooledStringPtr
>()(P1
),
63 std::hash
<PooledStringPtr
>()(Null
));
66 } // end anonymous namespace