コード例 #1
0
        static void AssertFileInBundle(string tmpDir, BindingProjectType type, string path, bool assertIsSymLink = false)
        {
            string bundlePath = Path.Combine(tmpDir, $"bin/Debug/{(type == BindingProjectType.Modern ? "UnifiedExample" : "XM45Example")}.app/Contents/{path}");

            Assert.True(File.Exists(bundlePath), $"{path} not in bundle as expected.");
            if (assertIsSymLink)
            {
                Assert.True(File.GetAttributes(bundlePath).HasFlag(FileAttributes.ReparsePoint));
            }
        }
コード例 #2
0
        public void ShouldBuildWithoutErrors_AndLinkCorrectFramework(BindingProjectType type, bool noEmbedding = false)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = GenerateTestProject(type, tmpDir);
                if (noEmbedding)
                {
                    SetNoEmbedding(projects.Item1);
                }

                var logs = SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference: false, setupDefaultNativeReference: noEmbedding);

                Assert.True(logs.Item1.Contains("csc"), "Bindings project must use csc:\n" + logs.Item1);

                var bgenInvocation = logs.Item1.SplitLines().First(x => x.Contains("bin/bgen"));
                var bgenParts      = bgenInvocation.Split(new char[] { ' ' });
                var mscorlib       = bgenParts.First(x => x.Contains("mscorlib.dll"));
                var system         = bgenParts.First(x => x.Contains("System.dll"));

                switch (type)
                {
                case BindingProjectType.Modern:
                case BindingProjectType.ModernNoTag:
                    Assert.True(mscorlib.EndsWith("lib/mono/Xamarin.Mac/mscorlib.dll", StringComparison.Ordinal), "mscorlib not found in expected Modern location: " + mscorlib);
                    Assert.True(system.EndsWith("lib/mono/Xamarin.Mac/System.dll", StringComparison.Ordinal), "system not found in expected Modern location: " + system);
                    break;

                case BindingProjectType.Full:
                case BindingProjectType.FullTVF:
                case BindingProjectType.FullXamMacTag:
                    Assert.True(mscorlib.EndsWith("lib/mono/4.5/mscorlib.dll", StringComparison.Ordinal), "mscorlib not found in expected Full location: " + mscorlib);
                    Assert.True(system.EndsWith("lib/mono/4.5/System.dll", StringComparison.Ordinal), "system not found in expected Full location: " + system);
                    break;

                default:
                    throw new NotImplementedException();
                }

                Assert.False(logs.Item1.Contains("CS1685"), "Binding should not contains CS1685 multiple definition warning:\n" + logs.Item1);

                Assert.False(logs.Item1.Contains("MSB9004"), "Binding should not contains MSB9004 warning:\n" + logs.Item1);

                string bindingName = RemoveCSProj(projects.Item1.ProjectName);
                string appName     = RemoveCSProj(projects.Item2.ProjectName);
                string libPath     = Path.Combine(tmpDir, $"bin/Debug/{appName}.app/Contents/MonoBundle/{bindingName}.dll");

                Assert.True(File.Exists(libPath));
                string results      = TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/monop", new [] { "--refs", "-r:" + libPath }, "monop");
                string mscorlibLine = results.Split(new char[] { '\n' }).First(x => x.Contains("mscorlib"));

                string expectedVersion = GetExpectedBCLVersion(type);
                Assert.True(mscorlibLine.Contains(expectedVersion), $"{mscorlibLine} did not contain expected version {expectedVersion}");
            });
        }
コード例 #3
0
        public void DoesNotSupportLinkWith(BindingProjectType type)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = BindingProjectTests.GenerateTestProject(type, tmpDir);
                BindingProjectTests.SetNoEmbedding(projects.Item1);

                projects.Item1.LinkWithName = "SimpleClassDylib.dylib";

                string libBuildLog = BindingProjectTests.SetupAndBuildBindingProject(projects.Item1, false, shouldFail: true);
                Assert.True(libBuildLog.Contains("Can't create a binding resource package unless there are native references in the binding project."), $"Did not fail as expected: {TI.PrintRedirectIfLong (libBuildLog)}");
            });
        }
