llvm-project
1179 строк · 45.2 Кб
1//===-- TextStubV4Tests.cpp - TBD V4 File Test ----------------------------===//
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 "TextStubHelpers.h"10#include "llvm/TextAPI/InterfaceFile.h"11#include "llvm/TextAPI/TextAPIReader.h"12#include "llvm/TextAPI/TextAPIWriter.h"13#include "gtest/gtest.h"14#include <string>15#include <vector>16
17using namespace llvm;18using namespace llvm::MachO;19
20
21namespace TBDv4 {22
23TEST(TBDv4, ReadFile) {24static const char TBDv4File[] =25"--- !tapi-tbd\n"26"tbd-version: 4\n"27"targets: [ i386-macos, x86_64-macos, x86_64-ios ]\n"28"uuids:\n"29" - target: i386-macos\n"30" value: 00000000-0000-0000-0000-000000000000\n"31" - target: x86_64-macos\n"32" value: 11111111-1111-1111-1111-111111111111\n"33" - target: x86_64-ios\n"34" value: 11111111-1111-1111-1111-111111111111\n"35"flags: [ flat_namespace, installapi ]\n"36"install-name: Umbrella.framework/Umbrella\n"37"current-version: 1.2.3\n"38"compatibility-version: 1.2\n"39"swift-abi-version: 5\n"40"parent-umbrella:\n"41" - targets: [ i386-macos, x86_64-macos, x86_64-ios ]\n"42" umbrella: System\n"43"allowable-clients:\n"44" - targets: [ i386-macos, x86_64-macos, x86_64-ios ]\n"45" clients: [ ClientA ]\n"46"reexported-libraries:\n"47" - targets: [ i386-macos ]\n"48" libraries: [ /System/Library/Frameworks/A.framework/A ]\n"49"exports:\n"50" - targets: [ i386-macos ]\n"51" symbols: [ _symA ]\n"52" objc-classes: []\n"53" objc-eh-types: []\n"54" objc-ivars: []\n"55" weak-symbols: []\n"56" thread-local-symbols: []\n"57" - targets: [ x86_64-ios ]\n"58" symbols: [_symB]\n"59" - targets: [ x86_64-macos, x86_64-ios ]\n"60" symbols: [_symAB]\n"61"reexports:\n"62" - targets: [ i386-macos ]\n"63" symbols: [_symC]\n"64" objc-classes: []\n"65" objc-eh-types: []\n"66" objc-ivars: []\n"67" weak-symbols: [weakReexport]\n"68" thread-local-symbols: []\n"69"undefineds:\n"70" - targets: [ i386-macos ]\n"71" symbols: [ _symD ]\n"72" objc-classes: []\n"73" objc-eh-types: []\n"74" objc-ivars: []\n"75" weak-symbols: [weakReference]\n"76" thread-local-symbols: []\n"77"...\n";78
79Expected<TBDFile> Result =80TextAPIReader::get(MemoryBufferRef(TBDv4File, "Test.tbd"));81EXPECT_TRUE(!!Result);82TBDFile File = std::move(Result.get());83EXPECT_EQ(FileType::TBD_V4, File->getFileType());84PlatformSet Platforms;85Platforms.insert(getPlatformFromName("macos"));86Platforms.insert(getPlatformFromName("ios"));87auto Archs = AK_i386 | AK_x86_64;88TargetList Targets = {89Target(AK_i386, PLATFORM_MACOS),90Target(AK_x86_64, PLATFORM_MACOS),91Target(AK_x86_64, PLATFORM_IOS),92};93EXPECT_EQ(Archs, File->getArchitectures());94EXPECT_EQ(Platforms.size(), File->getPlatforms().size());95for (auto Platform : File->getPlatforms())96EXPECT_EQ(Platforms.count(Platform), 1U);97EXPECT_EQ(std::string("Umbrella.framework/Umbrella"), File->getInstallName());98EXPECT_EQ(PackedVersion(1, 2, 3), File->getCurrentVersion());99EXPECT_EQ(PackedVersion(1, 2, 0), File->getCompatibilityVersion());100EXPECT_EQ(5U, File->getSwiftABIVersion());101EXPECT_FALSE(File->isTwoLevelNamespace());102EXPECT_TRUE(File->isApplicationExtensionSafe());103EXPECT_FALSE(File->isOSLibNotForSharedCache());104InterfaceFileRef client("ClientA", Targets);105InterfaceFileRef reexport("/System/Library/Frameworks/A.framework/A",106{Targets[0]});107EXPECT_EQ(1U, File->allowableClients().size());108EXPECT_EQ(client, File->allowableClients().front());109EXPECT_EQ(1U, File->reexportedLibraries().size());110EXPECT_EQ(reexport, File->reexportedLibraries().front());111
112ExportedSymbolSeq Exports, Reexports, Undefineds;113for (const auto *Sym : File->symbols()) {114ExportedSymbol Temp =115ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),116Sym->isWeakDefined() || Sym->isWeakReferenced(),117Sym->isThreadLocalValue()};118if (Sym->isUndefined()) {119EXPECT_FALSE(Sym->isWeakDefined());120Undefineds.emplace_back(std::move(Temp));121}122// Check that defined symbols cannot be set as weak referenced.123else if (Sym->isReexported()) {124EXPECT_FALSE(Sym->isWeakReferenced());125Reexports.emplace_back(std::move(Temp));126} else {127EXPECT_FALSE(Sym->isWeakReferenced());128Exports.emplace_back(std::move(Temp));129}130}131llvm::sort(Exports);132llvm::sort(Reexports);133llvm::sort(Undefineds);134
135static ExportedSymbol ExpectedExportedSymbols[] = {136{EncodeKind::GlobalSymbol, "_symA", false, false},137{EncodeKind::GlobalSymbol, "_symAB", false, false},138{EncodeKind::GlobalSymbol, "_symB", false, false},139};140
141static ExportedSymbol ExpectedReexportedSymbols[] = {142{EncodeKind::GlobalSymbol, "_symC", false, false},143{EncodeKind::GlobalSymbol, "weakReexport", true, false},144};145
146static ExportedSymbol ExpectedUndefinedSymbols[] = {147{EncodeKind::GlobalSymbol, "_symD", false, false},148{EncodeKind::GlobalSymbol, "weakReference", true, false},149};150
151EXPECT_EQ(std::size(ExpectedExportedSymbols), Exports.size());152EXPECT_EQ(std::size(ExpectedReexportedSymbols), Reexports.size());153EXPECT_EQ(std::size(ExpectedUndefinedSymbols), Undefineds.size());154EXPECT_TRUE(std::equal(Exports.begin(), Exports.end(),155std::begin(ExpectedExportedSymbols)));156EXPECT_TRUE(std::equal(Reexports.begin(), Reexports.end(),157std::begin(ExpectedReexportedSymbols)));158EXPECT_TRUE(std::equal(Undefineds.begin(), Undefineds.end(),159std::begin(ExpectedUndefinedSymbols)));160}
161
162TEST(TBDv4, ReadMultipleDocuments) {163static const char TBDv4Inlines[] =164"--- !tapi-tbd\n"165"tbd-version: 4\n"166"targets: [ i386-macos, i386-maccatalyst, x86_64-macos, "167"x86_64-maccatalyst ]\n"168"install-name: /System/Library/Frameworks/Umbrella.framework/Umbrella\n"169"parent-umbrella:\n"170" - targets: [ i386-macos, x86_64-macos ]\n"171" umbrella: System\n"172"reexported-libraries:\n"173" - targets: [ i386-macos, x86_64-macos ]\n"174" libraries: [ /System/Library/Frameworks/A.framework/A ]\n"175"--- !tapi-tbd\n"176"tbd-version: 4\n"177"targets: [ i386-macos, x86_64-macos ]\n"178"uuids:\n"179" - target: i386-macos\n"180" value: 20000000-0000-0000-0000-000000000000\n"181" - target: x86_64-macos\n"182" value: 21111111-1111-1111-1111-111111111111\n"183"flags: [ flat_namespace ]\n"184"install-name: /System/Library/Frameworks/A.framework/A\n"185"current-version: 1.2.3\n"186"compatibility-version: 1.2\n"187"swift-abi-version: 5\n"188"exports:\n"189" - targets: [ i386-macos ]\n"190" symbols: [ _symA ]\n"191" objc-classes: []\n"192" objc-eh-types: []\n"193" objc-ivars: []\n"194" weak-symbols: []\n"195" thread-local-symbols: []\n"196" - targets: [ x86_64-macos ]\n"197" symbols: [_symAB]\n"198"reexports:\n"199" - targets: [ i386-macos ]\n"200" symbols: [_symC]\n"201" objc-classes: []\n"202" objc-eh-types: []\n"203" objc-ivars: []\n"204" weak-symbols: []\n"205" thread-local-symbols: []\n"206"undefineds:\n"207" - targets: [ i386-macos ]\n"208" symbols: [ _symD ]\n"209" objc-classes: []\n"210" objc-eh-types: []\n"211" objc-ivars: []\n"212" weak-symbols: []\n"213" thread-local-symbols: []\n"214"...\n";215
216PlatformSet Platforms;217Platforms.insert(PLATFORM_MACOS);218Platforms.insert(PLATFORM_MACCATALYST);219ArchitectureSet Archs = AK_i386 | AK_x86_64;220TargetList Targets;221for (auto &&Arch : Archs)222for (auto &&Platform : Platforms)223Targets.emplace_back(Target(Arch, Platform));224TargetToAttr Uuids = {225{Targets[0], "00000000-0000-0000-0000-000000000000"},226{Targets[1], "00000000-0000-0000-0000-000000000002"},227{Targets[2], "11111111-1111-1111-1111-111111111111"},228{Targets[3], "11111111-1111-1111-1111-111111111112"},229};230
231Expected<TBDFile> Result =232TextAPIReader::get(MemoryBufferRef(TBDv4Inlines, "Test.tbd"));233EXPECT_TRUE(!!Result);234TBDFile File = std::move(Result.get());235EXPECT_EQ(FileType::TBD_V4, File->getFileType());236EXPECT_EQ(Archs, File->getArchitectures());237EXPECT_EQ(Platforms, File->getPlatforms());238EXPECT_EQ(239std::string("/System/Library/Frameworks/Umbrella.framework/Umbrella"),240File->getInstallName());241EXPECT_TRUE(File->isTwoLevelNamespace());242EXPECT_TRUE(File->isApplicationExtensionSafe());243EXPECT_EQ(PackedVersion(1, 0, 0), File->getCurrentVersion());244EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());245InterfaceFileRef reexport("/System/Library/Frameworks/A.framework/A",246{Targets[0], Targets[2]});247EXPECT_EQ(1U, File->reexportedLibraries().size());248EXPECT_EQ(reexport, File->reexportedLibraries().front());249EXPECT_TRUE(File->symbols().empty());250
251// Check Inlined Document252Targets.clear();253Uuids.clear();254PlatformType Platform = PLATFORM_MACOS;255for (auto &&Arch : Archs)256Targets.emplace_back(Target(Arch, Platform));257Uuids = {258{Targets[0], "20000000-0000-0000-0000-000000000000"},259{Targets[1], "21111111-1111-1111-1111-111111111111"},260};261
262TBDReexportFile Document = File->documents().front();263EXPECT_EQ(FileType::TBD_V4, Document->getFileType());264EXPECT_EQ(Archs, Document->getArchitectures());265EXPECT_EQ(1U, Document->getPlatforms().size());266EXPECT_EQ(Platform, *(Document->getPlatforms().begin()));267EXPECT_EQ(std::string("/System/Library/Frameworks/A.framework/A"),268Document->getInstallName());269EXPECT_EQ(PackedVersion(1, 2, 3), Document->getCurrentVersion());270EXPECT_EQ(PackedVersion(1, 2, 0), Document->getCompatibilityVersion());271EXPECT_EQ(5U, Document->getSwiftABIVersion());272EXPECT_FALSE(Document->isTwoLevelNamespace());273EXPECT_TRUE(Document->isApplicationExtensionSafe());274
275ExportedSymbolSeq Exports;276ExportedSymbolSeq Reexports, Undefineds;277for (const auto *Sym : Document->symbols()) {278ExportedSymbol Temp =279ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),280Sym->isWeakDefined(), Sym->isThreadLocalValue()};281EXPECT_FALSE(Sym->isWeakReferenced());282if (Sym->isUndefined())283Undefineds.emplace_back(std::move(Temp));284else285Sym->isReexported() ? Reexports.emplace_back(std::move(Temp))286: Exports.emplace_back(std::move(Temp));287}288llvm::sort(Exports);289llvm::sort(Reexports);290llvm::sort(Undefineds);291
292static ExportedSymbol ExpectedExportedSymbols[] = {293{EncodeKind::GlobalSymbol, "_symA", false, false},294{EncodeKind::GlobalSymbol, "_symAB", false, false},295};296
297static ExportedSymbol ExpectedReexportedSymbols[] = {298{EncodeKind::GlobalSymbol, "_symC", false, false},299};300
301static ExportedSymbol ExpectedUndefinedSymbols[] = {302{EncodeKind::GlobalSymbol, "_symD", false, false},303};304
305EXPECT_EQ(std::size(ExpectedExportedSymbols), Exports.size());306EXPECT_EQ(std::size(ExpectedReexportedSymbols), Reexports.size());307EXPECT_EQ(std::size(ExpectedUndefinedSymbols), Undefineds.size());308EXPECT_TRUE(std::equal(Exports.begin(), Exports.end(),309std::begin(ExpectedExportedSymbols)));310EXPECT_TRUE(std::equal(Reexports.begin(), Reexports.end(),311std::begin(ExpectedReexportedSymbols)));312EXPECT_TRUE(std::equal(Undefineds.begin(), Undefineds.end(),313std::begin(ExpectedUndefinedSymbols)));314}
315
316TEST(TBDv4, WriteFile) {317static const char TBDv4File[] =318"--- !tapi-tbd\n"319"tbd-version: 4\n"320"targets: [ i386-macos, x86_64-ios-simulator ]\n"321"install-name: 'Umbrella.framework/Umbrella'\n"322"current-version: 1.2.3\n"323"compatibility-version: 0\n"324"swift-abi-version: 5\n"325"parent-umbrella:\n"326" - targets: [ i386-macos, x86_64-ios-simulator ]\n"327" umbrella: System\n"328"allowable-clients:\n"329" - targets: [ i386-macos ]\n"330" clients: [ ClientA ]\n"331"exports:\n"332" - targets: [ i386-macos ]\n"333" symbols: [ _symA ]\n"334" objc-classes: [ Class1 ]\n"335" weak-symbols: [ _symC ]\n"336" - targets: [ x86_64-ios-simulator ]\n"337" symbols: [ _symB ]\n"338"...\n";339
340InterfaceFile File;341TargetList Targets = {342Target(AK_i386, PLATFORM_MACOS),343Target(AK_x86_64, PLATFORM_IOSSIMULATOR),344};345File.setInstallName("Umbrella.framework/Umbrella");346File.setFileType(FileType::TBD_V4);347File.addTargets(Targets);348File.setCurrentVersion(PackedVersion(1, 2, 3));349File.setTwoLevelNamespace();350File.setApplicationExtensionSafe(true);351File.setSwiftABIVersion(5);352File.addAllowableClient("ClientA", Targets[0]);353File.addParentUmbrella(Targets[0], "System");354File.addParentUmbrella(Targets[1], "System");355File.addSymbol(EncodeKind::GlobalSymbol, "_symA", {Targets[0]});356File.addSymbol(EncodeKind::GlobalSymbol, "_symB", {Targets[1]});357File.addSymbol(EncodeKind::GlobalSymbol, "_symC", {Targets[0]},358SymbolFlags::WeakDefined);359File.addSymbol(EncodeKind::ObjectiveCClass, "Class1", {Targets[0]});360
361SmallString<4096> Buffer;362raw_svector_ostream OS(Buffer);363Error Result = TextAPIWriter::writeToStream(OS, File);364EXPECT_FALSE(Result);365EXPECT_STREQ(TBDv4File, Buffer.c_str());366}
367
368TEST(TBDv4, WriteMultipleDocuments) {369static const char TBDv4Inlines[] =370"--- !tapi-tbd\n"371"tbd-version: 4\n"372"targets: [ i386-maccatalyst, x86_64-maccatalyst ]\n"373"install-name: "374"'/System/Library/Frameworks/Umbrella.framework/Umbrella'\n"375"reexported-libraries:\n"376" - targets: [ i386-maccatalyst, x86_64-maccatalyst ]\n"377" libraries: [ '/System/Library/Frameworks/A.framework/A' ]\n"378"--- !tapi-tbd\n"379"tbd-version: 4\n"380"targets: [ i386-maccatalyst, x86_64-maccatalyst ]\n"381"install-name: '/System/Library/Frameworks/A.framework/A'\n"382"exports:\n"383" - targets: [ i386-maccatalyst ]\n"384" weak-symbols: [ _symC ]\n"385" - targets: [ i386-maccatalyst, x86_64-maccatalyst ]\n"386" symbols: [ _symA ]\n"387" objc-classes: [ Class1 ]\n"388" - targets: [ x86_64-maccatalyst ]\n"389" symbols: [ _symAB ]\n"390"...\n";391
392InterfaceFile File;393PlatformType Platform = PLATFORM_MACCATALYST;394TargetList Targets = {395Target(AK_i386, Platform),396Target(AK_x86_64, Platform),397};398TargetToAttr Uuids = {{Targets[0], "00000000-0000-0000-0000-000000000002"},399{Targets[1], "11111111-1111-1111-1111-111111111112"}};400File.setInstallName("/System/Library/Frameworks/Umbrella.framework/Umbrella");401File.setFileType(FileType::TBD_V4);402File.addTargets(Targets);403File.setCompatibilityVersion(PackedVersion(1, 0, 0));404File.setCurrentVersion(PackedVersion(1, 0, 0));405File.setTwoLevelNamespace();406File.setApplicationExtensionSafe(true);407File.addReexportedLibrary("/System/Library/Frameworks/A.framework/A",408Targets[0]);409File.addReexportedLibrary("/System/Library/Frameworks/A.framework/A",410Targets[1]);411
412// Write Second Document413Uuids = {{Targets[0], "00000000-0000-0000-0000-000000000000"},414{Targets[1], "11111111-1111-1111-1111-111111111111"}};415InterfaceFile Document;416Document.setInstallName("/System/Library/Frameworks/A.framework/A");417Document.setFileType(FileType::TBD_V4);418Document.addTargets(Targets);419Document.setCompatibilityVersion(PackedVersion(1, 0, 0));420Document.setCurrentVersion(PackedVersion(1, 0, 0));421Document.setTwoLevelNamespace();422Document.setApplicationExtensionSafe(true);423Document.addSymbol(EncodeKind::GlobalSymbol, "_symA", Targets);424Document.addSymbol(EncodeKind::GlobalSymbol, "_symAB", {Targets[1]});425Document.addSymbol(EncodeKind::GlobalSymbol, "_symC", {Targets[0]},426SymbolFlags::WeakDefined);427Document.addSymbol(EncodeKind::ObjectiveCClass, "Class1", Targets);428File.addDocument(std::make_shared<InterfaceFile>(std::move(Document)));429
430SmallString<4096> Buffer;431raw_svector_ostream OS(Buffer);432Error Result = TextAPIWriter::writeToStream(OS, File);433EXPECT_FALSE(Result);434EXPECT_STREQ(TBDv4Inlines, Buffer.c_str());435}
436
437TEST(TBDv4, MultipleTargets) {438static const char TBDv4MultipleTargets[] =439"--- !tapi-tbd\n"440"tbd-version: 4\n"441"targets: [ i386-maccatalyst, x86_64-tvos, arm64-ios ]\n"442"install-name: Test.dylib\n"443"...\n";444
445Expected<TBDFile> Result =446TextAPIReader::get(MemoryBufferRef(TBDv4MultipleTargets, "Test.tbd"));447EXPECT_TRUE(!!Result);448PlatformSet Platforms;449Platforms.insert(PLATFORM_MACCATALYST);450Platforms.insert(PLATFORM_TVOS);451Platforms.insert(PLATFORM_IOS);452TBDFile File = std::move(Result.get());453EXPECT_EQ(FileType::TBD_V4, File->getFileType());454EXPECT_EQ(AK_x86_64 | AK_arm64 | AK_i386, File->getArchitectures());455EXPECT_EQ(Platforms.size(), File->getPlatforms().size());456for (auto Platform : File->getPlatforms())457EXPECT_EQ(Platforms.count(Platform), 1U);458
459SmallString<4096> Buffer;460raw_svector_ostream OS(Buffer);461Error WriteResult = TextAPIWriter::writeToStream(OS, *File);462EXPECT_TRUE(!WriteResult);463EXPECT_EQ(stripWhitespace(TBDv4MultipleTargets),464stripWhitespace(Buffer.c_str()));465}
466
467TEST(TBDv4, MultipleTargetsSameArch) {468static const char TBDv4TargetsSameArch[] =469"--- !tapi-tbd\n"470"tbd-version: 4\n"471"targets: [ x86_64-tvos , x86_64-maccatalyst ]\n"472"install-name: Test.dylib\n"473"...\n";474
475Expected<TBDFile> Result =476TextAPIReader::get(MemoryBufferRef(TBDv4TargetsSameArch, "Test.tbd"));477EXPECT_TRUE(!!Result);478PlatformSet Platforms;479Platforms.insert(PLATFORM_TVOS);480Platforms.insert(PLATFORM_MACCATALYST);481TBDFile File = std::move(Result.get());482EXPECT_EQ(FileType::TBD_V4, File->getFileType());483EXPECT_EQ(ArchitectureSet(AK_x86_64), File->getArchitectures());484EXPECT_EQ(Platforms.size(), File->getPlatforms().size());485for (auto Platform : File->getPlatforms())486EXPECT_EQ(Platforms.count(Platform), 1U);487
488SmallString<4096> Buffer;489raw_svector_ostream OS(Buffer);490Error WriteResult = TextAPIWriter::writeToStream(OS, *File);491EXPECT_TRUE(!WriteResult);492EXPECT_EQ(stripWhitespace(TBDv4TargetsSameArch),493stripWhitespace(Buffer.c_str()));494}
495
496TEST(TBDv4, MultipleTargetsSamePlatform) {497static const char TBDv4MultipleTargetsSamePlatform[] =498"--- !tapi-tbd\n"499"tbd-version: 4\n"500"targets: [ armv7k-ios , arm64-ios]\n"501"install-name: Test.dylib\n"502"...\n";503
504Expected<TBDFile> Result = TextAPIReader::get(505MemoryBufferRef(TBDv4MultipleTargetsSamePlatform, "Test.tbd"));506EXPECT_TRUE(!!Result);507TBDFile File = std::move(Result.get());508EXPECT_EQ(FileType::TBD_V4, File->getFileType());509EXPECT_EQ(AK_arm64 | AK_armv7k, File->getArchitectures());510EXPECT_EQ(File->getPlatforms().size(), 1U);511EXPECT_EQ(PLATFORM_IOS, *File->getPlatforms().begin());512
513SmallString<4096> Buffer;514raw_svector_ostream OS(Buffer);515Error WriteResult = TextAPIWriter::writeToStream(OS, *File);516EXPECT_TRUE(!WriteResult);517EXPECT_EQ(stripWhitespace(TBDv4MultipleTargetsSamePlatform),518stripWhitespace(Buffer.c_str()));519}
520
521TEST(TBDv4, Target_maccatalyst) {522static const char TBDv4TargetMacCatalyst[] =523"--- !tapi-tbd\n"524"tbd-version: 4\n"525"targets: [ x86_64-maccatalyst ]\n"526"install-name: Test.dylib\n"527"...\n";528
529Expected<TBDFile> Result =530TextAPIReader::get(MemoryBufferRef(TBDv4TargetMacCatalyst, "Test.tbd"));531EXPECT_TRUE(!!Result);532TBDFile File = std::move(Result.get());533EXPECT_EQ(FileType::TBD_V4, File->getFileType());534EXPECT_EQ(ArchitectureSet(AK_x86_64), File->getArchitectures());535EXPECT_EQ(File->getPlatforms().size(), 1U);536EXPECT_EQ(PLATFORM_MACCATALYST, *File->getPlatforms().begin());537
538SmallString<4096> Buffer;539raw_svector_ostream OS(Buffer);540Error WriteResult = TextAPIWriter::writeToStream(OS, *File);541EXPECT_TRUE(!WriteResult);542EXPECT_EQ(stripWhitespace(TBDv4TargetMacCatalyst),543stripWhitespace(Buffer.c_str()));544}
545
546TEST(TBDv4, Target_maccatalyst2) {547static const char TBDv4TargetMacCatalyst[] =548"--- !tapi-tbd\n"549"tbd-version: 4\n"550"targets: [ x86_64-maccatalyst ]\n"551"install-name: Test.dylib\n"552"...\n";553
554Expected<TBDFile> Result =555TextAPIReader::get(MemoryBufferRef(TBDv4TargetMacCatalyst, "Test.tbd"));556EXPECT_TRUE(!!Result);557TBDFile File = std::move(Result.get());558EXPECT_EQ(File->getPlatforms().size(), 1U);559EXPECT_EQ(getPlatformFromName("ios-macabi"), *File->getPlatforms().begin());560}
561
562TEST(TBDv4, Target_x86_ios) {563static const char TBDv4Targetx86iOS[] = "--- !tapi-tbd\n"564"tbd-version: 4\n"565"targets: [ x86_64-ios ]\n"566"install-name: Test.dylib\n"567"...\n";568
569Expected<TBDFile> Result =570TextAPIReader::get(MemoryBufferRef(TBDv4Targetx86iOS, "Test.tbd"));571EXPECT_TRUE(!!Result);572TBDFile File = std::move(Result.get());573EXPECT_EQ(FileType::TBD_V4, File->getFileType());574EXPECT_EQ(ArchitectureSet(AK_x86_64), File->getArchitectures());575EXPECT_EQ(File->getPlatforms().size(), 1U);576EXPECT_EQ(PLATFORM_IOS, *File->getPlatforms().begin());577
578SmallString<4096> Buffer;579raw_svector_ostream OS(Buffer);580Error WriteResult = TextAPIWriter::writeToStream(OS, *File);581EXPECT_TRUE(!WriteResult);582EXPECT_EQ(stripWhitespace(TBDv4Targetx86iOS),583stripWhitespace(Buffer.c_str()));584}
585
586TEST(TBDv4, Target_arm_bridgeOS) {587static const char TBDv4PlatformBridgeOS[] = "--- !tapi-tbd\n"588"tbd-version: 4\n"589"targets: [ armv7k-bridgeos ]\n"590"install-name: Test.dylib\n"591"...\n";592
593Expected<TBDFile> Result =594TextAPIReader::get(MemoryBufferRef(TBDv4PlatformBridgeOS, "Test.tbd"));595EXPECT_TRUE(!!Result);596TBDFile File = std::move(Result.get());597EXPECT_EQ(FileType::TBD_V4, File->getFileType());598EXPECT_EQ(File->getPlatforms().size(), 1U);599EXPECT_EQ(PLATFORM_BRIDGEOS, *File->getPlatforms().begin());600EXPECT_EQ(ArchitectureSet(AK_armv7k), File->getArchitectures());601
602SmallString<4096> Buffer;603raw_svector_ostream OS(Buffer);604Error WriteResult = TextAPIWriter::writeToStream(OS, *File);605EXPECT_TRUE(!WriteResult);606EXPECT_EQ(stripWhitespace(TBDv4PlatformBridgeOS),607stripWhitespace(Buffer.c_str()));608}
609
610TEST(TBDv4, Target_arm_iOS) {611static const char TBDv4ArchArm64e[] = "--- !tapi-tbd\n"612"tbd-version: 4\n"613"targets: [ arm64e-ios ]\n"614"install-name: Test.dylib\n"615"...\n";616
617Expected<TBDFile> Result =618TextAPIReader::get(MemoryBufferRef(TBDv4ArchArm64e, "Test.tbd"));619EXPECT_TRUE(!!Result);620TBDFile File = std::move(Result.get());621EXPECT_EQ(FileType::TBD_V4, File->getFileType());622EXPECT_EQ(File->getPlatforms().size(), 1U);623EXPECT_EQ(PLATFORM_IOS, *File->getPlatforms().begin());624EXPECT_EQ(ArchitectureSet(AK_arm64e), File->getArchitectures());625
626SmallString<4096> Buffer;627raw_svector_ostream OS(Buffer);628Error WriteResult = TextAPIWriter::writeToStream(OS, *File);629EXPECT_TRUE(!WriteResult);630EXPECT_EQ(stripWhitespace(TBDv4ArchArm64e), stripWhitespace(Buffer.c_str()));631}
632
633TEST(TBDv4, Target_x86_macos) {634static const char TBDv4Targetx86MacOS[] = "--- !tapi-tbd\n"635"tbd-version: 4\n"636"targets: [ x86_64-macos ]\n"637"install-name: Test.dylib\n"638"...\n";639
640Expected<TBDFile> Result =641TextAPIReader::get(MemoryBufferRef(TBDv4Targetx86MacOS, "Test.tbd"));642EXPECT_TRUE(!!Result);643TBDFile File = std::move(Result.get());644EXPECT_EQ(FileType::TBD_V4, File->getFileType());645EXPECT_EQ(ArchitectureSet(AK_x86_64), File->getArchitectures());646EXPECT_EQ(File->getPlatforms().size(), 1U);647EXPECT_EQ(PLATFORM_MACOS, *File->getPlatforms().begin());648
649SmallString<4096> Buffer;650raw_svector_ostream OS(Buffer);651Error WriteResult = TextAPIWriter::writeToStream(OS, *File);652EXPECT_TRUE(!WriteResult);653EXPECT_EQ(stripWhitespace(TBDv4Targetx86MacOS),654stripWhitespace(Buffer.c_str()));655}
656
657TEST(TBDv4, Target_x86_ios_simulator) {658static const char TBDv4Targetx86iOSSim[] =659"--- !tapi-tbd\n"660"tbd-version: 4\n"661"targets: [ x86_64-ios-simulator ]\n"662"install-name: Test.dylib\n"663"...\n";664
665Expected<TBDFile> Result =666TextAPIReader::get(MemoryBufferRef(TBDv4Targetx86iOSSim, "Test.tbd"));667EXPECT_TRUE(!!Result);668TBDFile File = std::move(Result.get());669EXPECT_EQ(FileType::TBD_V4, File->getFileType());670EXPECT_EQ(ArchitectureSet(AK_x86_64), File->getArchitectures());671EXPECT_EQ(File->getPlatforms().size(), 1U);672EXPECT_EQ(PLATFORM_IOSSIMULATOR, *File->getPlatforms().begin());673
674SmallString<4096> Buffer;675raw_svector_ostream OS(Buffer);676Error WriteResult = TextAPIWriter::writeToStream(OS, *File);677EXPECT_TRUE(!WriteResult);678EXPECT_EQ(stripWhitespace(TBDv4Targetx86iOSSim),679stripWhitespace(Buffer.c_str()));680}
681
682TEST(TBDv4, Target_x86_tvos_simulator) {683static const char TBDv4x86tvOSSim[] = "--- !tapi-tbd\n"684"tbd-version: 4\n"685"targets: [ x86_64-tvos-simulator ]\n"686"install-name: Test.dylib\n"687"...\n";688
689Expected<TBDFile> Result =690TextAPIReader::get(MemoryBufferRef(TBDv4x86tvOSSim, "Test.tbd"));691EXPECT_TRUE(!!Result);692TBDFile File = std::move(Result.get());693EXPECT_EQ(FileType::TBD_V4, File->getFileType());694EXPECT_EQ(ArchitectureSet(AK_x86_64), File->getArchitectures());695EXPECT_EQ(File->getPlatforms().size(), 1U);696EXPECT_EQ(PLATFORM_TVOSSIMULATOR, *File->getPlatforms().begin());697
698SmallString<4096> Buffer;699raw_svector_ostream OS(Buffer);700Error WriteResult = TextAPIWriter::writeToStream(OS, *File);701EXPECT_TRUE(!WriteResult);702EXPECT_EQ(stripWhitespace(TBDv4x86tvOSSim), stripWhitespace(Buffer.c_str()));703}
704
705TEST(TBDv4, Target_i386_watchos_simulator) {706static const char TBDv4i386watchOSSim[] =707"--- !tapi-tbd\n"708"tbd-version: 4\n"709"targets: [ i386-watchos-simulator ]\n"710"install-name: Test.dylib\n"711"...\n";712
713Expected<TBDFile> Result =714TextAPIReader::get(MemoryBufferRef(TBDv4i386watchOSSim, "Test.tbd"));715EXPECT_TRUE(!!Result);716TBDFile File = std::move(Result.get());717EXPECT_EQ(FileType::TBD_V4, File->getFileType());718EXPECT_EQ(ArchitectureSet(AK_i386), File->getArchitectures());719EXPECT_EQ(File->getPlatforms().size(), 1U);720EXPECT_EQ(PLATFORM_WATCHOSSIMULATOR, *File->getPlatforms().begin());721
722SmallString<4096> Buffer;723raw_svector_ostream OS(Buffer);724Error WriteResult = TextAPIWriter::writeToStream(OS, *File);725EXPECT_TRUE(!WriteResult);726EXPECT_EQ(stripWhitespace(TBDv4i386watchOSSim),727stripWhitespace(Buffer.c_str()));728}
729
730TEST(TBDv4, Target_i386_driverkit) {731static const char TBDv4i386DriverKit[] = "--- !tapi-tbd\n"732"tbd-version: 4\n"733"targets: [ i386-driverkit ]\n"734"install-name: Test.dylib\n"735"...\n";736
737Expected<TBDFile> Result =738TextAPIReader::get(MemoryBufferRef(TBDv4i386DriverKit, "Test.tbd"));739EXPECT_TRUE(!!Result);740TBDFile File = std::move(Result.get());741EXPECT_EQ(FileType::TBD_V4, File->getFileType());742EXPECT_EQ(ArchitectureSet(AK_i386), File->getArchitectures());743EXPECT_EQ(File->getPlatforms().size(), 1U);744EXPECT_EQ(PLATFORM_DRIVERKIT, *File->getPlatforms().begin());745
746SmallString<4096> Buffer;747raw_svector_ostream OS(Buffer);748Error WriteResult = TextAPIWriter::writeToStream(OS, *File);749EXPECT_TRUE(!WriteResult);750EXPECT_EQ(stripWhitespace(TBDv4i386DriverKit),751stripWhitespace(Buffer.c_str()));752}
753
754TEST(TBDv4, Target_arm64_xros) {755static const char TBDv4ArchArm64e[] =756"--- !tapi-tbd\n"757"tbd-version: 4\n"758"targets: [ arm64e-xros, arm64e-xros-simulator ]\n"759"install-name: Test.dylib\n"760"...\n";761
762auto Result =763TextAPIReader::get(MemoryBufferRef(TBDv4ArchArm64e, "Test.tbd"));764EXPECT_TRUE(!!Result);765auto File = std::move(Result.get());766EXPECT_EQ(FileType::TBD_V4, File->getFileType());767PlatformSet ExpectedSet;768ExpectedSet.insert(PLATFORM_XROS);769ExpectedSet.insert(PLATFORM_XROS_SIMULATOR);770EXPECT_EQ(File->getPlatforms().size(), 2U);771for (auto Platform : File->getPlatforms())772EXPECT_EQ(ExpectedSet.count(Platform), 1U);773
774EXPECT_EQ(ArchitectureSet(AK_arm64e), File->getArchitectures());775
776SmallString<4096> Buffer;777raw_svector_ostream OS(Buffer);778auto WriteResult = TextAPIWriter::writeToStream(OS, *File);779EXPECT_TRUE(!WriteResult);780EXPECT_EQ(stripWhitespace(TBDv4ArchArm64e), stripWhitespace(Buffer.c_str()));781}
782
783TEST(TBDv4, Swift_1) {784static const char TBDv4SwiftVersion1[] = "--- !tapi-tbd\n"785"tbd-version: 4\n"786"targets: [ x86_64-macos ]\n"787"install-name: Test.dylib\n"788"swift-abi-version: 1\n"789"...\n";790
791Expected<TBDFile> Result =792TextAPIReader::get(MemoryBufferRef(TBDv4SwiftVersion1, "Test.tbd"));793EXPECT_TRUE(!!Result);794TBDFile File = std::move(Result.get());795EXPECT_EQ(FileType::TBD_V4, File->getFileType());796EXPECT_EQ(1U, File->getSwiftABIVersion());797
798// No writer test because we emit "swift-abi-version:1.0".799}
800
801TEST(TBDv4, Swift_2) {802static const char TBDv4Swift2[] = "--- !tapi-tbd\n"803"tbd-version: 4\n"804"targets: [ x86_64-macos ]\n"805"install-name: Test.dylib\n"806"swift-abi-version: 2\n"807"...\n";808
809Expected<TBDFile> Result =810TextAPIReader::get(MemoryBufferRef(TBDv4Swift2, "Test.tbd"));811EXPECT_TRUE(!!Result);812TBDFile File = std::move(Result.get());813EXPECT_EQ(FileType::TBD_V4, File->getFileType());814EXPECT_EQ(2U, File->getSwiftABIVersion());815
816// No writer test because we emit "swift-abi-version:2.0".817}
818
819TEST(TBDv4, Swift_5) {820static const char TBDv4SwiftVersion5[] = "--- !tapi-tbd\n"821"tbd-version: 4\n"822"targets: [ x86_64-macos ]\n"823"install-name: Test.dylib\n"824"swift-abi-version: 5\n"825"...\n";826
827Expected<TBDFile> Result =828TextAPIReader::get(MemoryBufferRef(TBDv4SwiftVersion5, "Test.tbd"));829EXPECT_TRUE(!!Result);830TBDFile File = std::move(Result.get());831EXPECT_EQ(FileType::TBD_V4, File->getFileType());832EXPECT_EQ(5U, File->getSwiftABIVersion());833
834SmallString<4096> Buffer;835raw_svector_ostream OS(Buffer);836Error WriteResult = TextAPIWriter::writeToStream(OS, *File);837EXPECT_TRUE(!WriteResult);838EXPECT_EQ(stripWhitespace(TBDv4SwiftVersion5),839stripWhitespace(Buffer.c_str()));840}
841
842TEST(TBDv4, Swift_99) {843static const char TBDv4SwiftVersion99[] = "--- !tapi-tbd\n"844"tbd-version: 4\n"845"targets: [ x86_64-macos ]\n"846"install-name: Test.dylib\n"847"swift-abi-version: 99\n"848"...\n";849
850Expected<TBDFile> Result =851TextAPIReader::get(MemoryBufferRef(TBDv4SwiftVersion99, "Test.tbd"));852EXPECT_TRUE(!!Result);853TBDFile File = std::move(Result.get());854EXPECT_EQ(FileType::TBD_V4, File->getFileType());855EXPECT_EQ(99U, File->getSwiftABIVersion());856
857SmallString<4096> Buffer;858raw_svector_ostream OS(Buffer);859Error WriteResult = TextAPIWriter::writeToStream(OS, *File);860EXPECT_TRUE(!WriteResult);861EXPECT_EQ(stripWhitespace(TBDv4SwiftVersion99),862stripWhitespace(Buffer.c_str()));863}
864
865TEST(TBDv4, NotForSharedCache) {866
867static const char TBDv4NotForSharedCache[] =868"--- !tapi-tbd\n"869"tbd-version: 4\n"870"targets: [ arm64-macos ]\n"871"flags: [ not_for_dyld_shared_cache ]\n"872"install-name: /S/L/F/Foo.framework/Foo\n"873"...\n";874
875Expected<TBDFile> Result =876TextAPIReader::get(MemoryBufferRef(TBDv4NotForSharedCache, "Test.tbd"));877EXPECT_TRUE(!!Result);878Target ExpectedTarget = Target(AK_arm64, PLATFORM_MACOS);879TBDFile ReadFile = std::move(Result.get());880EXPECT_EQ(FileType::TBD_V4, ReadFile->getFileType());881EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"),882ReadFile->getInstallName());883EXPECT_TRUE(ReadFile->targets().begin() != ReadFile->targets().end());884EXPECT_EQ(*ReadFile->targets().begin(), ExpectedTarget);885EXPECT_TRUE(ReadFile->isOSLibNotForSharedCache());886}
887
888TEST(TBDv4, InvalidArchitecture) {889static const char TBDv4UnknownArch[] = "--- !tapi-tbd\n"890"tbd-version: 4\n"891"targets: [ foo-macos ]\n"892"install-name: Test.dylib\n"893"...\n";894
895Expected<TBDFile> Result =896TextAPIReader::get(MemoryBufferRef(TBDv4UnknownArch, "Test.tbd"));897EXPECT_FALSE(!!Result);898std::string ErrorMessage = toString(Result.takeError());899EXPECT_EQ("malformed file\nTest.tbd:3:12: error: unknown "900"architecture\ntargets: [ foo-macos ]\n"901" ^~~~~~~~~~\n",902ErrorMessage);903}
904
905TEST(TBDv4, InvalidPlatform) {906static const char TBDv4FInvalidPlatform[] = "--- !tapi-tbd\n"907"tbd-version: 4\n"908"targets: [ x86_64-maos ]\n"909"install-name: Test.dylib\n"910"...\n";911
912Expected<TBDFile> Result =913TextAPIReader::get(MemoryBufferRef(TBDv4FInvalidPlatform, "Test.tbd"));914EXPECT_FALSE(!!Result);915std::string ErrorMessage = toString(Result.takeError());916EXPECT_EQ("malformed file\nTest.tbd:3:12: error: unknown platform\ntargets: "917"[ x86_64-maos ]\n"918" ^~~~~~~~~~~~\n",919ErrorMessage);920}
921
922TEST(TBDv4, MalformedFile1) {923static const char TBDv4MalformedFile1[] = "--- !tapi-tbd\n"924"tbd-version: 4\n"925"...\n";926
927Expected<TBDFile> Result =928TextAPIReader::get(MemoryBufferRef(TBDv4MalformedFile1, "Test.tbd"));929EXPECT_FALSE(!!Result);930std::string ErrorMessage = toString(Result.takeError());931ASSERT_EQ("malformed file\nTest.tbd:2:1: error: missing required key "932"'targets'\ntbd-version: 4\n^\n",933ErrorMessage);934}
935
936TEST(TBDv4, MalformedFile2) {937static const char TBDv4MalformedFile2[] = "--- !tapi-tbd\n"938"tbd-version: 4\n"939"targets: [ x86_64-macos ]\n"940"install-name: Test.dylib\n"941"foobar: \"unsupported key\"\n"942"...\n";943
944Expected<TBDFile> Result =945TextAPIReader::get(MemoryBufferRef(TBDv4MalformedFile2, "Test.tbd"));946EXPECT_FALSE(!!Result);947std::string ErrorMessage = toString(Result.takeError());948ASSERT_EQ(949"malformed file\nTest.tbd:5:1: error: unknown key 'foobar'\nfoobar: "950"\"unsupported key\"\n^~~~~~\n",951ErrorMessage);952}
953
954TEST(TBDv4, MalformedFile3) {955static const char TBDv4MalformedSwift[] = "--- !tapi-tbd\n"956"tbd-version: 4\n"957"targets: [ x86_64-macos ]\n"958"install-name: Test.dylib\n"959"swift-abi-version: 1.1\n"960"...\n";961
962Expected<TBDFile> Result =963TextAPIReader::get(MemoryBufferRef(TBDv4MalformedSwift, "Test.tbd"));964EXPECT_FALSE(!!Result);965std::string ErrorMessage = toString(Result.takeError());966EXPECT_EQ("malformed file\nTest.tbd:5:20: error: invalid Swift ABI "967"version.\nswift-abi-version: 1.1\n ^~~\n",968ErrorMessage);969}
970
971TEST(TBDv4, InterfaceEquality) {972static const char TBDv4File[] =973"--- !tapi-tbd\n"974"tbd-version: 4\n"975"targets: [ i386-macos, x86_64-macos, x86_64-ios, i386-maccatalyst, "976"x86_64-maccatalyst ]\n"977"install-name: Umbrella.framework/Umbrella\n"978"current-version: 1.2.3\n"979"compatibility-version: 1.2\n"980"swift-abi-version: 5\n"981"parent-umbrella:\n"982" - targets: [ i386-macos, x86_64-macos, x86_64-ios ]\n"983" umbrella: System\n"984"allowable-clients:\n"985" - targets: [ i386-macos, x86_64-macos, x86_64-ios ]\n"986" clients: [ ClientA ]\n"987"reexported-libraries:\n"988" - targets: [ i386-macos ]\n"989" libraries: [ /System/Library/Frameworks/A.framework/A ]\n"990"exports:\n"991" - targets: [ i386-macos ]\n"992" symbols: [ _symA ]\n"993" objc-classes: []\n"994" objc-eh-types: []\n"995" objc-ivars: []\n"996" weak-symbols: []\n"997" thread-local-symbols: []\n"998" - targets: [ x86_64-ios ]\n"999" symbols: [_symB]\n"1000" - targets: [ x86_64-macos, x86_64-ios ]\n"1001" symbols: [_symAB]\n"1002" - targets: [ i386-maccatalyst ]\n"1003" weak-symbols: [ _symC ]\n"1004" - targets: [ i386-maccatalyst, x86_64-maccatalyst ]\n"1005" symbols: [ _symA ]\n"1006" objc-classes: [ Class1 ]\n"1007" - targets: [ x86_64-maccatalyst ]\n"1008" symbols: [ _symAB ]\n"1009"reexports:\n"1010" - targets: [ i386-macos ]\n"1011" symbols: [_symC]\n"1012" objc-classes: []\n"1013" objc-eh-types: []\n"1014" objc-ivars: []\n"1015" weak-symbols: []\n"1016" thread-local-symbols: []\n"1017"undefineds:\n"1018" - targets: [ i386-macos ]\n"1019" symbols: [ _symD ]\n"1020" objc-classes: []\n"1021" objc-eh-types: []\n"1022" objc-ivars: []\n"1023" weak-symbols: []\n"1024" thread-local-symbols: []\n"1025"...\n";1026
1027Expected<TBDFile> ResultA =1028TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestA.tbd"));1029EXPECT_TRUE(!!ResultA);1030InterfaceFile FileA = std::move(*ResultA.get());1031Expected<TBDFile> ResultB =1032TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestB.tbd"));1033EXPECT_TRUE(!!ResultB);1034InterfaceFile FileB = std::move(*ResultB.get());1035EXPECT_TRUE(FileA == FileB);1036}
1037
1038TEST(TBDv4, InterfaceDiffVersionsEquality) {1039static const char TBDv4File[] =1040"--- !tapi-tbd\n"1041"tbd-version: 4\n"1042"targets: [ i386-macos, x86_64-macos ]\n"1043"install-name: Umbrella.framework/Umbrella\n"1044"current-version: 1.2.3\n"1045"compatibility-version: 1.0\n"1046"swift-abi-version: 5\n"1047"parent-umbrella:\n"1048" - targets: [ i386-macos, x86_64-macos ]\n"1049" umbrella: System\n"1050"allowable-clients:\n"1051" - targets: [ i386-macos, x86_64-macos ]\n"1052" clients: [ ClientA ]\n"1053"reexported-libraries:\n"1054" - targets: [ i386-macos ]\n"1055" libraries: [ /System/Library/Frameworks/A.framework/A ]\n"1056"exports:\n"1057" - targets: [ i386-macos ]\n"1058" symbols: [ _sym5 ]\n"1059" objc-classes: [ class3]\n"1060" objc-eh-types: []\n"1061" objc-ivars: [ class1._ivar3 ]\n"1062" weak-symbols: [ _weak3 ]\n"1063" - targets: [ x86_64-macos ]\n"1064" symbols: [_symAB]\n"1065" - targets: [ i386-macos, x86_64-macos ]\n"1066" symbols: [_symA]\n"1067" objc-classes: [ class1, class2 ]\n"1068" objc-eh-types: [ class1 ]\n"1069" objc-ivars: [ class1._ivar1, class1._ivar2 ]\n"1070" weak-symbols: [ _weak1, _weak2 ]\n"1071" thread-local-symbols: [ _tlv1, _tlv3 ]\n"1072"undefineds:\n"1073" - targets: [ i386-macos ]\n"1074" symbols: [ _symC ]\n"1075" objc-classes: []\n"1076" objc-eh-types: []\n"1077" objc-ivars: []\n"1078" weak-symbols: []\n"1079" thread-local-symbols: []\n"1080"...\n";1081
1082static const char TBDv3File[] =1083"--- !tapi-tbd-v3\n"1084"archs: [ i386, x86_64 ]\n"1085"platform: macosx\n"1086"install-name: Umbrella.framework/Umbrella\n"1087"current-version: 1.2.3\n"1088"compatibility-version: 1.0\n"1089"swift-abi-version: 5\n"1090"parent-umbrella: System\n"1091"exports:\n"1092" - archs: [ i386, x86_64 ]\n"1093" allowable-clients: [ ClientA ]\n"1094" symbols: [ _symA ]\n"1095" objc-classes: [ class1, class2 ]\n"1096" objc-eh-types: [ class1 ]\n"1097" objc-ivars: [ class1._ivar1, class1._ivar2 ]\n"1098" weak-def-symbols: [ _weak1, _weak2 ]\n"1099" thread-local-symbols: [ _tlv1, _tlv3 ]\n"1100" - archs: [ i386 ]\n"1101" re-exports: [ /System/Library/Frameworks/A.framework/A ]\n"1102" symbols: [ _sym5 ]\n"1103" objc-classes: [ class3 ]\n"1104" objc-ivars: [ class1._ivar3 ]\n"1105" weak-def-symbols: [ _weak3 ]\n"1106" - archs: [ x86_64 ]\n"1107" symbols: [ _symAB ]\n"1108"undefineds:\n"1109" - archs: [ i386 ]\n"1110" symbols: [ _symC ]\n"1111"...\n";1112
1113Expected<TBDFile> ResultA =1114TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestA.tbd"));1115EXPECT_TRUE(!!ResultA);1116InterfaceFile FileA = std::move(*ResultA.get());1117Expected<TBDFile> ResultB =1118TextAPIReader::get(MemoryBufferRef(TBDv3File, "TestB.tbd"));1119EXPECT_TRUE(!!ResultB);1120InterfaceFile FileB = std::move(*ResultB.get());1121EXPECT_TRUE(FileA == FileB);1122}
1123
1124TEST(TBDv4, InterfaceInequality) {1125static const char TBDv4File[] = "--- !tapi-tbd\n"1126"tbd-version: 4\n"1127"targets: [ i386-macos, x86_64-macos ]\n"1128"install-name: Umbrella.framework/Umbrella\n"1129"...\n";1130
1131Expected<TBDFile> ResultA =1132TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestA.tbd"));1133EXPECT_TRUE(!!ResultA);1134InterfaceFile FileA = std::move(*ResultA.get());1135Expected<TBDFile> ResultB =1136TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestB.tbd"));1137EXPECT_TRUE(!!ResultB);1138InterfaceFile FileB = std::move(*ResultB.get());1139
1140EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1141File->addTarget(Target(AK_x86_64, PLATFORM_IOS));1142}));1143EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1144File->setCurrentVersion(PackedVersion(1, 2, 3));1145File->setCompatibilityVersion(PackedVersion(1, 0, 0));1146}));1147EXPECT_TRUE(checkEqualityOnTransform(1148FileA, FileB, [](InterfaceFile *File) { File->setSwiftABIVersion(5); }));1149EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1150File->setTwoLevelNamespace(false);1151}));1152EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1153File->setApplicationExtensionSafe(false);1154}));1155EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1156File->addParentUmbrella(Target(AK_x86_64, PLATFORM_MACOS), "System.dylib");1157}));1158EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1159File->addAllowableClient("ClientA", Target(AK_i386, PLATFORM_MACOS));1160}));1161EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1162File->addReexportedLibrary("/System/Library/Frameworks/A.framework/A",1163Target(AK_i386, PLATFORM_MACOS));1164}));1165EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1166File->addSymbol(EncodeKind::GlobalSymbol, "_symA",1167{Target(AK_x86_64, PLATFORM_MACOS)});1168}));1169EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {1170InterfaceFile Document;1171Document.setFileType(FileType::TBD_V4);1172Document.addTargets(TargetList{Target(AK_i386, PLATFORM_MACOS),1173Target(AK_x86_64, PLATFORM_MACOS)});1174Document.setInstallName("/System/Library/Frameworks/A.framework/A");1175File->addDocument(std::make_shared<InterfaceFile>(std::move(Document)));1176}));1177}
1178
1179} // end namespace TBDv41180