diff --git a/llvm/unittests/TextAPI/TextStubHelpers.h b/llvm/unittests/TextAPI/TextStubHelpers.h new file mode 100644 --- /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 +#include + +#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; +using UUIDs = std::vector>; + +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 --- 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; - -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 --- 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; - -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 --- 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; -using UUIDs = std::vector>; - -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 --- 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; -using UUIDs = std::vector>; - -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 @@ 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 @@ 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)));