use of com.sun.jna.platform.win32.Variant.VARIANT in project jna by java-native-access.
the class IFileSystem3 method testConvertIntTypes.
@Test
public void testConvertIntTypes() {
LONG testLONG = new LONG(42);
VARIANT resultLONG = Convert.toVariant(testLONG);
assertEquals(42, resultLONG.longValue());
assertEquals(Integer.class, Convert.toJavaObject(resultLONG, Object.class, fact, false, false).getClass());
assertEquals(42, Convert.toJavaObject(resultLONG, int.class, fact, false, false));
assertEquals(42, Convert.toJavaObject(resultLONG, Integer.class, fact, false, false));
SHORT testSHORT = new SHORT(42);
VARIANT resultSHORT = Convert.toVariant(testSHORT);
assertEquals(42, resultSHORT.longValue());
assertEquals(Short.class, Convert.toJavaObject(resultSHORT, Object.class, fact, false, false).getClass());
assertEquals((short) 42, Convert.toJavaObject(resultSHORT, short.class, fact, false, false));
assertEquals((short) 42, Convert.toJavaObject(resultSHORT, Short.class, fact, false, false));
BYTE testBYTE = new BYTE(42);
VARIANT resultBYTE = Convert.toVariant(testBYTE);
Byte testByteObj = 42;
VARIANT resultByteObj = Convert.toVariant(testByteObj);
byte testByte = 42;
VARIANT resultByte = Convert.toVariant(testByte);
assertEquals(42, resultBYTE.longValue());
assertEquals(42, resultByteObj.longValue());
assertEquals(42, resultByte.longValue());
assertEquals(Byte.class, Convert.toJavaObject(resultBYTE, Object.class, fact, false, false).getClass());
assertEquals(Byte.class, Convert.toJavaObject(resultByteObj, Object.class, fact, false, false).getClass());
assertEquals(Byte.class, Convert.toJavaObject(resultByte, Object.class, fact, false, false).getClass());
assertEquals((byte) 42, Convert.toJavaObject(resultBYTE, byte.class, fact, false, false));
assertEquals((byte) 42, Convert.toJavaObject(resultByteObj, byte.class, fact, false, false));
assertEquals((byte) 42, Convert.toJavaObject(resultByte, byte.class, fact, false, false));
assertEquals((byte) 42, Convert.toJavaObject(resultBYTE, Byte.class, fact, false, false));
assertEquals((byte) 42, Convert.toJavaObject(resultByteObj, Byte.class, fact, false, false));
assertEquals((byte) 42, Convert.toJavaObject(resultByte, Byte.class, fact, false, false));
Character testCharObj = 42;
VARIANT resultCharObj = Convert.toVariant(testCharObj);
char testChar = 42;
VARIANT resultChar = Convert.toVariant(testChar);
assertEquals(42, resultCharObj.longValue());
assertEquals(42, resultChar.longValue());
assertEquals(testCharObj, (Character) Convert.toJavaObject(resultCharObj, Object.class, fact, false, false));
assertEquals(testCharObj, (Character) Convert.toJavaObject(resultChar, Object.class, fact, false, false));
assertEquals(testCharObj, (Character) Convert.toJavaObject(resultCharObj, char.class, fact, false, false));
assertEquals(testCharObj, (Character) Convert.toJavaObject(resultChar, char.class, fact, false, false));
assertEquals(testCharObj, (Character) Convert.toJavaObject(resultCharObj, Character.class, fact, false, false));
assertEquals(testCharObj, (Character) Convert.toJavaObject(resultChar, Character.class, fact, false, false));
CHAR testCHAR = new CHAR(42);
VARIANT resultCHAR = Convert.toVariant(testCHAR);
assertEquals(42, resultCHAR.longValue());
assertEquals((byte) 42, Convert.toJavaObject(resultCHAR, Object.class, fact, false, false));
assertEquals((byte) 42, Convert.toJavaObject(resultCHAR, byte.class, fact, false, false));
assertEquals((byte) 42, Convert.toJavaObject(resultCHAR, Byte.class, fact, false, false));
Short testShortObj = 42;
VARIANT resultShortObj = Convert.toVariant(testShortObj);
short testShort = 42;
VARIANT resultShort = Convert.toVariant(testShort);
assertEquals(42, resultShortObj.longValue());
assertEquals(42, resultShort.longValue());
assertEquals((short) 42, Convert.toJavaObject(resultShortObj, Object.class, fact, false, false));
assertEquals((short) 42, Convert.toJavaObject(resultShort, Object.class, fact, false, false));
assertEquals((short) 42, Convert.toJavaObject(resultShortObj, short.class, fact, false, false));
assertEquals((short) 42, Convert.toJavaObject(resultShort, short.class, fact, false, false));
assertEquals((short) 42, Convert.toJavaObject(resultShortObj, Short.class, fact, false, false));
assertEquals((short) 42, Convert.toJavaObject(resultShort, Short.class, fact, false, false));
Integer testIntegerObj = 42;
VARIANT resultIntegerObj = Convert.toVariant(testIntegerObj);
int testInteger = 42;
VARIANT resultInteger = Convert.toVariant(testInteger);
assertEquals(42, resultIntegerObj.longValue());
assertEquals(42, resultInteger.longValue());
assertEquals((int) 42, Convert.toJavaObject(resultIntegerObj, Object.class, fact, false, false));
assertEquals((int) 42, Convert.toJavaObject(resultInteger, Object.class, fact, false, false));
assertEquals((int) 42, Convert.toJavaObject(resultIntegerObj, int.class, fact, false, false));
assertEquals((int) 42, Convert.toJavaObject(resultInteger, int.class, fact, false, false));
assertEquals((int) 42, Convert.toJavaObject(resultIntegerObj, Integer.class, fact, false, false));
assertEquals((int) 42, Convert.toJavaObject(resultInteger, Integer.class, fact, false, false));
Long testLongObj = 42L;
VARIANT resultLongObj = Convert.toVariant(testLongObj);
long testLong = 42;
VARIANT resultLong = Convert.toVariant(testLong);
assertEquals(42, resultLongObj.longValue());
assertEquals(42, resultLong.longValue());
assertEquals((long) 42, Convert.toJavaObject(resultLongObj, Object.class, fact, false, false));
assertEquals((long) 42, Convert.toJavaObject(resultLong, Object.class, fact, false, false));
assertEquals((long) 42, Convert.toJavaObject(resultLongObj, long.class, fact, false, false));
assertEquals((long) 42, Convert.toJavaObject(resultLong, long.class, fact, false, false));
assertEquals((long) 42, Convert.toJavaObject(resultLongObj, Long.class, fact, false, false));
assertEquals((long) 42, Convert.toJavaObject(resultLong, Long.class, fact, false, false));
}
use of com.sun.jna.platform.win32.Variant.VARIANT in project jna by java-native-access.
the class IFileSystem3 method testConvertString.
@Test
public void testConvertString() {
// This test leaks the allocated BSTR -- this is tollerated here, as memory usage is minimal
String testString = "Hallo";
BSTR testValue = new BSTR(testString);
VARIANT resultVariant = Convert.toVariant(testValue);
assertEquals(testString, resultVariant.stringValue());
assertEquals(testString, Convert.toJavaObject(resultVariant, Object.class, fact, false, false));
assertEquals(testString, Convert.toJavaObject(resultVariant, String.class, fact, false, false));
resultVariant = Convert.toVariant(testString);
assertEquals(testString, resultVariant.stringValue());
assertEquals(testString, Convert.toJavaObject(resultVariant, Object.class, fact, false, false));
assertEquals(testString, Convert.toJavaObject(resultVariant, String.class, fact, false, false));
}
use of com.sun.jna.platform.win32.Variant.VARIANT in project jna by java-native-access.
the class IFileSystem3 method testConvertFloat.
@Test
public void testConvertFloat() {
Float testFloatObj = 42.23f;
VARIANT resultFloatObj = Convert.toVariant(testFloatObj);
float testFloat = 42.23f;
VARIANT resultFloat = Convert.toVariant(testFloat);
assertEquals(42.23f, resultFloatObj.floatValue(), 0.01);
assertEquals(42.23f, resultFloat.floatValue(), 0.01);
assertEquals(42.23d, resultFloat.doubleValue(), 0.01);
assertEquals(42.23f, (Float) Convert.toJavaObject(resultFloatObj, Object.class, fact, false, false), 0.01);
assertEquals(42.23f, (Float) Convert.toJavaObject(resultFloat, Object.class, fact, false, false), 0.01);
assertEquals(42.23f, (Float) Convert.toJavaObject(resultFloatObj, float.class, fact, false, false), 0.01);
assertEquals(42.23f, (Float) Convert.toJavaObject(resultFloat, float.class, fact, false, false), 0.01);
assertEquals(42.23f, (Float) Convert.toJavaObject(resultFloatObj, Float.class, fact, false, false), 0.01);
assertEquals(42.23f, (Float) Convert.toJavaObject(resultFloat, Float.class, fact, false, false), 0.01);
assertEquals(42.23d, (Double) Convert.toJavaObject(resultFloat, double.class, fact, false, false), 0.01);
Double testDoubleObj = 42.23;
VARIANT resultDoubleObj = Convert.toVariant(testDoubleObj);
double testDouble = 42.23;
VARIANT resultDouble = Convert.toVariant(testDouble);
assertEquals(42.23, resultDoubleObj.doubleValue(), 0.01);
assertEquals(42.23, resultDouble.doubleValue(), 0.01);
assertEquals(42.23f, resultDouble.floatValue(), 0.01);
assertEquals(42.23, (Double) Convert.toJavaObject(resultDoubleObj, Object.class, fact, false, false), 0.01);
assertEquals(42.23, (Double) Convert.toJavaObject(resultDouble, Object.class, fact, false, false), 0.01);
assertEquals(42.23, (Double) Convert.toJavaObject(resultDoubleObj, double.class, fact, false, false), 0.01);
assertEquals(42.23, (Double) Convert.toJavaObject(resultDouble, double.class, fact, false, false), 0.01);
assertEquals(42.23, (Double) Convert.toJavaObject(resultDoubleObj, Double.class, fact, false, false), 0.01);
assertEquals(42.23, (Double) Convert.toJavaObject(resultDouble, Double.class, fact, false, false), 0.01);
assertEquals(42.23f, (Float) Convert.toJavaObject(resultDouble, float.class, fact, false, false), 0.01);
}
use of com.sun.jna.platform.win32.Variant.VARIANT in project jna by java-native-access.
the class SAFEARRAYTest method testSafeArrayPutGetElement.
@Test
public void testSafeArrayPutGetElement() throws Exception {
int rowCount = 2;
int colCount = 10;
SAFEARRAY varArray = SAFEARRAY.createSafeArray(rowCount, colCount);
assertThat(varArray.getDimensionCount(), is(2));
assertThat(varArray.getUBound(0), equalTo(rowCount - 1));
assertThat(varArray.getUBound(1), equalTo(colCount - 1));
for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
for (int colIdx = 0; colIdx < colCount; colIdx++) {
VARIANT variant = new VARIANT(rowIdx + "#" + colIdx);
varArray.putElement(variant, rowIdx, colIdx);
}
}
for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
for (int colIdx = 0; colIdx < colCount; colIdx++) {
VARIANT element = (VARIANT) varArray.getElement(rowIdx, colIdx);
assertEquals(rowIdx + "#" + colIdx, element.stringValue());
OleAuto.INSTANCE.VariantClear(element);
}
}
}
Aggregations