public void BI1117_classinternal() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "bug52570classinternal.cs"))); bgen.AssertExecute("build"); bgen.AssertNoWarnings(); }
public void BI1060() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "bug42855.cs"))); bgen.AssertExecute("build"); bgen.AssertWarning(1060, "The Bug42855Tests.MyFooClass protocol is decorated with [Model], but not [BaseType]. Please verify that [Model] is relevant for this protocol; if so, add [BaseType] as well, otherwise remove [Model]."); }
public void ResponseFile() { var bgen = new BGenTool(); bgen.CreateTemporaryBinding(""); bgen.ResponseFile = Path.Combine(Cache.CreateTemporaryDirectory(), "rspfile"); File.WriteAllLines(bgen.ResponseFile, new string [] { "--target-framework:Xamarin.iOS,v1.0" }); bgen.AssertExecute("response file"); bgen.AssertNoWarnings(); }
public void GH5416_setter() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.AddTestApiDefinition("ghissue5416a.cs"); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); bgen.AssertWarning(1118, "[NullAllowed] should not be used on methods, like 'System.Void set_Setter(Foundation.NSString)', but only on properties, parameters and return values."); }
public void Bug39614() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.AddTestApiDefinition("bug39614.cs"); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); bgen.AssertWarning(1103, "'FooType`1' does not live under a namespace; namespaces are a highly recommended .NET best practice"); }
public void NoAsyncWarningCS0219() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.AddTestApiDefinition("noasyncwarningcs0219.cs"); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); bgen.AssertNoWarnings(); }
public void FieldEnumTests() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.ProcessEnums = true; bgen.AddTestApiDefinition("fieldenumtests.cs"); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); bgen.AssertNoWarnings(); }
public void ClassNameCollision() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.Defines = BGenTool.GetDefaultDefines(bgen.Profile); bgen.Sources.Add(Path.Combine(Configuration.SourceRoot, "tests", "generator", "classNameCollision-enum.cs")); bgen.ApiDefinitions.Add(Path.Combine(Configuration.SourceRoot, "tests", "generator", "classNameCollision.cs")); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); bgen.AssertNoWarnings(); }
public void NativeEnum() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.ProcessEnums = true; bgen.Defines = BGenTool.GetDefaultDefines(bgen.Profile); bgen.Sources = new string [] { Path.Combine(Configuration.SourceRoot, "tests", "generator", "tests", "nativeenum-extensions.cs") }.ToList(); bgen.ApiDefinitions = new string [] { Path.Combine(Configuration.SourceRoot, "tests", "generator", "tests", "nativeenum.cs") }.ToList(); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); }
public void SmartEnumWithFramework() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.ProcessEnums = true; bgen.AddTestApiDefinition("smartenumwithframework.cs"); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); bgen.AssertApiLoadsField("SmartEnumWithFramework.FooEnumTestExtensions", "get_First", "ObjCRuntime.Libraries/CoreImage", "Handle", "First getter"); bgen.AssertApiLoadsField("SmartEnumWithFramework.FooEnumTestExtensions", "get_Second", "ObjCRuntime.Libraries/CoreImage", "Handle", "Second getter"); }
public void Bug31788(Profile profile) { var bgen = new BGenTool(); bgen.Profile = profile; bgen.Defines = BGenTool.GetDefaultDefines(bgen.Profile); bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "bug31788.cs"))); bgen.AssertExecute("build"); bgen.AssertNoWarnings(); bgen.AssertApiCallsMethod("Test", "MarshalInProperty", "get_Shared", "xamarin_IntPtr_objc_msgSend_exception", "MarshalInProperty.Shared getter"); bgen.AssertApiCallsMethod("Test", "MarshalOnProperty", "get_Shared", "xamarin_IntPtr_objc_msgSend_exception", "MarshalOnProperty.Shared getter"); }
BGenTool BuildFile(Profile profile, bool nowarnings, params string [] filenames) { var bgen = new BGenTool(); bgen.Profile = profile; bgen.Defines = BGenTool.GetDefaultDefines(bgen.Profile); bgen.CreateTemporaryBinding(filenames.Select((filename) => File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", filename))).ToArray()); bgen.AssertExecute("build"); if (nowarnings) { bgen.AssertNoWarnings(); } return(bgen); }
public void NoWarn(Profile profile) { const string message = "The member 'SomeMethod' is decorated with [Static] and its container class nowarnTests.FooObject_Extensions is decorated with [Category] this leads to hard to use code. Please inline SomeMethod into nowarnTests.FooObject class."; { // Enabled var bgen = new BGenTool(); bgen.Profile = profile; bgen.Defines = BGenTool.GetDefaultDefines(profile); bgen.NoWarn = string.Empty; bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "nowarn.cs"))); bgen.AssertExecute("build"); bgen.AssertNoWarnings(); } { // Disabled var bgen = new BGenTool(); bgen.Profile = profile; bgen.Defines = BGenTool.GetDefaultDefines(profile); bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "nowarn.cs"))); bgen.AssertExecute("build"); bgen.AssertWarning(1117, message); } { // Only 1116 var bgen = new BGenTool(); bgen.Profile = profile; bgen.Defines = BGenTool.GetDefaultDefines(profile); bgen.NoWarn = "1116"; bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "nowarn.cs"))); bgen.AssertExecute("build"); bgen.AssertWarning(1117, message); } { // Only 1117 var bgen = new BGenTool(); bgen.Profile = profile; bgen.Defines = BGenTool.GetDefaultDefines(profile); bgen.NoWarn = "1117"; bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "nowarn.cs"))); bgen.AssertExecute("build"); bgen.AssertNoWarnings(); } }
public void Bug46292() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.ProcessEnums = true; bgen.AddTestApiDefinition("bug46292.cs"); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); var allTypes = bgen.ApiAssembly.MainModule.GetTypes().ToArray(); var allMembers = ((IEnumerable <ICustomAttributeProvider>)allTypes) .Union(allTypes.SelectMany((type) => type.Methods)) .Union(allTypes.SelectMany((type) => type.Fields)) .Union(allTypes.SelectMany((type) => type.Properties)); var attribCount = allMembers.Count((v) => v.HasCustomAttributes && v.CustomAttributes.Any((ca) => ca.AttributeType.Name == "ObsoleteAttribute")); Assert.AreEqual(2, attribCount, "attribute count"); }
BGenTool BuildFile(Profile profile, bool nowarnings, bool processEnums, params string [] filenames) { var bgen = new BGenTool(); bgen.Profile = profile; bgen.ProcessEnums = processEnums; bgen.Defines = BGenTool.GetDefaultDefines(bgen.Profile); TestContext.Out.WriteLine(TestContext.CurrentContext.Test.FullName); foreach (var filename in filenames) { TestContext.Out.WriteLine($"\t{filename}"); } bgen.CreateTemporaryBinding(filenames.Select((filename) => File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", filename))).ToArray()); bgen.AssertExecute("build"); if (nowarnings) { bgen.AssertNoWarnings(); } return(bgen); }
public void NoAsyncInternalWrapper() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.AddTestApiDefinition("noasyncinternalwrapper.cs"); bgen.CreateTemporaryBinding(); bgen.AssertExecute("build"); var allTypes = bgen.ApiAssembly.MainModule.GetTypes().ToArray(); var allMembers = ((IEnumerable <MemberReference>)allTypes) .Union(allTypes.SelectMany((type) => type.Methods)) .Union(allTypes.SelectMany((type) => type.Fields)) .Union(allTypes.SelectMany((type) => type.Properties)); Assert.AreEqual(1, allMembers.Count((member) => member.Name == "RequiredMethodAsync"), "Expected 1 RequiredMethodAsync members in generated code. If you modified code that generates RequiredMethodAsync (AsyncAttribute) please update the RequiredMethodAsync count."); var attribs = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig; bgen.AssertMethod("NoAsyncInternalWrapperTests.MyFooDelegate_Extensions", "RequiredMethodAsync", attribs, "System.Threading.Tasks.Task", "NoAsyncInternalWrapperTests.IMyFooDelegate", "System.Int32"); }
public void VirtualWrap() { var bgen = new BGenTool(); bgen.Profile = Profile.iOS; bgen.AddTestApiDefinition("virtualwrap.cs"); bgen.CreateTemporaryBinding(); bgen.ProcessEnums = true; bgen.AssertExecute("build"); // verify virtual methods var attribs = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.NewSlot; bgen.AssertMethod("WrapTest.MyFooClass", "FromUrl", attribs, null, "Foundation.NSUrl"); bgen.AssertMethod("WrapTest.MyFooClass", "FromUrl", attribs, null, "System.String"); bgen.AssertMethod("WrapTest.MyFooClass", "get_FooNSString", attribs | MethodAttributes.SpecialName, "Foundation.NSString"); bgen.AssertMethod("WrapTest.MyFooClass", "get_FooString", attribs | MethodAttributes.SpecialName, "System.String"); // verify non-virtual methods attribs = MethodAttributes.Public | MethodAttributes.HideBySig; bgen.AssertMethod("WrapTest.MyFooClass", "FromUrlN", attribs, null, "System.String"); bgen.AssertMethod("WrapTest.MyFooClass", "get_FooNSStringN", attribs | MethodAttributes.SpecialName, "Foundation.NSString"); }
public void ResponseFile() { var bgen = new BGenTool(); bgen.CreateTemporaryBinding(""); bgen.ResponseFile = Path.Combine(Cache.CreateTemporaryDirectory(), "rspfile"); var arguments = new List <string> (); #if NET var targetFramework = TargetFramework.DotNet_6_0_iOS_String; var tf = TargetFramework.Parse(targetFramework); arguments.Add($"--baselib={Configuration.GetBaseLibrary (tf)}"); arguments.Add($"--attributelib={Configuration.GetBindingAttributePath (tf)}"); arguments.AddRange(Directory.GetFiles(Configuration.DotNet6BclDir, "*.dll").Select(v => $"-r:{v}")); #else var targetFramework = "Xamarin.iOS,v1.0"; #endif arguments.Add($"--target-framework={targetFramework}"); File.WriteAllLines(bgen.ResponseFile, arguments.ToArray()); bgen.AssertExecute("response file"); bgen.AssertNoWarnings(); }