blob: 4472b1c599350d3219dbaea28e56a6f82258bebd [file] [log] [blame]
Juergen Ributzka32cb5942019-03-22 22:46:52 +00001//===-- TextStubV1Tests.cpp - TBD V1 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 "llvm/TextAPI/MachO/InterfaceFile.h"
10#include "llvm/TextAPI/MachO/TextAPIReader.h"
11#include "llvm/TextAPI/MachO/TextAPIWriter.h"
12#include "gtest/gtest.h"
13#include <string>
14#include <vector>
15
16using namespace llvm;
17using namespace llvm::MachO;
18
19struct ExportedSymbol {
20 SymbolKind Kind;
21 std::string Name;
22 bool WeakDefined;
23 bool ThreadLocalValue;
24};
25using ExportedSymbolSeq = std::vector<ExportedSymbol>;
26
27inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
28 return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
29}
30
31inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
32 return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
33 std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
34}
35
36static ExportedSymbol TBDv1Symbols[] = {
37 {SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
38 {SymbolKind::GlobalSymbol, "_sym1", false, false},
39 {SymbolKind::GlobalSymbol, "_sym2", false, false},
40 {SymbolKind::GlobalSymbol, "_sym3", false, false},
41 {SymbolKind::GlobalSymbol, "_sym4", false, false},
42 {SymbolKind::GlobalSymbol, "_sym5", false, false},
43 {SymbolKind::GlobalSymbol, "_tlv1", false, true},
44 {SymbolKind::GlobalSymbol, "_tlv2", false, true},
45 {SymbolKind::GlobalSymbol, "_tlv3", false, true},
46 {SymbolKind::GlobalSymbol, "_weak1", true, false},
47 {SymbolKind::GlobalSymbol, "_weak2", true, false},
48 {SymbolKind::GlobalSymbol, "_weak3", true, false},
49 {SymbolKind::ObjectiveCClass, "class1", false, false},
50 {SymbolKind::ObjectiveCClass, "class2", false, false},
51 {SymbolKind::ObjectiveCClass, "class3", false, false},
52 {SymbolKind::ObjectiveCInstanceVariable, "class1._ivar1", false, false},
53 {SymbolKind::ObjectiveCInstanceVariable, "class1._ivar2", false, false},
54 {SymbolKind::ObjectiveCInstanceVariable, "class1._ivar3", false, false},
55};
56
57namespace TBDv1 {
58
59TEST(TBDv1, ReadFile) {
60 static const char tbd_v1_file1[] =
61 "---\n"
62 "archs: [ armv7, armv7s, armv7k, arm64 ]\n"
63 "platform: ios\n"
64 "install-name: Test.dylib\n"
65 "current-version: 2.3.4\n"
66 "compatibility-version: 1.0\n"
67 "swift-version: 1.1\n"
68 "exports:\n"
69 " - archs: [ armv7, armv7s, armv7k, arm64 ]\n"
70 " allowed-clients: [ clientA ]\n"
71 " re-exports: [ /usr/lib/libfoo.dylib ]\n"
72 " symbols: [ _sym1, _sym2, _sym3, _sym4, $ld$hide$os9.0$_sym1 ]\n"
73 " objc-classes: [ _class1, _class2 ]\n"
74 " objc-ivars: [ _class1._ivar1, _class1._ivar2 ]\n"
75 " weak-def-symbols: [ _weak1, _weak2 ]\n"
76 " thread-local-symbols: [ _tlv1, _tlv2 ]\n"
77 " - archs: [ armv7, armv7s, armv7k ]\n"
78 " symbols: [ _sym5 ]\n"
79 " objc-classes: [ _class3 ]\n"
80 " objc-ivars: [ _class1._ivar3 ]\n"
81 " weak-def-symbols: [ _weak3 ]\n"
82 " thread-local-symbols: [ _tlv3 ]\n"
83 "...\n";
84
Cyndy Ishida5f865ec2019-08-16 15:30:48 +000085 auto Result = TextAPIReader::get(MemoryBufferRef(tbd_v1_file1, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +000086 EXPECT_TRUE(!!Result);
87 auto File = std::move(Result.get());
88 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
Juergen Ributzka875565e2019-04-04 22:56:50 +000089 auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
Cyndy Ishida81669d52019-09-20 14:32:34 +000090 auto Platform = PlatformKind::iOS;
91 TargetList Targets;
92 for (auto &&arch : Archs)
93 Targets.emplace_back(Target(arch, Platform));
Juergen Ributzka32cb5942019-03-22 22:46:52 +000094 EXPECT_EQ(Archs, File->getArchitectures());
Cyndy Ishida81669d52019-09-20 14:32:34 +000095 EXPECT_EQ(File->getPlatforms().size(), 1U);
96 EXPECT_EQ(Platform, *File->getPlatforms().begin());
Juergen Ributzka32cb5942019-03-22 22:46:52 +000097 EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
98 EXPECT_EQ(PackedVersion(2, 3, 4), File->getCurrentVersion());
99 EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
100 EXPECT_EQ(2U, File->getSwiftABIVersion());
101 EXPECT_EQ(ObjCConstraintType::None, File->getObjCConstraint());
102 EXPECT_TRUE(File->isTwoLevelNamespace());
103 EXPECT_TRUE(File->isApplicationExtensionSafe());
104 EXPECT_FALSE(File->isInstallAPI());
Cyndy Ishida81669d52019-09-20 14:32:34 +0000105 InterfaceFileRef client("clientA", Targets);
106 InterfaceFileRef reexport("/usr/lib/libfoo.dylib", Targets);
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000107 EXPECT_EQ(1U, File->allowableClients().size());
108 EXPECT_EQ(client, File->allowableClients().front());
109 EXPECT_EQ(1U, File->reexportedLibraries().size());
110 EXPECT_EQ(reexport, File->reexportedLibraries().front());
111
112 ExportedSymbolSeq Exports;
113 for (const auto *Sym : File->symbols()) {
114 EXPECT_FALSE(Sym->isWeakReferenced());
115 EXPECT_FALSE(Sym->isUndefined());
116 Exports.emplace_back(ExportedSymbol{Sym->getKind(), Sym->getName(),
117 Sym->isWeakDefined(),
118 Sym->isThreadLocalValue()});
119 }
120 llvm::sort(Exports.begin(), Exports.end());
121
122 EXPECT_EQ(sizeof(TBDv1Symbols) / sizeof(ExportedSymbol), Exports.size());
123 EXPECT_TRUE(
124 std::equal(Exports.begin(), Exports.end(), std::begin(TBDv1Symbols)));
Cyndy Ishida81669d52019-09-20 14:32:34 +0000125
126 File->addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", {Targets[1]});
127 File->addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1",
128 {Targets[1]});
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000129}
130
131TEST(TBDv1, ReadFile2) {
132 static const char tbd_v1_file2[] = "--- !tapi-tbd-v1\n"
133 "archs: [ armv7, armv7s, armv7k, arm64 ]\n"
134 "platform: ios\n"
135 "install-name: Test.dylib\n"
136 "...\n";
137
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000138 auto Result = TextAPIReader::get(MemoryBufferRef(tbd_v1_file2, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000139 EXPECT_TRUE(!!Result);
140 auto File = std::move(Result.get());
141 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
Juergen Ributzka875565e2019-04-04 22:56:50 +0000142 auto Archs = AK_armv7 | AK_armv7s | AK_armv7k | AK_arm64;
Cyndy Ishida81669d52019-09-20 14:32:34 +0000143 auto Platform = PlatformKind::iOS;
144 TargetList Targets;
145 for (auto &&arch : Archs)
146 Targets.emplace_back(Target(arch, Platform));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000147 EXPECT_EQ(Archs, File->getArchitectures());
Cyndy Ishida81669d52019-09-20 14:32:34 +0000148 EXPECT_EQ(File->getPlatforms().size(), 1U);
149 EXPECT_EQ(Platform, *File->getPlatforms().begin());
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000150 EXPECT_EQ(std::string("Test.dylib"), File->getInstallName());
151 EXPECT_EQ(PackedVersion(1, 0, 0), File->getCurrentVersion());
152 EXPECT_EQ(PackedVersion(1, 0, 0), File->getCompatibilityVersion());
153 EXPECT_EQ(0U, File->getSwiftABIVersion());
154 EXPECT_EQ(ObjCConstraintType::None, File->getObjCConstraint());
155 EXPECT_TRUE(File->isTwoLevelNamespace());
156 EXPECT_TRUE(File->isApplicationExtensionSafe());
157 EXPECT_FALSE(File->isInstallAPI());
158 EXPECT_EQ(0U, File->allowableClients().size());
159 EXPECT_EQ(0U, File->reexportedLibraries().size());
160}
161
162TEST(TBDv1, WriteFile) {
163 static const char tbd_v1_file3[] =
164 "---\n"
165 "archs: [ i386, x86_64 ]\n"
166 "platform: macosx\n"
167 "install-name: '/usr/lib/libfoo.dylib'\n"
168 "current-version: 1.2.3\n"
169 "compatibility-version: 0\n"
170 "swift-version: 5\n"
171 "objc-constraint: retain_release\n"
Fangrui Song27ed1c52019-07-12 04:51:31 +0000172 "exports:\n"
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000173 " - archs: [ i386 ]\n"
174 " symbols: [ _sym1 ]\n"
175 " weak-def-symbols: [ _sym2 ]\n"
176 " thread-local-symbols: [ _sym3 ]\n"
177 " - archs: [ x86_64 ]\n"
178 " allowed-clients: [ clientA ]\n"
179 " re-exports: [ '/usr/lib/libfoo.dylib' ]\n"
180 " symbols: [ '_OBJC_EHTYPE_$_Class1' ]\n"
181 " objc-classes: [ _Class1 ]\n"
182 " objc-ivars: [ _Class1._ivar1 ]\n"
183 "...\n";
184
185 InterfaceFile File;
Cyndy Ishida81669d52019-09-20 14:32:34 +0000186 TargetList Targets;
187 for (auto &&arch : AK_i386 | AK_x86_64)
188 Targets.emplace_back(Target(arch, PlatformKind::macOS));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000189 File.setPath("libfoo.dylib");
190 File.setInstallName("/usr/lib/libfoo.dylib");
191 File.setFileType(FileType::TBD_V1);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000192 File.addTargets(Targets);
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000193 File.setCurrentVersion(PackedVersion(1, 2, 3));
194 File.setSwiftABIVersion(5);
195 File.setObjCConstraint(ObjCConstraintType::Retain_Release);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000196 File.addAllowableClient("clientA", Targets[1]);
197 File.addReexportedLibrary("/usr/lib/libfoo.dylib", Targets[1]);
198 File.addSymbol(SymbolKind::GlobalSymbol, "_sym1", {Targets[0]});
199 File.addSymbol(SymbolKind::GlobalSymbol, "_sym2", {Targets[0]},
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000200 SymbolFlags::WeakDefined);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000201 File.addSymbol(SymbolKind::GlobalSymbol, "_sym3", {Targets[0]},
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000202 SymbolFlags::ThreadLocalValue);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000203 File.addSymbol(SymbolKind::ObjectiveCClass, "Class1", {Targets[1]});
204 File.addSymbol(SymbolKind::ObjectiveCClassEHType, "Class1", {Targets[1]});
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000205 File.addSymbol(SymbolKind::ObjectiveCInstanceVariable, "Class1._ivar1",
Cyndy Ishida81669d52019-09-20 14:32:34 +0000206 {Targets[1]});
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000207
208 SmallString<4096> Buffer;
209 raw_svector_ostream OS(Buffer);
210 auto Result = TextAPIWriter::writeToStream(OS, File);
211 EXPECT_FALSE(Result);
212 EXPECT_STREQ(tbd_v1_file3, Buffer.c_str());
213}
214
215TEST(TBDv1, Platform_macOS) {
216 static const char tbd_v1_platform_macos[] = "---\n"
217 "archs: [ x86_64 ]\n"
218 "platform: macosx\n"
219 "install-name: Test.dylib\n"
220 "...\n";
221
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000222 auto Result =
223 TextAPIReader::get(MemoryBufferRef(tbd_v1_platform_macos, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000224 EXPECT_TRUE(!!Result);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000225 auto Platform = PlatformKind::macOS;
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000226 auto File = std::move(Result.get());
227 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
Cyndy Ishida81669d52019-09-20 14:32:34 +0000228 EXPECT_EQ(File->getPlatforms().size(), 1U);
229 EXPECT_EQ(Platform, *File->getPlatforms().begin());
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000230}
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000231
232TEST(TBDv1, Platform_iOS) {
233 static const char tbd_v1_platform_ios[] = "---\n"
234 "archs: [ arm64 ]\n"
235 "platform: ios\n"
236 "install-name: Test.dylib\n"
237 "...\n";
238
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000239 auto Result =
240 TextAPIReader::get(MemoryBufferRef(tbd_v1_platform_ios, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000241 EXPECT_TRUE(!!Result);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000242 auto Platform = PlatformKind::iOS;
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000243 auto File = std::move(Result.get());
244 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
Cyndy Ishida81669d52019-09-20 14:32:34 +0000245 EXPECT_EQ(File->getPlatforms().size(), 1U);
246 EXPECT_EQ(Platform, *File->getPlatforms().begin());
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000247}
248
249TEST(TBDv1, Platform_watchOS) {
250 static const char tbd_v1_platform_watchos[] = "---\n"
251 "archs: [ armv7k ]\n"
252 "platform: watchos\n"
253 "install-name: Test.dylib\n"
254 "...\n";
255
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000256 auto Result =
257 TextAPIReader::get(MemoryBufferRef(tbd_v1_platform_watchos, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000258 EXPECT_TRUE(!!Result);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000259 auto Platform = PlatformKind::watchOS;
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000260 auto File = std::move(Result.get());
261 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
Cyndy Ishida81669d52019-09-20 14:32:34 +0000262 EXPECT_EQ(File->getPlatforms().size(), 1U);
263 EXPECT_EQ(Platform, *File->getPlatforms().begin());
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000264}
265
266TEST(TBDv1, Platform_tvOS) {
267 static const char tbd_v1_platform_tvos[] = "---\n"
268 "archs: [ arm64 ]\n"
269 "platform: tvos\n"
270 "install-name: Test.dylib\n"
271 "...\n";
272
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000273 auto Result =
274 TextAPIReader::get(MemoryBufferRef(tbd_v1_platform_tvos, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000275 EXPECT_TRUE(!!Result);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000276 auto Platform = PlatformKind::tvOS;
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000277 auto File = std::move(Result.get());
278 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
Cyndy Ishida81669d52019-09-20 14:32:34 +0000279 EXPECT_EQ(File->getPlatforms().size(), 1U);
280 EXPECT_EQ(Platform, *File->getPlatforms().begin());
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000281}
282
283TEST(TBDv1, Platform_bridgeOS) {
284 static const char tbd_v1_platform_bridgeos[] = "---\n"
285 "archs: [ armv7k ]\n"
286 "platform: bridgeos\n"
287 "install-name: Test.dylib\n"
288 "...\n";
289
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000290 auto Result =
291 TextAPIReader::get(MemoryBufferRef(tbd_v1_platform_bridgeos, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000292 EXPECT_TRUE(!!Result);
Cyndy Ishida81669d52019-09-20 14:32:34 +0000293 auto Platform = PlatformKind::bridgeOS;
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000294 auto File = std::move(Result.get());
295 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
Cyndy Ishida81669d52019-09-20 14:32:34 +0000296 EXPECT_EQ(File->getPlatforms().size(), 1U);
297 EXPECT_EQ(Platform, *File->getPlatforms().begin());
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000298}
299
300TEST(TBDv1, Swift_1_0) {
301 static const char tbd_v1_swift_1_0[] = "---\n"
302 "archs: [ arm64 ]\n"
303 "platform: ios\n"
304 "install-name: Test.dylib\n"
305 "swift-version: 1.0\n"
306 "...\n";
307
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000308 auto Result =
309 TextAPIReader::get(MemoryBufferRef(tbd_v1_swift_1_0, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000310 EXPECT_TRUE(!!Result);
311 auto File = std::move(Result.get());
312 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
313 EXPECT_EQ(1U, File->getSwiftABIVersion());
314}
315
316TEST(TBDv1, Swift_1_1) {
317 static const char tbd_v1_swift_1_1[] = "---\n"
318 "archs: [ arm64 ]\n"
319 "platform: ios\n"
320 "install-name: Test.dylib\n"
321 "swift-version: 1.1\n"
322 "...\n";
323
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000324 auto Result =
325 TextAPIReader::get(MemoryBufferRef(tbd_v1_swift_1_1, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000326 EXPECT_TRUE(!!Result);
327 auto File = std::move(Result.get());
328 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
329 EXPECT_EQ(2U, File->getSwiftABIVersion());
330}
331
332TEST(TBDv1, Swift_2_0) {
333 static const char tbd_v1_swift_2_0[] = "---\n"
334 "archs: [ arm64 ]\n"
335 "platform: ios\n"
336 "install-name: Test.dylib\n"
337 "swift-version: 2.0\n"
338 "...\n";
339
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000340 auto Result =
341 TextAPIReader::get(MemoryBufferRef(tbd_v1_swift_2_0, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000342 EXPECT_TRUE(!!Result);
343 auto File = std::move(Result.get());
344 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
345 EXPECT_EQ(3U, File->getSwiftABIVersion());
346}
347
348TEST(TBDv1, Swift_3_0) {
349 static const char tbd_v1_swift_3_0[] = "---\n"
350 "archs: [ arm64 ]\n"
351 "platform: ios\n"
352 "install-name: Test.dylib\n"
353 "swift-version: 3.0\n"
354 "...\n";
355
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000356 auto Result =
357 TextAPIReader::get(MemoryBufferRef(tbd_v1_swift_3_0, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000358 EXPECT_TRUE(!!Result);
359 auto File = std::move(Result.get());
360 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
361 EXPECT_EQ(4U, File->getSwiftABIVersion());
362}
363
364TEST(TBDv1, Swift_4_0) {
365 static const char tbd_v1_swift_4_0[] = "---\n"
366 "archs: [ arm64 ]\n"
367 "platform: ios\n"
368 "install-name: Test.dylib\n"
369 "swift-version: 4.0\n"
370 "...\n";
371
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000372 auto Result =
373 TextAPIReader::get(MemoryBufferRef(tbd_v1_swift_4_0, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000374 EXPECT_FALSE(!!Result);
375 auto errorMessage = toString(Result.takeError());
376 EXPECT_EQ("malformed file\nTest.tbd:5:16: error: invalid Swift ABI "
377 "version.\nswift-version: 4.0\n ^~~\n",
378 errorMessage);
379}
380
381TEST(TBDv1, Swift_5) {
382 static const char tbd_v1_swift_5[] = "---\n"
383 "archs: [ arm64 ]\n"
384 "platform: ios\n"
385 "install-name: Test.dylib\n"
386 "swift-version: 5\n"
387 "...\n";
388
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000389 auto Result = TextAPIReader::get(MemoryBufferRef(tbd_v1_swift_5, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000390 EXPECT_TRUE(!!Result);
391 auto File = std::move(Result.get());
392 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
393 EXPECT_EQ(5U, File->getSwiftABIVersion());
394}
395
396TEST(TBDv1, Swift_99) {
397 static const char tbd_v1_swift_99[] = "---\n"
398 "archs: [ arm64 ]\n"
399 "platform: ios\n"
400 "install-name: Test.dylib\n"
401 "swift-version: 99\n"
402 "...\n";
403
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000404 auto Result =
405 TextAPIReader::get(MemoryBufferRef(tbd_v1_swift_99, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000406 EXPECT_TRUE(!!Result);
407 auto File = std::move(Result.get());
408 EXPECT_EQ(FileType::TBD_V1, File->getFileType());
409 EXPECT_EQ(99U, File->getSwiftABIVersion());
410}
411
412TEST(TBDv1, UnknownArchitecture) {
413 static const char tbd_v1_file_unknown_architecture[] =
414 "---\n"
415 "archs: [ foo ]\n"
416 "platform: macosx\n"
417 "install-name: Test.dylib\n"
418 "...\n";
419
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000420 auto Result = TextAPIReader::get(
421 MemoryBufferRef(tbd_v1_file_unknown_architecture, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000422 EXPECT_TRUE(!!Result);
423}
424
425TEST(TBDv1, UnknownPlatform) {
426 static const char tbd_v1_file_unknown_platform[] = "---\n"
427 "archs: [ i386 ]\n"
428 "platform: newOS\n"
429 "...\n";
430
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000431 auto Result = TextAPIReader::get(
432 MemoryBufferRef(tbd_v1_file_unknown_platform, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000433 EXPECT_FALSE(!!Result);
434 auto errorMessage = toString(Result.takeError());
435 EXPECT_EQ("malformed file\nTest.tbd:3:11: error: unknown platform\nplatform: "
436 "newOS\n ^~~~~\n",
437 errorMessage);
438}
439
440TEST(TBDv1, MalformedFile1) {
441 static const char malformed_file1[] = "---\n"
442 "archs: [ arm64 ]\n"
443 "foobar: \"Unsupported key\"\n"
444 "...\n";
445
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000446 auto Result =
447 TextAPIReader::get(MemoryBufferRef(malformed_file1, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000448 EXPECT_FALSE(!!Result);
449 auto errorMessage = toString(Result.takeError());
450 ASSERT_EQ("malformed file\nTest.tbd:2:1: error: missing required key "
451 "'platform'\narchs: [ arm64 ]\n^\n",
452 errorMessage);
453}
454
455TEST(TBDv1, MalformedFile2) {
456 static const char malformed_file2[] = "---\n"
457 "archs: [ arm64 ]\n"
458 "platform: ios\n"
459 "install-name: Test.dylib\n"
460 "foobar: \"Unsupported key\"\n"
461 "...\n";
462
Cyndy Ishida5f865ec2019-08-16 15:30:48 +0000463 auto Result =
464 TextAPIReader::get(MemoryBufferRef(malformed_file2, "Test.tbd"));
Juergen Ributzka32cb5942019-03-22 22:46:52 +0000465 EXPECT_FALSE(!!Result);
466 auto errorMessage = toString(Result.takeError());
467 ASSERT_EQ(
468 "malformed file\nTest.tbd:5:9: error: unknown key 'foobar'\nfoobar: "
469 "\"Unsupported key\"\n ^~~~~~~~~~~~~~~~~\n",
470 errorMessage);
471}
472
473} // end namespace TBDv1.