public void MX2107(Profile profile) { using (var bundler = new BundlerTool()) { var code = @" using System; using Foundation; using ObjCRuntime; class T { static void Main () { TypeConverter.ToManaged (""@""); Runtime.ConnectMethod (typeof (NSObject), typeof (T).GetMethod (""Main""), new Selector (""sel"")); Runtime.ConnectMethod (typeof (NSObject), typeof (T).GetMethod (""Main""), new ExportAttribute (""sel"")); Runtime.ConnectMethod (typeof (T).GetMethod (""Main""), new Selector (""sel"")); Runtime.RegisterAssembly (null); BlockLiteral bl = default (BlockLiteral); Action action = null; bl.SetupBlock (action, action); bl.SetupBlockUnsafe (action, action); } } "; bundler.Profile = profile; bundler.CreateTemporaryCacheDirectory(); bundler.CreateTemporaryApp(profile, code: code, extraArg: "/debug:full"); bundler.Linker = LinkerOption.LinkSdk; bundler.Registrar = RegistrarOption.Static; bundler.Optimize = new string [] { "remove-dynamic-registrar" }; bundler.AssertExecute(); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.TypeConverter.ToManaged (System.String)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.ConnectMethod (System.Type, System.Reflection.MethodInfo, ObjCRuntime.Selector)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.ConnectMethod (System.Type, System.Reflection.MethodInfo, Foundation.ExportAttribute)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.ConnectMethod (System.Reflection.MethodInfo, ObjCRuntime.Selector)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.RegisterAssembly (System.Reflection.Assembly)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.BlockLiteral.SetupBlock (System.Delegate, System.Delegate)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.BlockLiteral.SetupBlockUnsafe (System.Delegate, System.Delegate)'."); bundler.AssertWarningCount(7); // try again with link all, now the warnings about SetupBlock[Unsafe] should be gone bundler.Linker = LinkerOption.LinkAll; bundler.AssertExecute(); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.TypeConverter.ToManaged (System.String)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.ConnectMethod (System.Type, System.Reflection.MethodInfo, ObjCRuntime.Selector)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.ConnectMethod (System.Type, System.Reflection.MethodInfo, Foundation.ExportAttribute)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.ConnectMethod (System.Reflection.MethodInfo, ObjCRuntime.Selector)'."); bundler.AssertWarning(2107, "It's not safe to remove the dynamic registrar, because testApp references 'ObjCRuntime.Runtime.RegisterAssembly (System.Reflection.Assembly)'."); bundler.AssertWarningCount(5); } }
public void RegisterProtocolOptimization(Profile profile) { using (var bundler = new BundlerTool()) { bundler.Profile = profile; bundler.CreateTemporaryCacheDirectory(); bundler.CreateTemporaryApp(profile); bundler.Linker = LinkerOption.LinkAll; bundler.Registrar = RegistrarOption.Static; bundler.Optimize = new string [] { "register-protocols" }; bundler.AssertExecute(); bundler.AssertWarningCount(0); AssemblyDefinition ad = AssemblyDefinition.ReadAssembly(bundler.GetPlatformAssemblyInApp()); var failures = new List <string> (); foreach (var attrib in ad.MainModule.GetCustomAttributes()) { switch (attrib.AttributeType.Name) { case "ProtocolAttribute": case "ProtocolMemberAttribute": case "AdoptsAttribute": // Unfortunately the CustomAttribute doesn't know its owner, so we can't show that in the test failure message :( failures.Add($"Found an unexpected attribute: {attrib.AttributeType.FullName}"); break; } } Assert.That(failures, Is.Empty, "all these attributes should have been linked away"); } }
public void MX1502_3(Profile profile) { using (var bundler = new BundlerTool()) { var code = @" using System; using Foundation; using ObjCRuntime; class T { static void Main () { Console.WriteLine (typeof (NSObject)); } } "; bundler.Profile = profile; bundler.CreateTemporaryCacheDirectory(); bundler.CreateTemporaryApp(profile, code: code); bundler.Linker = LinkerOption.LinkAll; bundler.CustomArguments = new [] { "--warn-on-type-ref=Foundation.NSObject" }; bundler.AssertExecute(); bundler.AssertWarning(1502, "One or more reference(s) to type 'Foundation.NSObject' already exists inside 'testApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' before linking"); bundler.AssertWarning(1503, "One or more reference(s) to type 'Foundation.NSObject' still exists inside 'testApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' after linking"); bundler.AssertWarningCount(2); } }
public void MX4175(Profile profile) { var code = @" using System; using Foundation; using ObjCRuntime; class Issue4072Session : NSUrlSession { public Issue4072Session () : base (IntPtr.Zero) { } public override NSUrlSessionDataTask CreateDataTask (NSUrl url, [BlockProxy (typeof (Delegate))] NSUrlSessionResponse completionHandler) { return base.CreateDataTask (url, completionHandler); } static void Main () { Console.WriteLine (typeof (NSObject)); } } "; using (var bundler = new BundlerTool()) { bundler.Profile = profile; bundler.CreateTemporaryCacheDirectory(); bundler.CreateTemporaryApp(profile, code: code, extraArg: "/debug:full"); bundler.Registrar = RegistrarOption.Static; bundler.Linker = LinkerOption.DontLink; bundler.AssertExecute(); bundler.AssertWarning(4175, "The parameter 'completionHandler' in the method 'Issue4072Session.CreateDataTask(Foundation.NSUrl,Foundation.NSUrlSessionResponse)' has an invalid BlockProxy attribute (the type passed to the attribute does not have a 'Create' method).", "testApp.cs", 11); bundler.AssertWarningCount(1); bundler.CreateTemporaryApp(profile, code: code, extraArg: "/debug-"); // Build without debug info so that the source code location isn't available. #if !__MACOS__ bundler.Linker = LinkerOption.LinkAll; // This will remove the parameter name in Xamarin.iOS (the parameter name removal optimization (MetadataReducerSubStep) isn't implemented for Xamarin.Mac). #endif bundler.AssertExecute(); #if __MACOS__ bundler.AssertWarning(4175, "The parameter 'completionHandler' in the method 'Issue4072Session.CreateDataTask(Foundation.NSUrl,Foundation.NSUrlSessionResponse)' has an invalid BlockProxy attribute (the type passed to the attribute does not have a 'Create' method)."); #else bundler.AssertWarning(4175, "Parameter #2 in the method 'Issue4072Session.CreateDataTask(Foundation.NSUrl,Foundation.NSUrlSessionResponse)' has an invalid BlockProxy attribute (the type passed to the attribute does not have a 'Create' method)."); #endif bundler.AssertWarningCount(1); } }
public void ModifiedResponseFile(Profile profile) { using (var bundler = new BundlerTool()) { bundler.Profile = profile; bundler.CreateTemporaryCacheDirectory(); bundler.CreateTemporaryApp(profile); var tmpDir = bundler.CreateTemporaryDirectory(); var responseFile = Path.Combine(tmpDir, "test-arguments.txt"); File.WriteAllText(responseFile, ""); bundler.ResponseFile = responseFile; bundler.Linker = LinkerOption.DontLink; // faster test bundler.Debug = true; // faster test bundler.Verbosity = 4; bundler.AssertExecute(); bundler.AssertWarningCount(0); bundler.AssertOutputPattern("A full rebuild will be performed because the cache is either incomplete or entirely missing."); File.WriteAllText(responseFile, "/linksdkonly"); bundler.AssertExecute(); bundler.AssertWarningCount(0); bundler.AssertOutputPattern("A full rebuild has been forced because the cache for .* is not valid."); } }
public void MX2106(Profile profile) { using (var bundler = new BundlerTool()) { var code = @" using System; using Foundation; using ObjCRuntime; class T { [BindingImpl (BindingImplOptions.Optimizable)] void SetupBlockOptimized_Delegate (Action callback, Delegate block_callback) { BlockLiteral block = new BlockLiteral (); block.SetupBlock (block_callback, callback); // don't need anything here, since this won't be executed block.CleanupBlock (); } [BindingImpl (BindingImplOptions.Optimizable)] void SetupBlockOptimized_MulticastDelegate (Action callback, MulticastDelegate block_callback) { BlockLiteral block = new BlockLiteral (); block.SetupBlock (block_callback, callback); // don't need anything here, since this won't be executed block.CleanupBlock (); } static void Main () { Console.WriteLine (typeof (NSObject)); } } "; bundler.Profile = profile; bundler.CreateTemporaryCacheDirectory(); bundler.CreateTemporaryApp(profile, code: code, extraArg: "/debug:full"); bundler.Linker = LinkerOption.LinkAll; bundler.Optimize = new string [] { "blockliteral-setupblock" }; bundler.AssertExecute(); bundler.AssertWarning(2106, "Could not optimize the call to BlockLiteral.SetupBlock in System.Void T::SetupBlockOptimized_Delegate(System.Action,System.Delegate) because the type of the value passed as the first argument (the trampoline) is System.Delegate, which makes it impossible to compute the block signature.", "testApp.cs", 10); bundler.AssertWarning(2106, "Could not optimize the call to BlockLiteral.SetupBlock in System.Void T::SetupBlockOptimized_MulticastDelegate(System.Action,System.MulticastDelegate) because the type of the value passed as the first argument (the trampoline) is System.MulticastDelegate, which makes it impossible to compute the block signature.", "testApp.cs", 19); bundler.AssertWarningCount(2); } }