-
Notifications
You must be signed in to change notification settings - Fork 567
Expand file tree
/
Copy pathProjectTest.cs
More file actions
3254 lines (2904 loc) · 172 KB
/
ProjectTest.cs
File metadata and controls
3254 lines (2904 loc) · 172 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Diagnostics;
using System.Xml;
using Mono.Cecil;
#nullable enable
namespace Xamarin.Tests {
[TestFixture]
public class DotNetProjectTest : TestBaseClass {
[Test]
[TestCase (null)]
[TestCase ("iossimulator-x64")]
[TestCase ("iossimulator-arm64")]
[TestCase ("ios-arm64")]
public void BuildMySingleView (string runtimeIdentifier)
{
var platform = ApplePlatform.iOS;
var project_path = GetProjectPath ("MySingleView", runtimeIdentifiers: runtimeIdentifier, platform: platform, out var appPath);
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifier);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
var result = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerExecuted (result);
AssertAppContents (platform, appPath);
var infoPlistPath = Path.Combine (appPath, "Info.plist");
var infoPlist = PDictionary.FromFile (infoPlistPath)!;
Assert.AreEqual ("com.xamarin.mysingletitle", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier");
Assert.AreEqual ("MySingleTitle", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleShortVersionString").Value, "CFBundleShortVersionString");
}
[Test]
[TestCase (null)]
[TestCase ("osx-x64")]
[TestCase ("osx-arm64")]
public void BuildMyCocoaApp (string runtimeIdentifier)
{
var platform = ApplePlatform.MacOSX;
var project_path = GetProjectPath ("MyCocoaApp", runtimeIdentifiers: runtimeIdentifier, platform: platform, out var appPath);
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifier);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
var result = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerExecuted (result);
AssertAppContents (platform, appPath);
}
[Test]
[TestCase (null)]
[TestCase ("tvossimulator-x64")]
[TestCase ("tvossimulator-arm64")]
[TestCase ("tvos-arm64")]
public void BuildMyTVApp (string runtimeIdentifier)
{
var platform = ApplePlatform.TVOS;
var project_path = GetProjectPath ("MyTVApp", runtimeIdentifiers: runtimeIdentifier, platform: platform, out var appPath);
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifier);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
var result = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerExecuted (result);
AssertAppContents (platform, appPath);
}
[Test]
[TestCase (null)]
[TestCase ("maccatalyst-x64")]
[TestCase ("maccatalyst-arm64")]
public void BuildMyCatalystApp (string runtimeIdentifier)
{
var platform = ApplePlatform.MacCatalyst;
var project_path = GetProjectPath ("MyCatalystApp", runtimeIdentifiers: runtimeIdentifier, platform: platform, out var appPath);
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifier);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
var result = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerExecuted (result);
AssertAppContents (platform, appPath);
var infoPlistPath = Path.Combine (appPath, "Contents", "Info.plist");
var infoPlist = PDictionary.FromFile (infoPlistPath)!;
Assert.AreEqual ("com.xamarin.mycatalystapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier");
Assert.AreEqual ("MyCatalystApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleShortVersionString").Value, "CFBundleShortVersionString");
}
[TestCase ("iOS")]
[TestCase ("tvOS")]
[TestCase ("macOS")]
[TestCase ("MacCatalyst")]
[Category ("WindowsInclusive")]
public void BuildMyClassLibrary (string platform)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath ("MyClassLibrary", platform);
Clean (project_path);
var result = DotNet.AssertBuild (project_path, verbosity);
Assert.That (result.StandardOutput.ToString (), Does.Not.Contain ("Task \"ILLink\""), "Linker executed unexpectedly.");
}
[TestCase ("iOS")]
[TestCase ("tvOS")]
[TestCase ("macOS")]
[TestCase ("MacCatalyst")]
[Category ("WindowsInclusive")]
public void BuildEmbeddedResourcesTest (string platform)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var assemblyName = "EmbeddedResources";
var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet");
var project_dir = Path.Combine (dotnet_bindings_dir, platform);
var project_path = Path.Combine (project_dir, $"{assemblyName}.csproj");
Clean (project_path);
var result = DotNet.AssertBuild (project_path, verbosity);
var lines = BinLog.PrintToLines (result.BinLogPath);
// Find the resulting binding assembly from the build log
var assemblies = FilterToAssembly (lines, assemblyName);
Assert.That (assemblies, Is.Not.Empty, "Assemblies");
// Make sure there's no other assembly confusing our logic
assemblies = assemblies.Distinct ();
Assert.That (assemblies.Count (), Is.EqualTo (1), $"Unique assemblies\n\t{string.Join ("\n\t", assemblies)}");
var asm = assemblies.First ();
Assert.That (asm, Does.Exist, "Assembly existence");
// Verify that there's one resource in the assembly, and its name
var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
Assert.That (ad.MainModule.Resources.Count, Is.EqualTo (1), "1 resource");
Assert.That (ad.MainModule.Resources [0].Name, Is.EqualTo ("EmbeddedResources.Welcome.resources"), "libtest.a");
var asm_dir = Path.GetDirectoryName (asm)!;
Assert.That (Path.Combine (asm_dir, "en-AU", "EmbeddedResources.resources.dll"), Does.Exist, "en-AU");
Assert.That (Path.Combine (asm_dir, "de", "EmbeddedResources.resources.dll"), Does.Exist, "de");
Assert.That (Path.Combine (asm_dir, "es", "EmbeddedResources.resources.dll"), Does.Exist, "es");
}
[TestCase ("iOS")]
[TestCase ("tvOS")]
[TestCase ("macOS")]
[TestCase ("MacCatalyst")]
[Category ("WindowsInclusive")]
public void BuildFSharpLibraryTest (string platform)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var assemblyName = "fsharplibrary";
var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet");
var project_dir = Path.Combine (dotnet_bindings_dir, platform);
var project_path = Path.Combine (project_dir, $"{assemblyName}.fsproj");
Clean (project_path);
var result = DotNet.AssertBuild (project_path, verbosity);
var lines = BinLog.PrintToLines (result.BinLogPath);
// Find the resulting binding assembly from the build log
var assemblies = FilterToAssembly (lines, assemblyName).Distinct ();
Assert.That (assemblies, Is.Not.Empty, "Assemblies");
// Make sure there's no other assembly confusing our logic
Assert.That (assemblies.Count (), Is.EqualTo (1), $"Unique assemblies:\n\t{string.Join ("\n\t", assemblies)}");
var asm = assemblies.First ();
Assert.That (asm, Does.Exist, "Assembly existence");
// Verify that there's no resources in the assembly
var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
var expectedFSharpResources = new string [] {
"FSharpOptimizationCompressedData.fsharplibrary",
"FSharpSignatureCompressedData.fsharplibrary",
"FSharpSignatureCompressedDataB.fsharplibrary",
};
var actualFSharpResources = ad.MainModule.Resources.Select (v => v.Name).OrderBy (v => v).ToArray ();
Assert.That (actualFSharpResources, Is.EqualTo (expectedFSharpResources), "F# resources:"); // There are some embedded resources by default by the F# compiler.
}
[TestCase (ApplePlatform.iOS)]
[TestCase (ApplePlatform.TVOS)]
[TestCase (ApplePlatform.MacOSX)]
[TestCase (ApplePlatform.MacCatalyst)]
[Category ("WindowsInclusive")]
public void BuildBindingsTest (ApplePlatform platform)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var assemblyName = "bindings-test";
var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet");
var project_dir = Path.Combine (dotnet_bindings_dir, platform.AsString ());
var project_path = Path.Combine (project_dir, $"{assemblyName}.csproj");
Clean (project_path);
var result = DotNet.AssertBuild (project_path, verbosity);
var lines = BinLog.PrintToLines (result.BinLogPath).ToList ();
Console.WriteLine (string.Join ("\n", lines));
// Find the resulting binding assembly from the build log
var assemblies = FilterToAssembly (lines, assemblyName);
Assert.That (assemblies, Is.Not.Empty, "Assemblies");
// Make sure there's no other assembly confusing our logic
Assert.That (assemblies.Distinct ().Count (), Is.EqualTo (1), "Unique assemblies");
var asm = assemblies.First ();
Assert.That (asm, Does.Exist, "Assembly existence");
// Verify that there's one resource in the binding assembly, and its name
var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
Assert.That (ad.MainModule.Resources.Count, Is.EqualTo (0), "no embedded resources");
var resourceBundle = Path.Combine (project_dir, "bin", "Debug", platform.ToFramework (), assemblyName + ".resources");
var resourceZip = resourceBundle + ".zip";
if (!Directory.Exists (resourceBundle) && !File.Exists (resourceZip))
Assert.Fail ($"Neither the sidecar {resourceBundle} or the zipped sidecar {resourceZip} exists.");
}
[TestCase (ApplePlatform.iOS)]
[TestCase (ApplePlatform.TVOS)]
[TestCase (ApplePlatform.MacOSX)]
[TestCase (ApplePlatform.MacCatalyst)]
[Category ("WindowsInclusive")]
public void BuildBindingsTest2 (ApplePlatform platform)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var assemblyName = "bindings-test2";
var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet");
var project_dir = Path.Combine (dotnet_bindings_dir, platform.AsString ());
var project_path = Path.Combine (project_dir, $"{assemblyName}.csproj");
Clean (project_path);
var result = DotNet.AssertBuild (project_path, verbosity);
var lines = BinLog.PrintToLines (result.BinLogPath);
// Find the resulting binding assembly from the build log
var assemblies = FilterToAssembly (lines, assemblyName);
Assert.That (assemblies, Is.Not.Empty, "Assemblies");
// Make sure there's no other assembly confusing our logic
Assert.That (assemblies.Distinct ().Count (), Is.EqualTo (1), "Unique assemblies");
var asm = assemblies.First ();
Assert.That (asm, Does.Exist, "Assembly existence");
// Verify that there's one resource in the binding assembly, and its name
var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
Assert.That (ad.MainModule.Resources.Count, Is.EqualTo (0), "no embedded resources");
var resourceBundle = Path.Combine (project_dir, "bin", "Debug", platform.ToFramework (), assemblyName + ".resources");
Assert.That (resourceBundle, Does.Exist, "Bundle existence");
}
[TestCase ("iOS", "monotouch", true)]
[TestCase ("tvOS", "monotouch", true)]
[TestCase ("macOS", "xammac", true)]
[TestCase ("MacCatalyst", "monotouch", true)]
[TestCase ("iOS", "monotouch", false)]
[TestCase ("tvOS", "monotouch", false)]
[TestCase ("macOS", "xammac", false)]
[TestCase ("MacCatalyst", "monotouch", false)]
[TestCase ("iOS", "monotouch", null)]
[TestCase ("tvOS", "monotouch", null)]
[TestCase ("macOS", "xammac", null)]
[TestCase ("MacCatalyst", "monotouch", null)]
public void BuildBundledResources (string platform, string prefix, bool? bundleOriginalResources)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var assemblyName = "BundledResources";
var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet");
var project_dir = Path.Combine (dotnet_bindings_dir, platform);
var project_path = Path.Combine (project_dir, $"{assemblyName}.csproj");
Clean (project_path);
var properties = GetDefaultProperties ();
if (bundleOriginalResources.HasValue)
properties ["BundleOriginalResources"] = bundleOriginalResources.Value ? "true" : "false";
var result = DotNet.AssertBuild (project_path, properties);
var lines = BinLog.PrintToLines (result.BinLogPath);
// Find the resulting binding assembly from the build log
var assemblies = FilterToAssembly (lines, assemblyName);
Assert.That (assemblies, Is.Not.Empty, "Assemblies");
// Make sure there's no other assembly confusing our logic
Assert.That (assemblies.Distinct ().Count (), Is.EqualTo (1), "Unique assemblies");
var asm = assemblies.First ();
Assert.That (asm, Does.Exist, "Assembly existence");
// Verify the resource count in the binding assembly, and their names
var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
var resources = ad.MainModule.Resources.Select (v => v.Name).ToArray ();
var expectedResources = new string [] {
"basn3p08.png",
"basn3p08__with__loc.png",
"xamvideotest.mp4",
};
var oldPrefixed = expectedResources.Select (v => $"__{prefix}_content_{v}").ToArray ();
var newPrefixed = expectedResources.Select (v => $"__{prefix}_item_BundleResource_{v}").ToArray ();
Assert.That (resources, Is.EquivalentTo (oldPrefixed).Or.EquivalentTo (newPrefixed), "Resources");
}
[TestCase ("iOS")]
[TestCase ("tvOS")]
[TestCase ("macOS")]
[TestCase ("MacCatalyst")]
public void BuildInterdependentBindingProjects (string platform)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var assemblyName = "interdependent-binding-projects";
var dotnet_bindings_dir = Path.Combine (Configuration.SourceRoot, "tests", assemblyName, "dotnet");
var project_dir = Path.Combine (dotnet_bindings_dir, platform);
var project_path = Path.Combine (project_dir, $"{assemblyName}.csproj");
Clean (project_path);
var result = DotNet.AssertBuild (project_path, verbosity);
var lines = BinLog.PrintToLines (result.BinLogPath);
// Find the resulting binding assembly from the build log
var assemblies = FilterToAssembly (lines, assemblyName, true);
Assert.That (assemblies, Is.Not.Empty, "Assemblies");
// Make sure there's no other assembly confusing our logic
assemblies = assemblies.Distinct ();
Assert.That (assemblies.Count (), Is.EqualTo (1), $"Unique assemblies: {string.Join (", ", assemblies)}");
var asm = assemblies.First ();
Assert.That (asm, Does.Exist, "Assembly existence");
// Verify that the resources have been linked away
var asmDir = Path.GetDirectoryName (asm)!;
var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
Assert.That (ad.MainModule.Resources.Count, Is.EqualTo (0), "0 resources for interdependent-binding-projects.dll");
var ad1 = AssemblyDefinition.ReadAssembly (Path.Combine (asmDir, "bindings-test.dll"), new ReaderParameters { ReadingMode = ReadingMode.Deferred });
// The native library is removed from the resources by the linker
Assert.That (ad1.MainModule.Resources.Count, Is.EqualTo (0), "0 resources for bindings-test.dll");
var ad2 = AssemblyDefinition.ReadAssembly (Path.Combine (asmDir, "bindings-test2.dll"), new ReaderParameters { ReadingMode = ReadingMode.Deferred });
// The native library is removed from the resources by the linker
Assert.That (ad2.MainModule.Resources.Count, Is.EqualTo (0), "0 resources for bindings-test2.dll");
}
[Test]
[TestCase (ApplePlatform.iOS, "iossimulator-x64;iossimulator-arm64")]
[TestCase (ApplePlatform.TVOS, "tvossimulator-x64;tvossimulator-arm64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
public void BuildFatApp (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
var result = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerExecuted (result);
var infoPlistPath = GetInfoPListPath (platform, appPath);
Assert.That (infoPlistPath, Does.Exist, "Info.plist");
var infoPlist = PDictionary.FromFile (infoPlistPath)!;
Assert.AreEqual ("com.xamarin.mysimpleapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier");
Assert.AreEqual ("MySimpleApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleShortVersionString").Value, "CFBundleShortVersionString");
}
[Test]
[TestCase (ApplePlatform.iOS, "iossimulator-x64;iossimulator-arm64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
public void BuildFatMonoTouchTest (ApplePlatform platform, string runtimeIdentifiers, params string [] additionalProperties)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = Path.Combine (Configuration.SourceRoot, "tests", "monotouch-test", "dotnet", platform.AsString (), "monotouch-test.csproj");
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
if (additionalProperties is not null) {
foreach (var prop in additionalProperties) {
var eq = prop.IndexOf ('=');
var name = prop.Substring (0, eq);
var value = prop.Substring (eq + 1);
properties [name] = value;
}
}
var result = DotNet.AssertBuild (project_path, properties);
var appPath = Path.Combine (Path.GetDirectoryName (project_path)!, "bin", "Debug", platform.ToFramework (), "monotouchtest.app");
var infoPlistPath = GetInfoPListPath (platform, appPath);
Assert.That (infoPlistPath, Does.Exist, "Info.plist");
var infoPlist = PDictionary.FromFile (infoPlistPath)!;
Assert.AreEqual ("com.xamarin.monotouch-test", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier");
Assert.AreEqual ("MonoTouchTest", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName");
}
[Test]
[TestCase (ApplePlatform.iOS, "ios-arm64;iossimulator-x64")]
[TestCase (ApplePlatform.iOS, "ios-arm64;iossimulator-arm64")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64;tvossimulator-x64")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64;tvossimulator-arm64")]
public void InvalidRuntimeIdentifiers (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
var rv = DotNet.AssertBuildFailure (project_path, properties);
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
Assert.AreEqual (1, errors.Length, "Error count");
Assert.AreEqual ($"Building for all the runtime identifiers '{runtimeIdentifiers}' at the same time isn't possible, because they represent different platform variations.", errors [0].Message, "Error message");
}
[Test]
[TestCase (ApplePlatform.iOS, "iossimulator-x64", false)]
[TestCase (ApplePlatform.iOS, "ios-arm64", true)]
[TestCase (ApplePlatform.iOS, "ios-arm64", true, null, "Release")]
[TestCase (ApplePlatform.iOS, "ios-arm64", true, "PublishTrimmed=true;UseInterpreter=true")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", false)]
[Category ("WindowsInclusive")]
public void IsNotMacBuild (ApplePlatform platform, string runtimeIdentifiers, bool isDeviceBuild, string? extraProperties = null, string configuration = "Debug")
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath, configuration: configuration);
Configuration.IgnoreIfIgnoredPlatform (platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["IsMacEnabled"] = "false";
if (!string.IsNullOrEmpty (configuration))
properties ["Configuration"] = configuration;
if (extraProperties is not null) {
foreach (var assignment in extraProperties.Split (';')) {
var split = assignment.Split ('=');
properties [split [0]] = split [1];
}
}
var result = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerDidNotExecute (result);
switch (platform) {
case ApplePlatform.iOS:
var appExecutable = Path.Combine (appPath, Path.GetFileName (project_path));
Assert.That (appPath, Does.Not.Exist, "There is an .app");
Assert.That (appExecutable, Does.Not.Empty, "There is no executable");
Assert.That (Path.Combine (appPath, Configuration.GetBaseLibraryName (platform)), Does.Not.Exist, "Platform assembly is in the bundle");
break;
case ApplePlatform.MacCatalyst:
break;
}
}
[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
public void IsOverrideRuntimeIdentifier (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
// Be specific that we want "RuntimeIdentifier" specified on the command line, and "RuntimeIdentifiers" in a file
properties ["file:RuntimeIdentifiers"] = properties ["RuntimeIdentifiers"];
properties.Remove ("RuntimeIdentifiers");
properties ["cmdline:RuntimeIdentifier"] = "maccatalyst-x64";
var rv = DotNet.AssertBuild (project_path, properties);
var warnings = BinLog.GetBuildLogWarnings (rv.BinLogPath).ToArray ();
Assert.AreEqual (1, warnings.Length, "Warning Count");
Assert.AreEqual ("RuntimeIdentifier was set on the command line, and will override the value for RuntimeIdentifiers set in the project file.", warnings [0].Message, "Warning message");
}
[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
public void IsNotOverrideRuntimeIdentifier (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var projectPath = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (projectPath);
var props = GetDefaultProperties ();
props ["RuntimeIdentifier"] = "maccatalyst-x64";
props ["RuntimeIdentifiers"] = "maccatalyst-arm64";
var rv = DotNet.AssertBuildFailure (projectPath, props);
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
Assert.AreEqual ("Both RuntimeIdentifier and RuntimeIdentifiers were passed on the command line, but only one of them can be set at a time.", errors [0].Message);
Assert.AreEqual (1, errors.Length, "Error count");
}
[Test]
[TestCase ("NativeDynamicLibraryReferencesApp", ApplePlatform.iOS, "iossimulator-x64")]
[TestCase ("NativeDynamicLibraryReferencesApp", ApplePlatform.MacOSX, "osx-x64")]
[TestCase ("NativeFileReferencesApp", ApplePlatform.iOS, "iossimulator-x64")]
[TestCase ("NativeFileReferencesApp", ApplePlatform.MacOSX, "osx-x64")]
[TestCase ("NativeFrameworkReferencesApp", ApplePlatform.iOS, "iossimulator-x64")]
[TestCase ("NativeFrameworkReferencesApp", ApplePlatform.MacOSX, "osx-x64")]
[TestCase ("NativeXCFrameworkReferencesApp", ApplePlatform.iOS, "iossimulator-x64")]
[TestCase ("NativeXCFrameworkReferencesApp", ApplePlatform.MacOSX, "osx-x64")]
public void BuildAndExecuteNativeReferencesTestApp (string project, ApplePlatform platform, string runtimeIdentifier)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifier);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifier, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
DotNet.AssertBuild (project_path, properties);
if (platform == ApplePlatform.MacOSX || platform == ApplePlatform.MacCatalyst) {
var appExecutable = Path.Combine (appPath, "Contents", "MacOS", Path.GetFileNameWithoutExtension (project_path));
Assert.That (appExecutable, Does.Exist, "There is an executable");
ExecuteWithMagicWordAndAssert (appExecutable);
}
}
[Test]
[TestCase (ApplePlatform.iOS, "ios-x64", false)] // valid RID in a previous preview (and common mistake)
[TestCase (ApplePlatform.iOS, "iossimulator-x84", true)] // it's x86, not x84
[TestCase (ApplePlatform.iOS, "iossimulator-arm", true)] // we don't support this
[TestCase (ApplePlatform.iOS, "helloworld", true)] // random text
[TestCase (ApplePlatform.iOS, "tvos-arm64", false)] // valid RID for another platform
[TestCase (ApplePlatform.TVOS, "tvos-x64", false)] // valid RID in a previous preview (and common mistake)
[TestCase (ApplePlatform.TVOS, "tvossimulator-x46", true)] // it's x64, not x46
[TestCase (ApplePlatform.TVOS, "tvossimulator-arm", true)] // we don't support this
[TestCase (ApplePlatform.TVOS, "helloworld", true)] // random text
[TestCase (ApplePlatform.TVOS, "iossimulator-x64", false)] // valid RID for another platform
[TestCase (ApplePlatform.MacOSX, "osx-x46", true)] // it's x64, not x46
[TestCase (ApplePlatform.MacOSX, "macos-arm64", true)] // it's osx, not macos
[TestCase (ApplePlatform.MacOSX, "helloworld", true)] // random text
[TestCase (ApplePlatform.MacOSX, "ios-arm64", false)] // valid RID for another platform
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x46", true)] // it's x64, not x46
[TestCase (ApplePlatform.MacCatalyst, "helloworld", true)] // random text
[TestCase (ApplePlatform.MacCatalyst, "ios-arm64", false)] // valid RID for another platform
public void InvalidRuntimeIdentifier (ApplePlatform platform, string runtimeIdentifier, bool notRecognized)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
var rv = DotNet.AssertBuildFailure (project_path, properties);
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
var uniqueErrors = errors.Select (v => v.Message).Distinct ().ToArray ();
Assert.AreEqual (1, uniqueErrors.Length, "Error count");
string expectedError;
if (notRecognized) {
expectedError = $"The specified RuntimeIdentifier '{runtimeIdentifier}' is not recognized. See https://aka.ms/netsdk1083 for more information.";
} else {
expectedError = $"The RuntimeIdentifier '{runtimeIdentifier}' is invalid.";
}
Assert.AreEqual (expectedError, uniqueErrors [0], "Error message");
}
[Test]
[TestCase (ApplePlatform.iOS, "win10-x86", "The specified RuntimeIdentifier 'win10-x86' is not recognized.")]
[TestCase (ApplePlatform.TVOS, "win10-x64", "The specified RuntimeIdentifier 'win10-x64' is not recognized.")]
[TestCase (ApplePlatform.MacOSX, "win10-arm64", "The specified RuntimeIdentifier 'win10-arm64' is not recognized.")]
[TestCase (ApplePlatform.MacCatalyst, "win10-arm64", "The specified RuntimeIdentifier 'win10-arm64' is not recognized.")]
public void InvalidRuntimeIdentifier_Restore (ApplePlatform platform, string runtimeIdentifier, string? failureMessagePattern)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
if (string.IsNullOrEmpty (failureMessagePattern)) {
DotNet.AssertRestore (project_path, properties);
} else {
var rv = DotNet.Restore (project_path, properties);
Assert.AreNotEqual (0, rv.ExitCode, "Expected failure");
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
Assert.That (errors.Length, Is.GreaterThan (0), "Error count");
Assert.That (errors [0].Message, Does.Match (failureMessagePattern), "Message failure");
}
}
[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
public void FilesInAppBundle (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
// Build
DotNet.AssertBuild (project_path, properties);
// Simulate a crash dump
File.WriteAllText (Path.Combine (appPath, "mono_crash.mem.123456.something.blob"), "A crash dump");
File.WriteAllText (Path.Combine (appPath, "mono_crash.123456.somethingelse.blob"), "A crash dump");
// Build again
DotNet.AssertBuild (project_path, properties);
// Create a file that isn't a crash report.
File.WriteAllText (Path.Combine (appPath, "otherfile.txt"), "A file");
var otherFileInDir = Path.Combine (appPath, "otherdir", "otherfile.log");
Directory.CreateDirectory (Path.GetDirectoryName (otherFileInDir)!);
File.WriteAllText (otherFileInDir, "A log");
// Build again - this time it'll fail
var rv = DotNet.Build (project_path, properties);
var warnings = BinLog.GetBuildLogWarnings (rv.BinLogPath).ToArray ();
Assert.AreNotEqual (0, rv.ExitCode, "Unexpected success");
Assert.AreEqual (1, warnings.Length, "Warning Count");
Assert.AreEqual ($"Found files in the root directory of the app bundle. This will likely cause codesign to fail. Files:\nbin/Debug/{Configuration.DotNetTfm}-maccatalyst/maccatalyst-x64/MySimpleApp.app/otherfile.txt\nbin/Debug/{Configuration.DotNetTfm}-maccatalyst/maccatalyst-x64/MySimpleApp.app/otherdir\nbin/Debug/{Configuration.DotNetTfm}-maccatalyst/maccatalyst-x64/MySimpleApp.app/otherdir/otherfile.log", warnings [0].Message, "Warning");
// Build again, asking for automatic removal of the extraneous files.
var enableAutomaticCleanupProperties = new Dictionary<string, string> (properties);
enableAutomaticCleanupProperties ["EnableAutomaticAppBundleRootDirectoryCleanup"] = "true";
rv = DotNet.AssertBuild (project_path, enableAutomaticCleanupProperties);
warnings = BinLog.GetBuildLogWarnings (rv.BinLogPath).ToArray ();
Assert.AreEqual (0, warnings.Length, "Warning Count");
// Verify that the files were in fact removed.
Assert.That (Path.Combine (appPath, "otherfile.txt"), Does.Not.Exist, "otherfile");
Assert.That (Path.GetDirectoryName (otherFileInDir), Does.Not.Exist, "otherdir");
}
[Test]
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
public void BuildCoreCLR (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["UseMonoRuntime"] = "false";
var rv = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerExecuted (rv);
var infoPlistPath = GetInfoPListPath (platform, appPath);
Assert.That (infoPlistPath, Does.Exist, "Info.plist");
var infoPlist = PDictionary.FromFile (infoPlistPath)!;
Assert.AreEqual ("com.xamarin.mysimpleapp", infoPlist.GetString ("CFBundleIdentifier").Value, "CFBundleIdentifier");
Assert.AreEqual ("MySimpleApp", infoPlist.GetString ("CFBundleDisplayName").Value, "CFBundleDisplayName");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleVersion").Value, "CFBundleVersion");
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleShortVersionString").Value, "CFBundleShortVersionString");
var appExecutable = GetNativeExecutable (platform, appPath);
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);
var createdump = Path.Combine (appPath, "Contents", "MonoBundle", "createdump");
Assert.That (createdump, Does.Not.Exist, "createdump existence");
}
[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
public void AbsoluteOutputPath (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var outputPath = Cache.CreateTemporaryDirectory ();
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["OutputPath"] = outputPath + "/";
var rv = DotNet.AssertBuild (project_path, properties);
AssertThatLinkerExecuted (rv);
var appPath = Path.Combine (outputPath, project + ".app");
var appExecutable = GetNativeExecutable (platform, appPath);
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);
}
[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
public void SimpleAppWithOldReferences (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "SimpleAppWithOldReferences";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
DotNet.AssertBuild (project_path, GetDefaultProperties (runtimeIdentifiers));
var appExecutable = GetNativeExecutable (platform, appPath);
Assert.That (appExecutable, Does.Exist, "There is an executable");
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);
}
[Test]
[TestCase (ApplePlatform.iOS)]
[TestCase (ApplePlatform.TVOS)]
[TestCase (ApplePlatform.MacCatalyst)]
[TestCase (ApplePlatform.MacOSX)]
public void BindingWithDefaultCompileInclude (ApplePlatform platform)
{
var project = "BindingWithDefaultCompileInclude";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var rv = DotNet.AssertBuild (project_path, GetDefaultProperties ());
var dllPath = Path.Combine (Path.GetDirectoryName (project_path)!, "bin", "Debug", platform.ToFramework (), $"{project}.dll");
Assert.That (dllPath, Does.Exist, "Binding assembly");
// Verify that the MyNativeClass class exists in the assembly, and that it's actually a class.
var ad = AssemblyDefinition.ReadAssembly (dllPath, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
var myNativeClass = ad.MainModule.Types.FirstOrDefault (v => v.FullName == "MyApiDefinition.MyNativeClass");
Assert.IsFalse (myNativeClass!.IsInterface, "IsInterface");
var myStruct = ad.MainModule.Types.FirstOrDefault (v => v.FullName == "MyClassLibrary.MyStruct");
Assert.IsTrue (myStruct!.IsValueType, "MyStruct");
var warnings = BinLog.GetBuildLogWarnings (rv.BinLogPath).Select (v => v.Message);
Assert.That (warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");
}
[TestCase (ApplePlatform.iOS, "iossimulator-x64")]
[TestCase (ApplePlatform.iOS, "ios-arm64")]
[TestCase (ApplePlatform.TVOS, "tvossimulator-x64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")] // https://github.com/xamarin/xamarin-macios/issues/12410
public void AppWithResources (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "AppWithResources";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
DotNet.AssertBuild (project_path, GetDefaultProperties (runtimeIdentifiers));
var appExecutable = GetNativeExecutable (platform, appPath);
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);
var resourcesDirectory = GetResourcesDirectory (platform, appPath);
var fontDirectory = resourcesDirectory;
var fontAFile = Path.Combine (fontDirectory, "A.ttc");
var fontBFile = Path.Combine (fontDirectory, "B.otf");
var fontCFile = Path.Combine (fontDirectory, "C.ttf");
Assert.That (fontAFile, Does.Exist, "A.ttc existence");
Assert.That (fontBFile, Does.Exist, "B.otf existence");
Assert.That (fontCFile, Does.Exist, "C.ttf existence");
var plist = PDictionary.FromFile (GetInfoPListPath (platform, appPath))!;
switch (platform) {
case ApplePlatform.iOS:
case ApplePlatform.TVOS:
case ApplePlatform.MacCatalyst:
var uiAppFonts = plist.GetArray ("UIAppFonts");
Assert.IsNotNull (uiAppFonts, "UIAppFonts");
Assert.AreEqual (1, uiAppFonts.Count, "UIAppFonts.Count");
Assert.AreEqual ("B.otf", ((PString) uiAppFonts [0]).Value, "UIAppFonts [0]");
break;
case ApplePlatform.MacOSX:
var applicationFontsPath = plist.GetString ("ATSApplicationFontsPath")?.Value;
Assert.AreEqual (".", applicationFontsPath, "ATSApplicationFontsPath");
break;
default:
throw new ArgumentOutOfRangeException ($"Unknown platform: {platform}");
}
var assetsCar = Path.Combine (resourcesDirectory, "Assets.car");
Assert.That (assetsCar, Does.Exist, "Assets.car");
var mainStoryboard = Path.Combine (resourcesDirectory, "Main.storyboardc");
Assert.That (mainStoryboard, Does.Exist, "Main.storyboardc");
var scnAssetsDir = Path.Combine (resourcesDirectory, "art.scnassets");
Assert.That (Path.Combine (scnAssetsDir, "scene.scn"), Does.Exist, "scene.scn");
Assert.That (Path.Combine (scnAssetsDir, "texture.png"), Does.Exist, "texture.png");
var colladaScene = Path.Combine (resourcesDirectory, "scene.dae");
Assert.That (colladaScene, Does.Exist, "Collada - scene.dae");
var atlasTexture = Path.Combine (resourcesDirectory, "Archer_Attack.atlasc", "Archer_Attack.plist");
Assert.That (atlasTexture, Does.Exist, "AtlasTexture - Archer_Attack");
var mlModel = Path.Combine (resourcesDirectory, "SqueezeNet.mlmodelc");
Assert.That (mlModel, Does.Exist, "CoreMLModel");
var arm64txt = Path.Combine (resourcesDirectory, "arm64.txt");
var armtxt = Path.Combine (resourcesDirectory, "arm.txt");
var x64txt = Path.Combine (resourcesDirectory, "x64.txt");
Assert.AreEqual (runtimeIdentifiers.Split (';').Any (v => v.EndsWith ("-arm64")), File.Exists (arm64txt), "arm64.txt");
Assert.AreEqual (runtimeIdentifiers.Split (';').Any (v => v.EndsWith ("-arm")), File.Exists (armtxt), "arm.txt");
Assert.AreEqual (runtimeIdentifiers.Split (';').Any (v => v.EndsWith ("-x64")), File.Exists (x64txt), "x64.txt");
var b_otf = Path.Combine (Path.GetDirectoryName (project_path)!, "Resources", "B.otf");
Configuration.Touch (b_otf);
var rv = DotNet.AssertBuild (project_path, GetDefaultProperties (runtimeIdentifiers));
var allTargets = BinLog.GetAllTargets (rv.BinLogPath);
AssertTargetExecuted (allTargets, "_CompileAppManifest", "_CompileAppManifest rebuild");
rv = DotNet.AssertBuild (project_path, GetDefaultProperties (runtimeIdentifiers));
allTargets = BinLog.GetAllTargets (rv.BinLogPath);
AssertTargetNotExecuted (allTargets, "_CompileAppManifest", "_CompileAppManifest rebuild 2");
}
[Category ("Windows")]
[TestCase (ApplePlatform.iOS, true)]
[TestCase (ApplePlatform.iOS, false)]
[TestCase (ApplePlatform.iOS, null)]
public void LibraryWithResourcesOnWindows (ApplePlatform platform, bool? bundleOriginalResources)
{
Configuration.IgnoreIfNotOnWindows ();
// This should all execute locally on Windows when BundleOriginalResources=true
bool anyLibraryResources = bundleOriginalResources ?? Version.Parse (Configuration.DotNetTfm.Replace ("net", "")).Major >= 10;
LibraryWithResources (platform, anyLibraryResources: anyLibraryResources, bundleOriginalResources: bundleOriginalResources);
}
[Category ("RemoteWindows")]
[TestCase (ApplePlatform.iOS, true)]
[TestCase (ApplePlatform.iOS, false)]
public void LibraryWithResourcesOnRemoteWindows (ApplePlatform platform, bool? bundleOriginalResources)
{
Configuration.IgnoreIfNotOnWindows ();
// This should all execute locally on Windows when BundleOriginalResources=true, but either should work
LibraryWithResources (platform, bundleOriginalResources);
}
[TestCase (ApplePlatform.iOS, true)]
[TestCase (ApplePlatform.iOS, false)]
[TestCase (ApplePlatform.iOS, null)]
[TestCase (ApplePlatform.TVOS, true)]
[TestCase (ApplePlatform.TVOS, false)]
[TestCase (ApplePlatform.TVOS, null)]
[TestCase (ApplePlatform.MacCatalyst, true)]
[TestCase (ApplePlatform.MacCatalyst, false)]
[TestCase (ApplePlatform.MacCatalyst, null)]
[TestCase (ApplePlatform.MacOSX, true)]
[TestCase (ApplePlatform.MacOSX, false)]
[TestCase (ApplePlatform.MacOSX, null)]
public void LibraryWithResources (ApplePlatform platform, bool? bundleOriginalResources, bool anyLibraryResources = true)
{
var project = "LibraryWithResources";
Configuration.IgnoreIfIgnoredPlatform (platform);
var actualBundleOriginalResources = bundleOriginalResources ?? Version.Parse (Configuration.DotNetTfm.Replace ("net", "")).Major >= 10;
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties ();
if (bundleOriginalResources.HasValue)
properties ["BundleOriginalResources"] = bundleOriginalResources.Value ? "true" : "false";
var rv = DotNet.AssertBuild (project_path, properties);
var allTargets = BinLog.GetAllTargets (rv.BinLogPath).Where (v => !v.Skipped).Select (v => v.TargetName);
// https://github.com/xamarin/xamarin-macios/issues/15031
if (actualBundleOriginalResources) {
Assert.That (allTargets, Does.Not.Contain ("_CompileAppManifest"), "Didn't execute '_CompileAppManifest'");
Assert.That (allTargets, Does.Not.Contain ("_DetectSdkLocations"), "Didn't execute '_DetectSdkLocations'");
Assert.That (allTargets, Does.Not.Contain ("_SayHello"), "Didn't execute '_SayHello'");
} else {
Assert.That (allTargets, Does.Contain ("_CompileAppManifest"), "Did execute '_CompileAppManifest'");
Assert.That (allTargets, Does.Contain ("_DetectSdkLocations"), "Did execute '_DetectSdkLocations'");
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform (System.Runtime.InteropServices.OSPlatform.Windows))
Assert.That (allTargets, Does.Contain ("_SayHello"), "Did execute '_SayHello'");
}
var lines = BinLog.PrintToLines (rv.BinLogPath);
// Find the resulting binding assembly from the build log
var assemblies = FilterToAssembly (lines, project);
Assert.That (assemblies, Is.Not.Empty, "Assemblies");
// Make sure there's no other assembly confusing our logic
Assert.That (assemblies.Distinct ().Count (), Is.EqualTo (1), "Unique assemblies");
var asm = assemblies.First ();
Assert.That (asm, Does.Exist, "Assembly existence");
using var ad = AssemblyDefinition.ReadAssembly (asm, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
var actualResources = ad.MainModule.Resources.Select (v => v.Name).OrderBy (v => v).ToArray ();
string [] expectedResources;
if (anyLibraryResources) {
var platformPrefix = (platform == ApplePlatform.MacOSX) ? "xammac" : "monotouch";
if (actualBundleOriginalResources) {
expectedResources = new string [] {
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0001.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0002.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0003.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0004.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0005.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0006.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0007.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0008.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0009.png",
$"__{platformPrefix}_item_AtlasTexture_Archer__Attack.atlas_sarcher__attack__0010.png",
$"__{platformPrefix}_item_BundleResource_A.ttc",
$"__{platformPrefix}_item_BundleResource_B.otf",
$"__{platformPrefix}_item_BundleResource_C.ttf",
$"__{platformPrefix}_item_Collada_scene.dae",
$"__{platformPrefix}_item_CoreMLModel_SqueezeNet.mlmodel",
$"__{platformPrefix}_item_ImageAsset_Images.xcassets_sContents.json",
$"__{platformPrefix}_item_ImageAsset_Images.xcassets_sImage.imageset_sContents.json",
$"__{platformPrefix}_item_ImageAsset_Images.xcassets_sImage.imageset_sIcon16.png",
$"__{platformPrefix}_item_ImageAsset_Images.xcassets_sImage.imageset_sIcon32.png",
$"__{platformPrefix}_item_ImageAsset_Images.xcassets_sImage.imageset_sIcon64.png",
$"__{platformPrefix}_item_InterfaceDefinition_Main.storyboard",
$"__{platformPrefix}_item_PartialAppManifest_shared.plist",
$"__{platformPrefix}_item_SceneKitAsset_art.scnassets_sscene.scn",
$"__{platformPrefix}_item_SceneKitAsset_art.scnassets_stexture.png",
$"__{platformPrefix}_item_SceneKitAsset_DirWithResources_slinkedArt.scnassets_sscene.scn",
$"__{platformPrefix}_item_SceneKitAsset_DirWithResources_slinkedArt.scnassets_stexture.png",
};
} else {
var expectedList = new List<string> ();
expectedList.Add ($"__{platformPrefix}_content_A.ttc");
expectedList.Add ($"__{platformPrefix}_content_Archer__Attack.atlasc_sArcher__Attack.plist");
expectedList.Add ($"__{platformPrefix}_content_art.scnassets_sscene.scn");
expectedList.Add ($"__{platformPrefix}_content_art.scnassets_stexture.png");
expectedList.Add ($"__{platformPrefix}_content_Assets.car");
expectedList.Add ($"__{platformPrefix}_content_B.otf");
expectedList.Add ($"__{platformPrefix}_content_C.ttf");
expectedList.Add ($"__{platformPrefix}_content_DirWithResources_slinkedArt.scnassets_sscene.scn");
expectedList.Add ($"__{platformPrefix}_content_DirWithResources_slinkedArt.scnassets_stexture.png");
expectedList.Add ($"__{platformPrefix}_content_scene.dae");
switch (platform) {
case ApplePlatform.iOS:
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sBYZ-38-t0r-view-8bC-Xf-vdC.nib");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sInfo.plist");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sUIViewController-BYZ-38-t0r.nib");
break;
case ApplePlatform.TVOS:
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sBYZ-38-t0r-view-8bC-Xf-vdC.nib");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sInfo.plist");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sUIViewController-BYZ-38-t0r.nib");
break;
case ApplePlatform.MacCatalyst:
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_s1-view-2.nib");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sInfo.plist");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sUIViewController-1.nib");
break;
case ApplePlatform.MacOSX:
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sInfo.plist");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sMainMenu.nib");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sNSWindowController-B8D-0N-5wS.nib");
expectedList.Add ($"__{platformPrefix}_content_Main.storyboardc_sXfG-lQ-9wD-view-m2S-Jp-Qdl.nib");
break;
}
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_sanalytics_scoremldata.bin");
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_scoremldata.bin");
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_smetadata.json");
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_smodel.espresso.net");
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_smodel.espresso.shape");
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_smodel.espresso.weights");
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_smodel_scoremldata.bin");
expectedList.Add ($"__{platformPrefix}_content_SqueezeNet.mlmodelc_sneural__network__optionals_scoremldata.bin");
expectedResources = expectedList.ToArray ();
}
} else {
expectedResources = new string [0];
}
CollectionAssert.AreEquivalent (expectedResources, actualResources, "Resources");
}
[TestCase (ApplePlatform.iOS, "ios-arm64", false)]
[TestCase (ApplePlatform.iOS, "ios-arm64", true)]
[TestCase (ApplePlatform.TVOS, "tvossimulator-arm64", false)]
[TestCase (ApplePlatform.TVOS, "tvossimulator-arm64", true)]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64", false)]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", true)]
[TestCase (ApplePlatform.MacOSX, "osx-x64", true)]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64", false)]
public void AppWithLibraryWithResourcesReference (ApplePlatform platform, string runtimeIdentifiers, bool bundleOriginalResources)
{
AppWithLibraryWithResourcesReferenceImpl (platform, runtimeIdentifiers, bundleOriginalResources, false, false);
}
[Category ("RemoteWindows")]
[TestCase (ApplePlatform.iOS, "ios-arm64", false)]
[TestCase (ApplePlatform.iOS, "ios-arm64", true)]
public void AppWithLibraryWithResourcesReferenceOnRemoteWindows (ApplePlatform platform, string runtimeIdentifiers, bool bundleOriginalResources)
{
Configuration.IgnoreIfNotOnWindows ();
AppWithLibraryWithResourcesReferenceImpl (platform, runtimeIdentifiers, bundleOriginalResources, true, false);
}
[Category ("Windows")]
[TestCase (ApplePlatform.iOS, "ios-arm64", false)]
[TestCase (ApplePlatform.iOS, "ios-arm64", true)]
public void AppWithLibraryWithResourcesReferenceWithHotRestart (ApplePlatform platform, string runtimeIdentifiers, bool bundleOriginalResources)
{
Configuration.IgnoreIfNotOnWindows ();
AppWithLibraryWithResourcesReferenceImpl (platform, runtimeIdentifiers, bundleOriginalResources, false, isUsingHotRestart: true);
}
void AppWithLibraryWithResourcesReferenceImpl (ApplePlatform platform, string runtimeIdentifiers, bool bundleOriginalResources, bool remoteWindows, bool isUsingHotRestart)
{
var project = "AppWithLibraryWithResourcesReference";
var config = bundleOriginalResources ? "DebugOriginal" : "DebugCompiled";