Esempio n. 1
0
        public void BuildFatMonoTouchTest(ApplePlatform platform, string runtimeIdentifiers, params string[] additionalProperties)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = Path.Combine(Configuration.SourceRoot, "tests", "monotouch-test", "dotnet", platform.AsString(), "monotouch-test.csproj");

            Configuration.CopyDotNetSupportingFiles(Path.GetDirectoryName(Path.GetDirectoryName(project_path)));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "bindings-test", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "bindings-test2", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "EmbeddedResources", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "tests", "fsharplibrary", "dotnet"));
            Configuration.CopyDotNetSupportingFiles(Path.Combine(Configuration.SourceRoot, "external", "Touch.Unit", "Touch.Client", "dotnet"));
            Clean(project_path);
            var properties = GetDefaultProperties(runtimeIdentifiers);

            if (additionalProperties != 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");
        }
Esempio n. 2
0
        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);
            Configuration.CopyDotNetSupportingFiles(dotnet_bindings_dir);
            var result = DotNet.AssertBuild(project_path, verbosity);
            var lines  = result.StandardOutput.ToString().Split('\n');
            // 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");
        }
Esempio n. 3
0
        public void NativeReferenceStaticLibraryForceLoad(ApplePlatform platform, bool?simulator)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);

            var tmpdir = Cache.CreateTemporaryDirectory();
            var magic  = Guid.NewGuid().ToString();
            var pathToNativeLibrary         = Path.Combine(Configuration.GetTestLibraryDirectory(platform, simulator), "libtest.a");
            var relativePathToNativeLibrary = Path.GetRelativePath(tmpdir, pathToNativeLibrary);
            var csproj = $@"<Project Sdk=""Microsoft.NET.Sdk"">
	<PropertyGroup>
		<TargetFramework>{platform.ToFramework ()}</TargetFramework>
		<OutputType>Exe</OutputType>
	</PropertyGroup>
	<ItemGroup>
		<NativeReference Include=""{relativePathToNativeLibrary}"">
			<Kind>Static</Kind>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
	</ItemGroup>
</Project>";

            Configuration.CopyDotNetSupportingFiles(tmpdir);
            var project_path = Path.Combine(tmpdir, "TestProject.csproj");

            File.WriteAllText(project_path, csproj);
            File.WriteAllText(Path.Combine(tmpdir, "Info.plist"), EmptyAppManifest);
            File.WriteAllText(Path.Combine(tmpdir, "Main.cs"), EmptyMainFile);

            DotNet.AssertBuild(project_path, GetDefaultProperties());
        }
Esempio n. 4
0
        public void BuildBindingsTest2(string 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);
            var project_path        = Path.Combine(project_dir, $"{assemblyName}.csproj");

            Clean(project_path);
            Configuration.CopyDotNetSupportingFiles(dotnet_bindings_dir);
            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(1), "1 resource");
            Assert.That(ad.MainModule.Resources [0].Name, Is.EqualTo("libtest2.a"), "libtest2.a");
        }
Esempio n. 5
0
        public void BuildMySingleView(string runtimeIdentifier)
        {
            var platform     = ApplePlatform.iOS;
            var project_path = GetProjectPath("MySingleView");

            Configuration.IgnoreIfIgnoredPlatform(platform);
            Clean(project_path);
            var properties = new Dictionary <string, string> (verbosity);

            if (!string.IsNullOrEmpty(runtimeIdentifier))
            {
                properties ["RuntimeIdentifier"] = runtimeIdentifier;
            }
            else
            {
                runtimeIdentifier = "iossimulator-x64";                 // default RID for iOS projects. We set it here to make the rest of the test know where to expect files to be.
            }
            var result = DotNet.AssertBuild(project_path, properties);

            AssertThatLinkerExecuted(result);
            var appPath = Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", "net6.0-ios", runtimeIdentifier, "MySingleView.app");

            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");
        }
