Skip to content

Commit 1783ce0

Browse files
committed
Re-enable XamarinAndroid code target and update tests.
1 parent 03b9312 commit 1783ce0

27 files changed

+1808
-1350
lines changed

tests/generator-Tests/Integration-Tests/BaseGeneratorTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private byte[] ReadAllBytesIgnoringLineEndings (string path)
121121

122122
protected void RunAllTargets (string outputRelativePath, string apiDescriptionFile, string expectedRelativePath, string[] additionalSupportPaths = null, string enumFieldsMapFile = null, string enumMethodMapFile = null)
123123
{
124-
//Run (CodeGenerationTarget.XamarinAndroid, Path.Combine ("out", outputRelativePath), apiDescriptionFile, Path.Combine ("expected", expectedRelativePath), additionalSupportPaths, enumFieldsMapFile, enumMethodMapFile);
124+
Run (CodeGenerationTarget.XamarinAndroid, Path.Combine ("out", outputRelativePath), apiDescriptionFile, Path.Combine ("expected", expectedRelativePath), additionalSupportPaths, enumFieldsMapFile, enumMethodMapFile);
125125
Run (CodeGenerationTarget.JavaInterop1, Path.Combine ("out.ji", outputRelativePath), apiDescriptionFile, Path.Combine ("expected.ji", expectedRelativePath), additionalSupportPaths, enumFieldsMapFile, enumMethodMapFile);
126126
}
127127

