File tree 2 files changed +63
-0
lines changed
2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .sun .jna ;
2
+
3
+ class NativeMappedTestClass implements NativeMapped {
4
+
5
+ private String name ;
6
+
7
+ public NativeMappedTestClass () {}
8
+
9
+ @ Override
10
+ public Object fromNative (Object nativeValue , FromNativeContext context ) {
11
+ NativeMappedTestClass object = new NativeMappedTestClass ();
12
+ object .name = (String ) nativeValue ;
13
+
14
+ return object ;
15
+ }
16
+
17
+ @ Override
18
+ public Object toNative () {
19
+ return name ;
20
+ }
21
+
22
+ @ Override
23
+ public Class <?> nativeType () {
24
+ return String .class ;
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package com .sun .jna ;
2
+
3
+ import junit .framework .TestCase ;
4
+
5
+ public class NativedMappedConverterTest extends TestCase {
6
+
7
+ public void testDefaultValueForClass () {
8
+ NativeMappedConverter converter = new NativeMappedConverter (NativeMappedTestClass .class );
9
+
10
+ assertTrue (converter .defaultValue () instanceof NativeMappedTestClass );
11
+ }
12
+
13
+ public void testDefaultValueForEnum () {
14
+ NativeMappedConverter converter = new NativeMappedConverter (TestEnum .class );
15
+
16
+ assertSame (converter .defaultValue (), TestEnum .VALUE1 );
17
+ }
18
+
19
+ private enum TestEnum implements NativeMapped { VALUE1 , VALUE2 ;
20
+
21
+ @ Override
22
+ public Object fromNative (Object nativeValue , FromNativeContext context ) {
23
+ return values ()[(Integer ) nativeValue ];
24
+ }
25
+
26
+ @ Override
27
+ public Object toNative () {
28
+ return ordinal ();
29
+ }
30
+
31
+ @ Override
32
+ public Class <?> nativeType () {
33
+ return Integer .class ;
34
+ }
35
+ }
36
+
37
+ }
You can’t perform that action at this time.
0 commit comments