Esempio n. 6
0
        public void BuildFatApp(ApplePlatform platform, string runtimeIdentifiers)
        {
            var project = "MySimpleApp";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = GetProjectPath(project, platform: platform);

            Clean(project_path);
            var properties = new Dictionary <string, string> (verbosity);

            properties ["RuntimeIdentifiers"] = runtimeIdentifiers;
            var result = DotNet.AssertBuild(project_path, properties);

            AssertThatLinkerExecuted(result);
            var appPath       = Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", platform.ToFramework(), $"{project}.app");
            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");
        }
Esempio n. 7
0
        public void IsNotMacBuild(string runtimeIdentifier, bool isDeviceBuild)
        {
            if (isDeviceBuild)
            {
                Configuration.AssertDeviceAvailable();
            }

            var platform     = ApplePlatform.iOS;
            var project_path = GetProjectPath("MySingleView");

            Configuration.IgnoreIfIgnoredPlatform(platform);
            Clean(project_path);
            var properties = new Dictionary <string, string> (verbosity);

            properties ["RuntimeIdentifier"] = runtimeIdentifier;
            properties ["IsMacEnabled"]      = "false";
            var result = DotNet.AssertBuild(project_path, properties);

            AssertThatLinkerDidNotExecute(result);
            var appPath       = Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", "net6.0-ios", runtimeIdentifier, "MySingleView.app");
            var appExecutable = Path.Combine(appPath, Path.GetFileName(project_path));

            Assert.That(appPath, Does.Exist, "There is an .app");
            Assert.That(appExecutable, Does.Not.Empty, "There is no executable");
            Assert.That(Path.Combine(appPath, "Xamarin.iOS.dll"), Does.Exist, "Xamarin.iOS.dll is in the bundle");
        }
Esempio n. 8
0
        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);
            Configuration.CopyDotNetSupportingFiles(dotnet_bindings_dir);
            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 no resources in the assembly
            var ad = AssemblyDefinition.ReadAssembly(asm, new ReaderParameters {
                ReadingMode = ReadingMode.Deferred
            });

            Assert.That(ad.MainModule.Resources.Count(), Is.EqualTo(2), "2 resources");                // There are 2 embedded resources by default by the F# compiler.
        }
Esempio n. 9
0
        public void BuildBundledResources(string platform, string prefix)
        {
            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);
            Configuration.CopyDotNetSupportingFiles(dotnet_bindings_dir);
            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(2), "2 resources");
            // Sort the resources before we assert, since we don't care about the order, and sorted order makes the asserts simpler.
            var resources = ad.MainModule.Resources.OrderBy(v => v.Name).ToArray();

            Assert.That(resources [0].Name, Is.EqualTo($"__{prefix}_content_basn3p08.png"), $"__{prefix}_content_basn3p08.png");
            Assert.That(resources [1].Name, Is.EqualTo($"__{prefix}_content_xamvideotest.mp4"), $"__{prefix}_content_xamvideotest.mp4");
        }
Esempio n. 10
0
        public void BuildCoreCLR(ApplePlatform platform, string runtimeIdentifiers)
        {
            var project = "MySimpleApp";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            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.Exist, "createdump existence");
        }
Esempio n. 11
0
        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)}");
        }
Esempio n. 12
0
        public void BuildBindingsTest2(string platform)
        {
            if (!Configuration.include_mac)
            {
                Assert.Ignore("Ignore until Xamarin.Mac is re-enabled. Issue: https://github.com/xamarin/xamarin-macios/issues/9680");
            }
            var assemblyName        = "bindings-test2";
            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);
            Configuration.CopyDotNetSupportingFiles(dotnet_bindings_dir);
            var result = DotNet.AssertBuild(project_path, verbosity);
            var lines  = result.StandardOutput.ToString().Split('\n');
            // 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(1), "1 resource");
            Assert.That(ad.MainModule.Resources [0].Name, Is.EqualTo("libtest2.a"), "libtest2.a");
        }
Esempio n. 13
0
		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.");
		}
        public void BuildMyTVApp()
        {
            var project_path = GetProjectPath("MyTVApp");

            Clean(project_path);
            var result = DotNet.AssertBuild(project_path);

            AssertThatLinkerExecuted(result);
        }
