From 2fb35682a2ddba9638b4d478aceb9bb5ca64e2b8 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 3 Jul 2017 19:16:33 +0200 Subject: [PATCH] [tests] Add generated runtime tests for the BindAs attribute. --- tests/test-libraries/.gitignore | 2 + tests/test-libraries/libtest.h | 3 + tests/test-libraries/libtest.m | 3 + tests/test-libraries/testgenerator.cs | 1128 ++++++++++++++++++++++++- tests/tests.sln | 28 + 5 files changed, 1161 insertions(+), 3 deletions(-) diff --git a/tests/test-libraries/.gitignore b/tests/test-libraries/.gitignore index dcb5821d82..444f92e71a 100644 --- a/tests/test-libraries/.gitignore +++ b/tests/test-libraries/.gitignore @@ -6,4 +6,6 @@ libtest-object.m libtest.structs.h libtest.properties.h libtest.decompile.m +libtest.methods.h +libtest.methods.m diff --git a/tests/test-libraries/libtest.h b/tests/test-libraries/libtest.h index d766173067..61572027c0 100644 --- a/tests/test-libraries/libtest.h +++ b/tests/test-libraries/libtest.h @@ -85,6 +85,9 @@ typedef unsigned int (^RegistrarTestBlock) (unsigned int magic); -(bool) testBlocks; -(void) idAsIntPtr: (id)p1; + +#include "libtest.methods.h" + @end /* diff --git a/tests/test-libraries/libtest.m b/tests/test-libraries/libtest.m index b8ac5d3ab5..0a8727be58 100644 --- a/tests/test-libraries/libtest.m +++ b/tests/test-libraries/libtest.m @@ -199,6 +199,9 @@ static UltimateMachine *shared; { // Nothing to do here. } + +#include "libtest.methods.m" + @end @implementation ObjCExceptionTest diff --git a/tests/test-libraries/testgenerator.cs b/tests/test-libraries/testgenerator.cs index a0fed5a378..506f6bfafd 100644 --- a/tests/test-libraries/testgenerator.cs +++ b/tests/test-libraries/testgenerator.cs @@ -49,6 +49,56 @@ static class C { static string [] structs = structs_and_stret.Select ((v) => v.IndexOf (':') >= 0 ? v.Substring (0, v.IndexOf (':')) : v).ToArray (); static Architecture [] strets = structs_and_stret.Select ((v) => v.IndexOf (':') >= 0 ? (Architecture) int.Parse (v.Substring (v.IndexOf (':') + 1)) : Architecture.None).ToArray (); + class BindAsData + { + public string Managed; + public string Native; + public string ManagedCondition; + public string ManagedNewExpression; + public string Map; + public string MapFrom; + } + + static BindAsData [] bindas_nsnumber = new [] { + new BindAsData { Managed = "Byte", Native = "uint8_t", ManagedNewExpression = "((byte) 1)", Map = ".ByteValue" }, + new BindAsData { Managed = "SByte", Native = "int8_t", ManagedNewExpression = "((sbyte) 1)", Map = ".SByteValue" }, + new BindAsData { Managed = "Int16", Native = "int16_t", ManagedNewExpression = "((short) 1)", Map = ".Int16Value" }, + new BindAsData { Managed = "UInt16", Native = "uint16_t", ManagedNewExpression = "((ushort) 1)", Map = ".UInt16Value" }, + new BindAsData { Managed = "Int32", Native = "int32_t", ManagedNewExpression = "((int) 1)", Map = ".Int32Value" }, + new BindAsData { Managed = "UInt32", Native = "uint32_t", ManagedNewExpression = "((uint) 1)", Map = ".UInt32Value" }, + new BindAsData { Managed = "Int64", Native = "int64_t", ManagedNewExpression = "((long) 1)", Map = ".Int64Value" }, + new BindAsData { Managed = "UInt64", Native = "uint64_t", ManagedNewExpression = "((ulong) 1)", Map = ".UInt64Value" }, + new BindAsData { Managed = "Single", Native = "float", ManagedNewExpression = "((float) 1.1)", Map = ".FloatValue" }, + new BindAsData { Managed = "Double", Native = "double", ManagedNewExpression = "((double) 1.2)", Map = ".DoubleValue" }, + new BindAsData { Managed = "nint", Native = "NSInteger", ManagedNewExpression = "((nint) 1)", Map = ".NIntValue" }, + new BindAsData { Managed = "nuint", Native = "NSUInteger", ManagedNewExpression = "((nuint) 1)", Map = ".NUIntValue" }, + new BindAsData { Managed = "nfloat", Native = "NSFloat", ManagedNewExpression = "((nfloat) 1)", Map = ".NFloatValue" }, + new BindAsData { Managed = "Boolean", Native = "BOOL", ManagedNewExpression = "true", Map = ".BoolValue" }, + }; + static BindAsData[] bindas_nsvalue = new [] { + new BindAsData { Managed = "CGAffineTransform", Native = "CGAffineTransform", ManagedNewExpression = "new CGAffineTransform (1, 2, 3, 4, 5, 6)", Map = ".CGAffineTransformValue", MapFrom = "FromCGAffineTransform" }, + new BindAsData { Managed = "NSRange", Native = "NSRange", ManagedNewExpression = "new NSRange (7, 8)", Map = ".RangeValue", MapFrom = "FromRange" }, + new BindAsData { Managed = "CGVector", Native = "CGVector", ManagedNewExpression = "new CGVector (9, 10)", Map = ".CGVectorValue", MapFrom = "FromCGVector" }, + new BindAsData { Managed = "SCNMatrix4", Native = "SCNMatrix4", ManagedNewExpression = "SCNMatrix4.Identity", Map = ".SCNMatrix4Value", MapFrom = "FromSCNMatrix4" }, + new BindAsData { Managed = "CLLocationCoordinate2D", Native = "CLLocationCoordinate2D", ManagedNewExpression = "new CLLocationCoordinate2D (11, 12)", Map = ".CoordinateValue", MapFrom = "FromMKCoordinate" }, + new BindAsData { Managed = "SCNVector3", Native = "SCNVector3", ManagedNewExpression = "new SCNVector3 (13, 14, 15)", Map = ".Vector3Value", MapFrom = "FromVector" }, + new BindAsData { Managed = "SCNVector4", Native = "SCNVector4", ManagedNewExpression = "new SCNVector4 (16, 17, 18, 19)", Map = ".Vector4Value", MapFrom = "FromVector" }, + new BindAsData { Managed = "CGPoint", Native = "CGPoint", ManagedCondition = "XAMCORE_2_0", ManagedNewExpression = "new CGPoint (19, 20)", Map = ".CGPointValue", MapFrom = "FromCGPoint" }, + new BindAsData { Managed = "CGSize", Native = "CGSize", ManagedCondition = "XAMCORE_2_0", ManagedNewExpression = "new CGSize (21, 22)", Map = ".CGSizeValue", MapFrom = "FromCGSize" }, + new BindAsData { Managed = "CGRect", Native = "CGRect", ManagedCondition = "XAMCORE_2_0", ManagedNewExpression = "new CGRect (23, 24, 25, 26)", Map = ".CGRectValue", MapFrom = "FromCGRect" }, + new BindAsData { Managed = "UIEdgeInsets", Native = "UIEdgeInsets", ManagedCondition = "HAVE_UIKIT", ManagedNewExpression = "new UIEdgeInsets (27, 28, 29, 30)", Map = ".UIEdgeInsetsValue", MapFrom = "FromUIEdgeInsets" }, + new BindAsData { Managed = "UIOffset", Native = "UIOffset", ManagedCondition = "HAVE_UIKIT", ManagedNewExpression = "new UIOffset (31, 32)", Map = ".UIOffsetValue", MapFrom = "FromUIOffset" }, + new BindAsData { Managed = "MKCoordinateSpan", Native = "MKCoordinateSpan", ManagedCondition = "HAVE_MAPKIT", ManagedNewExpression = "new MKCoordinateSpan (33, 34)", Map = ".CoordinateSpanValue", MapFrom = "FromMKCoordinateSpan" }, + new BindAsData { Managed = "CMTimeRange", Native = "CMTimeRange", ManagedCondition = "HAVE_COREMEDIA", ManagedNewExpression = "new CMTimeRange { Duration = new CMTime (37, 38), Start = new CMTime (39, 40) }", Map = ".CMTimeRangeValue", MapFrom = "FromCMTimeRange" }, + new BindAsData { Managed = "CMTime", Native = "CMTime", ManagedCondition = "HAVE_COREMEDIA", ManagedNewExpression = "new CMTime (35, 36)", Map = ".CMTimeValue", MapFrom = "FromCMTime" }, + new BindAsData { Managed = "CMTimeMapping", Native = "CMTimeMapping", ManagedCondition = "HAVE_COREMEDIA", ManagedNewExpression = "new CMTimeMapping { Source = new CMTimeRange { Duration = new CMTime (42, 43), Start = new CMTime (44, 45) } }", Map = ".CMTimeMappingValue", MapFrom = "FromCMTimeMapping" }, + new BindAsData { Managed = "CATransform3D", Native = "CATransform3D", ManagedCondition = "HAVE_COREANIMATION", ManagedNewExpression = "new CATransform3D { m11 = 41 }", Map = ".CATransform3DValue", MapFrom = "FromCATransform3D" }, + }; + + static BindAsData [] bindas_nsstring = new [] { + new BindAsData { Managed = "AVMediaTypes", ManagedNewExpression = "AVMediaTypes.Audio" }, + }; + static string GetNativeName (char t) { switch (t) { @@ -144,22 +194,178 @@ static class C { foreach (var s in structs) w.AppendLine ($"\t@property struct S{s} PS{s};"); + w.AppendLine (); + foreach (var v in bindas_nsnumber) { + w.AppendLine ($"\t@property (retain) NSNumber* P{v.Managed}Number;"); + w.AppendLine ($"\t@property (retain) NSArray * P{v.Managed}Array;"); + } + + w.AppendLine (); + foreach (var v in bindas_nsvalue) { + w.AppendLine ($"\t@property (retain) NSValue* P{v.Managed}Value;"); + w.AppendLine ($"\t@property (retain) NSArray * P{v.Managed}Array;"); + } + + w.AppendLine (); + foreach (var v in bindas_nsstring) { + w.AppendLine ($"\t@property (retain) NSString *PSmart{v.Managed}Property;"); + w.AppendLine ($"\t@property (retain) NSArray * PSmart{v.Managed}Properties;"); + } File.WriteAllText ("libtest.properties.h", w.ToString ()); } + static void WriteLibTestMethodsH () + { + var w = new StringBuilder (); + + w.AppendLine (); + foreach (var v in bindas_nsnumber) { + w.AppendLine ($"\t-(NSNumber *) get{v.Managed}NumberNonNullable;"); + w.AppendLine ($"\t-(void) set{v.Managed}NumberNonNullable: (NSNumber *) value;"); + w.AppendLine (); + w.AppendLine ($"\t-(NSNumber *) get{v.Managed}NumberNullable;"); + w.AppendLine ($"\t-(void) set{v.Managed}NumberNullable: (NSNumber *) value;"); + w.AppendLine (); + w.AppendLine ($"\t-(NSArray *) get{v.Managed}Array;"); + w.AppendLine ($"\t-(void) set{v.Managed}Array: (NSArray *) value;"); + w.AppendLine (); + } + + w.AppendLine (); + foreach (var v in bindas_nsvalue) { + w.AppendLine ($"\t-(NSValue *) get{v.Managed}ValueNonNullable;"); + w.AppendLine ($"\t-(void) set{v.Managed}ValueNonNullable: (NSValue *) value;"); + w.AppendLine (); + w.AppendLine ($"\t-(NSValue *) get{v.Managed}ValueNullable;"); + w.AppendLine ($"\t-(void) set{v.Managed}ValueNullable: (NSValue *) value;"); + w.AppendLine (); + w.AppendLine ($"\t-(NSArray *) get{v.Managed}Array;"); + w.AppendLine ($"\t-(void) set{v.Managed}Array: (NSArray *) value;"); + w.AppendLine (); + } + + w.AppendLine (); + foreach (var v in bindas_nsstring) { + // plain value + w.AppendLine ($"\t-(NSString *) getSmart{v.Managed}Value;"); + w.AppendLine ($"\t-(void) setSmart{v.Managed}Value: (NSString *) value;"); + w.AppendLine (); + + // nullable + w.AppendLine ($"\t-(NSString *) getSmartNullable{v.Managed}Value;"); + w.AppendLine ($"\t-(void) setSmartNullable{v.Managed}Value: (NSString *) value;"); + w.AppendLine (); + + // array of plain value + w.AppendLine ($"\t-(NSArray *) getSmart{v.Managed}Values;"); + w.AppendLine ($"\t-(void) setSmart{v.Managed}Values: (NSArray *) value;"); + w.AppendLine (); + } + + File.WriteAllText ("libtest.methods.h", w.ToString ()); + } + + static void WriteLibTestMethodsM () + { + var w = new StringBuilder (); + + w.AppendLine (); + foreach (var v in bindas_nsnumber) { + w.AppendLine ($"\t-(NSNumber *) get{v.Managed}NumberNonNullable {{ return self.P{v.Managed}Number; }}"); + w.AppendLine ($"\t-(void) set{v.Managed}NumberNonNullable: (NSNumber *) value {{ self.P{v.Managed}Number = value; }}"); + w.AppendLine (); + w.AppendLine ($"\t-(NSNumber *) get{v.Managed}NumberNullable {{ return self.P{v.Managed}Number; }}"); + w.AppendLine ($"\t-(void) set{v.Managed}NumberNullable: (NSNumber *) value {{ self.P{v.Managed}Number = value; }}"); + w.AppendLine (); + w.AppendLine ($"\t-(NSArray *) get{v.Managed}Array {{ return self.P{v.Managed}Array; }}"); + w.AppendLine ($"\t-(void) set{v.Managed}Array: (NSArray *) value {{ self.P{v.Managed}Array = value; }}"); + w.AppendLine (); + } + + w.AppendLine (); + foreach (var v in bindas_nsvalue) { + w.AppendLine ($"\t-(NSValue *) get{v.Managed}ValueNonNullable {{ return self.P{v.Managed}Value; }}"); + w.AppendLine ($"\t-(void) set{v.Managed}ValueNonNullable: (NSValue *) value {{ self.P{v.Managed}Value = value; }}"); + w.AppendLine (); + w.AppendLine ($"\t-(NSValue *) get{v.Managed}ValueNullable {{ return self.P{v.Managed}Value; }}"); + w.AppendLine ($"\t-(void) set{v.Managed}ValueNullable: (NSValue *) value {{ self.P{v.Managed}Value = value; }}"); + w.AppendLine (); + w.AppendLine ($"\t-(NSArray *) get{v.Managed}Array {{ return self.P{v.Managed}Array; }}"); + w.AppendLine ($"\t-(void) set{v.Managed}Array: (NSArray *) value {{ self.P{v.Managed}Array = value; }}"); + w.AppendLine (); + } + + w.AppendLine (); + foreach (var v in bindas_nsstring) { + // plain value + w.AppendLine ($"\t-(NSString *) getSmart{v.Managed}Value {{ return self.PSmart{v.Managed}Property; }}"); + w.AppendLine ($"\t-(void) setSmart{v.Managed}Value: (NSString *) value {{ self.PSmart{v.Managed}Property = value; }}"); + w.AppendLine (); + + // nullable + w.AppendLine ($"\t-(NSString *) getSmartNullable{v.Managed}Value {{ return self.PSmart{v.Managed}Property; }}"); + w.AppendLine ($"\t-(void) setSmartNullable{v.Managed}Value: (NSString *) value {{ self.PSmart{v.Managed}Property = value; }}"); + w.AppendLine (); + + // array of plain value + w.AppendLine ($"\t-(NSArray *) getSmart{v.Managed}Values {{ return self.PSmart{v.Managed}Properties; }}"); + w.AppendLine ($"\t-(void) setSmart{v.Managed}Values: (NSArray *) value {{ self.PSmart{v.Managed}Properties = value; }}"); + w.AppendLine (); + } + + File.WriteAllText ("libtest.methods.m", w.ToString ()); + } + + static void WriteFrameworkDefines (StringBuilder w) + { + w.AppendLine (@" +#if __IOS__ || __MACOS__ || __TVOS__ +#define HAVE_COREANIMATION +#endif + +#if __IOS__ || __MACOS__ || __TVOS__ +#define HAVE_COREMEDIA +#endif + +#if __IOS__ || __WATCHOS__ || __TVOS__ +#define HAVE_UIKIT +#endif + +#if XAMCORE_2_0 +#define HAVE_MAPKIT +#endif"); + + } + static void WriteApiDefinition () { var w = new StringBuilder (); - - w.AppendLine (@"using System; + WriteFrameworkDefines (w); + w.AppendLine (@" +using System; #if !__WATCHOS__ using System.Drawing; #endif #if __UNIFIED__ -using ObjCRuntime; +using AVFoundation; +#if HAVE_COREANIMATION +using CoreAnimation; +#endif +using CoreGraphics; +using CoreLocation; +#if HAVE_COREMEDIA +using CoreMedia; +#endif using Foundation; +#if HAVE_MAPKIT +using MapKit; +#endif +using ObjCRuntime; +using SceneKit; +#if HAVE_UIKIT using UIKit; +#endif #else using MonoTouch.ObjCRuntime; using MonoTouch.Foundation; @@ -177,6 +383,336 @@ namespace Bindings.Test { w.AppendLine (); } + w.AppendLine ("\t\t// BindAs: NSNumber"); + foreach (var v in bindas_nsnumber) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + // no BindAs + + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Number\")]"); + w.AppendLine ($"\t\tNSNumber P{v.Managed}Number {{ get; set; }}"); + + // plain value + w.AppendLine (); + w.AppendLine ("\t\t[Sealed]"); + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Number\")]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}))]"); + w.AppendLine ($"\t\tNSNumber P{v.Managed}NumberNonNullable {{ get; set; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"get{v.Managed}NumberNonNullable\")]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}))]"); + w.AppendLine ($"\t\t[return: NullAllowed] // This should be the default"); + w.AppendLine ($"\t\tNSNumber Get{v.Managed}NumberNonNullable ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"set{v.Managed}NumberNonNullable:\")]"); + w.AppendLine ($"\t\tvoid Set{v.Managed}NumberNonNullable ([BindAs (typeof ({v.Managed}))] NSNumber value);"); + + // nullable value + w.AppendLine (); + w.AppendLine ("\t\t[Sealed]"); + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Number\")]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?))]"); + w.AppendLine ($"\t\t[NullAllowed] // This should be the default"); + w.AppendLine ($"\t\tNSNumber P{v.Managed}NumberNullable {{ get; set; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"get{v.Managed}NumberNullable\")]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}?))]"); + w.AppendLine ($"\t\tNSNumber Get{v.Managed}NumberNullable ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"set{v.Managed}NumberNullable:\")]"); + w.AppendLine ($"\t\tvoid Set{v.Managed}NumberNullable ([BindAs (typeof ({v.Managed}?))] [NullAllowed /* this should be the default */] NSNumber value);"); + + // ref/out plain value is not supported (error BI1048: bgen: Unsupported type Boolean decorated with [BindAs]) + // ref/out nullable value is not supported (error BI1048: bgen: Unsupported type Boolean decorated with [BindAs]) + + // array of plain value + w.AppendLine (); + w.AppendLine ("\t\t[Sealed]"); + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Array\")]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[]))]"); + w.AppendLine ($"\t\t[NullAllowed]"); + w.AppendLine ($"\t\tNSNumber[] P{v.Managed}Array {{ get; set; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"get{v.Managed}Array\")]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}[]))]"); + w.AppendLine ($"\t\t[return: NullAllowed]"); + w.AppendLine ($"\t\tNSNumber[] Get{v.Managed}Array ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"set{v.Managed}Array:\")]"); + w.AppendLine ($"\t\tvoid Set{v.Managed}Array ([NullAllowed] [BindAs (typeof ({v.Managed}[]))] NSNumber[] value);"); + + // multidimensional array of plain value + // https://bugzilla.xamarin.com/show_bug.cgi?id=57795 + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}Multi1Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[,]))]"); + //w.AppendLine ($"\t\tNSNumber[,] P{v.Managed}Multi1ArrayValue {{ get; set; }}"); + + // BI1048: bgen: Unsupported type Boolean[][] decorated with [BindAs] + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}Multi2Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[][]))]"); + //w.AppendLine ($"\t\tNSNumber[][] P{v.Managed}Multi2ArrayValue {{ get; set; }}"); + + // array of nullable value + // https://bugzilla.xamarin.com/show_bug.cgi?id=57797 + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}NullableArray\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?[]))]"); + //w.AppendLine ($"\t\tNSNumber[] P{v.Managed}NullableArrayValue {{ get; set; }}"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[Export (\"get{v.Managed}NullableArray\")]"); + //w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}?[]))]"); + //w.AppendLine ($"\t\tNSNumber[] Get{v.Managed}NullableArrayValue ();"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[Export (\"set{v.Managed}NullableArray:\")]"); + //w.AppendLine ($"\t\tvoid Set{v.Managed}NullableArray ([BindAs (typeof ({v.Managed}?[]))] NSNumber[] value);"); + + // multidimensional array of nullable value + // https://bugzilla.xamarin.com/show_bug.cgi?id=57797 + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}NullableMulti1Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?[,]))]"); + //w.AppendLine ($"\t\tNSNumber[,] P{v.Managed}NullableMulti1ArrayValue {{ get; set; }}"); + + // BI1048: bgen: Unsupported type Nullable`1[][] decorated with [BindAs] + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}NullableMulti2Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?[][]))]"); + //w.AppendLine ($"\t\tNSNumber[][] P{v.Managed}NullableMulti2ArrayValue {{ get; set; }}"); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + w.AppendLine (); + } + + w.AppendLine ("\t\t// BindAs: NSValue"); + foreach (var v in bindas_nsvalue) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + // no BindAs + + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Value\")]"); + w.AppendLine ($"\t\tNSValue P{v.Managed}Value {{ get; set; }}"); + + // plain value + w.AppendLine (); + w.AppendLine ("\t\t[Sealed]"); + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Value\")]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}))]"); + w.AppendLine ($"\t\tNSValue P{v.Managed}ValueNonNullable {{ get; set; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"get{v.Managed}ValueNonNullable\")]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}))]"); + w.AppendLine ($"\t\t[return: NullAllowed] // This should be the default"); + w.AppendLine ($"\t\tNSValue Get{v.Managed}ValueNonNullable ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"set{v.Managed}ValueNonNullable:\")]"); + w.AppendLine ($"\t\tvoid Set{v.Managed}ValueNonNullable ([BindAs (typeof ({v.Managed}))] NSValue value);"); + + // nullable + + w.AppendLine (); + w.AppendLine ($"\t\t[Sealed]"); + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Value\")]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?))]"); + w.AppendLine ($"\t\t[NullAllowed] // This should be the default"); + w.AppendLine ($"\t\tNSValue P{v.Managed}ValueNullable {{ get; set; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"get{v.Managed}ValueNullable\")]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}?))]"); + w.AppendLine ($"\t\tNSValue Get{v.Managed}ValueNullable ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"set{v.Managed}ValueNullable:\")]"); + w.AppendLine ($"\t\tvoid Set{v.Managed}ValueNullable ([BindAs (typeof ({v.Managed}?))] [NullAllowed /* this should be the default */] NSValue value);"); + + // ref/out plain value is not supported (error BI1048: bgen: Unsupported type CATransform3D decorated with [BindAs]) + // ref/out nullable value is not supported (error BI1048: bgen: Unsupported type CATransform3D decorated with [BindAs]) + + // array of plain value + w.AppendLine (); + w.AppendLine ("\t\t[Sealed]"); + w.AppendLine ($"\t\t[Export (\"P{v.Managed}Array\")]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[]))]"); + w.AppendLine ($"\t\t[NullAllowed]"); + w.AppendLine ($"\t\tNSValue[] P{v.Managed}Array {{ get; set; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"get{v.Managed}Array\")]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}[]))]"); + w.AppendLine ($"\t\t[return: NullAllowed]"); + w.AppendLine ($"\t\tNSValue[] Get{v.Managed}Array ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"set{v.Managed}Array:\")]"); + w.AppendLine ($"\t\tvoid Set{v.Managed}Array ([NullAllowed] [BindAs (typeof ({v.Managed}[]))] NSValue[] value);"); + + // multidimensional array of plain value + // https://bugzilla.xamarin.com/show_bug.cgi?id=57795 + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}Multi1Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[,]))]"); + //w.AppendLine ($"\t\tNSValue[,] P{v.Managed}Multi1ArrayValue {{ get; set; }}"); + + // BI1048: bgen: Unsupported type CATransform3D[][] decorated with [BindAs] + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}Multi2Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[][]))]"); + //w.AppendLine ($"\t\tNSValue[][] P{v.Managed}Multi2ArrayValue {{ get; set; }}"); + + // array of nullable value + // https://bugzilla.xamarin.com/show_bug.cgi?id=57797 + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}NullableArray\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?[]))]"); + //w.AppendLine ($"\t\tNSValue[] P{v.Managed}NullableArrayValue {{ get; set; }}"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[Export (\"get{v.Managed}NullableArray\")]"); + //w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}?[]))]"); + //w.AppendLine ($"\t\tNSValue[] Get{v.Managed}NullableArrayValue ();"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[Export (\"set{v.Managed}NullableArray:\")]"); + //w.AppendLine ($"\t\tvoid Set{v.Managed}NullableArray ([BindAs (typeof ({v.Managed}?[]))] NSValue[] value);"); + + // multidimensional array of nullable value + // https://bugzilla.xamarin.com/show_bug.cgi?id=57797 + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}NullableMulti1Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?[,]))]"); + //w.AppendLine ($"\t\tNSValue[,] P{v.Managed}NullableMulti1 {{ get; set; }}"); + + // BI1048: bgen: Unsupported type Nullable`1[][] decorated with [BindAs] + //w.AppendLine (); + //w.AppendLine ("\t\t[Sealed]"); + //w.AppendLine ($"\t\t[Export (\"P{v.Managed}NullableMulti2Array\")]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?[][]))]"); + //w.AppendLine ($"\t\tNSValue[][] P{v.Managed}NullableMulti2ArrayValue {{ get; set; }}"); + + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + w.AppendLine (); + } + + w.AppendLine ("\t\t// BindAs: NSString"); + foreach (var v in bindas_nsstring) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + // plain value + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}))]"); + w.AppendLine ($"\t\t[Export (\"getSmart{v.Managed}Value\")]"); + w.AppendLine ($"\t\tNSString GetSmart{v.Managed}Value ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"setSmart{v.Managed}Value:\")]"); + w.AppendLine ($"\t\tvoid SetSmart{v.Managed}Value ([BindAs (typeof ({v.Managed}))] NSString value);"); + + w.AppendLine (); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}))]"); + w.AppendLine ($"\t\t[Export (\"PSmart{v.Managed}Property\")]"); + w.AppendLine ($"\t\tNSString PSmart{v.Managed}Property {{ get; set; }}"); + + // nullable + w.AppendLine (); + w.AppendLine ($"\t\t[return: NullAllowed]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}?))]"); + w.AppendLine ($"\t\t[Export (\"getSmartNullable{v.Managed}Value\")]"); + w.AppendLine ($"\t\tNSString GetSmartNullable{v.Managed}Value ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"setSmartNullable{v.Managed}Value:\")]"); + w.AppendLine ($"\t\tvoid SetSmartNullable{v.Managed}Value ([NullAllowed] [BindAs (typeof ({v.Managed}?))] NSString value);"); + + w.AppendLine (); + w.AppendLine ($"\t\t[NullAllowed]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?))]"); + w.AppendLine ($"\t\t[Export (\"smartNullable{v.Managed}Property\")]"); + w.AppendLine ($"\t\tNSString SmartNullable{v.Managed}Property {{ get; set; }}"); + + // array of plain value + w.AppendLine (); + w.AppendLine ($"\t\t[return: NullAllowed]"); + w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}[]))]"); + w.AppendLine ($"\t\t[Export (\"getSmart{v.Managed}Values\")]"); + w.AppendLine ($"\t\tNSString[] GetSmart{v.Managed}Values ();"); + + w.AppendLine (); + w.AppendLine ($"\t\t[Export (\"setSmart{v.Managed}Values:\")]"); + w.AppendLine ($"\t\tvoid SetSmart{v.Managed}Values ([NullAllowed] [BindAs (typeof ({v.Managed}[]))] NSString[] value);"); + + w.AppendLine (); + w.AppendLine ($"\t\t[NullAllowed]"); + w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[]))]"); + w.AppendLine ($"\t\t[Export (\"PSmart{v.Managed}Properties\")]"); + w.AppendLine ($"\t\tNSString[] PSmart{v.Managed}Properties {{ get; set; }}"); + + // array of nullable values + // https://bugzilla.xamarin.com/show_bug.cgi?id=57797 + //w.AppendLine (); + //w.AppendLine ($"\t\t[return: NullAllowed]"); + //w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}?[]))]"); + //w.AppendLine ($"\t\t[Export (\"getSmartNullable{v.Managed}Values\")]"); + //w.AppendLine ($"\t\tNSString[] GetSmartNullable{v.Managed}Values ();"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[Export (\"setSmartNullable{v.Managed}Values\")]"); + //w.AppendLine ($"\t\tvoid SetSmartNullable{v.Managed}Values ([NullAllowed] [BindAs (typeof ({v.Managed}?[]))] NSString[] value);"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[NullAllowed]"); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}?[]))]"); + //w.AppendLine ($"\t\t[Export (\"smartNullable{v.Managed}Properties:\")]"); + //w.AppendLine ($"\t\tNSString[] SmartNullable{v.Managed}Properties {{ get; set; }}"); + + // multidimensional array of plain value + // https://bugzilla.xamarin.com/show_bug.cgi?id=57795 + //w.AppendLine (); + //w.AppendLine ($"\t\t[return: BindAs (typeof ({v.Managed}[,]))]"); + //w.AppendLine ($"\t\t[Export (\"getSmart{v.Managed}ValuesMulti\")]"); + //w.AppendLine ($"\t\tNSString[,] GetSmart{v.Managed}ValuesMulti ();"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[Export (\"setSmart{v.Managed}ValuesMulti:\")]"); + //w.AppendLine ($"\t\tvoid SetSmart{v.Managed}ValuesMulti ([BindAs (typeof ({v.Managed}[]))] NSString[,] value);"); + + //w.AppendLine (); + //w.AppendLine ($"\t\t[BindAs (typeof ({v.Managed}[,]))]"); + //w.AppendLine ($"\t\t[Export (\"PSmart{v.Managed}PropertiesMulti:\")]"); + //w.AppendLine ($"\t\tNSString[,] PSmart{v.Managed}PropertiesMulti {{ get; set; }}"); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + w.AppendLine (); + } + + + // multi-dimensional array of plain value + w.AppendLine (@" } }"); @@ -224,10 +760,28 @@ namespace Bindings.Test { var w = new StringBuilder (); + WriteFrameworkDefines (w); w.AppendLine (@" +using System; #if XAMCORE_2_0 +using AVFoundation; +#if HAVE_COREANIMATION +using CoreAnimation; +#endif +using CoreGraphics; +using CoreLocation; +#if HAVE_COREMEDIA +using CoreMedia; +#endif using Foundation; +#if HAVE_MAPKIT +using MapKit; +#endif using ObjCRuntime; +using SceneKit; +#if HAVE_UIKIT +using UIKit; +#endif using MonoTouchException=ObjCRuntime.RuntimeException; using NativeException=Foundation.MonoTouchException; #else @@ -270,6 +824,572 @@ namespace MonoTouchFixtures.ObjCRuntime { w.AppendLine (); } + w.AppendLine ("\t\tinternal class BindAsTestClassGenerated : ObjCRegistrarTest {"); + + w.AppendLine ("\t\t\t// BindAs: NSNumber"); + foreach (var v in bindas_nsnumber) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + w.AppendLine ($"\t\t\t{v.Managed}? _{v.Managed};"); + w.AppendLine ($"\t\t\tpublic {v.Managed}? {v.Managed}Number {{ get {{ return _{v.Managed}; }} set {{ _{v.Managed} = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed}? Get{v.Managed}NumberNullable () {{ return _{v.Managed}; }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed} Get{v.Managed}NumberNonNullable () {{ return _{v.Managed}.Value; }}"); + w.AppendLine ($"\t\t\tpublic override void Set{v.Managed}NumberNullable ({v.Managed}? value) {{ _{v.Managed} = value; }}"); + w.AppendLine ($"\t\t\tpublic override void Set{v.Managed}NumberNonNullable ({v.Managed} value) {{ _{v.Managed} = value; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t\t{v.Managed}[] _{v.Managed}Array;"); + w.AppendLine ($"\t\t\tpublic {v.Managed}[] {v.Managed}Array {{ get {{ return _{v.Managed}Array; }} set {{ _{v.Managed}Array = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed}[] Get{v.Managed}Array () {{ return _{v.Managed}Array; }}"); + w.AppendLine ($"\t\t\tpublic override void Set{v.Managed}Array ({v.Managed}[] value) {{ _{v.Managed}Array = value; }}"); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + w.AppendLine (); + } + + w.AppendLine ("\t\t\t// BindAs: NSValue"); + foreach (var v in bindas_nsvalue) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + w.AppendLine ($"\t\t\t{v.Managed}? _{v.Managed};"); + w.AppendLine ($"\t\t\tpublic {v.Managed}? {v.Managed}Value {{ get {{ return _{v.Managed}; }} set {{ _{v.Managed} = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed}? Get{v.Managed}ValueNullable () {{ return _{v.Managed}; }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed} Get{v.Managed}ValueNonNullable () {{ return _{v.Managed}.Value; }}"); + w.AppendLine ($"\t\t\tpublic override void Set{v.Managed}ValueNullable ({v.Managed}? value) {{ _{v.Managed} = value; }}"); + w.AppendLine ($"\t\t\tpublic override void Set{v.Managed}ValueNonNullable ({v.Managed} value) {{ _{v.Managed} = value; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t\t{v.Managed}[] _{v.Managed}Array;"); + w.AppendLine ($"\t\t\tpublic {v.Managed}[] {v.Managed}Array {{ get {{ return _{v.Managed}Array; }} set {{ _{v.Managed}Array = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed}[] Get{v.Managed}Array () {{ return _{v.Managed}Array; }}"); + w.AppendLine ($"\t\t\tpublic override void Set{v.Managed}Array ({v.Managed}[] value) {{ _{v.Managed}Array = value; }}"); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + w.AppendLine (); + } + + w.AppendLine ("\t\t\t// BindAs: NSString"); + foreach (var v in bindas_nsstring) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + w.AppendLine ($"\t\t\t{v.Managed}? _{v.Managed};"); + w.AppendLine ($"\t\t\tpublic {v.Managed}? {v.Managed}Value {{ get {{ return _{v.Managed}; }} set {{ _{v.Managed} = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed} PSmart{v.Managed}Property {{ get {{ return {v.Managed}Value.Value; }} set {{ {v.Managed}Value = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed} GetSmart{v.Managed}Value () {{ return _{v.Managed}.Value; }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed}? GetSmartNullable{v.Managed}Value () {{ return _{v.Managed}; }}"); + w.AppendLine ($"\t\t\tpublic override void SetSmart{v.Managed}Value ({v.Managed} value) {{ _{v.Managed} = value; }}"); + w.AppendLine ($"\t\t\tpublic override void SetSmartNullable{v.Managed}Value ({v.Managed}? value) {{ _{v.Managed} = value; }}"); + + w.AppendLine (); + w.AppendLine ($"\t\t\t{v.Managed}[] _{v.Managed}Array;"); + w.AppendLine ($"\t\t\tpublic {v.Managed}[] {v.Managed}Array {{ get {{ return _{v.Managed}Array; }} set {{ _{v.Managed}Array = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed}[] PSmart{v.Managed}Properties {{ get {{ return _{v.Managed}Array; }} set {{ _{v.Managed}Array = value; }} }}"); + w.AppendLine ($"\t\t\tpublic override {v.Managed}[] GetSmart{v.Managed}Values () {{ return _{v.Managed}Array; }}"); + w.AppendLine ($"\t\t\tpublic override void SetSmart{v.Managed}Values ({v.Managed}[] value) {{ _{v.Managed}Array = value; }}"); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + w.AppendLine (); + } + w.AppendLine ("\t\t}"); + + foreach (var v in bindas_nsnumber) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + // Bindings + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSNumberBindAs_{v.Managed}_Bindings ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new ObjCRegistrarTest ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Number, \"initial null property\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}NumberNullable, \"initial nullable null property\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}NumberNullable (), \"initial null method\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\t{v.Managed}? value = default ({v.Managed});"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}NumberNonNullable (value.Value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.P{v.Managed}NumberNullable, \"nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.P{v.Managed}NumberNonNullable, \"non-nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.Get{v.Managed}NumberNullable (), \"nullable get method after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.Get{v.Managed}NumberNonNullable (), \"non-nullable get method after setting default value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}NumberNonNullable (value.Value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.P{v.Managed}NumberNullable, \"nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.P{v.Managed}NumberNonNullable, \"non-nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.Get{v.Managed}NumberNullable (), \"nullable get method after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.Get{v.Managed}NumberNonNullable (), \"non-nullable get method after setting custom value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = null;"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}NumberNullable (value);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Number, \"null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}NumberNullable, \"nullable null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}NumberNullable (), \"null method after setting null value\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + // Overrides + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSNumberBindAs_{v.Managed}_Overrides ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new BindAsTestClassGenerated ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Number, \"initial null\");"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}NumberNullable:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Number, \"null after setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Number = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}NumberNullable:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Number, \"null after re-setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvar value = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tusing (var input = new NSNumber (value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}NumberNullable:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.{v.Managed}Number, \"after setting A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Number = null;"); + w.AppendLine ($"\t\t\t\tusing (var input = new NSNumber (value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}NumberNonNullable:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.{v.Managed}Number.Value, \"after setting B\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Number = null;"); + w.AppendLine ($"\t\t\t\tvar number = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}NumberNullable\")));"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (number, \"null from getter A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Number = value;"); + w.AppendLine ($"\t\t\t\tnumber = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}NumberNullable\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, number{v.Map}, \"getter B\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Number = value;"); + w.AppendLine ($"\t\t\t\tnumber = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}NumberNonNullable\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, number{v.Map}, \"getter C\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + + // Array_Bindings + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSNumberBindAs_{v.Managed}Array_Bindings ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new ObjCRegistrarTest ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Array, \"initial null property\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}Array (), \"initial null method\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\t{v.Managed}[] value = null;"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}Array (value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.P{v.Managed}Array, \"nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.Get{v.Managed}Array (), \"nullable get method after setting default value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}Array (value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (1, obj.P{v.Managed}Array.Length, \"nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (1, obj.Get{v.Managed}Array ().Length, \"nullable get method after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.P{v.Managed}Array [0], \"nullable property after setting custom value element\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.Get{v.Managed}Array () [0], \"nullable get method after setting custom value element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = null;"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}Array (value);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Array, \"null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}Array (), \"null method after setting null value\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + // Array_Overrides + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSNumberBindAs_{v.Managed}_Array_Overrides ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new BindAsTestClassGenerated ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Array, \"initial null\");"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Array, \"null after setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Array, \"null after re-setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvar value = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tusing (var input = NSArray.FromNSObjects<{v.Managed}> ((v) => new NSNumber (v), value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, obj.{v.Managed}Array.Length, \"after setting A\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.{v.Managed}Array [0], \"after setting A element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = null;"); + w.AppendLine ($"\t\t\t\tusing (var input = NSArray.FromNSObjects<{v.Managed}> ((v) => new NSNumber (v), value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, obj.{v.Managed}Array.Length, \"after setting B\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.{v.Managed}Array [0], \"after setting B element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = null;"); + w.AppendLine ($"\t\t\t\tvar array = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}Array\")));"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (array, \"null from getter A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = value;"); + w.AppendLine ($"\t\t\t\tarray = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}Array\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, array.Count, \"getter B\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], array.GetItem (0){v.Map}, \"getter B element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + + w.AppendLine (); + } + + + foreach (var v in bindas_nsvalue) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + // Bindings + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSValueBindAs_{v.Managed}_Bindings ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new ObjCRegistrarTest ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Value, \"initial null property\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}ValueNullable, \"initial nullable null property\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}ValueNullable (), \"initial null method\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\t{v.Managed}? value = default ({v.Managed});"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}ValueNonNullable (value.Value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.P{v.Managed}ValueNullable, \"nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.P{v.Managed}ValueNonNullable, \"non-nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.Get{v.Managed}ValueNullable (), \"nullable get method after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.Get{v.Managed}ValueNonNullable (), \"non-nullable get method after setting default value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}ValueNonNullable (value.Value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.P{v.Managed}ValueNullable, \"nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.P{v.Managed}ValueNonNullable, \"non-nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.Get{v.Managed}ValueNullable (), \"nullable get method after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.Get{v.Managed}ValueNonNullable (), \"non-nullable get method after setting custom value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = null;"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}ValueNullable (value);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Value, \"null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}ValueNullable, \"nullable null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}ValueNullable (), \"null method after setting null value\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + // Overrides + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSValueBindAs_{v.Managed}_Overrides ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new BindAsTestClassGenerated ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Value, \"initial null\");"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}ValueNullable:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Value, \"null after setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Value = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}ValueNullable:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Value, \"null after re-setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvar value = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tusing (var input = NSValue.{v.MapFrom} (value))"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}ValueNullable:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.{v.Managed}Value, \"after setting A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Value = null;"); + w.AppendLine ($"\t\t\t\tusing (var input = NSValue.{v.MapFrom} (value))"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}ValueNonNullable:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.{v.Managed}Value, \"after setting B\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Value = null;"); + w.AppendLine ($"\t\t\t\tvar Value = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}ValueNullable\")));"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (Value, \"null from getter A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Value = value;"); + w.AppendLine ($"\t\t\t\tValue = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}ValueNullable\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, Value{v.Map}, \"getter B\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Value = value;"); + w.AppendLine ($"\t\t\t\tValue = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}ValueNonNullable\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, Value{v.Map}, \"getter C\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + + // Array_Bindings + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSValueBindAs_{v.Managed}Array_Bindings ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new ObjCRegistrarTest ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Array, \"initial null property\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}Array (), \"initial null method\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\t{v.Managed}[] value = null;"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}Array (value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.P{v.Managed}Array, \"nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.Get{v.Managed}Array (), \"nullable get method after setting default value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}Array (value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (1, obj.P{v.Managed}Array.Length, \"nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (1, obj.Get{v.Managed}Array ().Length, \"nullable get method after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.P{v.Managed}Array [0], \"nullable property after setting custom value element\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.Get{v.Managed}Array () [0], \"nullable get method after setting custom value element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = null;"); + w.AppendLine ($"\t\t\t\tobj.Set{v.Managed}Array (value);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.P{v.Managed}Array, \"null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.Get{v.Managed}Array (), \"null method after setting null value\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + // Array_Overrides + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSValueBindAs_{v.Managed}_Array_Overrides ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new BindAsTestClassGenerated ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Array, \"initial null\");"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Array, \"null after setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.{v.Managed}Array, \"null after re-setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvar value = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tusing (var input = NSArray.FromNSObjects<{v.Managed}> ((v) => NSValue.{v.MapFrom} (v), value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, obj.{v.Managed}Array.Length, \"after setting A\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.{v.Managed}Array [0], \"after setting A element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = null;"); + w.AppendLine ($"\t\t\t\tusing (var input = NSArray.FromNSObjects<{v.Managed}> ((v) => NSValue.{v.MapFrom} (v), value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"set{v.Managed}Array:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, obj.{v.Managed}Array.Length, \"after setting B\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.{v.Managed}Array [0], \"after setting B element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = null;"); + w.AppendLine ($"\t\t\t\tvar array = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}Array\")));"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (array, \"null from getter A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tobj.{v.Managed}Array = value;"); + w.AppendLine ($"\t\t\t\tarray = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"get{v.Managed}Array\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, array.Count, \"getter B\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], array.GetItem (0){v.Map}, \"getter B element\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + + w.AppendLine (); + } + + foreach (var v in bindas_nsstring) { + if (v.ManagedCondition != null) + w.AppendLine ($"#if {v.ManagedCondition}"); + + // Bindings + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSStringBindAs_{v.Managed}_Bindings ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new ObjCRegistrarTest ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.Throws (() => {{ Console.WriteLine (obj.PSmart{v.Managed}Property); }}, \"initial zero property\");"); + w.AppendLine ($"\t\t\t\tAssert.Throws (() => {{ Console.WriteLine (obj.GetSmart{v.Managed}Value ()); }}, \"initial zero method\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.GetSmartNullable{v.Managed}Value (), \"initial null method\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\t{v.Managed}? value = default ({v.Managed});"); + w.AppendLine ($"\t\t\t\tobj.SetSmartNullable{v.Managed}Value (value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.PSmart{v.Managed}Property, \"zero property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.GetSmart{v.Managed}Value (), \"non-nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.GetSmartNullable{v.Managed}Value (), \"nullable get method after setting default value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.SetSmart{v.Managed}Value (value.Value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.PSmart{v.Managed}Property, \"non-nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.GetSmartNullable{v.Managed}Value (), \"nullable get method after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Value, obj.GetSmart{v.Managed}Value (), \"non-nullable get method after setting custom value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = null;"); + w.AppendLine ($"\t\t\t\tobj.SetSmartNullable{v.Managed}Value (value);"); + w.AppendLine ($"\t\t\t\tAssert.Throws (() => {{ Console.WriteLine (obj.PSmart{v.Managed}Property); }}, \"null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.Throws (() => {{ Console.WriteLine (obj.GetSmart{v.Managed}Value ()); }}, \"non-nullable method after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.GetSmartNullable{v.Managed}Value (), \"null method after setting null value\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + // Overrides + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSStringBindAs_{v.Managed}_Overrides ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new BindAsTestClassGenerated ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.Throws (() => {{ Console.WriteLine (obj.PSmart{v.Managed}Property); }}, \"initial null\");"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmartNullable{v.Managed}Value:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.Throws (() => {{ Console.WriteLine (obj.PSmart{v.Managed}Property); }}, \"null after setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Property = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmartNullable{v.Managed}Value:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.Throws (() => {{ Console.WriteLine (obj.PSmart{v.Managed}Property); }}, \"null after re-setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvar value = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tusing (var input = value.GetConstant ())"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmartNullable{v.Managed}Value:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.PSmart{v.Managed}Property, \"after setting A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Property = 0;"); + w.AppendLine ($"\t\t\t\tusing (var input = value.GetConstant ())"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmart{v.Managed}Value:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.PSmart{v.Managed}Property, \"after setting B\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Property = 0;"); + w.AppendLine ($"\t\t\t\tvar Value = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"getSmartNullable{v.Managed}Value\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (default ({v.Managed}).GetConstant ().ToString (), Value.ToString (), \"zero from getter A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Property = value;"); + w.AppendLine ($"\t\t\t\tValue = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"getSmartNullable{v.Managed}Value\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, {v.Managed}Extensions.GetValue (Value), \"getter B\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = {v.ManagedNewExpression};"); + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Property = value;"); + w.AppendLine ($"\t\t\t\tValue = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"getSmart{v.Managed}Value\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, {v.Managed}Extensions.GetValue (Value), \"getter C\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + + // Array_Bindings + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSStringBindAs_{v.Managed}Array_Bindings ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new ObjCRegistrarTest ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.PSmart{v.Managed}Properties, \"initial null property\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.GetSmart{v.Managed}Values (), \"initial null method\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\t{v.Managed}[] value = null;"); + w.AppendLine ($"\t\t\t\tobj.SetSmart{v.Managed}Values (value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.PSmart{v.Managed}Properties, \"nullable property after setting default value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value, obj.GetSmart{v.Managed}Values (), \"nullable get method after setting default value\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tobj.SetSmart{v.Managed}Values (value);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (1, obj.PSmart{v.Managed}Properties.Length, \"nullable property after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (1, obj.GetSmart{v.Managed}Values ().Length, \"nullable get method after setting custom value\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.PSmart{v.Managed}Properties [0], \"nullable property after setting custom value element\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.GetSmart{v.Managed}Values () [0], \"nullable get method after setting custom value element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = null;"); + w.AppendLine ($"\t\t\t\tobj.SetSmart{v.Managed}Values (value);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.PSmart{v.Managed}Properties, \"null property after setting null value\");"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.GetSmart{v.Managed}Values (), \"null method after setting null value\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + // Array_Overrides + w.AppendLine ("\t\t[Test]"); + w.AppendLine ($"\t\tpublic void NSStringBindAs_{v.Managed}_Array_Overrides ()"); + w.AppendLine ("\t\t{"); + w.AppendLine ($"\t\t\tusing (var obj = new BindAsTestClassGenerated ()) {{"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.PSmart{v.Managed}Properties, \"initial null\");"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmart{v.Managed}Values:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.PSmart{v.Managed}Properties, \"null after setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Properties = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmart{v.Managed}Values:\"), IntPtr.Zero);"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (obj.PSmart{v.Managed}Properties, \"null after re-setting null\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvar value = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tusing (var input = NSArray.FromNSObjects<{v.Managed}> ((v) => v.GetConstant (), value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmart{v.Managed}Values:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, obj.PSmart{v.Managed}Properties.Length, \"after setting A\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.PSmart{v.Managed}Properties [0], \"after setting A element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Properties = null;"); + w.AppendLine ($"\t\t\t\tusing (var input = NSArray.FromNSObjects<{v.Managed}> ((v) => v.GetConstant (), value))"); + w.AppendLine ($"\t\t\t\t\tMessaging.void_objc_msgSend_IntPtr (obj.Handle, Selector.GetHandle (\"setSmart{v.Managed}Values:\"), input.Handle);"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, obj.PSmart{v.Managed}Properties.Length, \"after setting B\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], obj.PSmart{v.Managed}Properties [0], \"after setting B element\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Properties = null;"); + w.AppendLine ($"\t\t\t\tvar array = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"getSmart{v.Managed}Values\")));"); + w.AppendLine ($"\t\t\t\tAssert.IsNull (array, \"null from getter A\");"); + w.AppendLine (); + + w.AppendLine ($"\t\t\t\tvalue = new {v.Managed} [] {{ {v.ManagedNewExpression} }};"); + w.AppendLine ($"\t\t\t\tobj.PSmart{v.Managed}Properties = value;"); + w.AppendLine ($"\t\t\t\tarray = Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle (\"getSmart{v.Managed}Values\")));"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value.Length, array.Count, \"getter B\");"); + w.AppendLine ($"\t\t\t\tAssert.AreEqual (value [0], {v.Managed}Extensions.GetValue (array.GetItem (0)), \"getter B element\");"); + w.AppendLine ($"\t\t\t}}"); + w.AppendLine ("\t\t}"); + w.AppendLine (); + + if (v.ManagedCondition != null) + w.AppendLine ("#endif"); + + w.AppendLine (); + } + w.AppendLine (@" } }"); @@ -524,6 +1644,8 @@ namespace MonoTouchFixtures.ObjCRuntime { WriteLibTestStructH (); WriteLibTestDecompileM (); WriteLibTestPropertiesH (); + WriteLibTestMethodsH (); + WriteLibTestMethodsM (); /* binding code */ WriteApiDefinition (); diff --git a/tests/tests.sln b/tests/tests.sln index ac36fbc5d2..b433295466 100644 --- a/tests/tests.sln +++ b/tests/tests.sln @@ -69,6 +69,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mscorlib-0", "bcl-test\msco EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mscorlib-1", "bcl-test\mscorlib\mscorlib-1.csproj", "{6F47C092-2F85-43D6-2222-E687426F6BF3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testgenerator", "test-libraries\testgenerator.csproj", "{CD430449-8E59-4ECD-ADD9-ACF79E9E660B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|iPhoneSimulator = Debug|iPhoneSimulator @@ -758,5 +760,31 @@ Global {6F47C092-2F85-43D6-2222-E687426F6BF3}.Release32|iPhone.Build.0 = Release|Any CPU {6F47C092-2F85-43D6-2222-E687426F6BF3}.Release64|iPhone.ActiveCfg = Release|Any CPU {6F47C092-2F85-43D6-2222-E687426F6BF3}.Release64|iPhone.Build.0 = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug|iPhone.Build.0 = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release|iPhone.ActiveCfg = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release|iPhone.Build.0 = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release-bitcode|iPhone.ActiveCfg = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release-bitcode|iPhone.Build.0 = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release|Any CPU.Build.0 = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release-bitcode|Any CPU.ActiveCfg = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release-bitcode|Any CPU.Build.0 = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release-bitcode|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release-bitcode|iPhoneSimulator.Build.0 = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug32|iPhone.ActiveCfg = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug32|iPhone.Build.0 = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug64|iPhone.ActiveCfg = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Debug64|iPhone.Build.0 = Debug|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release32|iPhone.ActiveCfg = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release32|iPhone.Build.0 = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release64|iPhone.ActiveCfg = Release|Any CPU + {CD430449-8E59-4ECD-ADD9-ACF79E9E660B}.Release64|iPhone.Build.0 = Release|Any CPU EndGlobalSection EndGlobal