brintos

brintos / llvm-project-archived public Read only

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