aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/TextAPI
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2020-02-13 12:51:19 -0800
committerJonas Devlieghere <jonas@devlieghere.com>2020-02-13 12:53:24 -0800
commit5810ed5186dcad03d4ae53abc103638462519f11 (patch)
tree5ccad629d238a259aca9e81fe451392b2b0c4890 /llvm/unittests/TextAPI
parentc6e8bfe7c9363129d98941373a94e22c226b4c08 (diff)
downloadllvm-5810ed5186dcad03d4ae53abc103638462519f11.zip
llvm-5810ed5186dcad03d4ae53abc103638462519f11.tar.gz
llvm-5810ed5186dcad03d4ae53abc103638462519f11.tar.bz2
[llvm][TextAPI/MachO] Extract common code into unittest helper (NFC)
This extract common code between the 4 TBD formats in a header that can be shared. Differential revision: https://reviews.llvm.org/D73332
Diffstat (limited to 'llvm/unittests/TextAPI')
-rw-r--r--llvm/unittests/TextAPI/TextStubHelpers.h41
-rw-r--r--llvm/unittests/TextAPI/TextStubV1Tests.cpp18
-rw-r--r--llvm/unittests/TextAPI/TextStubV2Tests.cpp19
-rw-r--r--llvm/unittests/TextAPI/TextStubV3Tests.cpp25
-rw-r--r--llvm/unittests/TextAPI/TextStubV4Tests.cpp45
5 files changed, 56 insertions, 92 deletions
diff --git a/llvm/unittests/TextAPI/TextStubHelpers.h b/llvm/unittests/TextAPI/TextStubHelpers.h
new file mode 100644
index 0000000..c33a45e
--- /dev/null
+++ b/llvm/unittests/TextAPI/TextStubHelpers.h
@@ -0,0 +1,41 @@
+//===-- TextStubHelpers.cpp -------------------------------------*- C++ -*-===//
+//
+// 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/TextAPI/MachO/InterfaceFile.h"
+#include <algorithm>
+#include <string>
+
+#ifndef TEXT_STUB_HELPERS_H
+#define TEXT_STUB_HELPERS_H
+
+namespace llvm {
+struct ExportedSymbol {
+ llvm::MachO::SymbolKind Kind;
+ std::string Name;
+ bool WeakDefined;
+ bool ThreadLocalValue;
+};
+
+using ExportedSymbolSeq = std::vector<ExportedSymbol>;
+using UUIDs = std::vector<std::pair<llvm::MachO::Target, std::string>>;
+
+inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
+ return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
+}
+
+inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
+ return std::tie(LHS.Kind, LHS.Name, LHS.WeakDefined, LHS.ThreadLocalValue) ==
+ std::tie(RHS.Kind, RHS.Name, RHS.WeakDefined, RHS.ThreadLocalValue);
+}
+
+inline std::string stripWhitespace(std::string S) {
+ S.erase(std::remove_if(S.begin(), S.end(), ::isspace), S.end());
+ return S;
+}
+} // namespace llvm
+#endif
diff --git a/llvm/unittests/TextAPI/TextStubV1Tests.cpp b/llvm/unittests/TextAPI/TextStubV1Tests.cpp
index 68baac1..441db0a 100644
--- a/llvm/unittests/TextAPI/TextStubV1Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV1Tests.cpp
@@ -6,6 +6,7 @@
//
//===-----------------------------------------------------------------------===/
+#include "TextStubHelpers.h"
#include "llvm/TextAPI/MachO/InterfaceFile.h"
#include "llvm/TextAPI/MachO/TextAPIReader.h"
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -16,23 +17,6 @@
using namespace llvm;
using namespace llvm::MachO;
-struct ExportedSymbol {
- SymbolKind Kind;
- std::string Name;
- bool WeakDefined;
- bool ThreadLocalValue;
-};
-using ExportedSymbolSeq = std::vector<ExportedSymbol>;
-
-inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
- return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
-}
-
-inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
- return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
- std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
-}
-
static ExportedSymbol TBDv1Symbols[] = {
{SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
{SymbolKind::GlobalSymbol, "_sym1", false, false},
diff --git a/llvm/unittests/TextAPI/TextStubV2Tests.cpp b/llvm/unittests/TextAPI/TextStubV2Tests.cpp
index 31de7fd..4864d8a 100644
--- a/llvm/unittests/TextAPI/TextStubV2Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV2Tests.cpp
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===-----------------------------------------------------------------------===/
-
+#include "TextStubHelpers.h"
#include "llvm/TextAPI/MachO/InterfaceFile.h"
#include "llvm/TextAPI/MachO/TextAPIReader.h"
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -16,23 +16,6 @@
using namespace llvm;
using namespace llvm::MachO;
-struct ExportedSymbol {
- SymbolKind Kind;
- std::string Name;
- bool WeakDefined;
- bool ThreadLocalValue;
-};
-using ExportedSymbolSeq = std::vector<ExportedSymbol>;
-
-inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
- return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
-}
-
-inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
- return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
- std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
-}
-
static ExportedSymbol TBDv2Symbols[] = {
{SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
{SymbolKind::GlobalSymbol, "_sym1", false, false},
diff --git a/llvm/unittests/TextAPI/TextStubV3Tests.cpp b/llvm/unittests/TextAPI/TextStubV3Tests.cpp
index a9e5480..fe71fa5 100644
--- a/llvm/unittests/TextAPI/TextStubV3Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV3Tests.cpp
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===-----------------------------------------------------------------------===/
-
+#include "TextStubHelpers.h"
#include "llvm/TextAPI/MachO/InterfaceFile.h"
#include "llvm/TextAPI/MachO/TextAPIReader.h"
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -16,29 +16,6 @@
using namespace llvm;
using namespace llvm::MachO;
-struct ExportedSymbol {
- SymbolKind Kind;
- std::string Name;
- bool WeakDefined;
- bool ThreadLocalValue;
-};
-using ExportedSymbolSeq = std::vector<ExportedSymbol>;
-using UUIDs = std::vector<std::pair<Target, std::string>>;
-
-inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
- return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
-}
-
-inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
- return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
- std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
-}
-
-inline std::string stripWhitespace(std::string s) {
- s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
- return s;
-}
-
static ExportedSymbol TBDv3Symbols[] = {
{SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
{SymbolKind::GlobalSymbol, "_sym1", false, false},
diff --git a/llvm/unittests/TextAPI/TextStubV4Tests.cpp b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
index 53e9bd9..07af8f2 100644
--- a/llvm/unittests/TextAPI/TextStubV4Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
@@ -5,6 +5,8 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===-----------------------------------------------------------------------===/
+
+#include "TextStubHelpers.h"
#include "llvm/TextAPI/MachO/InterfaceFile.h"
#include "llvm/TextAPI/MachO/TextAPIReader.h"
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -15,40 +17,17 @@
using namespace llvm;
using namespace llvm::MachO;
-struct ExampleSymbol {
- SymbolKind Kind;
- std::string Name;
- bool WeakDefined;
- bool ThreadLocalValue;
-};
-using ExampleSymbolSeq = std::vector<ExampleSymbol>;
-using UUIDs = std::vector<std::pair<Target, std::string>>;
-
-inline bool operator<(const ExampleSymbol &LHS, const ExampleSymbol &RHS) {
- return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
-}
-
-inline bool operator==(const ExampleSymbol &LHS, const ExampleSymbol &RHS) {
- return std::tie(LHS.Kind, LHS.Name, LHS.WeakDefined, LHS.ThreadLocalValue) ==
- std::tie(RHS.Kind, RHS.Name, RHS.WeakDefined, RHS.ThreadLocalValue);
-}
-
-inline std::string stripWhitespace(std::string s) {
- s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
- return s;
-}
-
-static ExampleSymbol TBDv4ExportedSymbols[] = {
+static ExportedSymbol TBDv4ExportedSymbols[] = {
{SymbolKind::GlobalSymbol, "_symA", false, false},
{SymbolKind::GlobalSymbol, "_symAB", false, false},
{SymbolKind::GlobalSymbol, "_symB", false, false},
};
-static ExampleSymbol TBDv4ReexportedSymbols[] = {
+static ExportedSymbol TBDv4ReexportedSymbols[] = {
{SymbolKind::GlobalSymbol, "_symC", false, false},
};
-static ExampleSymbol TBDv4UndefinedSymbols[] = {
+static ExportedSymbol TBDv4UndefinedSymbols[] = {
{SymbolKind::GlobalSymbol, "_symD", false, false},
};
@@ -146,11 +125,11 @@ TEST(TBDv4, ReadFile) {
EXPECT_EQ(1U, File->reexportedLibraries().size());
EXPECT_EQ(reexport, File->reexportedLibraries().front());
- ExampleSymbolSeq Exports, Reexports, Undefineds;
- ExampleSymbol temp;
+ ExportedSymbolSeq Exports, Reexports, Undefineds;
+ ExportedSymbol temp;
for (const auto *Sym : File->symbols()) {
- temp = ExampleSymbol{Sym->getKind(), std::string(Sym->getName()),
- Sym->isWeakDefined(), Sym->isThreadLocalValue()};
+ temp = ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),
+ Sym->isWeakDefined(), Sym->isThreadLocalValue()};
EXPECT_FALSE(Sym->isWeakReferenced());
if (Sym->isUndefined())
Undefineds.emplace_back(std::move(temp));
@@ -162,11 +141,11 @@ TEST(TBDv4, ReadFile) {
llvm::sort(Reexports.begin(), Reexports.end());
llvm::sort(Undefineds.begin(), Undefineds.end());
- EXPECT_EQ(sizeof(TBDv4ExportedSymbols) / sizeof(ExampleSymbol),
+ EXPECT_EQ(sizeof(TBDv4ExportedSymbols) / sizeof(ExportedSymbol),
Exports.size());
- EXPECT_EQ(sizeof(TBDv4ReexportedSymbols) / sizeof(ExampleSymbol),
+ EXPECT_EQ(sizeof(TBDv4ReexportedSymbols) / sizeof(ExportedSymbol),
Reexports.size());
- EXPECT_EQ(sizeof(TBDv4UndefinedSymbols) / sizeof(ExampleSymbol),
+ EXPECT_EQ(sizeof(TBDv4UndefinedSymbols) / sizeof(ExportedSymbol),
Undefineds.size());
EXPECT_TRUE(std::equal(Exports.begin(), Exports.end(),
std::begin(TBDv4ExportedSymbols)));