1 //===- llvm/unittest/DebugInfo/LogicalView/StringPoolTest.cpp -------------===//
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 "llvm/DebugInfo/LogicalView/Core/LVStringPool.h"
12 #include "gtest/gtest.h"
15 using namespace llvm::logicalview
;
19 TEST(StringPoolTest
, AddStrings
) {
20 LVStringPool PoolInstance
;
21 EXPECT_EQ(0u, PoolInstance
.getSize());
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());
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());
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());
47 // Empty string gets the index zero.
48 EXPECT_EQ(0u, PoolInstance
.getIndex(""));
49 EXPECT_EQ(5u, PoolInstance
.getSize());
51 // Empty string for invalid index.
52 EXPECT_EQ("", PoolInstance
.getString(620));
55 EXPECT_EQ(5u, PoolInstance
.findIndex("five"));
56 EXPECT_TRUE(PoolInstance
.isValidIndex(PoolInstance
.findIndex("five")));
57 EXPECT_FALSE(PoolInstance
.isValidIndex(PoolInstance
.findIndex("FIVE")));