Esempio n. 1
0
        public void BI1036(Profile profile)
        {
            var bgen = new BGenTool();

            bgen.Profile = profile;
            bgen.Defines = BGenTool.GetDefaultDefines(profile);
            bgen.ApiDefinitions.Add(Path.Combine(Configuration.SourceRoot, "tests", "generator", "bi1036.cs"));
            bgen.CreateTemporaryBinding();
            bgen.AssertExecuteError("build");
            bgen.AssertError(1036, "The last parameter in the method 'NS.Foo.Method' must be a delegate (it's 'System.String').");
        }
Esempio n. 2
0
        public void BI1046()
        {
            var bgen = new BGenTool();

            bgen.Profile = Profile.iOS;
            bgen.AddTestApiDefinition("bi1046.cs");
            bgen.CreateTemporaryBinding();
            bgen.ProcessEnums = true;
            bgen.AssertExecuteError("build");
            bgen.AssertError(1046, "The [Field] constant HMAccessoryCategoryTypeGarageDoorOpener cannot only be used once inside enum HMAccessoryCategoryType.");
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        public void BI1042()
        {
            var bgen = new BGenTool();

            bgen.Profile = Profile.iOS;
            bgen.AddTestApiDefinition("bi1042.cs");
            bgen.CreateTemporaryBinding();
            bgen.ProcessEnums = true;
            bgen.AssertExecuteError("build");
            bgen.AssertError(1042, "Missing '[Field (LibraryName=value)]' for BindingTests.Tools.DoorOpener (e.g.\"__Internal\")");
        }
Esempio n. 5
0
        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");
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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");
        }
Esempio n. 8
0
        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");
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public void BI1067_1070()
        {
            BGenTool bgen = new BGenTool {
                Profile = Profile.iOS,
            };

            bgen.CreateTemporaryBinding(File.ReadAllText(Path.Combine(Configuration.SourceRoot, "tests", "generator", "tests", "diamond-protocol-errors.cs")));
            bgen.AssertExecuteError("build");
            bgen.AssertError(1067, "The type 'DiamondProtocol.A.C' is trying to inline the property 'P1' from the protocols 'DiamondProtocol.A.P1' and 'DiamondProtocol.A.P2', but the inlined properties don't share the same accessors ('DiamondProtocol.A.P1 P1' is read-only, while '$DiamondProtocol.A.P2 P1' is write-only).");
            bgen.AssertWarning(1068, "The type 'DiamondProtocol.D.C' is trying to inline the property 'P1' from the protocols 'DiamondProtocol.D.P1' and 'DiamondProtocol.D.P2', and the inlined properties use different selectors (P1.P1 uses 'pA', and P2.P1 uses 'pB'.");
            bgen.AssertError(1069, "The type 'DiamondProtocol.Y.C' is trying to inline the methods binding the selector 'm1:' from the protocols 'DiamondProtocol.Y.P1' and 'DiamondProtocol.Y.P2', using methods with different signatures ('Void M1(System.Int32)' vs 'Int32 M1(System.Boolean)').");
            bgen.AssertError(1070, "The type 'DiamondProtocol.C.C' is trying to inline the property 'P1' from the protocols 'DiamondProtocol.C.P1' and 'DiamondProtocol.C.P2', but the inlined properties are of different types ('DiamondProtocol.C.P1 P1' is int, while 'DiamondProtocol.C.P2 P1' is int).");
            bgen.AssertErrorCount(3);
            bgen.AssertWarningCount(1);
        }
Esempio n. 11
0
        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();
            }
        }