tests/generator-Tests/Integration-Tests/Enumerations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace generatortests
77
[TestFixture]
88
public class Enumerations : BaseGeneratorTest
99
{
10-
//[Test]
10+
[Test]
1111
public void FixedUp_OK ()
1212
{
1313
Cleanup ("out/EnumerationFixup");

tests/generator-Tests/Integration-Tests/Java_Lang_Object.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ public class Java_Lang_Object : BaseGeneratorTest
1212
[Test]
1313
public void Generated_OK ()
1414
{
15-
//Run (target: Xamarin.Android.Binder.CodeGenerationTarget.XamarinAndroid,
16-
// outputPath: "out/java.lang.Object",
17-
// apiDescriptionFile: "expected/java.lang.Object/java.lang.Object.xml",
18-
// expectedPath: "expected/java.lang.Object");
15+
Run (target: Xamarin.Android.Binder.CodeGenerationTarget.XamarinAndroid,
16+
outputPath: "out/java.lang.Object",
17+
apiDescriptionFile: "expected/java.lang.Object/java.lang.Object.xml",
18+
expectedPath: "expected/java.lang.Object");
1919

20-
//var javaLangObject = BuiltAssembly.GetType ("Java.Lang.Object");
20+
var javaLangObject = BuiltAssembly.GetType ("Java.Lang.Object");
2121

22-
//Assert.IsNotNull (javaLangObject);
23-
//Assert.IsTrue (javaLangObject.IsPublic);
24-
//Assert.IsTrue (javaLangObject.FullName == "Java.Lang.Object");
25-
//Assert.IsTrue (javaLangObject.GetCustomAttributes (false).Any (x => x.GetType ().Name == "RegisterAttribute"));
22+
Assert.IsNotNull (javaLangObject);
23+
Assert.IsTrue (javaLangObject.IsPublic);
24+
Assert.IsTrue (javaLangObject.FullName == "Java.Lang.Object");
25+
Assert.IsTrue (javaLangObject.GetCustomAttributes (false).Any (x => x.GetType ().Name == "RegisterAttribute"));
2626

2727
Run (target: Xamarin.Android.Binder.CodeGenerationTarget.JavaInterop1,
2828
outputPath: "out.ji/java.lang.Object",

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/Common/WriteInterfaceRedeclaredDefaultMethod.txt

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,80 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface2']"
22
[Register ("java/code/IMyInterface2", "", "java.code.IMyInterface2Invoker")]
33
public partial interface IMyInterface2 : java.code.IMyInterface {
4-
54
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]"
65
[Register ("DoSomething", "()V", "GetDoSomethingHandler:java.code.IMyInterface2Invoker, MyAssembly")]
76
void DoSomething ();
8-
7+
8+
}
9+
[global::Android.Runtime.Register ("java/code/IMyInterface2", DoNotGenerateAcw=true)]
10+
internal partial class IMyInterface2Invoker : global::Java.Lang.Object, IMyInterface2 {
11+
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface2", typeof (IMyInterface2Invoker));
12+
13+
static IntPtr java_class_ref {
14+
get { return _members.JniPeerType.PeerReference.Handle; }
15+
}
16+
17+
public override global::Java.Interop.JniPeerMembers JniPeerMembers {
18+
get { return _members; }
19+
}
20+
21+
protected override IntPtr ThresholdClass {
22+
get { return class_ref; }
23+
}
24+
25+
protected override global::System.Type ThresholdType {
26+
get { return _members.ManagedPeerType; }
27+
}
28+
29+
IntPtr class_ref;
30+
31+
public static IMyInterface2 GetObject (IntPtr handle, JniHandleOwnership transfer)
32+
{
33+
return global::Java.Lang.Object.GetObject<IMyInterface2> (handle, transfer);
34+
}
35+
36+
static IntPtr Validate (IntPtr handle)
37+
{
38+
if (!JNIEnv.IsInstanceOf (handle, java_class_ref))
39+
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface2"));
40+
return handle;
41+
}
42+
43+
protected override void Dispose (bool disposing)
44+
{
45+
if (this.class_ref != IntPtr.Zero)
46+
JNIEnv.DeleteGlobalRef (this.class_ref);
47+
this.class_ref = IntPtr.Zero;
48+
base.Dispose (disposing);
49+
}
50+
51+
public IMyInterface2Invoker (IntPtr handle, JniHandleOwnership transfer) : base (Validate (handle), transfer)
52+
{
53+
IntPtr local_ref = JNIEnv.GetObjectClass (((global::Java.Lang.Object) this).Handle);
54+
this.class_ref = JNIEnv.NewGlobalRef (local_ref);
55+
JNIEnv.DeleteLocalRef (local_ref);
56+
}
57+
58+
static Delegate cb_DoSomething;
59+
#pragma warning disable 0169
60+
static Delegate GetDoSomethingHandler ()
61+
{
62+
if (cb_DoSomething == null)
63+
cb_DoSomething = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_DoSomething);
64+
return cb_DoSomething;
65+
}
66+
static void n_DoSomething (IntPtr jnienv, IntPtr native__this)
67+
{
68+
var __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface2> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
69+
__this.DoSomething ();
70+
}
71+
#pragma warning restore 0169
72+
IntPtr id_DoSomething;
73+
public unsafe void DoSomething ()
74+
{
75+
if (id_DoSomething == IntPtr.Zero)
76+
id_DoSomething = JNIEnv.GetMethodID (class_ref, "DoSomething", "()V");
77+
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_DoSomething);
78+
}
79+
980
}
10-

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteDefaultInterfaceMethodInvoker.txt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
1+
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
2+
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
3+
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
4+
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
5+
6+
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoDeclaration' and count(parameter)=0]"
7+
[Register ("DoDeclaration", "()V", "GetDoDeclarationHandler:java.code.IMyInterfaceInvoker, MyAssembly")]
8+
void DoDeclaration ();
9+
10+
private static Delegate cb_DoDefault;
11+
#pragma warning disable 0169
12+
private static Delegate GetDoDefaultHandler ()
13+
{
14+
if (cb_DoDefault == null)
15+
cb_DoDefault = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_DoDefault);
16+
return cb_DoDefault;
17+
}
18+
private static void n_DoDefault (IntPtr jnienv, IntPtr native__this)
19+
{
20+
var __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
21+
__this.DoDefault ();
22+
}
23+
#pragma warning restore 0169
24+
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoDefault' and count(parameter)=0]"
25+
[Register ("DoDefault", "()V", "GetDoDefaultHandler:java.code.IMyInterface, MyAssembly")]
26+
virtual unsafe void DoDefault ()
27+
{
28+
const string __id = "DoDefault.()V";
29+
try {
30+
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null);
31+
} finally {
32+
}
33+
}
34+
35+
}
136
[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
237
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface {
3-
438
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker));
539

