|
1 | 1 | using System;
|
2 | 2 | using System.Linq;
|
| 3 | +using System.Text; |
| 4 | +using System.Xml; |
3 | 5 | using Java.Interop.Tools.JavaTypeSystem.Models;
|
4 | 6 | using NUnit.Framework;
|
5 | 7 |
|
@@ -83,5 +85,57 @@ public void GenericConstructors ()
|
83 | 85 | var m = t.Constructors.FirstOrDefault ();
|
84 | 86 | Assert.IsNotNull (m.TypeParameters, "constructor not found");
|
85 | 87 | }
|
| 88 | + |
| 89 | + [Test] |
| 90 | + public void PreferRealApi () |
| 91 | + { |
| 92 | + // Our base method is abstract, and our derived method is not. However their is also a "matching" non-abstract |
| 93 | + // base method that is "synthetic, bridge". If this method is chosen as the base then we will not write the derived |
| 94 | + // method because it is not "different" from the base. (They are both not-abstract.) In reality, we need to |
| 95 | + // match to the "not-synthetic, not-bridge" method that *is* abstract, so that the derived method is different |
| 96 | + // enough to get written to the output. |
| 97 | + // See "JavaXmlApiExporter.SaveMethod ()" for what constitutes "different" enough to be written. |
| 98 | + string xml = @"<api> |
| 99 | + <package name='com.google.crypto.tink.streamingaead' jni-name='com/google/crypto/tink/streamingaead'> |
| 100 | + |
| 101 | + <class abstract='true' deprecated='not deprecated' jni-extends='Ljava/lang/Object;' extends='java.lang.Object' extends-generic-aware='java.lang.Object' final='false' name='StreamingAeadKey' jni-signature='Lcom/google/crypto/tink/streamingaead/StreamingAeadKey;' source-file-name='StreamingAeadKey.java' static='false' visibility='public'> |
| 102 | + <method abstract='false' deprecated='not deprecated' final='false' name='getParameters' native='false' return='java.lang.Object' jni-return='Ljava/lang/Object;' static='false' synchronized='false' visibility='public' bridge='true' synthetic='true' jni-signature='()Ljava/lang/Object;' /> |
| 103 | + <method abstract='true' deprecated='not deprecated' final='false' name='getParameters' native='false' return='java.lang.Object' jni-return='Ljava/lang/Object;' static='false' synchronized='false' visibility='public' bridge='false' synthetic='false' jni-signature='()Ljava/lang/Object;' /> |
| 104 | + </class> |
| 105 | + |
| 106 | + <class abstract='false' deprecated='not deprecated' jni-extends='Lcom/google/crypto/tink/streamingaead/StreamingAeadKey;' extends='com.google.crypto.tink.streamingaead.StreamingAeadKey' extends-generic-aware='com.google.crypto.tink.streamingaead.StreamingAeadKey' final='true' name='AesGcmHkdfStreamingKey' jni-signature='Lcom/google/crypto/tink/streamingaead/AesGcmHkdfStreamingKey;' source-file-name='AesGcmHkdfStreamingKey.java' static='false' visibility='public'> |
| 107 | + <method abstract='false' deprecated='not deprecated' final='false' name='getParameters' native='false' return='java.lang.Object' jni-return='Ljava/lang/Object;' static='false' synchronized='false' visibility='public' bridge='false' synthetic='false' jni-signature='()Ljava/lang/Object;' /> |
| 108 | + </class> |
| 109 | + |
| 110 | + </package> |
| 111 | +</api>"; |
| 112 | + |
| 113 | + var xapi = JavaApiTestHelper.GetLoadedApi (); |
| 114 | + JavaXmlApiImporter.ParseString (xml, xapi); |
| 115 | + |
| 116 | + var results = xapi.ResolveCollection (); |
| 117 | + |
| 118 | + var t = xapi.Packages ["com.google.crypto.tink.streamingaead"].Types.First (_ => _.Name == "AesGcmHkdfStreamingKey") as JavaClassModel; |
| 119 | + var m = t.Methods.FirstOrDefault (); |
| 120 | + |
| 121 | + // The non-synthetic, non-bridge, abstract base method should be chosen |
| 122 | + Assert.IsFalse (m.BaseMethod.IsSynthetic); |
| 123 | + Assert.IsFalse (m.BaseMethod.IsBridge); |
| 124 | + Assert.IsTrue (m.BaseMethod.IsAbstract); |
| 125 | + |
| 126 | + var sb = new StringBuilder (); |
| 127 | + |
| 128 | + // Write the results out to XML |
| 129 | + using (var xw = XmlWriter.Create (sb)) |
| 130 | + JavaXmlApiExporter.Save (xapi, xw); |
| 131 | + |
| 132 | + // Read results back in to ensure AesGcmHkdfStreamingKey.getParameters was output |
| 133 | + var new_collection = JavaXmlApiImporter.ParseString (sb.ToString ()); |
| 134 | + |
| 135 | + var t2 = new_collection.Packages ["com.google.crypto.tink.streamingaead"].Types.First (_ => _.Name == "AesGcmHkdfStreamingKey") as JavaClassModel; |
| 136 | + var m2 = t.Methods.FirstOrDefault (); |
| 137 | + |
| 138 | + Assert.IsNotNull (m2); |
| 139 | + } |
86 | 140 | }
|
87 | 141 | }
|
0 commit comments