[tests] Add mtouch tests for the BindAs attribute.

This commit is contained in:
Rolf Bjarne Kvinge 2017-07-03 19:16:53 +02:00
Родитель fecf315fab
Коммит eea87f4889
2 изменённых файлов: 97 добавлений и 0 удалений

Просмотреть файл

@ -154,6 +154,18 @@ namespace Xamarin.Tests
return false;
}
public int ErrorCount {
get {
return messages.Count ((v) => v.IsError);
}
}
public int WarningCount {
get {
return messages.Count ((v) => v.IsWarning);
}
}
public bool HasError (string prefix, int number, string message)
{
foreach (var msg in messages) {
@ -163,6 +175,11 @@ namespace Xamarin.Tests
return false;
}
public void AssertErrorCount (int count, string message = "errors")
{
Assert.AreEqual (count, ErrorCount, message);
}
public void AssertErrorPattern (int number, string messagePattern)
{
AssertErrorPattern (MessagePrefix, number, messagePattern);

Просмотреть файл

@ -720,6 +720,86 @@ class X : ReplayKit.RPBroadcastControllerDelegate
}
}
[Test]
public void MT4170 ()
{
using (var mtouch = new MTouchTool ()) {
var code = @"
namespace NS {
using System;
using Foundation;
using ObjCRuntime;
class X : NSObject {
[Export (""a"")]
[return: BindAs (typeof (ConsoleColor), OriginalType = typeof (NSNumber))]
ConsoleColor A () { throw new NotImplementedException (); }
[Export (""b"")]
[return: BindAs (typeof (ConsoleColor?), OriginalType = typeof (NSNumber))]
ConsoleColor? B () { throw new NotImplementedException (); }
}
}";
mtouch.Linker = MTouchLinker.DontLink; // faster
mtouch.Registrar = MTouchRegistrar.Static;
mtouch.CreateTemporaryApp (extraCode: code, extraArg: "-debug");
mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build");
mtouch.AssertError (4170, "The registrar can't convert from 'System.ConsoleColor' to 'Foundation.NSNumber' for the return value in the method NS.X.A.", "testApp.cs", 9);
mtouch.AssertError (4170, "The registrar can't convert from 'System.Nullable`1<System.ConsoleColor>' to 'Foundation.NSNumber' for the return value in the method NS.X.B.", "testApp.cs", 12);
mtouch.AssertErrorCount (4 /* errors are duplicated */);
}
}
[Test]
public void MT4172 ()
{
using (var mtouch = new MTouchTool ()) {
var code = @"
namespace NS {
using System;
using Foundation;
using ObjCRuntime;
class X : NSObject {
[Export (""a:"")]
void A ([BindAs (typeof (ConsoleColor), OriginalType = typeof (NSNumber))] ConsoleColor value) {}
[Export (""b:"")]
void B ([BindAs (typeof (ConsoleColor?), OriginalType = typeof (NSNumber))] ConsoleColor? value) {}
[Export (""d:"")]
void D ([BindAs (typeof (int?[]), OriginalType = typeof (NSNumber[]))] int?[] value) {}
[Export (""e:"")]
void E ([BindAs (typeof (int), OriginalType = typeof (NSNumber))] ref int value) {}
[Export (""f:"")]
void F ([BindAs (typeof (int), OriginalType = typeof (NSNumber))] out int value) { throw new NotImplementedException (); }
[Export (""g:"")]
void G ([BindAs (typeof (int[,]), OriginalType = typeof (NSNumber[,]))] int[,] value) {}
[Export (""h:"")]
void H ([BindAs (typeof (int?[,]), OriginalType = typeof (NSNumber[,]))] int?[,] value) {}
}
enum E {
V,
}
class EClass : NSObject {
[Export (""a:"")]
void A ([BindAs (typeof (E), OriginalType = typeof (NSString))] E value) {}
[Export (""d:"")]
void D ([BindAs (typeof (E?[]), OriginalType = typeof (NSString[]))] E?[] value) {}
}
}";
mtouch.Linker = MTouchLinker.DontLink; // faster
mtouch.Registrar = MTouchRegistrar.Static;
mtouch.CreateTemporaryApp (extraCode: code, extraArg: "-debug");
mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build");
mtouch.AssertError (4172, "The registrar can't convert from 'System.ConsoleColor' to 'Foundation.NSNumber' for the parameter 'value' in the method NS.X.A.", "testApp.cs", 8);
mtouch.AssertError (4172, "The registrar can't convert from 'System.Nullable`1<System.ConsoleColor>' to 'Foundation.NSNumber' for the parameter 'value' in the method NS.X.B.", "testApp.cs", 10);
mtouch.AssertError (4172, "The registrar can't convert from 'System.Nullable`1<System.Int32>[]' to 'Foundation.NSNumber[]' for the parameter 'value' in the method NS.X.D.", "testApp.cs", 12);
mtouch.AssertError (4172, "The registrar can't convert from 'System.Int32&' to 'Foundation.NSNumber' for the parameter 'value' in the method NS.X.E.", "testApp.cs", 14);
mtouch.AssertError (4172, "The registrar can't convert from 'System.Int32&' to 'Foundation.NSNumber' for the parameter 'value' in the method NS.X.F.", "testApp.cs", 16);
mtouch.AssertError (4172, "The registrar can't convert from 'System.Int32[0...,0...]' to 'Foundation.NSNumber[,]' for the parameter 'value' in the method NS.X.G.", "testApp.cs", 18);
mtouch.AssertError (4172, "The registrar can't convert from 'System.Nullable`1<System.Int32>[0...,0...]' to 'Foundation.NSNumber[,]' for the parameter 'value' in the method NS.X.H.", "testApp.cs", 20);
mtouch.AssertError (4172, "The registrar can't convert from 'NS.E' to 'Foundation.NSString' for the parameter 'value' in the method NS.EClass.A.", "testApp.cs", 27);
mtouch.AssertError (4172, "The registrar can't convert from 'System.Nullable`1<NS.E>[]' to 'Foundation.NSString[]' for the parameter 'value' in the method NS.EClass.D.", "testApp.cs", 29);
mtouch.AssertErrorCount (9);
}
}
[Test]
public void NoWarnings ()
{