[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / unittests / TextAPI / TextStubV4Tests.cpp
blob43b3c4adadbddd80af919853bf6fe21238e7a065
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 //===-----------------------------------------------------------------------===/
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>
17 using namespace llvm;
18 using namespace llvm::MachO;
21 namespace TBDv4 {
23 TEST(TBDv4, ReadFile) {
24 static 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";
79 Expected<TBDFile> Result =
80 TextAPIReader::get(MemoryBufferRef(TBDv4File, "Test.tbd"));
81 EXPECT_TRUE(!!Result);
82 TBDFile File = std::move(Result.get());
83 EXPECT_EQ(FileType::TBD_V4, File->getFileType());
84 PlatformSet Platforms;
85 Platforms.insert(getPlatformFromName("macos"));
86 Platforms.insert(getPlatformFromName("ios"));
87 auto Archs = AK_i386 | AK_x86_64;
88 TargetList Targets = {
89 Target(AK_i386, PLATFORM_MACOS),
90 Target(AK_x86_64, PLATFORM_MACOS),
91 Target(AK_x86_64, PLATFORM_IOS),
93 EXPECT_EQ(Archs, File->getArchitectures());
94 EXPECT_EQ(Platforms.size(), File->getPlatforms().size());
95 for (auto Platform : File->getPlatforms())
96 EXPECT_EQ(Platforms.count(Platform), 1U);
97 EXPECT_EQ(std::string("Umbrella.framework/Umbrella"), File->getInstallName());
98 EXPECT_EQ(PackedVersion(1, 2, 3), File->getCurrentVersion());
99 EXPECT_EQ(PackedVersion(1, 2, 0), File->getCompatibilityVersion());
100 EXPECT_EQ(5U, File->getSwiftABIVersion());
101 EXPECT_FALSE(File->isTwoLevelNamespace());
102 EXPECT_TRUE(File->isApplicationExtensionSafe());
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());
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));
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));
130 llvm::sort(Exports);
131 llvm::sort(Reexports);
132 llvm::sort(Undefineds);
134 static ExportedSymbol ExpectedExportedSymbols[] = {
135 {SymbolKind::GlobalSymbol, "_symA", false, false},
136 {SymbolKind::GlobalSymbol, "_symAB", false, false},
137 {SymbolKind::GlobalSymbol, "_symB", false, false},
140 static ExportedSymbol ExpectedReexportedSymbols[] = {
141 {SymbolKind::GlobalSymbol, "_symC", false, false},
142 {SymbolKind::GlobalSymbol, "weakReexport", true, false},
145 static ExportedSymbol ExpectedUndefinedSymbols[] = {
146 {SymbolKind::GlobalSymbol, "_symD", false, false},
147 {SymbolKind::GlobalSymbol, "weakReference", true, false},
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)));
161 TEST(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";
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"},
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());
250 // Check Inlined Document
251 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"},
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());
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 else
284 Sym->isReexported() ? Reexports.emplace_back(std::move(Temp))
285 : Exports.emplace_back(std::move(Temp));
287 llvm::sort(Exports);
288 llvm::sort(Reexports);
289 llvm::sort(Undefineds);
291 static ExportedSymbol ExpectedExportedSymbols[] = {
292 {SymbolKind::GlobalSymbol, "_symA", false, false},
293 {SymbolKind::GlobalSymbol, "_symAB", false, false},
296 static ExportedSymbol ExpectedReexportedSymbols[] = {
297 {SymbolKind::GlobalSymbol, "_symC", false, false},
300 static ExportedSymbol ExpectedUndefinedSymbols[] = {
301 {SymbolKind::GlobalSymbol, "_symD", false, false},
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)));
315 TEST(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";
339 InterfaceFile File;
340 TargetList Targets = {
341 Target(AK_i386, PLATFORM_MACOS),
342 Target(AK_x86_64, PLATFORM_IOSSIMULATOR),
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(SymbolKind::GlobalSymbol, "_symA", {Targets[0]});
355 File.addSymbol(SymbolKind::GlobalSymbol, "_symB", {Targets[1]});
356 File.addSymbol(SymbolKind::GlobalSymbol, "_symC", {Targets[0]},
357 SymbolFlags::WeakDefined);
358 File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", {Targets[0]});
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());
367 TEST(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";
391 InterfaceFile File;
392 PlatformType Platform = PLATFORM_MACCATALYST;
393 TargetList Targets = {
394 Target(AK_i386, Platform),
395 Target(AK_x86_64, Platform),
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]);
411 // Write Second Document
412 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(SymbolKind::GlobalSymbol, "_symA", Targets);
423 Document.addSymbol(SymbolKind::GlobalSymbol, "_symAB", {Targets[1]});
424 Document.addSymbol(SymbolKind::GlobalSymbol, "_symC", {Targets[0]},
425 SymbolFlags::WeakDefined);
426 Document.addSymbol(SymbolKind::ObjectiveCClass, "Class1", Targets);
427 File.addDocument(std::make_shared<InterfaceFile>(std::move(Document)));
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());
436 TEST(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";
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);
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()));
466 TEST(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";
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);
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()));
495 TEST(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";
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());
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()));
520 TEST(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";
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());
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()));
545 TEST(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";
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());
561 TEST(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";
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());
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()));
585 TEST(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";
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());
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()));
609 TEST(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";
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());
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()));
632 TEST(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";
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());
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()));
656 TEST(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";
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());
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()));
681 TEST(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";
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());
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()));
704 TEST(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";
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());
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()));
729 TEST(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";
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());
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()));
753 TEST(TBDv4, Swift_1) {
754 static const char TBDv4SwiftVersion1[] = "--- !tapi-tbd\n"
755 "tbd-version: 4\n"
756 "targets: [ x86_64-macos ]\n"
757 "install-name: Test.dylib\n"
758 "swift-abi-version: 1\n"
759 "...\n";
761 Expected<TBDFile> Result =
762 TextAPIReader::get(MemoryBufferRef(TBDv4SwiftVersion1, "Test.tbd"));
763 EXPECT_TRUE(!!Result);
764 TBDFile File = std::move(Result.get());
765 EXPECT_EQ(FileType::TBD_V4, File->getFileType());
766 EXPECT_EQ(1U, File->getSwiftABIVersion());
768 // No writer test because we emit "swift-abi-version:1.0".
771 TEST(TBDv4, Swift_2) {
772 static const char TBDv4Swift2[] = "--- !tapi-tbd\n"
773 "tbd-version: 4\n"
774 "targets: [ x86_64-macos ]\n"
775 "install-name: Test.dylib\n"
776 "swift-abi-version: 2\n"
777 "...\n";
779 Expected<TBDFile> Result =
780 TextAPIReader::get(MemoryBufferRef(TBDv4Swift2, "Test.tbd"));
781 EXPECT_TRUE(!!Result);
782 TBDFile File = std::move(Result.get());
783 EXPECT_EQ(FileType::TBD_V4, File->getFileType());
784 EXPECT_EQ(2U, File->getSwiftABIVersion());
786 // No writer test because we emit "swift-abi-version:2.0".
789 TEST(TBDv4, Swift_5) {
790 static const char TBDv4SwiftVersion5[] = "--- !tapi-tbd\n"
791 "tbd-version: 4\n"
792 "targets: [ x86_64-macos ]\n"
793 "install-name: Test.dylib\n"
794 "swift-abi-version: 5\n"
795 "...\n";
797 Expected<TBDFile> Result =
798 TextAPIReader::get(MemoryBufferRef(TBDv4SwiftVersion5, "Test.tbd"));
799 EXPECT_TRUE(!!Result);
800 TBDFile File = std::move(Result.get());
801 EXPECT_EQ(FileType::TBD_V4, File->getFileType());
802 EXPECT_EQ(5U, File->getSwiftABIVersion());
804 SmallString<4096> Buffer;
805 raw_svector_ostream OS(Buffer);
806 Error WriteResult = TextAPIWriter::writeToStream(OS, *File);
807 EXPECT_TRUE(!WriteResult);
808 EXPECT_EQ(stripWhitespace(TBDv4SwiftVersion5),
809 stripWhitespace(Buffer.c_str()));
812 TEST(TBDv4, Swift_99) {
813 static const char TBDv4SwiftVersion99[] = "--- !tapi-tbd\n"
814 "tbd-version: 4\n"
815 "targets: [ x86_64-macos ]\n"
816 "install-name: Test.dylib\n"
817 "swift-abi-version: 99\n"
818 "...\n";
820 Expected<TBDFile> Result =
821 TextAPIReader::get(MemoryBufferRef(TBDv4SwiftVersion99, "Test.tbd"));
822 EXPECT_TRUE(!!Result);
823 TBDFile File = std::move(Result.get());
824 EXPECT_EQ(FileType::TBD_V4, File->getFileType());
825 EXPECT_EQ(99U, File->getSwiftABIVersion());
827 SmallString<4096> Buffer;
828 raw_svector_ostream OS(Buffer);
829 Error WriteResult = TextAPIWriter::writeToStream(OS, *File);
830 EXPECT_TRUE(!WriteResult);
831 EXPECT_EQ(stripWhitespace(TBDv4SwiftVersion99),
832 stripWhitespace(Buffer.c_str()));
835 TEST(TBDv4, InvalidArchitecture) {
836 static const char TBDv4UnknownArch[] = "--- !tapi-tbd\n"
837 "tbd-version: 4\n"
838 "targets: [ foo-macos ]\n"
839 "install-name: Test.dylib\n"
840 "...\n";
842 Expected<TBDFile> Result =
843 TextAPIReader::get(MemoryBufferRef(TBDv4UnknownArch, "Test.tbd"));
844 EXPECT_FALSE(!!Result);
845 std::string ErrorMessage = toString(Result.takeError());
846 EXPECT_EQ("malformed file\nTest.tbd:3:12: error: unknown "
847 "architecture\ntargets: [ foo-macos ]\n"
848 " ^~~~~~~~~~\n",
849 ErrorMessage);
852 TEST(TBDv4, InvalidPlatform) {
853 static const char TBDv4FInvalidPlatform[] = "--- !tapi-tbd\n"
854 "tbd-version: 4\n"
855 "targets: [ x86_64-maos ]\n"
856 "install-name: Test.dylib\n"
857 "...\n";
859 Expected<TBDFile> Result =
860 TextAPIReader::get(MemoryBufferRef(TBDv4FInvalidPlatform, "Test.tbd"));
861 EXPECT_FALSE(!!Result);
862 std::string ErrorMessage = toString(Result.takeError());
863 EXPECT_EQ("malformed file\nTest.tbd:3:12: error: unknown platform\ntargets: "
864 "[ x86_64-maos ]\n"
865 " ^~~~~~~~~~~~\n",
866 ErrorMessage);
869 TEST(TBDv4, MalformedFile1) {
870 static const char TBDv4MalformedFile1[] = "--- !tapi-tbd\n"
871 "tbd-version: 4\n"
872 "...\n";
874 Expected<TBDFile> Result =
875 TextAPIReader::get(MemoryBufferRef(TBDv4MalformedFile1, "Test.tbd"));
876 EXPECT_FALSE(!!Result);
877 std::string ErrorMessage = toString(Result.takeError());
878 ASSERT_EQ("malformed file\nTest.tbd:2:1: error: missing required key "
879 "'targets'\ntbd-version: 4\n^\n",
880 ErrorMessage);
883 TEST(TBDv4, MalformedFile2) {
884 static const char TBDv4MalformedFile2[] = "--- !tapi-tbd\n"
885 "tbd-version: 4\n"
886 "targets: [ x86_64-macos ]\n"
887 "install-name: Test.dylib\n"
888 "foobar: \"unsupported key\"\n"
889 "...\n";
891 Expected<TBDFile> Result =
892 TextAPIReader::get(MemoryBufferRef(TBDv4MalformedFile2, "Test.tbd"));
893 EXPECT_FALSE(!!Result);
894 std::string ErrorMessage = toString(Result.takeError());
895 ASSERT_EQ(
896 "malformed file\nTest.tbd:5:1: error: unknown key 'foobar'\nfoobar: "
897 "\"unsupported key\"\n^~~~~~\n",
898 ErrorMessage);
901 TEST(TBDv4, MalformedFile3) {
902 static const char TBDv4MalformedSwift[] = "--- !tapi-tbd\n"
903 "tbd-version: 4\n"
904 "targets: [ x86_64-macos ]\n"
905 "install-name: Test.dylib\n"
906 "swift-abi-version: 1.1\n"
907 "...\n";
909 Expected<TBDFile> Result =
910 TextAPIReader::get(MemoryBufferRef(TBDv4MalformedSwift, "Test.tbd"));
911 EXPECT_FALSE(!!Result);
912 std::string ErrorMessage = toString(Result.takeError());
913 EXPECT_EQ("malformed file\nTest.tbd:5:20: error: invalid Swift ABI "
914 "version.\nswift-abi-version: 1.1\n ^~~\n",
915 ErrorMessage);
918 TEST(TBDv4, InterfaceEquality) {
919 static const char TBDv4File[] =
920 "--- !tapi-tbd\n"
921 "tbd-version: 4\n"
922 "targets: [ i386-macos, x86_64-macos, x86_64-ios, i386-maccatalyst, "
923 "x86_64-maccatalyst ]\n"
924 "install-name: Umbrella.framework/Umbrella\n"
925 "current-version: 1.2.3\n"
926 "compatibility-version: 1.2\n"
927 "swift-abi-version: 5\n"
928 "parent-umbrella:\n"
929 " - targets: [ i386-macos, x86_64-macos, x86_64-ios ]\n"
930 " umbrella: System\n"
931 "allowable-clients:\n"
932 " - targets: [ i386-macos, x86_64-macos, x86_64-ios ]\n"
933 " clients: [ ClientA ]\n"
934 "reexported-libraries:\n"
935 " - targets: [ i386-macos ]\n"
936 " libraries: [ /System/Library/Frameworks/A.framework/A ]\n"
937 "exports:\n"
938 " - targets: [ i386-macos ]\n"
939 " symbols: [ _symA ]\n"
940 " objc-classes: []\n"
941 " objc-eh-types: []\n"
942 " objc-ivars: []\n"
943 " weak-symbols: []\n"
944 " thread-local-symbols: []\n"
945 " - targets: [ x86_64-ios ]\n"
946 " symbols: [_symB]\n"
947 " - targets: [ x86_64-macos, x86_64-ios ]\n"
948 " symbols: [_symAB]\n"
949 " - targets: [ i386-maccatalyst ]\n"
950 " weak-symbols: [ _symC ]\n"
951 " - targets: [ i386-maccatalyst, x86_64-maccatalyst ]\n"
952 " symbols: [ _symA ]\n"
953 " objc-classes: [ Class1 ]\n"
954 " - targets: [ x86_64-maccatalyst ]\n"
955 " symbols: [ _symAB ]\n"
956 "reexports:\n"
957 " - targets: [ i386-macos ]\n"
958 " symbols: [_symC]\n"
959 " objc-classes: []\n"
960 " objc-eh-types: []\n"
961 " objc-ivars: []\n"
962 " weak-symbols: []\n"
963 " thread-local-symbols: []\n"
964 "undefineds:\n"
965 " - targets: [ i386-macos ]\n"
966 " symbols: [ _symD ]\n"
967 " objc-classes: []\n"
968 " objc-eh-types: []\n"
969 " objc-ivars: []\n"
970 " weak-symbols: []\n"
971 " thread-local-symbols: []\n"
972 "...\n";
974 Expected<TBDFile> ResultA =
975 TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestA.tbd"));
976 EXPECT_TRUE(!!ResultA);
977 InterfaceFile FileA = std::move(*ResultA.get());
978 Expected<TBDFile> ResultB =
979 TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestB.tbd"));
980 EXPECT_TRUE(!!ResultB);
981 InterfaceFile FileB = std::move(*ResultB.get());
982 EXPECT_TRUE(FileA == FileB);
985 TEST(TBDv4, InterfaceDiffVersionsEquality) {
986 static const char TBDv4File[] =
987 "--- !tapi-tbd\n"
988 "tbd-version: 4\n"
989 "targets: [ i386-macos, x86_64-macos ]\n"
990 "install-name: Umbrella.framework/Umbrella\n"
991 "current-version: 1.2.3\n"
992 "compatibility-version: 1.0\n"
993 "swift-abi-version: 5\n"
994 "parent-umbrella:\n"
995 " - targets: [ i386-macos, x86_64-macos ]\n"
996 " umbrella: System\n"
997 "allowable-clients:\n"
998 " - targets: [ i386-macos, x86_64-macos ]\n"
999 " clients: [ ClientA ]\n"
1000 "reexported-libraries:\n"
1001 " - targets: [ i386-macos ]\n"
1002 " libraries: [ /System/Library/Frameworks/A.framework/A ]\n"
1003 "exports:\n"
1004 " - targets: [ i386-macos ]\n"
1005 " symbols: [ _sym5 ]\n"
1006 " objc-classes: [ class3]\n"
1007 " objc-eh-types: []\n"
1008 " objc-ivars: [ class1._ivar3 ]\n"
1009 " weak-symbols: [ _weak3 ]\n"
1010 " - targets: [ x86_64-macos ]\n"
1011 " symbols: [_symAB]\n"
1012 " - targets: [ i386-macos, x86_64-macos ]\n"
1013 " symbols: [_symA]\n"
1014 " objc-classes: [ class1, class2 ]\n"
1015 " objc-eh-types: [ class1 ]\n"
1016 " objc-ivars: [ class1._ivar1, class1._ivar2 ]\n"
1017 " weak-symbols: [ _weak1, _weak2 ]\n"
1018 " thread-local-symbols: [ _tlv1, _tlv3 ]\n"
1019 "undefineds:\n"
1020 " - targets: [ i386-macos ]\n"
1021 " symbols: [ _symC ]\n"
1022 " objc-classes: []\n"
1023 " objc-eh-types: []\n"
1024 " objc-ivars: []\n"
1025 " weak-symbols: []\n"
1026 " thread-local-symbols: []\n"
1027 "...\n";
1029 static const char TBDv3File[] =
1030 "--- !tapi-tbd-v3\n"
1031 "archs: [ i386, x86_64 ]\n"
1032 "platform: macosx\n"
1033 "install-name: Umbrella.framework/Umbrella\n"
1034 "current-version: 1.2.3\n"
1035 "compatibility-version: 1.0\n"
1036 "swift-abi-version: 5\n"
1037 "parent-umbrella: System\n"
1038 "exports:\n"
1039 " - archs: [ i386, x86_64 ]\n"
1040 " allowable-clients: [ ClientA ]\n"
1041 " symbols: [ _symA ]\n"
1042 " objc-classes: [ class1, class2 ]\n"
1043 " objc-eh-types: [ class1 ]\n"
1044 " objc-ivars: [ class1._ivar1, class1._ivar2 ]\n"
1045 " weak-def-symbols: [ _weak1, _weak2 ]\n"
1046 " thread-local-symbols: [ _tlv1, _tlv3 ]\n"
1047 " - archs: [ i386 ]\n"
1048 " re-exports: [ /System/Library/Frameworks/A.framework/A ]\n"
1049 " symbols: [ _sym5 ]\n"
1050 " objc-classes: [ class3 ]\n"
1051 " objc-ivars: [ class1._ivar3 ]\n"
1052 " weak-def-symbols: [ _weak3 ]\n"
1053 " - archs: [ x86_64 ]\n"
1054 " symbols: [ _symAB ]\n"
1055 "undefineds:\n"
1056 " - archs: [ i386 ]\n"
1057 " symbols: [ _symC ]\n"
1058 "...\n";
1060 Expected<TBDFile> ResultA =
1061 TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestA.tbd"));
1062 EXPECT_TRUE(!!ResultA);
1063 InterfaceFile FileA = std::move(*ResultA.get());
1064 Expected<TBDFile> ResultB =
1065 TextAPIReader::get(MemoryBufferRef(TBDv3File, "TestB.tbd"));
1066 EXPECT_TRUE(!!ResultB);
1067 InterfaceFile FileB = std::move(*ResultB.get());
1068 EXPECT_TRUE(FileA == FileB);
1071 TEST(TBDv4, InterfaceInequality) {
1072 static const char TBDv4File[] = "--- !tapi-tbd\n"
1073 "tbd-version: 4\n"
1074 "targets: [ i386-macos, x86_64-macos ]\n"
1075 "install-name: Umbrella.framework/Umbrella\n"
1076 "...\n";
1078 Expected<TBDFile> ResultA =
1079 TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestA.tbd"));
1080 EXPECT_TRUE(!!ResultA);
1081 InterfaceFile FileA = std::move(*ResultA.get());
1082 Expected<TBDFile> ResultB =
1083 TextAPIReader::get(MemoryBufferRef(TBDv4File, "TestB.tbd"));
1084 EXPECT_TRUE(!!ResultB);
1085 InterfaceFile FileB = std::move(*ResultB.get());
1087 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1088 File->addTarget(Target(AK_x86_64, PLATFORM_IOS));
1089 }));
1090 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1091 File->setCurrentVersion(PackedVersion(1, 2, 3));
1092 File->setCompatibilityVersion(PackedVersion(1, 0, 0));
1093 }));
1094 EXPECT_TRUE(checkEqualityOnTransform(
1095 FileA, FileB, [](InterfaceFile *File) { File->setSwiftABIVersion(5); }));
1096 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1097 File->setTwoLevelNamespace(false);
1098 }));
1099 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1100 File->setApplicationExtensionSafe(false);
1101 }));
1102 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1103 File->addParentUmbrella(Target(AK_x86_64, PLATFORM_MACOS), "System.dylib");
1104 }));
1105 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1106 File->addAllowableClient("ClientA", Target(AK_i386, PLATFORM_MACOS));
1107 }));
1108 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1109 File->addReexportedLibrary("/System/Library/Frameworks/A.framework/A",
1110 Target(AK_i386, PLATFORM_MACOS));
1111 }));
1112 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1113 File->addSymbol(SymbolKind::GlobalSymbol, "_symA",
1114 {Target(AK_x86_64, PLATFORM_MACOS)});
1115 }));
1116 EXPECT_TRUE(checkEqualityOnTransform(FileA, FileB, [](InterfaceFile *File) {
1117 InterfaceFile Document;
1118 Document.setFileType(FileType::TBD_V4);
1119 Document.addTargets(TargetList{Target(AK_i386, PLATFORM_MACOS),
1120 Target(AK_x86_64, PLATFORM_MACOS)});
1121 Document.setInstallName("/System/Library/Frameworks/A.framework/A");
1122 File->addDocument(std::make_shared<InterfaceFile>(std::move(Document)));
1123 }));
1126 } // end namespace TBDv4