1 //===----- SymbolStringPoolTest.cpp - Unit tests for SymbolStringPool -----===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h" 11 #include "gtest/gtest.h" 12 13 using namespace llvm; 14 using namespace llvm::orc; 15 16 namespace { 17 18 TEST(SymbolStringPool, UniquingAndComparisons) { 19 SymbolStringPool SP; 20 auto P1 = SP.intern("hello"); 21 22 std::string S("hel"); 23 S += "lo"; 24 auto P2 = SP.intern(S); 25 26 auto P3 = SP.intern("goodbye"); 27 28 EXPECT_EQ(P1, P2) << "Failed to unique entries"; 29 EXPECT_NE(P1, P3) << "Inequal pooled symbol strings comparing equal"; 30 31 // We want to test that less-than comparison of SymbolStringPtrs compiles, 32 // however we can't test the actual result as this is a pointer comparison and 33 // SymbolStringPtr doesn't expose the underlying address of the string. 34 (void)(P1 < P3); 35 } 36 37 TEST(SymbolStringPool, ClearDeadEntries) { 38 SymbolStringPool SP; 39 { 40 auto P1 = SP.intern("s1"); 41 SP.clearDeadEntries(); 42 EXPECT_FALSE(SP.empty()) << "\"s1\" entry in pool should still be retained"; 43 } 44 SP.clearDeadEntries(); 45 EXPECT_TRUE(SP.empty()) << "pool should be empty"; 46 } 47 48 } 49