brintos

brintos / llvm-project-archived public Read only

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