public void DisposeWithJavaObjectDisposesObject([Values(true, false)] bool register) { var native = new JavaObject(); if (!register) { native.UnregisterFromRuntime(); } var instance = new DynamicJavaInstance(native); Assert.AreEqual(1, JavaClassInfo.GetClassInfoCount("java/lang/Object")); Assert.AreSame(native, instance.Value); instance.Dispose(); Assert.AreEqual(null, instance.Value); Assert.AreEqual(-1, JavaClassInfo.GetClassInfoCount("java/lang/Object")); if (register) { Assert.IsTrue(native.PeerReference.IsValid); } else { Assert.IsFalse(native.PeerReference.IsValid); } }
public void JniClassName() { dynamic Arrays = new DynamicJavaClass(Arrays_class); Assert.AreEqual(1, JavaClassInfo.GetClassInfoCount(Arrays_class)); Assert.AreEqual(Arrays_class, Arrays.JniClassName); Arrays.Dispose(); Assert.AreEqual(-1, JavaClassInfo.GetClassInfoCount(Arrays_class)); }
public void InvokeConstructor() { dynamic Integer = new DynamicJavaClass(Integer_class); Assert.AreEqual(1, JavaClassInfo.GetClassInfoCount(Integer_class)); dynamic value = Integer(42); Assert.AreEqual(2, JavaClassInfo.GetClassInfoCount(Integer_class)); Assert.IsTrue(value is DynamicJavaInstance); value.Dispose(); Assert.AreEqual(1, JavaClassInfo.GetClassInfoCount(Integer_class)); Integer.Dispose(); Assert.AreEqual(-1, JavaClassInfo.GetClassInfoCount(Integer_class)); }
public void DisposedInstanceThrowsObjectDisposedException() { dynamic Integer = new DynamicJavaClass(Integer_class); Assert.AreEqual(1, JavaClassInfo.GetClassInfoCount(Integer_class)); Integer.Dispose(); Assert.AreEqual(-1, JavaClassInfo.GetClassInfoCount(Integer_class)); Integer.Dispose(); // Dispose() is idempotent Assert.Catch <Exception> (() => Integer.bitCount(2)); Assert.Catch <Exception> (() => { int max = Integer.MAX_INT; max = max > 0 ? max : max; }); Assert.Catch <Exception> (() => { Integer.MAX_INT = 42; }); }