1
/* Copyright (c) 2009 Timothy Wall, All Rights Reserved
3
* This library is free software; you can redistribute it and/or
4
* modify it under the terms of the GNU Lesser General Public
5
* License as published by the Free Software Foundation; either
6
* version 2.1 of the License, or (at your option) any later version.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
15
import java.util.HashMap;
18
import junit.framework.TestCase;
20
import com.sun.jna.ReturnTypesTest.TestLibrary.SimpleStructure;
21
import com.sun.jna.ReturnTypesTest.TestLibrary.TestStructure;
22
import com.sun.jna.ReturnTypesTest.TestLibrary.TestSmallStructure;
24
/** Exercise a range of native methods.
26
* @author twall@users.sf.net
28
public class DirectReturnTypesTest extends ReturnTypesTest {
30
public static class DirectTestLibrary implements TestLibrary {
32
public Object returnObjectArgument(Object s) {
33
throw new IllegalArgumentException(s.getClass().getName());
35
public TestObject returnObjectArgument(TestObject s) {
36
throw new IllegalArgumentException(s.getClass().getName());
38
public native boolean returnFalse();
39
public native boolean returnTrue();
40
public native int returnInt32Zero();
41
public native int returnInt32Magic();
42
public native long returnInt64Zero();
43
public native long returnInt64Magic();
44
public native NativeLong returnLongZero();
45
public native NativeLong returnLongMagic();
46
public native float returnFloatZero();
47
public native float returnFloatMagic();
48
public native double returnDoubleZero();
49
public native double returnDoubleMagic();
50
public native String returnStringMagic();
51
public native WString returnWStringMagic();
52
public native SimpleStructure returnStaticTestStructure();
53
public native SimpleStructure returnNullTestStructure();
54
public native TestSmallStructure.ByValue returnSmallStructureByValue();
55
public native TestStructure.ByValue returnStructureByValue();
57
public Pointer[] returnPointerArgument(Pointer[] arg) {throw new UnsupportedOperationException();}
58
public String[] returnPointerArgument(String[] arg) {throw new UnsupportedOperationException();}
59
public WString[] returnPointerArgument(WString[] arg) {throw new UnsupportedOperationException();}
62
Native.register("testlib");
66
protected void setUp() {
67
lib = new DirectTestLibrary();
70
public static class DirectObjectTestLibrary extends DirectTestLibrary {
71
public DirectObjectTestLibrary(Map options) {
72
Native.register(getClass(), NativeLibrary.getInstance("testlib", options));
76
public static class DirectNativeMappedLibrary implements NativeMappedLibrary {
77
public native Custom returnInt32Argument(int arg);
79
Native.register("testlib");
82
protected NativeMappedLibrary loadNativeMappedLibrary() {
83
return new DirectNativeMappedLibrary();
86
// Override not-yet-supported tests
87
public void testReturnObject() { }
88
public void testReturnPointerArray() { }
89
public void testReturnStringArray() { }
90
public void testReturnWStringArray() { }
92
public static void main(java.lang.String[] argList) {
93
junit.textui.TestRunner.run(DirectReturnTypesTest.class);