1 //===- llvm/unittest/DebugInfo/LogicalView/StringPoolTest.cpp -------------===// 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 "llvm/DebugInfo/LogicalView/Core/LVStringPool.h" 10 #include <vector> 11 12 #include "gtest/gtest.h" 13 14 using namespace llvm; 15 using namespace llvm::logicalview; 16 17 namespace { 18 19 TEST(StringPoolTest, AddStrings) { 20 LVStringPool PoolInstance; 21 EXPECT_EQ(0u, PoolInstance.getSize()); 22 23 // Get indexes for the initial strings. 24 EXPECT_EQ(1u, PoolInstance.getIndex("one")); 25 EXPECT_EQ(2u, PoolInstance.getIndex("two")); 26 EXPECT_EQ(3u, PoolInstance.getIndex("three")); 27 EXPECT_EQ(4u, PoolInstance.getIndex("four")); 28 EXPECT_EQ(5u, PoolInstance.getIndex("five")); 29 EXPECT_EQ(5u, PoolInstance.getSize()); 30 31 // Verify the string returned by the given index. 32 EXPECT_EQ("one", PoolInstance.getString(1)); 33 EXPECT_EQ("two", PoolInstance.getString(2)); 34 EXPECT_EQ("three", PoolInstance.getString(3)); 35 EXPECT_EQ("four", PoolInstance.getString(4)); 36 EXPECT_EQ("five", PoolInstance.getString(5)); 37 EXPECT_EQ(5u, PoolInstance.getSize()); 38 39 // Get indexes for the same initial strings. 40 EXPECT_EQ(5u, PoolInstance.getIndex("five")); 41 EXPECT_EQ(4u, PoolInstance.getIndex("four")); 42 EXPECT_EQ(3u, PoolInstance.getIndex("three")); 43 EXPECT_EQ(2u, PoolInstance.getIndex("two")); 44 EXPECT_EQ(1u, PoolInstance.getIndex("one")); 45 EXPECT_EQ(5u, PoolInstance.getSize()); 46 47 // Empty string gets the index zero. 48 EXPECT_EQ(0u, PoolInstance.getIndex("")); 49 EXPECT_EQ(5u, PoolInstance.getSize()); 50 51 // Empty string for invalid index. 52 EXPECT_EQ("", PoolInstance.getString(620)); 53 54 // Lookup for strings 55 EXPECT_EQ(5u, PoolInstance.findIndex("five")); 56 EXPECT_TRUE(PoolInstance.isValidIndex(PoolInstance.findIndex("five"))); 57 EXPECT_FALSE(PoolInstance.isValidIndex(PoolInstance.findIndex("FIVE"))); 58 } 59 60 } // namespace 61