[llvm] [cmake] Add possibility to use ChooseMSVCCRT.cmake when include LLVM library
[llvm-core.git] / unittests / ExecutionEngine / Orc / SymbolStringPoolTest.cpp
bloba68da0be960656f1ff6d15dc610022dbe2868694
1 //===----- SymbolStringPoolTest.cpp - Unit tests for SymbolStringPool -----===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
13 using namespace llvm::orc;
15 namespace {
17 TEST(SymbolStringPool, UniquingAndComparisons) {
18 SymbolStringPool SP;
19 auto P1 = SP.intern("hello");
21 std::string S("hel");
22 S += "lo";
23 auto P2 = SP.intern(S);
25 auto P3 = SP.intern("goodbye");
27 EXPECT_EQ(P1, P2) << "Failed to unique entries";
28 EXPECT_NE(P1, P3) << "Inequal pooled symbol strings comparing equal";
30 // We want to test that less-than comparison of SymbolStringPtrs compiles,
31 // however we can't test the actual result as this is a pointer comparison and
32 // SymbolStringPtr doesn't expose the underlying address of the string.
33 (void)(P1 < P3);
36 TEST(SymbolStringPool, Dereference) {
37 SymbolStringPool SP;
38 auto Foo = SP.intern("foo");
39 EXPECT_EQ(*Foo, "foo") << "Equality on dereferenced string failed";
42 TEST(SymbolStringPool, ClearDeadEntries) {
43 SymbolStringPool SP;
45 auto P1 = SP.intern("s1");
46 SP.clearDeadEntries();
47 EXPECT_FALSE(SP.empty()) << "\"s1\" entry in pool should still be retained";
49 SP.clearDeadEntries();
50 EXPECT_TRUE(SP.empty()) << "pool should be empty";