Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Java.Interop/Tests/Java.Interop/JavaArrayContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ public abstract class JavaArrayContract<T> : ListContract<T>
{
int lrefStartCount;

#if __ANDROID__
[TestFixtureSetUp]
#else // __ANDROID__
[OneTimeSetUp]
#endif // __ANDROID__
public void StartArrayTests ()
{
lrefStartCount = JniEnvironment.LocalReferenceCount;
}

#if __ANDROID__
[TestFixtureTearDown]
#else // __ANDROID__
[OneTimeTearDown]
#endif // __ANDROID__
public void EndArrayTests ()
{
int lref = JniEnvironment.LocalReferenceCount;
Expand Down
12 changes: 12 additions & 0 deletions src/Java.Interop/Tests/Java.Interop/JavaExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public void StackTrace ()
// Dalvik, JVM
e.JavaStackTrace.StartsWith ("java.lang.NoClassDefFoundError: this/type/had/better/not/exist", StringComparison.Ordinal));
e.Dispose ();
#if __ANDROID__
} catch (Java.Lang.Throwable e) {
Assert.IsTrue (
string.Equals ("this/type/had/better/not/exist", e.Message, StringComparison.OrdinalIgnoreCase) ||
e.Message.StartsWith ("Didn't find class \"this.type.had.better.not.exist\" on path: DexPathList"));
Assert.IsTrue (
// ART
e.StackTrace.Contains ("java.lang.ClassNotFoundException: ", StringComparison.Ordinal) ||
// Dalvik, JVM
e.StackTrace.Contains ("java.lang.NoClassDefFoundError: this/type/had/better/not/exist", StringComparison.Ordinal));
e.Dispose ();
#endif // __ANDROID__
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/Java.Interop/Tests/Java.Interop/JavaObjectArrayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ public class JavaObjectArray_object_ContractTest : JavaObjectArrayContractTest<o

int grefStartCount;

#if __ANDROID__
[TestFixtureSetUp]
#else // __ANDROID__
[OneTimeSetUp]
#endif // __ANDROID__
public void BeginCheckGlobalRefCount ()
{
// So that the JavaProxyObject.TypeRef GREF isn't counted.
Expand All @@ -139,7 +143,11 @@ public void BeginCheckGlobalRefCount ()
grefStartCount = JniEnvironment.Runtime.GlobalReferenceCount;
}

#if __ANDROID__
[TestFixtureTearDown]
#else // __ANDROID__
[OneTimeTearDown]
#endif // __ANDROID__
public void EndCheckGlobalRefCount ()
{
int gref = JniEnvironment.Runtime.GlobalReferenceCount;
Expand Down
4 changes: 4 additions & 0 deletions src/Java.Interop/Tests/Java.Interop/JavaObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ public void Ctor_Exceptions ()

// Note: This may break if/when JavaVM provides "default"
Assert.Throws<NotSupportedException> (() => new JavaObjectWithNoJavaPeer ());
#if __ANDROID__
Assert.Throws<Java.Lang.ClassNotFoundException> (() => new JavaObjectWithMissingJavaPeer ()).Dispose ();
#else // !__ANDROID__
Assert.Throws<JavaException> (() => new JavaObjectWithMissingJavaPeer ()).Dispose ();
#endif // !__ANDROID__
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void GetValue_ReturnsNullWithInvalidSafeHandle ()
Assert.IsNull (JniRuntime.CurrentRuntime.ValueManager.GetValue (ref invalid, JniObjectReferenceOptions.CopyAndDispose));
}

#if !NO_MARSHAL_MEMBER_BUILDER_SUPPORT
[Test]
public unsafe void GetValue_FindBestMatchType ()
{
Expand All @@ -138,6 +139,7 @@ public unsafe void GetValue_FindBestMatchType ()
}
}
}
#endif // !NO_MARSHAL_MEMBER_BUILDER_SUPPORT
}
}

3 changes: 3 additions & 0 deletions src/Java.Interop/Tests/Java.Interop/JniTypeManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public void GetTypeSignature_Type ()
AssertGetJniTypeInfoForType (typeof (JavaArray<int[]>), "[[I", true, 2);
AssertGetJniTypeInfoForType (typeof (JavaArray<int[]>[]), "[[[I", true, 3);

#if !__ANDROID__
// Re-enable once typemap files contain `JavaObject` subclasses, not just Java.Lang.Object subclasses
AssertGetJniTypeInfoForType (typeof (GenericHolder<int>), GenericHolder<int>.JniTypeName, false, 0);
#endif // !__ANDROID__
}

