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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
/* Copyright (c) 2009 Timothy Wall, All Rights Reserved
*
* The contents of this file is dual-licensed under 2
* alternative Open Source/Free licenses: LGPL 2.1 or later and
* Apache License 2.0. (starting with JNA version 4.0.0).
*
* You can freely decide which license you want to apply to
* the project.
*
* You may obtain a copy of the LGPL License at:
*
* http://www.gnu.org/licenses/licenses.html
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "LGPL2.1".
*
* You may obtain a copy of the Apache License at:
*
* http://www.apache.org/licenses/
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "AL2.0".
*/
package com.sun.jna;
/** Exercise a range of native methods.
*
* @author twall@users.sf.net
*/
public class DirectArgumentsMarshalTest extends ArgumentsMarshalTest {
public static class DirectTestLibrary implements TestLibrary {
/** Dummy. Automatically fail when passed an object. */
@Override
public String returnStringArgument(Object arg) {throw new IllegalArgumentException(arg.getClass().getName()); }
@Override
public native boolean returnBooleanArgument(boolean arg);
@Override
public native byte returnInt8Argument(byte arg);
@Override
public native char returnWideCharArgument(char arg);
@Override
public native short returnInt16Argument(short arg);
@Override
public native int returnInt32Argument(int i);
@Override
public native long returnInt64Argument(long l);
@Override
public native NativeLong returnLongArgument(NativeLong l);
@Override
public native float returnFloatArgument(float f);
@Override
public native double returnDoubleArgument(double d);
@Override
public native String returnStringArgument(String s);
@Override
public native WString returnWStringArgument(WString s);
@Override
public native Pointer returnPointerArgument(Pointer p);
@Override
public String returnStringArrayElement(String[] args, int which) {throw new UnsupportedOperationException();}
@Override
public WString returnWideStringArrayElement(WString[] args, int which) {throw new UnsupportedOperationException();}
@Override
public Pointer returnPointerArrayElement(Pointer[] args, int which) {throw new UnsupportedOperationException();}
@Override
public TestPointerType returnPointerArrayElement(TestPointerType[] args, int which) {throw new UnsupportedOperationException();}
@Override
public CheckFieldAlignment returnPointerArrayElement(CheckFieldAlignment.ByReference[] args, int which) {throw new UnsupportedOperationException();}
@Override
public int returnRotatedArgumentCount(String[] args) {throw new UnsupportedOperationException();}
@Override
public native long checkInt64ArgumentAlignment(int i, long j, int i2, long j2);
@Override
public native double checkDoubleArgumentAlignment(float i, double j, float i2, double j2);
@Override
public native Pointer testStructurePointerArgument(CheckFieldAlignment p);
@Override
public native int testStructureByValueArgument(CheckFieldAlignment.ByValue p);
@Override
public int testStructureArrayInitialization(CheckFieldAlignment[] p, int len) {
throw new UnsupportedOperationException();
}
@Override
public int testStructureByReferenceArrayInitialization(CheckFieldAlignment.ByReference[] p, int len) {
throw new UnsupportedOperationException();
}
@Override
public void modifyStructureArray(CheckFieldAlignment[] p, int length) {
throw new UnsupportedOperationException();
}
@Override
public void modifyStructureByReferenceArray(CheckFieldAlignment.ByReference[] p, int length) {
throw new UnsupportedOperationException();
}
@Override
public native int fillInt8Buffer(byte[] buf, int len, byte value);
@Override
public native int fillInt16Buffer(short[] buf, int len, short value);
@Override
public native int fillInt32Buffer(int[] buf, int len, int value);
@Override
public native int fillInt64Buffer(long[] buf, int len, long value);
@Override
public native int fillFloatBuffer(float[] buf, int len, float value);
@Override
public native int fillDoubleBuffer(double[] buf, int len, double value);
@Override
public native int fillInt8Buffer(boolean[] buf, int len, byte value);
@Override
public native int fillInt16Buffer(char[] buf, int len, short value);
// dummy to avoid causing Native.register to fail
@Override
public boolean returnBooleanArgument(Object arg) {throw new IllegalArgumentException();}
@Override
public native Pointer testStructurePointerArgument(MinTestStructure s);
@Override
public native String returnStringFromVariableSizedStructure(VariableSizedStructure s);
@Override
public native void setCallbackInStruct(CbStruct s);
@Override
public native int stringifyMixedUnion1(
byte[] buffer, int bufferLength,
int dummyInt1, double dummyDouble1,
MixedUnion1.ByValue union1, MixedUnion1.ByValue union2,
int dummyInt2, double dummyDouble2);
static {
Native.register("testlib");
}
}
/* Override original. */
@Override
protected void setUp() {
lib = new DirectTestLibrary();
}
public static class DirectNativeMappedLibrary implements NativeMappedLibrary {
@Override
public native int returnInt32Argument(Custom arg);
@Override
public native int returnInt32Argument(size_t arg);
@Override
public native long returnInt64Argument(size_t arg);
static {
Native.register("testlib");
}
}
@Override
protected NativeMappedLibrary loadNativeMappedLibrary() {
return new DirectNativeMappedLibrary();
}
// This test crashes on w32 IBM J9 unless -Xint is used
// (jvmwi3260-20080415_18762)
@Override
public void testWideCharArgument() {
if (Platform.isWindows()
&& "IBM".equals(System.getProperty("java.vm.vendor"))) {
fail("XFAIL, crash avoided");
}
super.testWideCharArgument();
}
// This test crashes on w32 IBM J9 unless -Xint is used
// (jvmwi3260-20080415_18762)
@Override
public void testWStringArgumentReturn() {
if (Platform.isWindows()
&& "IBM".equals(System.getProperty("java.vm.vendor"))) {
fail("XFAIL, crash avoided");
}
super.testWStringArgumentReturn();
}
// Override tests not yet supported in direct mode
@Override
public void testStringArrayArgument() { }
@Override
public void testWriteStructureArrayArgumentMemory() { }
@Override
public void testUninitializedStructureArrayArgument() { }
@Override
public void testRejectNoncontiguousStructureArrayArgument() { }
@Override
public void testRejectIncompatibleStructureArrayArgument() { }
@Override
public void testWideStringArrayArgument() { }
@Override
public void testPointerArrayArgument() { }
@Override
public void testNativeMappedArrayArgument() { }
@Override
public void testStructureByReferenceArrayArgument() { }
@Override
public void testWriteStructureByReferenceArrayArgumentMemory() { }
@Override
public void testReadStructureByReferenceArrayArgumentMemory() { }
@Override
public void testModifiedCharArrayArgument() { }
public static void main(java.lang.String[] argList) {
junit.textui.TestRunner.run(DirectArgumentsMarshalTest.class);
}
}
|