use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class Kernel32VolumeManagementFunctionsTest method testEnumVolumeMountMoints.
private void testEnumVolumeMountMoints(String volumeGUID) {
char[] lpszVolumeMountPoint = new char[WinDef.MAX_PATH + 1];
HANDLE hFindVolumeMountPoint = Kernel32.INSTANCE.FindFirstVolumeMountPoint(volumeGUID, lpszVolumeMountPoint, lpszVolumeMountPoint.length);
if (WinNT.INVALID_HANDLE_VALUE.equals(hFindVolumeMountPoint)) {
int hr = Kernel32.INSTANCE.GetLastError();
if (// e.g., network or hidden volumes
(hr == WinError.ERROR_ACCESS_DENIED) || // e.g., DVD drive
(hr == WinError.ERROR_NOT_READY) || // No folders found
(hr == WinError.ERROR_NO_MORE_FILES) || (hr == WinError.ERROR_PATH_NOT_FOUND)) {
// System.out.append('\t').append('[').append(volumeGUID).append(']').append(" - skipped: reason=").println(hr);
return;
}
fail("Cannot (error=" + hr + ") open mount point search handle for " + volumeGUID);
}
try {
do {
String name = Native.toString(lpszVolumeMountPoint);
assertTrue("Empty mount point for " + volumeGUID, name.length() > 0);
// System.out.append('\t').append("testEnumVolumeMountMoints").append('[').append(volumeGUID).append(']').append(" - ").println(name);
} while (Kernel32.INSTANCE.FindNextVolumeMountPoint(hFindVolumeMountPoint, lpszVolumeMountPoint, lpszVolumeMountPoint.length));
int hr = Kernel32.INSTANCE.GetLastError();
assertEquals("Mount points enum termination reason for " + volumeGUID, WinError.ERROR_NO_MORE_FILES, hr);
} finally {
assertCallSucceeded("FindVolumeMountPointClose(" + volumeGUID + ")", Kernel32.INSTANCE.FindVolumeMountPointClose(hFindVolumeMountPoint));
}
}
use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class Advapi32Test method testRegEnumValue.
public void testRegEnumValue() {
HKEYByReference phKey = new HKEYByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, WinNT.KEY_READ, phKey));
IntByReference lpcValues = new IntByReference();
IntByReference lpcMaxValueNameLen = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(phKey.getValue(), null, null, null, null, null, null, lpcValues, lpcMaxValueNameLen, null, null, null));
char[] name = new char[lpcMaxValueNameLen.getValue() + 1];
for (int i = 0; i < lpcValues.getValue(); i++) {
IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1);
IntByReference lpType = new IntByReference();
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumValue(phKey.getValue(), i, name, lpcchValueName, null, lpType, null, null));
assertEquals(Native.toString(name).length(), lpcchValueName.getValue());
}
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
}
use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class VariantTest method testVariantConstructors.
public void testVariantConstructors() {
VARIANT variant;
// skipped: BSTRByReference constructor
// skipped: empty constructor
// skipped: pointer constructor
// skipped: IDispatch constructor
String testString = "TeST$รถ";
BSTR bstr = OleAuto.INSTANCE.SysAllocString(testString);
variant = new VARIANT(bstr);
assertThat(variant.getValue(), instanceOf(BSTR.class));
assertThat(((BSTR) variant.getValue()).getValue(), equalTo(testString));
assertThat(variant.stringValue(), equalTo(testString));
variant = new VARIANT(testString);
assertThat(variant.getValue(), instanceOf(BSTR.class));
assertThat(((BSTR) variant.getValue()).getValue(), equalTo(testString));
assertThat(variant.stringValue(), equalTo(testString));
OleAuto.INSTANCE.SysFreeString(bstr);
OleAuto.INSTANCE.SysFreeString((BSTR) variant.getValue());
BOOL boolTrue = new WinDef.BOOL(true);
variant = new VARIANT(Variant.VARIANT_TRUE);
assertThat(variant.getValue(), instanceOf(VARIANT_BOOL.class));
assertThat(((VARIANT_BOOL) variant.getValue()).shortValue(), equalTo((short) 0xFFFF));
assertThat(variant.booleanValue(), equalTo(true));
variant = new VARIANT(boolTrue);
assertThat(variant.getValue(), instanceOf(VARIANT_BOOL.class));
assertThat(((VARIANT_BOOL) variant.getValue()).shortValue(), equalTo((short) 0xFFFF));
assertThat(variant.booleanValue(), equalTo(true));
int testInt = 4223;
LONG testIntWin = new LONG(testInt);
variant = new VARIANT(testIntWin);
assertThat(variant.getValue(), instanceOf(LONG.class));
assertThat(((LONG) variant.getValue()).intValue(), equalTo(testInt));
assertThat(variant.intValue(), equalTo(testInt));
variant = new VARIANT(testInt);
assertThat(variant.getValue(), instanceOf(LONG.class));
assertThat(((LONG) variant.getValue()).intValue(), equalTo(testInt));
assertThat(variant.intValue(), equalTo(testInt));
short testShort = 23;
SHORT testShortWin = new SHORT(testShort);
variant = new VARIANT(testShortWin);
assertThat(variant.getValue(), instanceOf(SHORT.class));
assertThat(((SHORT) variant.getValue()).shortValue(), equalTo(testShort));
assertThat(variant.shortValue(), equalTo(testShort));
variant = new VARIANT(testShort);
assertThat(variant.getValue(), instanceOf(SHORT.class));
assertThat(((SHORT) variant.getValue()).shortValue(), equalTo(testShort));
assertThat(variant.shortValue(), equalTo(testShort));
long testLong = 4223L + Integer.MAX_VALUE;
variant = new VARIANT(testLong);
assertThat(variant.getValue(), instanceOf(LONGLONG.class));
assertThat(((LONGLONG) variant.getValue()).longValue(), equalTo(testLong));
assertThat(variant.longValue(), equalTo(testLong));
Date testDate = new Date(2042 - 1900, 2, 3, 23, 0, 0);
variant = new VARIANT(testDate);
assertThat(variant.getValue(), instanceOf(DATE.class));
assertThat(variant.dateValue(), equalTo(testDate));
byte testByte = 42;
BYTE testByteWin = new BYTE(testByte);
CHAR testByteWin2 = new CHAR(testByte);
variant = new VARIANT(testByte);
assertThat(variant.getValue(), instanceOf(BYTE.class));
assertThat(((BYTE) variant.getValue()).byteValue(), equalTo(testByte));
assertThat(variant.byteValue(), equalTo(testByte));
variant = new VARIANT(testByteWin);
assertThat(variant.getValue(), instanceOf(BYTE.class));
assertThat(((BYTE) variant.getValue()).byteValue(), equalTo(testByte));
assertThat(variant.byteValue(), equalTo(testByte));
variant = new VARIANT(testByteWin2);
assertThat(variant.getValue(), instanceOf(CHAR.class));
assertThat(((CHAR) variant.getValue()).byteValue(), equalTo(testByte));
assertThat(variant.byteValue(), equalTo(testByte));
variant = new VARIANT(testByteWin2);
assertThat(variant.getValue(), instanceOf(CHAR.class));
assertThat(((CHAR) variant.getValue()).byteValue(), equalTo(testByte));
assertThat(variant.byteValue(), equalTo(testByte));
double testDouble = 42.23;
variant = new VARIANT(testDouble);
assertThat(variant.getValue(), instanceOf(Double.class));
// If this fails introduce comparison with range
assertThat(variant.doubleValue(), equalTo(testDouble));
float testFloat = 42.23f;
variant = new VARIANT(testFloat);
assertThat(variant.getValue(), instanceOf(Float.class));
// If this fails introduce comparison with range
assertThat(variant.floatValue(), equalTo(testFloat));
char testChar = 42 + Short.MAX_VALUE;
variant = new VARIANT(testChar);
assertThat(variant.getValue(), instanceOf(USHORT.class));
assertThat(((USHORT) variant.getValue()).intValue(), equalTo((int) testChar));
assertThat(variant.intValue(), equalTo((int) testChar));
}
use of com.sun.jna.platform.win32.WinDef.CHAR 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.WinDef.CHAR in project jna by java-native-access.
the class PdhTest method makeCounterPath.
private static String makeCounterPath(Pdh pdh, PDH_COUNTER_PATH_ELEMENTS pathElements) {
DWORDByReference pcchBufferSize = new DWORDByReference();
int status = pdh.PdhMakeCounterPath(pathElements, null, pcchBufferSize, 0);
assertEquals("Unexpected status code: 0x" + Integer.toHexString(status), PdhMsg.PDH_MORE_DATA, status);
DWORD bufSize = pcchBufferSize.getValue();
int numChars = bufSize.intValue();
assertTrue("Bad required buffer size: " + numChars, numChars > 0);
char[] szFullPathBuffer = new char[numChars + 1];
pcchBufferSize.setValue(new DWORD(szFullPathBuffer.length));
assertErrorSuccess("PdhMakeCounterPath", pdh.PdhMakeCounterPath(pathElements, szFullPathBuffer, pcchBufferSize, 0), true);
return Native.toString(szFullPathBuffer);
}
Aggregations