static void AssertGetJniTypeInfoForType (Type type, string jniType, bool isKeyword, int arrayRank)
Expand Down
31 changes: 19 additions & 12 deletions src/Java.Interop/Tests/Java.Interop/JniTypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public unsafe void Sanity ()
[Test]
public void Ctor_ThrowsIfTypeNotFound ()
{
#if __ANDROID__
Assert.Throws<Java.Lang.ClassNotFoundException> (() => new JniType ("__this__/__type__/__had__/__better__/__not__/__Exist__")).Dispose ();
#else // __ANDROID__
Assert.Throws<JavaException> (() => new JniType ("__this__/__type__/__had__/__better__/__not__/__Exist__")).Dispose ();
#endif // __ANDROID__
}

[Test]
Expand Down Expand Up @@ -92,27 +96,29 @@ public void IsAssignableFrom ()
}

[Test]
public void IsInstanceOfType ()
public unsafe void IsInstanceOfType ()
{
using (var t = new JniType ("java/lang/Object"))
using (var b = new TestType ()) {
Assert.IsTrue (t.IsInstanceOfType (b.PeerReference));
}
}

[Test]
public void ObjectBinding ()
{
using (var b = new TestType ()) {
Console.WriteLine ("# ObjectBinding: {0}", b.ToString ());
using (var Object_class = new JniType ("java/lang/Object"))
using (var String_class = new JniType ("java/lang/String")) {
var String_ctor = String_class.GetConstructor ("()V");
var s = String_class.NewObject (String_ctor, null);
try {
Assert.IsTrue (Object_class.IsInstanceOfType (s), "java.lang.String IS-NOT-A java.lang.Object?!");
} finally {
JniObjectReference.Dispose (ref s);
}
}
}

[Test]
public void InvalidSignatureThrowsJniException ()
{
using (var Integer_class = new JniType ("java/lang/Integer")) {
#if __ANDROID__
Assert.Throws<Java.Lang.NoSuchMethodError> (() => Integer_class.GetConstructor ("(C)V")).Dispose ();
#else // __ANDROID__
Assert.Throws<JavaException> (() => Integer_class.GetConstructor ("(C)V")).Dispose ();
#endif // __ANDROID__
}
}

Expand All @@ -122,6 +128,7 @@ public void GetStaticFieldID ()
using (var System_class = new JniType ("java/lang/System")) {
var System_in = System_class.GetStaticField ("in", "Ljava/io/InputStream;");
Assert.IsNotNull (System_in);
Assert.IsTrue (System_in.ID != IntPtr.Zero);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Java.Interop/Tests/Java.Interop/TestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Java.InteropTests
{
#if !NO_MARSHAL_MEMBER_BUILDER_SUPPORT
[JniTypeSignature (TestType.JniTypeName)]
public partial class TestType : JavaObject
{
Expand Down Expand Up @@ -204,5 +205,6 @@ public string GetStringValue (int value)
return value.ToString ();
}
}
#endif // !NO_MARSHAL_MEMBER_BUILDER_SUPPORT
}

18 changes: 18 additions & 0 deletions src/Java.Interop/Tests/Java.Interop/TestTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@

namespace Java.InteropTests
{
#if !NO_MARSHAL_MEMBER_BUILDER_SUPPORT
[TestFixture]
public class TestTypeTests : JavaVMFixture
{
int lrefStartCount;

#if __ANDROID__
[TestFixtureSetUp]
#else // __ANDROID__
[OneTimeSetUp]
#endif // __ANDROID__
public void StartArrayTests ()
{
lrefStartCount = JniEnvironment.LocalReferenceCount;
}

#if __ANDROID__
[TestFixtureTearDown]
#else // __ANDROID__
[OneTimeTearDown]
#endif // __ANDROID__
public void EndArrayTests ()
{
int lref = JniEnvironment.LocalReferenceCount;
Expand Down Expand Up @@ -52,6 +61,14 @@ public void TestCase ()
}
}

[Test]
public void ObjectBinding ()
{
using (var b = new TestType ()) {
Console.WriteLine ("# ObjectBinding: {0}", b.ToString ());
}
}

[Test]
public void UpdateInt32Array ()
{
Expand Down Expand Up @@ -143,5 +160,6 @@ public void PropogateException ()
}
}
}
#endif // !NO_MARSHAL_MEMBER_BUILDER_SUPPORT
}