1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
//===- llvm/unittest/CodeGen/DwarfStringPoolEntryRefTest.cpp --------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
using namespace llvm;
TEST(DwarfStringPoolEntryRefTest, TestFullEntry) {
BumpPtrAllocator Allocator;
StringMapEntry<DwarfStringPoolEntry> *StringEntry1 =
StringMapEntry<DwarfStringPoolEntry>::Create(
"Key1", Allocator, DwarfStringPoolEntry{nullptr, 0, 0});
EXPECT_TRUE(StringEntry1->getKey() == "Key1");
EXPECT_TRUE(StringEntry1->second.Symbol == nullptr);
EXPECT_TRUE(StringEntry1->second.Offset == 0);
EXPECT_TRUE(StringEntry1->second.Index == 0);
DwarfStringPoolEntryRef Ref1(*StringEntry1);
EXPECT_TRUE(Ref1.getString() == "Key1");
EXPECT_TRUE(Ref1.getOffset() == 0);
EXPECT_TRUE(Ref1.getIndex() == 0);
DwarfStringPoolEntryRef Ref2(*StringEntry1);
EXPECT_TRUE(Ref2.getString() == "Key1");
EXPECT_TRUE(Ref2.getOffset() == 0);
EXPECT_TRUE(Ref2.getIndex() == 0);
EXPECT_TRUE(Ref1 == Ref2);
EXPECT_FALSE(Ref1 != Ref2);
StringMapEntry<DwarfStringPoolEntry> *StringEntry2 =
StringMapEntry<DwarfStringPoolEntry>::Create(
"Key2", Allocator, DwarfStringPoolEntry{nullptr, 0x1000, 1});
EXPECT_TRUE(StringEntry2->getKey() == "Key2");
EXPECT_TRUE(StringEntry2->second.Symbol == nullptr);
EXPECT_TRUE(StringEntry2->second.Offset == 0x1000);
EXPECT_TRUE(StringEntry2->second.Index == 1);
DwarfStringPoolEntryRef Ref3(*StringEntry2);
EXPECT_TRUE(Ref3.getString() == "Key2");
EXPECT_TRUE(Ref3.getOffset() == 0x1000);
EXPECT_TRUE(Ref3.getIndex() == 1);
EXPECT_TRUE(Ref1 != Ref3);
}
bool isEntryEqual(const DwarfStringPoolEntry &LHS,
const DwarfStringPoolEntry &RHS) {
return LHS.Symbol == RHS.Symbol && LHS.Offset == RHS.Offset &&
LHS.Index == RHS.Index;
}
TEST(DwarfStringPoolEntryRefTest, TestShortEntry) {
BumpPtrAllocator Allocator;
DwarfStringPoolEntry DwarfEntry1 = {nullptr, 0, 0};
StringMapEntry<DwarfStringPoolEntry *> *StringEntry1 =
StringMapEntry<DwarfStringPoolEntry *>::Create("Key1", Allocator,
&DwarfEntry1);
EXPECT_TRUE(StringEntry1->getKey() == "Key1");
EXPECT_TRUE(StringEntry1->second->Symbol == nullptr);
EXPECT_TRUE(StringEntry1->second->Offset == 0);
EXPECT_TRUE(StringEntry1->second->Index == 0);
DwarfStringPoolEntryRef Ref1(*StringEntry1);
EXPECT_TRUE(Ref1.getString() == "Key1");
EXPECT_TRUE(Ref1.getOffset() == 0);
EXPECT_TRUE(Ref1.getIndex() == 0);
EXPECT_TRUE(isEntryEqual(Ref1.getEntry(), DwarfEntry1));
DwarfStringPoolEntryRef Ref2(*StringEntry1);
EXPECT_TRUE(Ref2.getString() == "Key1");
EXPECT_TRUE(Ref2.getOffset() == 0);
EXPECT_TRUE(isEntryEqual(Ref2.getEntry(), DwarfEntry1));
EXPECT_TRUE(Ref1 == Ref2);
EXPECT_FALSE(Ref1 != Ref2);
DwarfStringPoolEntry DwarfEntry2 = {nullptr, 0x1000, 1};
StringMapEntry<DwarfStringPoolEntry *> *StringEntry2 =
StringMapEntry<DwarfStringPoolEntry *>::Create("Key2", Allocator,
&DwarfEntry2);
EXPECT_TRUE(StringEntry2->getKey() == "Key2");
EXPECT_TRUE(StringEntry2->second->Symbol == nullptr);
EXPECT_TRUE(StringEntry2->second->Offset == 0x1000);
EXPECT_TRUE(StringEntry2->second->Index == 1);
DwarfStringPoolEntryRef Ref3(*StringEntry2);
EXPECT_TRUE(Ref3.getString() == "Key2");
EXPECT_TRUE(Ref3.getOffset() == 0x1000);
EXPECT_TRUE(Ref3.getIndex() == 1);
EXPECT_TRUE(isEntryEqual(Ref3.getEntry(), DwarfEntry2));
EXPECT_TRUE(Ref1 != Ref3);
}
TEST(DwarfStringPoolEntryRefTest, CompareFullAndShort) {
BumpPtrAllocator Allocator;
DwarfStringPoolEntry DwarfEntry1 = {nullptr, 0, 0};
StringMapEntry<DwarfStringPoolEntry *> *StringEntry1 =
StringMapEntry<DwarfStringPoolEntry *>::Create("Key1", Allocator,
&DwarfEntry1);
DwarfStringPoolEntryRef Ref1(*StringEntry1);
StringMapEntry<DwarfStringPoolEntry> *StringEntry2 =
StringMapEntry<DwarfStringPoolEntry>::Create(
"Key1", Allocator, DwarfStringPoolEntry{nullptr, 0, 0});
DwarfStringPoolEntryRef Ref2(*StringEntry2);
EXPECT_FALSE(Ref1 == Ref2);
}
|