forked from dotnet/java-interop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicJavaInstanceTests.cs
More file actions
73 lines (60 loc) · 1.7 KB
/
DynamicJavaInstanceTests.cs
File metadata and controls
73 lines (60 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using Java.Interop;
using Java.Interop.Dynamic;
using NUnit.Framework;
namespace Java.Interop.DynamicTests {
[TestFixture]
class DynamicJavaInstanceTests : Java.InteropTests.JavaVMFixture
{
[Test]
public void Constructor ()
{
Assert.Throws<ArgumentNullException> (() => new DynamicJavaInstance (null));
}
[Test]
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);
}
}
[Test]
public void Demo ()
{
dynamic Integer = new DynamicJavaClass ("java/lang/Integer");
dynamic value = Integer (42);
Integer.Dispose ();
sbyte byteV = value.byteValue ();
Assert.AreEqual ((sbyte) 42, byteV);
dynamic str = value.toString ();
var s = (string) str;
Assert.AreEqual ("42", s);
str.Dispose ();
value.Dispose ();
}
[Test]
public void Boxing ()
{
dynamic Integer = new DynamicJavaClass ("java/lang/Integer");
dynamic value = Integer (42);
int c = value.compareTo ((int?) 42);
Assert.AreEqual (0, c);
}
}
}