use of com.sun.jna.platform.win32.WinNT.LARGE_INTEGER in project jna by java-native-access.
the class Kernel32Test method testFileTimeFromLargeInteger.
/**
* Test FILETIME's LARGE_INTEGER constructor
* @throws IOException
*/
public final void testFileTimeFromLargeInteger() throws IOException {
File tmp = File.createTempFile("testGetFileInformationByHandleEx", "jna");
tmp.deleteOnExit();
HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_WRITE, WinNT.FILE_SHARE_WRITE, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
try {
Memory p = new Memory(FILE_BASIC_INFO.sizeOf());
if (false == Kernel32.INSTANCE.GetFileInformationByHandleEx(hFile, WinBase.FileBasicInfo, p, new DWORD(p.size()))) {
fail("GetFileInformationByHandleEx failed with " + Kernel32.INSTANCE.GetLastError());
}
FILE_BASIC_INFO fbi = new FILE_BASIC_INFO(p);
FILETIME ft = new FILETIME(fbi.LastWriteTime);
SYSTEMTIME stUTC = new SYSTEMTIME();
SYSTEMTIME stLocal = new SYSTEMTIME();
Kernel32.INSTANCE.FileTimeToSystemTime(ft, stUTC);
// Covert to local
Kernel32.INSTANCE.SystemTimeToTzSpecificLocalTime(null, stUTC, stLocal);
FileTime calculatedCreateTime = FileTime.fromMillis(stLocal.toCalendar().getTimeInMillis());
// Actual file's createTime
FileTime createTime = Files.getLastModifiedTime(Paths.get(tmp.getAbsolutePath()));
assertEquals(createTime.toMillis(), calculatedCreateTime.toMillis());
} finally {
Kernel32.INSTANCE.CloseHandle(hFile);
}
}
use of com.sun.jna.platform.win32.WinNT.LARGE_INTEGER in project jna by java-native-access.
the class WinNTTypesTest method testLargeIntegerUnionLongValue.
@Test
public void testLargeIntegerUnionLongValue() {
for (long expected : new long[] { Long.MIN_VALUE, Integer.MIN_VALUE, Short.MIN_VALUE, Byte.MIN_VALUE, 0L, Long.MAX_VALUE, Integer.MAX_VALUE, Short.MAX_VALUE, Byte.MAX_VALUE }) {
LARGE_INTEGER large = new LARGE_INTEGER(expected);
assertEquals("Mismatched large value", expected, large.getValue());
LARGE_INTEGER.LowHigh loHi = new LARGE_INTEGER.LowHigh(expected);
assertEquals("Mismatched low part", loHi.LowPart, large.getLow());
assertEquals("Mismatched high part", loHi.HighPart, large.getHigh());
}
}
Aggregations