コード例 #4
0
        public void LibrariesEmbeddedProperly(BindingProjectType type, bool useProjectReference)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = BindingProjectTests.GenerateTestProject(type, tmpDir);
                BindingProjectTests.SetNoEmbedding(projects.Item1);

                string appBuildLog = BindingProjectTests.SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference, setupDefaultNativeReference: true).Item2;

                AssertNoResourceWithName(tmpDir, projects.Item1.ProjectName, "SimpleClassDylib.dylib");
                AssertFileInBundle(tmpDir, type, "MonoBundle/SimpleClassDylib.dylib");
            });
        }
コード例 #5
0
        public void DoesNotSupportLinkWith(BindingProjectType type)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = BindingProjectTests.GenerateTestProject(type, tmpDir);
                BindingProjectTests.SetNoEmbedding(projects.Item1);

                projects.Item1.LinkWithName = "SimpleClassDylib.dylib";

                var buildResult = BindingProjectTests.SetupAndBuildBindingProject(projects.Item1, false, shouldFail: true);
                buildResult.Messages.AssertError(7068, "Can't create a binding resource package unless there are native references in the binding project.\n        ");
            });
        }
コード例 #6
0
        public void ShouldRemovePackagedLibrary_OnceInBundle(BindingProjectType type)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = GenerateTestProject(type, tmpDir);
                SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference: false, setupDefaultNativeReference: false);

                string bindingName = RemoveCSProj(projects.Item1.ProjectName);
                string appName     = RemoveCSProj(projects.Item2.ProjectName);

                string libPath = Path.Combine(tmpDir, $"bin/Debug/{appName}.app/Contents/MonoBundle/{bindingName}.dll");
                Assert.True(File.Exists(libPath), $"Did not find expected library: {libPath}");
                string monoDisResults = TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/monodis", new [] { "--presources", libPath }, "monodis");
                Assert.IsFalse(monoDisResults.Contains("SimpleClassDylib.dylib"));
            });
        }
コード例 #7
0
        public void FrameworksEmbeddedProperly(BindingProjectType type, bool useProjectReference)
        {
            MMPTests.RunMMPTest(tmpDir => {
                string frameworkPath = FrameworkBuilder.CreateThinFramework(tmpDir);

                var projects = BindingProjectTests.GenerateTestProject(type, tmpDir);
                BindingProjectTests.SetNoEmbedding(projects.Item1);
                projects.Item1.ItemGroup = NativeReferenceTests.CreateSingleNativeRef(frameworkPath, "Framework");

                string appBuildLog = BindingProjectTests.SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference, false).Item2;

                AssertNoResourceWithName(tmpDir, projects.Item1.ProjectName, "Foo");
                AssertFileInBundle(tmpDir, type, "Frameworks/Foo.framework/Foo", assertIsSymLink: true);
            });
        }
コード例 #8
0
        static string GetExpectedBCLVersion(BindingProjectType type)
        {
            switch (type)
            {
            case BindingProjectType.Modern:
            case BindingProjectType.ModernNoTag:
                return("2.0.5.0");

            case BindingProjectType.Full:
            case BindingProjectType.FullTVF:
            case BindingProjectType.FullXamMacTag:
                return("4.0.0.0");

            default:
                throw new NotImplementedException();
            }
        }
コード例 #9
0
        internal static Tuple <TI.UnifiedTestConfig, TI.UnifiedTestConfig> GenerateTestProject(BindingProjectType type, string tmpDir)
        {
            TI.UnifiedTestConfig binding = new TI.UnifiedTestConfig(tmpDir);
            TI.UnifiedTestConfig project = new TI.UnifiedTestConfig(tmpDir);
            switch (type)
            {
            case BindingProjectType.Modern:
                binding.ProjectName = "MobileBinding.csproj";
                project.XM45        = false;
                break;

            case BindingProjectType.ModernNoTag:
                binding.ProjectName = "BindingProjectWithNoTag.csproj";
                project.XM45        = false;
                break;

            case BindingProjectType.Full:
                binding.ProjectName = "XM45Binding.csproj";
                binding.CustomProjectReplacement = new Tuple <string, string> (
                    "<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>",
                    "<UseXamMacFullFramework>true</UseXamMacFullFramework><TargetFrameworkVersion>4.5</TargetFrameworkVersion>");
                project.XM45 = true;
                break;

            case BindingProjectType.FullTVF:
                binding.ProjectName = "XM45Binding.csproj";
                project.XM45        = true;
                break;

            case BindingProjectType.FullXamMacTag:
                binding.ProjectName = "XM45Binding.csproj";
                binding.CustomProjectReplacement = new Tuple <string, string> (
                    "<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>",
                    "<UseXamMacFullFramework>true</UseXamMacFullFramework>");
                project.XM45 = true;
                break;

            default:
                throw new NotImplementedException();
            }
            return(new Tuple <TI.UnifiedTestConfig, TI.UnifiedTestConfig> (binding, project));
        }
