1//===---------- string_pool_test.cpp - Unit tests for StringPool ----------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "string_pool.h"
10#include "gtest/gtest.h"
11
12using namespace __orc_rt;
13
14namespace {
15
16TEST(StringPool, UniquingAndComparisons) {
17 StringPool SP;
18 auto P1 = SP.intern("hello");
19
20 std::string S("hel");
21 S += "lo";
22 auto P2 = SP.intern(S);
23
24 auto P3 = SP.intern("goodbye");
25
26 EXPECT_EQ(P1, P2) << "Failed to unique entries";
27 EXPECT_NE(P1, P3) << "Unequal pooled strings comparing equal";
28
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.
32 (void)(P1 < P3);
33}
34
35TEST(StringPool, Dereference) {
36 StringPool SP;
37 auto Foo = SP.intern("foo");
38 EXPECT_EQ(*Foo, "foo") << "Equality on dereferenced string failed";
39}
40
41TEST(StringPool, ClearDeadEntries) {
42 StringPool SP;
43 {
44 auto P1 = SP.intern("s1");
45 SP.clearDeadEntries();
46 EXPECT_FALSE(SP.empty()) << "\"s1\" entry in pool should still be retained";
47 }
48 SP.clearDeadEntries();
49 EXPECT_TRUE(SP.empty()) << "pool should be empty";
50}
51
52TEST(StringPool, NullPtr) {
53 // Make sure that we can default construct and then destroy a null
54 // PooledStringPtr.
55 PooledStringPtr Null;
56}
57
58TEST(StringPool, Hashable) {
59 StringPool SP;
60 PooledStringPtr P1 = SP.intern("s1");
61 PooledStringPtr Null;
62 EXPECT_NE(std::hash<PooledStringPtr>()(P1),
63 std::hash<PooledStringPtr>()(Null));
64}
65
66} // end anonymous namespace
67

source code of compiler-rt/lib/orc/tests/unit/string_pool_test.cpp