Beispiel #1
0
        public void MultipleDependencyChain(bool useProjectReference)
        {
            // App can depend on Lib that depends on binding lib with native reference and everything gets packaged in correctly
            MMPTests.RunMMPTest(tmpDir => {
                TI.UnifiedTestConfig binding = new TI.UnifiedTestConfig(tmpDir)
                {
                    ProjectName = "MobileBinding.csproj"
                };
                binding.ItemGroup           += NativeReferenceTests.CreateSingleNativeRef(NativeReferenceTests.SimpleDylibPath, "Dynamic");
                binding.APIDefinitionConfig += @"[BaseType (typeof (NSObject))]
  interface SimpleClass {
    [Export (""doIt"")]
    int DoIt ();
  }";
                BindingProjectTests.SetNoEmbedding(binding);

                TI.GenerateBindingLibraryProject(binding);
                TI.BuildProject(Path.Combine(tmpDir, "MobileBinding.csproj"), true);


                TI.UnifiedTestConfig library = new TI.UnifiedTestConfig(tmpDir)
                {
                    ProjectName = "UnifiedLibrary"
                };
                library.TestCode = "public class MyClass { public static void Go () { var c = new ExampleBinding.SimpleClass (); c.DoIt (); } }";

                if (useProjectReference)
                {
                    library.References = $@"<ProjectReference Include=""MobileBinding.csproj"" />";
                }
                else
                {
                    library.References = $@"<Reference Include=""MobileBinding""><HintPath>{Path.Combine (tmpDir, "bin/Debug", "MobileBinding.dll")}</HintPath></Reference>";
                }

                TI.GenerateUnifiedLibraryProject(library);
                TI.BuildProject(Path.Combine(tmpDir, "UnifiedLibrary.csproj"), true);

                TI.UnifiedTestConfig project = new TI.UnifiedTestConfig(tmpDir)
                {
                    ProjectName = "UnifiedExample.csproj"
                };
                project.TestCode = "MyClass.Go ();";

                if (useProjectReference)
                {
                    project.References = $@"<ProjectReference Include=""UnifiedLibrary.csproj"" />";
                }
                else
                {
                    project.References = $@"<Reference Include=""UnifiedLibrary""><HintPath>{Path.Combine (tmpDir, "bin/Debug", "UnifiedLibrary.dll")}</HintPath></Reference>";
                }

                TI.GenerateUnifiedExecutableProject(project);
                TI.BuildProject(Path.Combine(tmpDir, "UnifiedExample.csproj"), true);
            });
        }
        internal static string SetupAndBuildBindingProject(TI.UnifiedTestConfig binding, bool setupDefaultNativeReference, bool shouldFail = false)
        {
            if (setupDefaultNativeReference)
            {
                binding.ItemGroup += NativeReferenceTests.CreateSingleNativeRef(Path.GetFullPath(NativeReferenceTests.SimpleDylibPath), "Dynamic");
            }

            binding.StructsAndEnumsConfig = "public class UnifiedWithDepNativeRefLibTestClass {}";

            string projectPath = TI.GenerateBindingLibraryProject(binding);

            return(TI.BuildProject(projectPath, shouldFail: shouldFail));
        }
Beispiel #3
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);
            });
        }
Beispiel #4
0
        public void ShouldNotUnnecessarilyRebuildBindingProject(bool framework)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = BindingProjectTests.GenerateTestProject(BindingProjectType.Modern, tmpDir);
                BindingProjectTests.SetNoEmbedding(projects.Item1);

                string projectPath               = Path.Combine(tmpDir, "MobileBinding.csproj");
                string bindingFilePath           = Path.Combine(tmpDir, "ApiDefinition.cs");
                const string CreatePackageString = "Creating binding resource package";

                // First build should create a package
                string frameworkPath = null;

                if (framework)
                {
                    frameworkPath             = FrameworkBuilder.CreateThinFramework(tmpDir);
                    projects.Item1.ItemGroup += NativeReferenceTests.CreateSingleNativeRef(Path.GetFullPath(frameworkPath), "Framework");
                }
                string libBuildLog = BindingProjectTests.SetupAndBuildBindingProject(projects.Item1, setupDefaultNativeReference: !framework);

                Assert.True(libBuildLog.Contains(CreatePackageString), $"First build did not create package? {TI.PrintRedirectIfLong (libBuildLog)}");

                // No change build should not
                libBuildLog = TI.BuildProject(projectPath, true);
                Assert.False(libBuildLog.Contains(CreatePackageString), $"Rebuild build did create package? {TI.PrintRedirectIfLong (libBuildLog)}");

                // Touching the binding project should
                Touch(projectPath);
                libBuildLog = TI.BuildProject(projectPath, true);
                Assert.True(libBuildLog.Contains(CreatePackageString), $"Binding Project build did not create package? {TI.PrintRedirectIfLong (libBuildLog)}");

                // Touching the binding file should
                Touch(bindingFilePath);
                libBuildLog = TI.BuildProject(projectPath, true);
                Assert.True(libBuildLog.Contains(CreatePackageString), $"Binding File build did not create package? {TI.PrintRedirectIfLong (libBuildLog)}");

                // No change build should not
                libBuildLog = TI.BuildProject(projectPath, true);
                Assert.False(libBuildLog.Contains(CreatePackageString), $"Second Rebuild build did create package? {TI.PrintRedirectIfLong (libBuildLog)}");

                // Touching native library should
                Touch(framework ? frameworkPath + "/Foo" : NativeReferenceTests.SimpleDylibPath);
                libBuildLog = TI.BuildProject(projectPath, true);
                Assert.True(libBuildLog.Contains(CreatePackageString), $"Native Library build did not create package? {TI.PrintRedirectIfLong (libBuildLog)}");
            });
        }
        static Tuple <string, string> BuildLinkedTestProjects(TI.UnifiedTestConfig binding, TI.UnifiedTestConfig project, string tmpDir)
        {
            binding.ItemGroup             = NativeReferenceTests.CreateSingleNativeRef(Path.GetFullPath(NativeReferenceTests.SimpleDylibPath), "Dynamic");
            binding.StructsAndEnumsConfig = "public class UnifiedWithDepNativeRefLibTestClass {}";

            string projectPath     = TI.GenerateBindingLibraryProject(binding);
            string bindingBuildLog = TI.BuildProject(projectPath, true);

            string bindingName = RemoveCSProj(binding.ProjectName);

            project.References = string.Format(@"<Reference Include=""{0}""><HintPath>{1}</HintPath></Reference>", bindingName, Path.Combine(tmpDir, "bin/Debug", bindingName + ".dll"));
            project.TestCode   = "System.Console.WriteLine (typeof (ExampleBinding.UnifiedWithDepNativeRefLibTestClass));";

            string appBuildLog = TI.TestUnifiedExecutable(project).BuildOutput;

            return(new Tuple <string, string> (bindingBuildLog, appBuildLog));
        }