Esempio n. 12
0
        public void BI1063_NoDoubleWrapTest()
        {
            var bgen = new BGenTool {
                Profile      = Profile.iOS,
                ProcessEnums = true
            };

            bgen.CreateTemporaryBinding(@"
using System;
using Foundation;

namespace BI1063Tests {

	enum PersonRelationship {
		[Field (null)]
		None,

		[Field (""INPersonRelationshipFather"", ""__Internal"")]
		Father,

		[Field (""INPersonRelationshipMother"", ""__Internal"")]
		Mother
	}

	[BaseType (typeof (NSObject))]
	interface Wrappers {

		// SmartEnum -- Normal Wrap getter Property

		[Export (""presenceType"")]
		NSString _PresenceType { get; }

		[Wrap (""PersonRelationshipExtensions.GetValue (_PresenceType)"")]
		PersonRelationship PresenceType {
			[Wrap (""PersonRelationshipExtensions.GetValue (_PresenceType)"")]
			get;
		}
	}
}");
            bgen.AssertExecuteError("build");
            bgen.AssertError(1063, "The 'WrapAttribute' can only be used at the property or at getter/setter level at a given time. Property: 'BI1063Tests.Wrappers.PresenceType'");
        }
Esempio n. 13
0
        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");
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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");
        }
Esempio n. 16
0
        public void Bug57094Test()
        {
            // https://bugzilla.xamarin.com/show_bug.cgi?id=57094
            var bgen = new BGenTool();

            bgen.Profile = Profile.iOS;
            bgen.CreateTemporaryBinding(@"
using System;
using Foundation;
using ObjCRuntime;

namespace Bug57094 {

	[BaseType (typeof (NSObject))]
	interface FooObject {

		[Field (""SomeField"", ""__Internal"")]
		byte [] SomeField { get; }
	}
}");
            bgen.AssertExecuteError("build");
            bgen.AssertError(1014, "Unsupported type for Fields: byte[] for 'Bug57094.FooObject SomeField'.");
        }
Esempio n. 17
0
        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");
        }
Esempio n. 18
0
        public void BindAsNoOutParam()
        {
            var bgen = new BGenTool();

            bgen.Profile = Profile.iOS;
            bgen.CreateTemporaryBinding(@"
using System;
using Foundation;
using CoreGraphics;
using ObjCRuntime;

namespace Bug57804TestsRef {

	[BaseType (typeof (NSObject))]
	interface FooObject {

		[Export (""setCGAffineTransformValueOutNonNullable:"")]
		void SetCGAffineTransformValueOutNonNullable ([BindAs (typeof (CGAffineTransform))] out NSValue value);
	}
}");
            bgen.AssertExecuteError("build");
            bgen.AssertError(1048, "Unsupported type 'ref/out NSValue' decorated with [BindAs]");
        }
Esempio n. 19
0
        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();
        }
Esempio n. 20
0
        public void BI1062_NoAsyncMethodRefParameterTest()
        {
            var bgen = new BGenTool();

            bgen.Profile = Profile.iOS;
            bgen.CreateTemporaryBinding(@"
using System;
using Foundation;

namespace BI1062Tests {

	delegate void MyHandler (bool staaph, NSError error);

	[BaseType (typeof (NSObject))]
	interface FooObject {

		[Async]
		[Export (""fooMethod:completion:"")]
		void FooMethod (ref NSObject obj, Action<bool, NSError> handler);
	}
}");
            bgen.AssertExecuteError("build");
            bgen.AssertError(1062, "The member 'FooObject.FooMethod' contains ref/out parameters and must not be decorated with [Async].");
        }
Esempio n. 21
0
        public void BindAsNoMultidimensionalArrays()
        {
            var bgen = new BGenTool();

            bgen.Profile = Profile.iOS;
            bgen.CreateTemporaryBinding(@"
using System;
using Foundation;
using AVFoundation;
using ObjCRuntime;

namespace Bug57795Tests {

	[BaseType (typeof (NSObject))]
	interface FooObject {

		[BindAs (typeof (AVMediaTypes [,]))]
		[Export (""strongAVMediaTypesPropertiesMulti:"")]
		NSString [,] StrongAVMediaTypesPropertiesMulti { get; set; }
	}
}");
            bgen.AssertExecuteError("build");
            bgen.AssertError(1048, "Unsupported type AVMediaTypes[,] decorated with [BindAs]");
        }