640
static IntPtr java_class_ref {

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDeclaration.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']"
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
3-
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
3+
public partial interface IMyInterface : IJavaObject {
44

55
int Count {
66
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Count' and count(parameter)=0]"

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDefaultMethod.txt

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,80 @@
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
44
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
5-
5+
66
private static Delegate cb_DoSomething;
7-
#pragma warning disable 0169
7+
#pragma warning disable 0169
88
private static Delegate GetDoSomethingHandler ()
99
{
1010
if (cb_DoSomething == null)
1111
cb_DoSomething = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_V) n_DoSomething);
1212
return cb_DoSomething;
1313
}
14-
1514
private static void n_DoSomething (IntPtr jnienv, IntPtr native__this)
1615
{
1716
var __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1817
__this.DoSomething ();
1918
}
20-
#pragma warning restore 0169
21-
19+
#pragma warning restore 0169
2220
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]"
2321
[Register ("DoSomething", "()V", "GetDoSomethingHandler:java.code.IMyInterface, MyAssembly")]
24-
virtual unsafe void DoSomething ()
22+
virtual unsafe void DoSomething ()
2523
{
2624
const string __id = "DoSomething.()V";
2725
try {
28-
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null);
26+
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null);
2927
} finally {
3028
}
3129
}
32-
30+
31+
}
32+
[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
33+
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface {
34+
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker));
35+
36+
static IntPtr java_class_ref {
37+
get { return _members.JniPeerType.PeerReference.Handle; }
38+
}
39+
40+
public override global::Java.Interop.JniPeerMembers JniPeerMembers {
41+
get { return _members; }
42+
}
43+
44+
protected override IntPtr ThresholdClass {
45+
get { return class_ref; }
46+
}
47+
48+
protected override global::System.Type ThresholdType {
49+
get { return _members.ManagedPeerType; }
50+
}
51+
52+
IntPtr class_ref;
53+
54+
public static IMyInterface GetObject (IntPtr handle, JniHandleOwnership transfer)
55+
{
56+
return global::Java.Lang.Object.GetObject<IMyInterface> (handle, transfer);
57+
}
58+
59+
static IntPtr Validate (IntPtr handle)
60+
{
61+
if (!JNIEnv.IsInstanceOf (handle, java_class_ref))
62+
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
63+
return handle;
64+
}
65+
66+
protected override void Dispose (bool disposing)
67+
{
68+
if (this.class_ref != IntPtr.Zero)
69+
JNIEnv.DeleteGlobalRef (this.class_ref);
70+
this.class_ref = IntPtr.Zero;
71+
base.Dispose (disposing);
72+
}
73+
74+
public IMyInterfaceInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Validate (handle), transfer)
75+
{
76+
IntPtr local_ref = JNIEnv.GetObjectClass (((global::Java.Lang.Object) this).Handle);
77+
this.class_ref = JNIEnv.NewGlobalRef (local_ref);
78+
JNIEnv.DeleteLocalRef (local_ref);
79+
}
80+
3381
}
34-

tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDefaultProperty.txt

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,43 @@
22
[Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")]
33
public partial interface IMyInterface : IJavaObject, IJavaPeerable {
44
private static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true);
5-
5+
66
private static Delegate cb_get_Value;
7-
#pragma warning disable 0169
7+
#pragma warning disable 0169
88
private static Delegate Getget_ValueHandler ()
99
{
1010
if (cb_get_Value == null)
1111
cb_get_Value = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_I) n_get_Value);
1212
return cb_get_Value;
1313
}
14-
1514
private static int n_get_Value (IntPtr jnienv, IntPtr native__this)
1615
{
1716
var __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
1817
return __this.Value;
1918
}
20-
#pragma warning restore 0169
21-
19+
#pragma warning restore 0169
2220
private static Delegate cb_set_Value_I;
23-
#pragma warning disable 0169
21+
#pragma warning disable 0169
2422
private static Delegate Getset_Value_IHandler ()
2523
{
2624
if (cb_set_Value_I == null)
2725
cb_set_Value_I = JNINativeWrapper.CreateDelegate ((_JniMarshal_PPI_V) n_set_Value_I);
2826
return cb_set_Value_I;
2927
}
30-
3128
private static void n_set_Value_I (IntPtr jnienv, IntPtr native__this, int value)
3229
{
3330
var __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);
3431
__this.Value = value;
3532
}
36-
#pragma warning restore 0169
37-
38-
virtual unsafe int Value {
33+
#pragma warning restore 0169
34+
virtual unsafe int Value {
3935
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Value' and count(parameter)=0]"
4036
[Register ("get_Value", "()I", "Getget_ValueHandler:java.code.IMyInterface, MyAssembly")]
4137
get {
4238
const string __id = "get_Value.()I";
4339
try {
44-
var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null);
45-
return __rm;
40+
var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null);
41+
return __rm;
4642
} finally {
4743
}
4844
}
@@ -51,13 +47,62 @@ public partial interface IMyInterface : IJavaObject, IJavaPeerable {
5147
set {
5248
const string __id = "set_Value.(I)V";
5349
try {
54-
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
55-
__args [0] = new JniArgumentValue (value);
56-
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
50+
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
51+
__args [0] = new JniArgumentValue (value);
52+
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args);
5753
} finally {
5854
}
5955
}
6056
}
61-
57+
58+
}
59+
[global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)]
60+
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface {
61+
static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker));
62+
63+
static IntPtr java_class_ref {
64+
get { return _members.JniPeerType.PeerReference.Handle; }
65+
}
66+
67+
public override global::Java.Interop.JniPeerMembers JniPeerMembers {
68+
get { return _members; }
69+
}
70+
71+
protected override IntPtr ThresholdClass {
72+
get { return class_ref; }
73+
}
74+
75+
protected override global::System.Type ThresholdType {
76+
get { return _members.ManagedPeerType; }
77+
}
78+
79+
IntPtr class_ref;
80+
81+
public static IMyInterface GetObject (IntPtr handle, JniHandleOwnership transfer)
82+
{
83+
return global::Java.Lang.Object.GetObject<IMyInterface> (handle, transfer);
84+
}
85+
86+
static IntPtr Validate (IntPtr handle)
87+
{
88+
if (!JNIEnv.IsInstanceOf (handle, java_class_ref))
89+
throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", JNIEnv.GetClassNameFromInstance (handle), "java.code.IMyInterface"));
90+
return handle;
91+
}
92+
93+
protected override void Dispose (bool disposing)
94+
{
95+
if (this.class_ref != IntPtr.Zero)
96+
JNIEnv.DeleteGlobalRef (this.class_ref);
97+
this.class_ref = IntPtr.Zero;
98+
base.Dispose (disposing);
99+
}
100+
101+
public IMyInterfaceInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Validate (handle), transfer)
102+
{
103+
IntPtr local_ref = JNIEnv.GetObjectClass (((global::Java.Lang.Object) this).Handle);
104+
this.class_ref = JNIEnv.NewGlobalRef (local_ref);
105+
JNIEnv.DeleteLocalRef (local_ref);
106+
}
107+
62108
}
63-

0 commit comments

Comments
 (0)