Beispiel #6
0
        public void MultipleNativeReferences(bool useProjectReference)
        {
            MMPTests.RunMMPTest(tmpDir => {
                // This is a bit of a hack, you can't just rename dylibs like this
                string secondNativeLibPath = Path.Combine(tmpDir, "SimpleClassDylib2.dylib");
                File.Copy(NativeReferenceTests.SimpleDylibPath, secondNativeLibPath);

                var projects = BindingProjectTests.GenerateTestProject(BindingProjectType.Modern, tmpDir);
                BindingProjectTests.SetNoEmbedding(projects.Item1);
                projects.Item1.ItemGroup += NativeReferenceTests.CreateSingleNativeRef(secondNativeLibPath, "Dynamic");

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

                // manifest and 2 dylibs
                Assert.AreEqual(3, Directory.GetFiles(Path.Combine(tmpDir, "bin/Debug/MobileBinding.resources")).Length);

                // 2 dylibs + libMonoPosixHelper.dylib
                Assert.AreEqual(3, Directory.GetFiles(Path.Combine(tmpDir, "bin/Debug/UnifiedExample.app/Contents/MonoBundle")).Where(x => x.EndsWith(".dylib")).Count());
            });
        }
Beispiel #7
0
        public void ShouldNotUnnecessarilyRebuildFinalProject(bool useProjectReference, bool framework)
        {
            MMPTests.RunMMPTest(tmpDir => {
                var projects = BindingProjectTests.GenerateTestProject(BindingProjectType.Modern, tmpDir);
                BindingProjectTests.SetNoEmbedding(projects.Item1);

                const string BuildString = "xcrun -sdk macosx clang";

                string frameworkPath = null;
                if (framework)
                {
                    frameworkPath             = FrameworkBuilder.CreateThinFramework(tmpDir);
                    projects.Item1.ItemGroup += NativeReferenceTests.CreateSingleNativeRef(Path.GetFullPath(frameworkPath), "Framework");
                }
                string appBuildLog = BindingProjectTests.SetupAndBuildLinkedTestProjects(projects.Item1, projects.Item2, tmpDir, useProjectReference, setupDefaultNativeReference: !framework).Item2;

                Assert.True(appBuildLog.Contains(BuildString), $"First build did not run mmp? {TI.PrintRedirectIfLong (appBuildLog)}");

                string projectPath = Path.Combine(tmpDir, "UnifiedExample.csproj");
                string mainPath    = Path.Combine(tmpDir, "Main.cs");

                // No change build should not
                string buildLog = TI.BuildProject(projectPath, true);
                Assert.False(buildLog.Contains(BuildString), $"Rebuild ran mmp again? {TI.PrintRedirectIfLong (buildLog)}");

                if (useProjectReference)
                {
                    // Touching the binding definition should
                    Touch(Path.Combine(tmpDir, "ApiDefinition.cs"));
                    buildLog = TI.BuildProject(projectPath, true);
                    Assert.True(buildLog.Contains(BuildString), $"Binding definition build did not run mmp again? {TI.PrintRedirectIfLong (buildLog)}");
                }
                else
                {
                    // Touching the binding assembly should
                    Touch(Path.Combine(tmpDir, "bin/Debug/MobileBinding.dll"));
                    buildLog = TI.BuildProject(projectPath, true);
                    Assert.True(buildLog.Contains(BuildString), $"Binding build did not run mmp again? {TI.PrintRedirectIfLong (buildLog)}");
                }
            });
        }