Esempio n. 15
0
		// [TestCase ("watchOS")] // No watchOS Touch.Client project for .NET yet
		// [TestCase ("macOS")] // No macOS Touch.Client project for .NET yet
		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);
			Configuration.CopyDotNetSupportingFiles (dotnet_bindings_dir);
			Configuration.CopyDotNetSupportingFiles (dotnet_bindings_dir.Replace (assemblyName, "bindings-test"));
			Configuration.CopyDotNetSupportingFiles (dotnet_bindings_dir.Replace (assemblyName, "bindings-test2"));
			var cleanupSupportFiles = Configuration.CopyDotNetSupportingFiles (Path.Combine (Configuration.SourceRoot, "external", "Touch.Unit", "Touch.Client/dotnet"));
			try {
				var result = DotNet.AssertBuild (project_path, verbosity);
				var lines = BinLog.PrintToLines (result.BinLogPath);
				// Find the resulting binding assembly from the build log
				var assemblies = lines.
					Select (v => v.Trim ()).
					Where (v => {
						if (v.Length < 10)
							return false;
						if (v [0] != '/')
							return false;
						if (!v.EndsWith ($"{assemblyName}.dll", StringComparison.Ordinal))
							return false;
						if (!v.Contains ("/bin/", StringComparison.Ordinal))
							return false;
						if (!v.Contains ($"{assemblyName}.app", StringComparison.Ordinal))
							return false;
						return 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");
			} finally {
				foreach (var file in cleanupSupportFiles)
					File.Delete (file);
			}
		}
Esempio n. 16
0
		public void BuildMyTVApp ()
		{
			var platform = ApplePlatform.TVOS;
			var project_path = GetProjectPath ("MyTVApp");
			Configuration.IgnoreIfIgnoredPlatform (platform);
			Clean (project_path);
			var result = DotNet.AssertBuild (project_path, verbosity);
			AssertThatLinkerExecuted (result);
			AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-tvos", "tvos-x64", "MyTVApp.app"));
		}
Esempio n. 17
0
        public void BuildMyCocoaApp()
        {
            var platform     = ApplePlatform.MacOSX;
            var project_path = GetProjectPath("MyCocoaApp");

            Clean(project_path);
            var result = DotNet.AssertBuild(project_path, verbosity);

            AssertThatLinkerExecuted(result);
            AssertAppContents(platform, Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", "net5.0", "osx-x64", "MyCocoaApp.app"));
        }
Esempio n. 18
0
        public void BuildMySingleView()
        {
            var platform     = ApplePlatform.iOS;
            var project_path = GetProjectPath("MySingleView");

            Clean(project_path);
            var result = DotNet.AssertBuild(project_path, verbosity);

            AssertThatLinkerExecuted(result);
            AssertAppContents(platform, Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", "net5.0-ios", "ios-x64", "MySingleView.app"));
        }
Esempio n. 19
0
        public void BuildEmbeddedResourcesTest(string 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);
            CopyDotNetSupportingFiles(dotnet_bindings_dir);
            var result = DotNet.AssertBuild(project_path, verbosity);
            var lines  = result.StandardOutput.ToString().Split('\n');
            // Find the resulting binding assembly from the build log
            var assemblies = lines.
                             Select(v => v.Trim()).
                             Where(v => {
                if (v.Length < 10)
                {
                    return(false);
                }
                if (v [0] != '/')
                {
                    return(false);
                }
                if (!v.EndsWith($"{assemblyName}.dll", StringComparison.Ordinal))
                {
                    return(false);
                }
                if (!v.Contains("/bin/", StringComparison.Ordinal))
                {
                    return(false);
                }
                return(true);
            });

            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 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");
        }
Esempio n. 20
0
        public void BuildMyClassLibrary(string platform)
        {
            if (platform == "macOS" && !Configuration.include_mac)
            {
                Assert.Ignore("Ignore until Xamarin.Mac is re-enabled. Issue: https://github.com/xamarin/xamarin-macios/issues/9680");
            }
            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.");
        }
Esempio n. 21
0
        public void BuildMyTVApp(string runtimeIdentifier)
        {
            var platform     = ApplePlatform.TVOS;
            var project_path = GetProjectPath("MyTVApp", runtimeIdentifiers: runtimeIdentifier, platform: platform, out var appPath);

            Configuration.IgnoreIfIgnoredPlatform(platform);
            Clean(project_path);
            var properties = GetDefaultProperties(runtimeIdentifier);
            var result     = DotNet.AssertBuild(project_path, properties);

            AssertThatLinkerExecuted(result);
            AssertAppContents(platform, appPath);
        }
Esempio n. 22
0
        public void DoubleBuild(ApplePlatform platform, string runtimeIdentifiers)
        {
            var project = "AppWithResources";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            var projectPath = GetProjectPath(project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out _);

            Clean(projectPath);

            DotNet.AssertBuild(projectPath, GetDefaultProperties(runtimeIdentifiers));
            DotNet.AssertBuild(projectPath, GetDefaultProperties(runtimeIdentifiers));
        }
Esempio n. 23
0
        public void CreateAndBuildTemplate(TemplateInfo info)
        {
            if (!info.ValidateSuccessfulBuild)
            {
                return;
            }

            Configuration.IgnoreIfIgnoredPlatform(info.Platform);
            var tmpDir = Cache.CreateTemporaryDirectory();

            Configuration.CopyDotNetSupportingFiles(tmpDir);
            var outputDir = Path.Combine(tmpDir, info.Template);

            DotNet.AssertNew(outputDir, info.Template);
            var csproj   = Path.Combine(outputDir, info.Template + ".csproj");
            var rv       = DotNet.AssertBuild(csproj);
            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);

            Assert.That(warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");

            if (info.Execute)
            {
                var platform           = info.Platform;
                var runtimeIdentifiers = GetDefaultRuntimeIdentifier(platform);

                Assert.IsTrue(CanExecute(info.Platform, runtimeIdentifiers), "Must be executable to execute!");

                // First add some code to exit the template if it launches successfully.
                var mainFile              = Path.Combine(outputDir, "Main.cs");
                var mainContents          = File.ReadAllText(mainFile);
                var exitSampleWithSuccess = @"NSTimer.CreateScheduledTimer (1, (v) => {
	Console.WriteLine (Environment.GetEnvironmentVariable (""MAGIC_WORD""));
	Environment.Exit (0);
			});
			"            ;
                var modifiedMainContents  = mainContents.Replace("// This is the main entry point of the application.", exitSampleWithSuccess);
                Assert.AreNotEqual(modifiedMainContents, mainContents, "Failed to modify the main content");
                File.WriteAllText(mainFile, modifiedMainContents);

                // Build the sample
                rv = DotNet.AssertBuild(csproj);

                // There should still not be any warnings
                warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);
                Assert.That(warnings, Is.Empty, $"Build warnings (2):\n\t{string.Join ("\n\t", warnings)}");

                var appPath       = GetAppPath(csproj, platform, runtimeIdentifiers);
                var appExecutable = GetNativeExecutable(platform, appPath);
                ExecuteWithMagicWordAndAssert(appExecutable);
            }
        }
