| 1 |
//===-- FormatEntityTest.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 "lldb/Core/FormatEntity.h" |
| 10 |
#include "lldb/Utility/Status.h" |
| 11 |
|
| 12 |
#include "llvm/ADT/StringRef.h" |
| 13 |
#include "gtest/gtest.h" |
| 14 |
|
| 15 |
using namespace lldb_private; |
| 16 |
|
| 17 |
using Definition = FormatEntity::Entry::Definition; |
| 18 |
using Entry = FormatEntity::Entry; |
| 19 |
|
| 20 |
TEST(FormatEntityTest, DefinitionConstructionNameAndType) { |
| 21 |
Definition d("foo", FormatEntity::Entry::Type::Invalid); |
| 22 |
|
| 23 |
EXPECT_STREQ(d.name, "foo"); |
| 24 |
EXPECT_EQ(d.string, nullptr); |
| 25 |
EXPECT_EQ(d.type, FormatEntity::Entry::Type::Invalid); |
| 26 |
EXPECT_EQ(d.data, 0UL); |
| 27 |
EXPECT_EQ(d.num_children, 0UL); |
| 28 |
EXPECT_EQ(d.children, nullptr); |
| 29 |
EXPECT_FALSE(d.keep_separator); |
| 30 |
} |
| 31 |
|
| 32 |
TEST(FormatEntityTest, DefinitionConstructionNameAndString) { |
| 33 |
Definition d("foo", "string"); |
| 34 |
|
| 35 |
EXPECT_STREQ(d.name, "foo"); |
| 36 |
EXPECT_STREQ(d.string, "string"); |
| 37 |
EXPECT_EQ(d.type, FormatEntity::Entry::Type::EscapeCode); |
| 38 |
EXPECT_EQ(d.data, 0UL); |
| 39 |
EXPECT_EQ(d.num_children, 0UL); |
| 40 |
EXPECT_EQ(d.children, nullptr); |
| 41 |
EXPECT_FALSE(d.keep_separator); |
| 42 |
} |
| 43 |
|
| 44 |
TEST(FormatEntityTest, DefinitionConstructionNameTypeData) { |
| 45 |
Definition d("foo", FormatEntity::Entry::Type::Invalid, 33); |
| 46 |
|
| 47 |
EXPECT_STREQ(d.name, "foo"); |
| 48 |
EXPECT_EQ(d.string, nullptr); |
| 49 |
EXPECT_EQ(d.type, FormatEntity::Entry::Type::Invalid); |
| 50 |
EXPECT_EQ(d.data, 33UL); |
| 51 |
EXPECT_EQ(d.num_children, 0UL); |
| 52 |
EXPECT_EQ(d.children, nullptr); |
| 53 |
EXPECT_FALSE(d.keep_separator); |
| 54 |
} |
| 55 |
|
| 56 |
TEST(FormatEntityTest, DefinitionConstructionNameTypeChildren) { |
| 57 |
Definition d("foo", FormatEntity::Entry::Type::Invalid, 33); |
| 58 |
Definition parent("parent", FormatEntity::Entry::Type::Invalid, 1, &d); |
| 59 |
EXPECT_STREQ(parent.name, "parent"); |
| 60 |
EXPECT_STREQ(parent.string, nullptr); |
| 61 |
EXPECT_EQ(parent.type, FormatEntity::Entry::Type::Invalid); |
| 62 |
EXPECT_EQ(parent.num_children, 1UL); |
| 63 |
EXPECT_EQ(parent.children, &d); |
| 64 |
EXPECT_FALSE(parent.keep_separator); |
| 65 |
|
| 66 |
EXPECT_STREQ(parent.children[0].name, "foo"); |
| 67 |
EXPECT_EQ(parent.children[0].string, nullptr); |
| 68 |
EXPECT_EQ(parent.children[0].type, FormatEntity::Entry::Type::Invalid); |
| 69 |
EXPECT_EQ(parent.children[0].data, 33UL); |
| 70 |
EXPECT_EQ(parent.children[0].num_children, 0UL); |
| 71 |
EXPECT_EQ(parent.children[0].children, nullptr); |
| 72 |
EXPECT_FALSE(d.keep_separator); |
| 73 |
} |
| 74 |
|
| 75 |
constexpr llvm::StringRef lookupStrings[] = { |
| 76 |
"${addr.load}", |
| 77 |
"${addr.file}", |
| 78 |
"${ansi.fg.black}", |
| 79 |
"${ansi.fg.red}", |
| 80 |
"${ansi.fg.green}", |
| 81 |
"${ansi.fg.yellow}", |
| 82 |
"${ansi.fg.blue}", |
| 83 |
"${ansi.fg.purple}", |
| 84 |
"${ansi.fg.cyan}", |
| 85 |
"${ansi.fg.white}", |
| 86 |
"${ansi.bg.black}", |
| 87 |
"${ansi.bg.red}", |
| 88 |
"${ansi.bg.green}", |
| 89 |
"${ansi.bg.yellow}", |
| 90 |
"${ansi.bg.blue}", |
| 91 |
"${ansi.bg.purple}", |
| 92 |
"${ansi.bg.cyan}", |
| 93 |
"${ansi.bg.white}", |
| 94 |
"${file.basename}", |
| 95 |
"${file.dirname}", |
| 96 |
"${file.fullpath}", |
| 97 |
"${frame.index}", |
| 98 |
"${frame.pc}", |
| 99 |
"${frame.fp}", |
| 100 |
"${frame.sp}", |
| 101 |
"${frame.flags}", |
| 102 |
"${frame.no-debug}", |
| 103 |
"${frame.reg.*}", |
| 104 |
"${frame.is-artificial}", |
| 105 |
"${function.id}", |
| 106 |
"${function.name}", |
| 107 |
"${function.name-without-args}", |
| 108 |
"${function.name-with-args}", |
| 109 |
"${function.mangled-name}", |
| 110 |
"${function.addr-offset}", |
| 111 |
"${function.concrete-only-addr-offset-no-padding}", |
| 112 |
"${function.line-offset}", |
| 113 |
"${function.pc-offset}", |
| 114 |
"${function.initial-function}", |
| 115 |
"${function.changed}", |
| 116 |
"${function.is-optimized}", |
| 117 |
"${line.file.basename}", |
| 118 |
"${line.file.dirname}", |
| 119 |
"${line.file.fullpath}", |
| 120 |
"${line.number}", |
| 121 |
"${line.column}", |
| 122 |
"${line.start-addr}", |
| 123 |
"${line.end-addr}", |
| 124 |
"${module.file.basename}", |
| 125 |
"${module.file.dirname}", |
| 126 |
"${module.file.fullpath}", |
| 127 |
"${process.id}", |
| 128 |
"${process.name}", |
| 129 |
"${process.file.basename}", |
| 130 |
"${process.file.dirname}", |
| 131 |
"${process.file.fullpath}", |
| 132 |
"${script.frame}", |
| 133 |
"${script.process}", |
| 134 |
"${script.target}", |
| 135 |
"${script.thread}", |
| 136 |
"${script.var}", |
| 137 |
"${script.svar}", |
| 138 |
"${script.thread}", |
| 139 |
"${svar.dummy-svar-to-test-wildcard}", |
| 140 |
"${thread.id}", |
| 141 |
"${thread.protocol_id}", |
| 142 |
"${thread.index}", |
| 143 |
"${thread.info.*}", |
| 144 |
"${thread.queue}", |
| 145 |
"${thread.name}", |
| 146 |
"${thread.stop-reason}", |
| 147 |
"${thread.stop-reason-raw}", |
| 148 |
"${thread.return-value}", |
| 149 |
"${thread.completed-expression}", |
| 150 |
"${target.arch}", |
| 151 |
"${var.dummy-var-to-test-wildcard}"}; |
| 152 |
|
| 153 |
TEST(FormatEntity, LookupAllEntriesInTree) { |
| 154 |
for (const llvm::StringRef testString : lookupStrings) { |
| 155 |
Entry e; |
| 156 |
EXPECT_TRUE(FormatEntity::Parse(testString, e).Success()) |
| 157 |
<< "Formatting " << testString << " did not succeed"; |
| 158 |
} |
| 159 |
} |