public void BindDefaultInterfaceMethods(string classParser) { var proj = new XamarinAndroidBindingProject { IsRelease = true, }; // The sources for the .jar is in the jar itself. string classesJarBase64 = @" UEsDBBQACAgIANWk6UwAAAAAAAAAAAAAAAAJAAQATUVUQS1JTkYv/soAAAMAUEsHCAAAAAACAAAAAAA AAFBLAwQUAAgICADVpOlMAAAAAAAAAAAAAAAAFAAAAE1FVEEtSU5GL01BTklGRVNULk1G803My0xLLS 7RDUstKs7Mz7NSMNQz4OVyLkpNLElN0XWqBAlY6BnEG5obKmj4FyUm56QqOOcXFeQXJZYA1WvycvFyA QBQSwcIFGFrLUQAAABFAAAAUEsDBAoAAAgAAK2k6UwAAAAAAAAAAAAAAAAEAAAAY29tL1BLAwQKAAAI AACtpOlMAAAAAAAAAAAAAAAADAAAAGNvbS94YW1hcmluL1BLAwQKAAAIAACwpOlMAAAAAAAAAAAAAAA AEQAAAGNvbS94YW1hcmluL3Rlc3QvUEsDBBQACAgIAJmk6UwAAAAAAAAAAAAAAAAuAAAAY29tL3hhbW FyaW4vdGVzdC9EZWZhdWx0SW50ZXJmYWNlTWV0aG9kcy5jbGFzc3WOvU7DMBSFjxsnKeWnXUE8QLrgh ScAhBSJnwHE7qQ3JVUSC8dGFc/EwsrAA/BQiOuqLKnw8Pn4+LuWv38+vwCcY5biKMVUIKqMYWbzXEBe mgUJTG/qju58W5B91EXDTbIkd6HtX3jj0G+DzPL5E28v3q8FJg/G25Ku6zB1ekWV9o3LO0e20iXdkns 2i/5spV+1QFaaVq11q23dKUe9U//4ArMwoRrdLdV9saLSJQICI4QVc4ogmTGfThBugFH0zuR/MpNNE7 x015NDL3C868VDL2XuYbL1joMTjI+BNpYC+/xcaA820uEvUEsHCIw1aijpAAAAhQEAAFBLAwQUAAgIC ACYpOlMAAAAAAAAAAAAAAAAHAAAAERlZmF1bHRJbnRlcmZhY2VNZXRob2RzLmphdmF1zLEOwiAQBuCd p7hRl0Zd2YyLgw9xwlGJFCocTWPTdxdSHarxxv///utR3bElUKFrRuwwWt8wJZZC9PnqrALrmaJBRXA ig9nx+RNciG9BJzEJKKeXtnowIcBmCxNE4hw97CTMP6glPmJcuf1f91y5w7cbgtWQ3rCOBnSZymJhNX nkPJYnUsziBVBLBwgzfz2miQAAAPUAAABQSwECFAAUAAgICADVpOlMAAAAAAIAAAAAAAAACQAEAAAAA AAAAAAAAAAAAAAATUVUQS1JTkYv/soAAFBLAQIUABQACAgIANWk6UwUYWstRAAAAEUAAAAUAAAAAAAA AAAAAAAAAD0AAABNRVRBLUlORi9NQU5JRkVTVC5NRlBLAQIKAAoAAAgAAK2k6UwAAAAAAAAAAAAAAAA EAAAAAAAAAAAAAAAAAMMAAABjb20vUEsBAgoACgAACAAAraTpTAAAAAAAAAAAAAAAAAwAAAAAAAAAAA AAAAAA5QAAAGNvbS94YW1hcmluL1BLAQIKAAoAAAgAALCk6UwAAAAAAAAAAAAAAAARAAAAAAAAAAAAA AAAAA8BAABjb20veGFtYXJpbi90ZXN0L1BLAQIUABQACAgIAJmk6UyMNWoo6QAAAIUBAAAuAAAAAAAA AAAAAAAAAD4BAABjb20veGFtYXJpbi90ZXN0L0RlZmF1bHRJbnRlcmZhY2VNZXRob2RzLmNsYXNzUEs BAhQAFAAICAgAmKTpTDN/PaaJAAAA9QAAABwAAAAAAAAAAAAAAAAAgwIAAERlZmF1bHRJbnRlcmZhY2 VNZXRob2RzLmphdmFQSwUGAAAAAAcABwDOAQAAVgMAAAAA "; proj.Jars.Add(new AndroidItem.EmbeddedJar("dim.jar") { BinaryContent = () => Convert.FromBase64String(classesJarBase64) }); proj.AndroidClassParser = classParser; proj.SetProperty("_EnableInterfaceMembers", "True"); proj.SetProperty("LangVersion", "preview"); using (var b = CreateDllBuilder()) { proj.NuGetRestore(b.ProjectDirectory); Assert.IsTrue(b.Build(proj), "Build should have succeeded."); string asmpath = Path.Combine(Root, b.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll"); Assert.IsTrue(File.Exists(asmpath), "assembly does not exist"); var cs = b.Output.GetIntermediaryAsText(Path.Combine("generated", "src", "Com.Xamarin.Test.IDefaultInterfaceMethods.cs")); Assert.IsTrue(cs.Contains("int Quux ();"), "Quux not generated."); Assert.IsTrue(cs.Contains("virtual unsafe int Foo ()"), "Foo not generated."); Assert.IsTrue(cs.Contains("virtual unsafe int Bar {"), "Bar not generated."); Assert.IsTrue(cs.Contains("set {"), "(Baz) setter not generated."); } }
public void JavaDocJar() { var binding = new XamarinAndroidBindingProject() { AndroidClassParser = "class-parse", }; binding.SetProperty("DocumentationFile", "UnnamedProject.xml"); using (var bindingBuilder = CreateDllBuilder()) { binding.Jars.Add(new AndroidItem.EmbeddedJar("javasourcejartest.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestJar, }); binding.OtherBuildItems.Add(new BuildItem("JavaDocJar", "javasourcejartest-javadoc.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestJavadocJar, }); Assert.IsTrue(bindingBuilder.Build(binding), "binding build should have succeeded"); var cs_file = bindingBuilder.Output.GetIntermediaryPath( Path.Combine("generated", "src", "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest.cs")); FileAssert.Exists(cs_file); StringAssert.Contains("Greet (string name, global::Java.Util.Date date)", File.ReadAllText(cs_file)); } }
public void JavaSourceJar() { var binding = new XamarinAndroidBindingProject() { AndroidClassParser = "class-parse", }; binding.SetProperty("DocumentationFile", "UnnamedProject.xml"); using (var bindingBuilder = CreateDllBuilder()) { binding.Jars.Add(new AndroidItem.EmbeddedJar("javasourcejartest.jar") { BinaryContent = () => Convert.FromBase64String(InlineData.JavaClassesJarBase64) }); binding.OtherBuildItems.Add(new BuildItem("JavaSourceJar", "javasourcejartest-sources.jar") { BinaryContent = () => Convert.FromBase64String(InlineData.JavaSourcesJarBase64) }); Assert.IsTrue(bindingBuilder.Build(binding), "binding build should have succeeded"); var jdkVersion = GetJdkVersion(); if (jdkVersion > new Version(9, 0)) { Assert.Ignore("JDK 11 and @(JavaSourceJar) don't currently mix."); return; } string xml = bindingBuilder.Output.GetIntermediaryAsText("docs/Com.Xamarin.Android.Test.Msbuildtest/JavaSourceJarTest.xml"); Assert.IsTrue(xml.Contains("<param name=\"name\"> - name to display.</param>"), "missing doc"); } }
public void BindingCheckHiddenFiles([Values(true, false)] bool useShortFileNames) { var binding = new XamarinAndroidBindingProject() { UseLatestPlatformSdk = true, IsRelease = true, }; binding.AndroidClassParser = "class-parse"; binding.Jars.Add(new AndroidItem.LibraryProjectZip("Jars\\mylibrary.aar") { WebContentFileNameFromAzure = "mylibrary.aar" }); binding.Jars.Add(new AndroidItem.EmbeddedJar("Jars\\svg-android.jar") { WebContentFileNameFromAzure = "javaBindingIssue.jar" }); var path = Path.Combine("temp", TestContext.CurrentContext.Test.Name); binding.SetProperty(binding.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames); using (var bindingBuilder = CreateDllBuilder(Path.Combine(path, "Binding"))) { bindingBuilder.Verbosity = Microsoft.Build.Framework.LoggerVerbosity.Diagnostic; Assert.IsTrue(bindingBuilder.Build(binding), "binding build should have succeeded"); var proj = new XamarinAndroidApplicationProject(); proj.OtherBuildItems.Add(new BuildItem("ProjectReference", "..\\Binding\\UnnamedProject.csproj")); proj.SetProperty(proj.ActiveConfigurationProperties, "UseShortFileNames", useShortFileNames); using (var b = CreateApkBuilder(Path.Combine(path, "App"))) { Assert.IsTrue(b.Build(proj), "Build should have succeeded."); var assemblyMap = b.Output.GetIntermediaryPath(Path.Combine("lp", "map.cache")); if (useShortFileNames) { Assert.IsTrue(File.Exists(assemblyMap), $"{assemblyMap} should exist."); } else { Assert.IsFalse(File.Exists(assemblyMap), $"{assemblyMap} should not exist."); } var assemblyIdentityMap = new List <string> (); if (useShortFileNames) { foreach (var s in File.ReadLines(assemblyMap)) { assemblyIdentityMap.Add(s); } } var assmeblyIdentity = useShortFileNames ? assemblyIdentityMap.IndexOf("UnnamedProject").ToString() : "UnnamedProject"; var libaryImportsFolder = useShortFileNames ? "lp" : "__library_projects__"; var jlibs = useShortFileNames ? "jl" : "library_project_imports"; var dsStorePath = Path.Combine(Root, b.ProjectDirectory, proj.IntermediateOutputPath, libaryImportsFolder, assmeblyIdentity, jlibs); Assert.IsTrue(Directory.Exists(dsStorePath), "{0} should exist.", dsStorePath); Assert.IsFalse(File.Exists(Path.Combine(dsStorePath, ".DS_Store")), "{0} should NOT exist.", Path.Combine(dsStorePath, ".DS_Store")); var _macOSStorePath = Path.Combine(dsStorePath, "_MACOSX"); Assert.IsFalse(Directory.Exists(_macOSStorePath), "{0} should NOT exist.", _macOSStorePath); var svgJar = Path.Combine(dsStorePath, "svg-android.jar"); Assert.IsTrue(File.Exists(svgJar), $"{svgJar} should exist."); } } }
public void NullableReferenceTypes(string classParser) { var proj = new XamarinAndroidBindingProject { AndroidClassParser = classParser, Jars = { new AndroidItem.EmbeddedJar("foo.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestJar, } } }; proj.SetProperty("Nullable", "enable"); using (var b = CreateDllBuilder()) { Assert.IsTrue(b.Build(proj), "Build should have succeeded."); var cs_file = b.Output.GetIntermediaryPath( Path.Combine("generated", "src", "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest.cs")); FileAssert.Exists(cs_file); StringAssert.Contains("string? Greet", File.ReadAllText(cs_file)); } }
public void JavaSourceJar() { var binding = new XamarinAndroidBindingProject() { AndroidClassParser = "class-parse", }; binding.SetProperty("DocumentationFile", "UnnamedProject.xml"); using (var bindingBuilder = CreateDllBuilder()) { binding.Jars.Add(new AndroidItem.EmbeddedJar("javasourcejartest.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestJar, }); binding.OtherBuildItems.Add(new BuildItem("JavaSourceJar", "javasourcejartest-sources.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar, }); Assert.IsTrue(bindingBuilder.Build(binding), "binding build should have succeeded"); var path = Path.Combine(Root, bindingBuilder.ProjectDirectory, binding.OutputPath, "UnnamedProject.xml"); var xml = File.ReadAllText(path); Assert.IsTrue(xml.Contains("<param name=\"name\">name to display.</param>"), "param `name` documentation not imported!"); } }