|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Linq;
|
| 4 | +using generator.SourceWriters; |
4 | 5 | using MonoDroid.Generation;
|
5 | 6 | using NUnit.Framework;
|
6 | 7 | using Xamarin.Android.Binder;
|
| 8 | +using Xamarin.SourceWriter; |
7 | 9 |
|
8 | 10 | namespace generatortests
|
9 | 11 | {
|
@@ -1271,5 +1273,55 @@ public void WriteClassInternalBase ()
|
1271 | 1273 | Assert.True (result.Contains ("internal static new IntPtr class_ref".NormalizeLineEndings ()));
|
1272 | 1274 | Assert.False (result.Contains ("internal static IntPtr class_ref".NormalizeLineEndings ()));
|
1273 | 1275 | }
|
| 1276 | + |
| 1277 | + [Test] |
| 1278 | + public void WriteBoundMethodAbstractDeclarationWithGenericReturn () |
| 1279 | + { |
| 1280 | + // Fix a case where the ReturnType of a class method implementing a generic interface method |
| 1281 | + // that has a generic parameter type return (like T) wasn't getting set, resulting in a NRE. |
| 1282 | + var gens = ParseApiDefinition (@"<api> |
| 1283 | + <package name='java.lang' jni-name='java/lang'> |
| 1284 | + <class abstract='false' deprecated='not deprecated' final='false' name='Object' static='false' visibility='public' jni-signature='Ljava/lang/Object;' /> |
| 1285 | + <interface abstract='false' deprecated='not deprecated' final='false' name='Comparable' static='false' visibility='public' jni-signature='Ljava/lang/Double;' /> |
| 1286 | + </package> |
| 1287 | +
|
| 1288 | + <package name='com.example' jni-name='com/example'> |
| 1289 | + <interface abstract='true' deprecated='not deprecated' final='false' name='FlowIterator' static='false' visibility='public' jni-signature='Lcom/example/FlowIterator;'> |
| 1290 | + <typeParameters> |
| 1291 | + <typeParameter name='R' classBound='java.lang.Object' jni-classBound='Ljava/lang/Object;'></typeParameter> |
| 1292 | + </typeParameters> |
| 1293 | + <method abstract='true' deprecated='not deprecated' final='false' name='next' jni-signature='()Ljava/lang/Object;' bridge='false' native='false' return='R' jni-return='TR;' static='false' synchronized='false' synthetic='false' visibility='public' /> |
| 1294 | + </interface> |
| 1295 | + <class abstract='true' deprecated='not deprecated' extends='java.lang.Object' extends-generic-aware='java.lang.Object' jni-extends='Ljava/lang/Object;' final='false' name='FlowIterator.RangeIterator' static='true' visibility='public' jni-signature='Lcom/example/FlowIterator$RangeIterator;'> |
| 1296 | + <implements name='com.example.FlowIterator' name-generic-aware='com.example.FlowIterator<T>' jni-type='Lcom/example/FlowIterator<TT;>;'></implements> |
| 1297 | + <typeParameters> |
| 1298 | + <typeParameter name='T' interfaceBounds='java.lang.Comparable<T>' jni-interfaceBounds='Ljava/lang/Comparable<TT;>;'> |
| 1299 | + <genericConstraints> |
| 1300 | + <genericConstraint type='java.lang.Comparable<T>'></genericConstraint> |
| 1301 | + </genericConstraints> |
| 1302 | + </typeParameter> |
| 1303 | + </typeParameters> |
| 1304 | + <method abstract='false' deprecated='not deprecated' final='false' name='next' jni-signature='()Ljava/lang/Comparable;' bridge='false' native='false' return='T' jni-return='TT;' static='false' synchronized='false' synthetic='false' visibility='public' /> |
| 1305 | + </class> |
| 1306 | + </package> |
| 1307 | + </api>"); |
| 1308 | + |
| 1309 | + var declIface = gens.OfType<InterfaceGen> ().Single (c => c.Name == "IFlowIterator"); |
| 1310 | + var declClass = declIface.NestedTypes.OfType<ClassGen> ().Single (c => c.Name == "FlowIteratorRangeIterator"); |
| 1311 | + var method = declClass.Methods.Single (); |
| 1312 | + |
| 1313 | + var bmad = new BoundMethodAbstractDeclaration (declClass, method, options, null); |
| 1314 | + var source_writer = new CodeWriter (writer); |
| 1315 | + |
| 1316 | + bmad.Write (source_writer); |
| 1317 | + |
| 1318 | + var expected = @"Java.Lang.Object Com.Example.FlowIteratorRangeIterator.Next () |
| 1319 | + { |
| 1320 | + throw new NotImplementedException (); |
| 1321 | + }"; |
| 1322 | + |
| 1323 | + // Ignore nullable operator so this test works on all generators ;) |
| 1324 | + Assert.AreEqual (expected.NormalizeLineEndings (), writer.ToString ().NormalizeLineEndings ().Replace ("?", "")); |
| 1325 | + } |
1274 | 1326 | }
|
1275 | 1327 | }
|
0 commit comments