Esempio n. 24
0
        public void BuildMyCocoaApp()
        {
            if (!Configuration.include_mac)
            {
                Assert.Ignore("Ignore until Xamarin.Mac is re-enabled. Issue: https://github.com/xamarin/xamarin-macios/issues/9680");
            }
            var platform     = ApplePlatform.MacOSX;
            var project_path = GetProjectPath("MyCocoaApp");

            Clean(project_path);
            var result = DotNet.AssertBuild(project_path, verbosity);

            AssertThatLinkerExecuted(result);
            AssertAppContents(platform, Path.Combine(Path.GetDirectoryName(project_path), "bin", "Debug", "net5.0-macos", "osx-x64", "MyCocoaApp.app"));
        }
Esempio n. 25
0
        public void CreateAndBuildTemplate(string platform, string template)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);
            var tmpDir = Cache.CreateTemporaryDirectory();

            Configuration.CopyDotNetSupportingFiles(tmpDir);
            var outputDir = Path.Combine(tmpDir, template);

            DotNet.AssertNew(outputDir, template);
            var csproj   = Path.Combine(outputDir, template + ".csproj");
            var rv       = DotNet.AssertBuild(csproj);
            var warnings = BinLog.GetBuildLogWarnings(rv.BinLogPath).Select(v => v.Message);

            Assert.That(warnings, Is.Empty, $"Build warnings:\n\t{string.Join ("\n\t", warnings)}");
        }
