[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / CodeGen / DwarfStringPoolEntryRefTest.cpp
blob623ac4e1a878e5e072db82a48c86551b5be22fc2
1 //===- llvm/unittest/CodeGen/DwarfStringPoolEntryRefTest.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 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
10 #include "llvm/Support/Allocator.h"
11 #include "llvm/Testing/Support/Error.h"
13 #include "gmock/gmock.h"
14 #include "gtest/gtest.h"
15 #include <string>
17 using namespace llvm;
19 TEST(DwarfStringPoolEntryRefTest, TestFullEntry) {
20 BumpPtrAllocator Allocator;
21 StringMapEntry<DwarfStringPoolEntry> *StringEntry1 =
22 StringMapEntry<DwarfStringPoolEntry>::Create(
23 "Key1", Allocator, DwarfStringPoolEntry{nullptr, 0, 0});
25 EXPECT_TRUE(StringEntry1->getKey() == "Key1");
26 EXPECT_TRUE(StringEntry1->second.Symbol == nullptr);
27 EXPECT_TRUE(StringEntry1->second.Offset == 0);
28 EXPECT_TRUE(StringEntry1->second.Index == 0);
30 DwarfStringPoolEntryRef Ref1(*StringEntry1);
31 EXPECT_TRUE(Ref1.getString() == "Key1");
32 EXPECT_TRUE(Ref1.getOffset() == 0);
33 EXPECT_TRUE(Ref1.getIndex() == 0);
35 DwarfStringPoolEntryRef Ref2(*StringEntry1);
36 EXPECT_TRUE(Ref2.getString() == "Key1");
37 EXPECT_TRUE(Ref2.getOffset() == 0);
38 EXPECT_TRUE(Ref2.getIndex() == 0);
39 EXPECT_TRUE(Ref1 == Ref2);
40 EXPECT_FALSE(Ref1 != Ref2);
42 StringMapEntry<DwarfStringPoolEntry> *StringEntry2 =
43 StringMapEntry<DwarfStringPoolEntry>::Create(
44 "Key2", Allocator, DwarfStringPoolEntry{nullptr, 0x1000, 1});
45 EXPECT_TRUE(StringEntry2->getKey() == "Key2");
46 EXPECT_TRUE(StringEntry2->second.Symbol == nullptr);
47 EXPECT_TRUE(StringEntry2->second.Offset == 0x1000);
48 EXPECT_TRUE(StringEntry2->second.Index == 1);
50 DwarfStringPoolEntryRef Ref3(*StringEntry2);
51 EXPECT_TRUE(Ref3.getString() == "Key2");
52 EXPECT_TRUE(Ref3.getOffset() == 0x1000);
53 EXPECT_TRUE(Ref3.getIndex() == 1);
54 EXPECT_TRUE(Ref1 != Ref3);
57 bool isEntryEqual(const DwarfStringPoolEntry &LHS,
58 const DwarfStringPoolEntry &RHS) {
59 return LHS.Symbol == RHS.Symbol && LHS.Offset == RHS.Offset &&
60 LHS.Index == RHS.Index;
63 TEST(DwarfStringPoolEntryRefTest, TestShortEntry) {
64 BumpPtrAllocator Allocator;
65 DwarfStringPoolEntry DwarfEntry1 = {nullptr, 0, 0};
66 StringMapEntry<DwarfStringPoolEntry *> *StringEntry1 =
67 StringMapEntry<DwarfStringPoolEntry *>::Create("Key1", Allocator,
68 &DwarfEntry1);
70 EXPECT_TRUE(StringEntry1->getKey() == "Key1");
71 EXPECT_TRUE(StringEntry1->second->Symbol == nullptr);
72 EXPECT_TRUE(StringEntry1->second->Offset == 0);
73 EXPECT_TRUE(StringEntry1->second->Index == 0);
75 DwarfStringPoolEntryRef Ref1(*StringEntry1);
76 EXPECT_TRUE(Ref1.getString() == "Key1");
77 EXPECT_TRUE(Ref1.getOffset() == 0);
78 EXPECT_TRUE(Ref1.getIndex() == 0);
79 EXPECT_TRUE(isEntryEqual(Ref1.getEntry(), DwarfEntry1));
81 DwarfStringPoolEntryRef Ref2(*StringEntry1);
82 EXPECT_TRUE(Ref2.getString() == "Key1");
83 EXPECT_TRUE(Ref2.getOffset() == 0);
84 EXPECT_TRUE(isEntryEqual(Ref2.getEntry(), DwarfEntry1));
85 EXPECT_TRUE(Ref1 == Ref2);
86 EXPECT_FALSE(Ref1 != Ref2);
88 DwarfStringPoolEntry DwarfEntry2 = {nullptr, 0x1000, 1};
89 StringMapEntry<DwarfStringPoolEntry *> *StringEntry2 =
90 StringMapEntry<DwarfStringPoolEntry *>::Create("Key2", Allocator,
91 &DwarfEntry2);
92 EXPECT_TRUE(StringEntry2->getKey() == "Key2");
93 EXPECT_TRUE(StringEntry2->second->Symbol == nullptr);
94 EXPECT_TRUE(StringEntry2->second->Offset == 0x1000);
95 EXPECT_TRUE(StringEntry2->second->Index == 1);
97 DwarfStringPoolEntryRef Ref3(*StringEntry2);
98 EXPECT_TRUE(Ref3.getString() == "Key2");
99 EXPECT_TRUE(Ref3.getOffset() == 0x1000);
100 EXPECT_TRUE(Ref3.getIndex() == 1);
101 EXPECT_TRUE(isEntryEqual(Ref3.getEntry(), DwarfEntry2));
102 EXPECT_TRUE(Ref1 != Ref3);
105 TEST(DwarfStringPoolEntryRefTest, CompareFullAndShort) {
106 BumpPtrAllocator Allocator;
108 DwarfStringPoolEntry DwarfEntry1 = {nullptr, 0, 0};
109 StringMapEntry<DwarfStringPoolEntry *> *StringEntry1 =
110 StringMapEntry<DwarfStringPoolEntry *>::Create("Key1", Allocator,
111 &DwarfEntry1);
112 DwarfStringPoolEntryRef Ref1(*StringEntry1);
114 StringMapEntry<DwarfStringPoolEntry> *StringEntry2 =
115 StringMapEntry<DwarfStringPoolEntry>::Create(
116 "Key1", Allocator, DwarfStringPoolEntry{nullptr, 0, 0});
117 DwarfStringPoolEntryRef Ref2(*StringEntry2);
119 EXPECT_FALSE(Ref1 == Ref2);