コード例 #10
0
        public void ShouldBuildWithoutErrors_AndLinkCorrectFramework(BindingProjectType type, bool noEmbedding = false)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = GenerateTestProject(type, tmpDir);
                if (noEmbedding)
                {
                    SetNoEmbedding(projects.Item1);
                }

                var logs = SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference: false, setupDefaultNativeReference: noEmbedding);

                Assert.True(logs.BindingBuildResult.BuildOutput.Contains("csc"), "Bindings project must use csc:\n" + logs.Item1);

                var bgenInvocation = logs.BindingBuildResult.BuildOutputLines.First(x => x.Contains("bin/bgen"));
                Assert.IsTrue(StringUtils.TryParseArguments(bgenInvocation, out var bgenArguments, out var _), "Parse bgen arguments");
                // unfurl any response files
                var bgenParts     = bgenArguments.ToList();
                var responseFiles = bgenParts.Where(v => v [0] == '@').ToArray();
                bgenParts.RemoveAll(v => v [0] == '@');
                foreach (var rsp in responseFiles)
                {
                    Assert.IsTrue(StringUtils.TryParseArguments(File.ReadAllText(rsp.Substring(1)).Replace('\n', ' '), out var args, out var _), "Parse response file");
                    bgenParts.AddRange(args);
                }
                var mscorlib = bgenParts.First(x => x.Contains("mscorlib.dll"));
                var system   = bgenParts.First(x => x.Contains("System.dll"));

                switch (type)
                {
                case BindingProjectType.Modern:
                case BindingProjectType.ModernNoTag:
                    Assert.That(mscorlib, Does.EndWith("lib/mono/Xamarin.Mac/mscorlib.dll"), "mscorlib not found in expected Modern location: " + mscorlib);
                    Assert.That(system, Does.EndWith("lib/mono/Xamarin.Mac/System.dll"), "system not found in expected Modern location: " + system);
                    break;

                case BindingProjectType.Full:
                case BindingProjectType.FullTVF:
                case BindingProjectType.FullXamMacTag:
                    Assert.That(mscorlib, Does.EndWith("lib/mono/4.5/mscorlib.dll"), "mscorlib not found in expected Full location: " + mscorlib);
                    Assert.That(system, Does.EndWith("lib/mono/4.5/System.dll"), "system not found in expected Full location: " + system);
                    break;

                default:
                    throw new NotImplementedException();
                }

                Assert.False(logs.BindingBuildResult.BuildOutput.Contains("CS1685"), "Binding should not contains CS1685 multiple definition warning.");

                Assert.False(logs.BindingBuildResult.BuildOutput.Contains("MSB9004"), "Binding should not contains MSB9004 warning");

                string bindingName = RemoveCSProj(projects.Item1.ProjectName);
                string appName     = RemoveCSProj(projects.Item2.ProjectName);
                string libPath     = Path.Combine(tmpDir, $"bin/Debug/{appName}.app/Contents/MonoBundle/{bindingName}.dll");

                Assert.True(File.Exists(libPath));
                string results      = TI.RunAndAssert("/Library/Frameworks/Mono.framework/Commands/monop", new [] { "--refs", "-r:" + libPath }, "monop");
                string mscorlibLine = results.Split(new char[] { '\n' }).First(x => x.Contains("mscorlib"));

                string expectedVersion = GetExpectedBCLVersion(type);
                Assert.True(mscorlibLine.Contains(expectedVersion), $"{mscorlibLine} did not contain expected version {expectedVersion}");
            });
        }