Esempio n. 26
0
        public void NativeLink(ApplePlatform platform, string runtimeIdentifiers)
        {
            Configuration.IgnoreIfIgnoredPlatform(platform);

            var project_path = GenerateProject(platform, name: nameof(NativeLink), runtimeIdentifiers: runtimeIdentifiers, out var appPath);
            var properties   = new Dictionary <string, string> (verbosity);

            SetRuntimeIdentifiers(properties, runtimeIdentifiers);

            var mainContents = @"
class MainClass {
	static int Main ()
	{
		return 123;
	}
}
";
            var mainFile     = Path.Combine(Path.GetDirectoryName(project_path), "Main.cs");

            File.WriteAllText(mainFile, mainContents);

            // Build the first time
            var rv         = DotNet.AssertBuild(project_path, properties);
            var allTargets = BinLog.GetAllTargets(rv.BinLogPath);

            AssertTargetExecuted(allTargets, "_AOTCompile", "A");
            AssertTargetExecuted(allTargets, "_CompileNativeExecutable", "A");
            AssertTargetExecuted(allTargets, "_LinkNativeExecutable", "A");

            // Capture the current time
            var timestamp = DateTime.UtcNow;

            File.WriteAllText(mainFile, mainContents + "\n");

            // Build again
            rv = DotNet.AssertBuild(project_path, properties);

            // Check that some targets executed
            allTargets = BinLog.GetAllTargets(rv.BinLogPath);
            AssertTargetExecuted(allTargets, "_AOTCompile", "B");
            AssertTargetNotExecuted(allTargets, "_CompileNativeExecutable", "B");
            AssertTargetExecuted(allTargets, "_LinkNativeExecutable", "B");

            // Verify that the timestamp of the executable has been updated
            var executable = GetNativeExecutable(platform, appPath);

            Assert.That(File.GetLastWriteTimeUtc(executable), Is.GreaterThan(timestamp), "B: Executable modified");
        }
Esempio n. 27
0
        public void AppWithGenericLibraryReference(ApplePlatform platform, string runtimeIdentifiers)
        {
            var project = "AppWithGenericLibraryReference";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            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);
        }
Esempio n. 28
0
        public void BuildFSharpLibraryTest(string 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);
            CopyDotNetSupportingFiles(dotnet_bindings_dir);
            var result = DotNet.AssertBuild(project_path, verbosity);
            var lines  = result.StandardOutput.ToString().Split('\n');
            // Find the resulting binding assembly from the build log
            var assemblies = lines.
                             Select(v => v.Trim()).
                             Where(v => {
                if (v.Length < 10)
                {
                    return(false);
                }
                if (v [0] != '/')
                {
                    return(false);
                }
                if (!v.EndsWith($"{assemblyName}.dll", StringComparison.Ordinal))
                {
                    return(false);
                }
                if (!v.Contains("/bin/", StringComparison.Ordinal))
                {
                    return(false);
                }
                return(true);
            });

            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 no resources in the assembly
            var ad = AssemblyDefinition.ReadAssembly(asm, new ReaderParameters {
                ReadingMode = ReadingMode.Deferred
            });

            Assert.That(ad.MainModule.Resources.Count(), Is.EqualTo(2), "2 resources");                // There are 2 embedded resources by default by the F# compiler.
        }
Esempio n. 29
0
        public void SimpleAppWithOldReferences(ApplePlatform platform, string runtimeIdentifiers)
        {
            var project = "SimpleAppWithOldReferences";

            Configuration.IgnoreIfIgnoredPlatform(platform);

            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);
        }
Esempio n. 30
0
		public void BuildMySingleView ()
		{
			var platform = ApplePlatform.iOS;
			var project_path = GetProjectPath ("MySingleView");
			Configuration.IgnoreIfIgnoredPlatform (platform);
			Clean (project_path);
			var result = DotNet.AssertBuild (project_path, verbosity);
			AssertThatLinkerExecuted (result);
			var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-ios", "ios-x64", "MySingleView.app");
			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");
		}