use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Kernel32DiskManagementFunctionsTest method testGetDiskFreeSpace.
private void testGetDiskFreeSpace(String lpRootPathName) {
DWORDByReference lpSectorsPerCluster = new DWORDByReference();
DWORDByReference lpBytesPerSector = new DWORDByReference();
DWORDByReference lpNumberOfFreeClusters = new DWORDByReference();
DWORDByReference lpTotalNumberOfClusters = new DWORDByReference();
assertCallSucceeded("GetDiskFreeSpace(" + lpRootPathName + ")", Kernel32.INSTANCE.GetDiskFreeSpace(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters));
// System.out.append(getCurrentTestName()).append('[').append(lpRootPathName).println(']');
// System.out.append('\t').append("SectorsPerCluster: ").println(lpSectorsPerCluster.getValue());
// System.out.append('\t').append("BytesPerSector: ").println(lpBytesPerSector.getValue());
// System.out.append('\t').append("NumberOfFreeClusters: ").println(lpNumberOfFreeClusters.getValue());
// System.out.append('\t').append("TotalNumberOfClusters: ").println(lpTotalNumberOfClusters.getValue());
DWORD freeSize = lpNumberOfFreeClusters.getValue();
assertTrue("No free clusters for " + lpRootPathName, freeSize.longValue() > 0L);
DWORD totalSize = lpTotalNumberOfClusters.getValue();
assertTrue("Free clusters (" + freeSize + ") not below total (" + totalSize + ") for " + lpRootPathName, freeSize.longValue() < totalSize.longValue());
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Kernel32Test method testFindFirstFileExFindExInfoBasic.
public void testFindFirstFileExFindExInfoBasic() throws IOException {
Path tmpDir = Files.createTempDirectory("testFindFirstFileExFindExInfoBasic");
File tmpFile = new File(Files.createTempFile(tmpDir, "testFindFirstFileExFindExInfoBasic", ".jna").toString());
Memory p = new Memory(WIN32_FIND_DATA.sizeOf());
// Add the file name to the search to get just that one entry
HANDLE hFile = Kernel32.INSTANCE.FindFirstFileEx(tmpDir.toAbsolutePath().toString() + "\\" + tmpFile.getName(), WinBase.FindExInfoBasic, p, WinBase.FindExSearchNameMatch, null, new DWORD(0));
assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
try {
// Get data and confirm the 1st name is for the file itself
WIN32_FIND_DATA fd = new WIN32_FIND_DATA(p);
String actualFileName = new String(fd.getFileName());
actualFileName = new String(fd.getFileName());
assertTrue(actualFileName.contentEquals(tmpFile.getName()));
// FindExInfoBasic does not return the short name, so confirm that its empty
String alternateFileName = fd.getAlternateFileName();
assertTrue(alternateFileName.isEmpty());
// No more files in directory
assertFalse(Kernel32.INSTANCE.FindNextFile(hFile, p));
assertEquals(WinNT.ERROR_NO_MORE_FILES, Kernel32.INSTANCE.GetLastError());
} finally {
Kernel32.INSTANCE.FindClose(hFile);
tmpFile.delete();
Files.delete(tmpDir);
}
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Kernel32Test method testFindFirstFileExFindExInfoStandard.
public void testFindFirstFileExFindExInfoStandard() throws IOException {
Path tmpDir = Files.createTempDirectory("testFindFirstFileExFindExInfoStandard");
File tmpFile = new File(Files.createTempFile(tmpDir, "testFindFirstFileExFindExInfoStandard", ".jna").toString());
Memory p = new Memory(WIN32_FIND_DATA.sizeOf());
HANDLE hFile = Kernel32.INSTANCE.FindFirstFileEx(tmpDir.toAbsolutePath().toString() + "\\*", WinBase.FindExInfoStandard, p, WinBase.FindExSearchNameMatch, null, new DWORD(0));
assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
try {
// Get data and confirm the 1st name is . for the directory itself.
WIN32_FIND_DATA fd = new WIN32_FIND_DATA(p);
String actualFileName = new String(fd.getFileName());
assertTrue(actualFileName.contentEquals("."));
// Get data and confirm the 2nd name is .. for the directory's parent
assertTrue(Kernel32.INSTANCE.FindNextFile(hFile, p));
fd = new WIN32_FIND_DATA(p);
actualFileName = new String(fd.getFileName());
assertTrue(actualFileName.contentEquals(".."));
// Get data and confirm the 3rd name is the tmp file name
assertTrue(Kernel32.INSTANCE.FindNextFile(hFile, p));
fd = new WIN32_FIND_DATA(p);
actualFileName = new String(fd.getFileName());
assertTrue(actualFileName.contentEquals(tmpFile.getName()));
// No more files in directory
assertFalse(Kernel32.INSTANCE.FindNextFile(hFile, p));
assertEquals(WinNT.ERROR_NO_MORE_FILES, Kernel32.INSTANCE.GetLastError());
} finally {
Kernel32.INSTANCE.FindClose(hFile);
tmpFile.delete();
Files.delete(tmpDir);
}
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Kernel32Test method testSetFileInformationByHandleFileBasicInfo.
public void testSetFileInformationByHandleFileBasicInfo() throws IOException, InterruptedException {
File tmp = File.createTempFile("testSetFileInformationByHandleFileBasicInfo", "jna");
tmp.deleteOnExit();
HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_READ | WinNT.GENERIC_WRITE, WinNT.FILE_SHARE_READ | 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);
// Add TEMP attribute
fbi.FileAttributes = fbi.FileAttributes | WinNT.FILE_ATTRIBUTE_TEMPORARY;
fbi.ChangeTime = new WinNT.LARGE_INTEGER(0);
fbi.CreationTime = new WinNT.LARGE_INTEGER(0);
fbi.LastAccessTime = new WinNT.LARGE_INTEGER(0);
fbi.LastWriteTime = new WinNT.LARGE_INTEGER(0);
fbi.write();
if (false == Kernel32.INSTANCE.SetFileInformationByHandle(hFile, WinBase.FileBasicInfo, fbi.getPointer(), new DWORD(FILE_BASIC_INFO.sizeOf())))
fail("GetFileInformationByHandleEx failed with " + Kernel32.INSTANCE.GetLastError());
if (false == Kernel32.INSTANCE.GetFileInformationByHandleEx(hFile, WinBase.FileBasicInfo, p, new DWORD(p.size())))
fail("GetFileInformationByHandleEx failed with " + Kernel32.INSTANCE.GetLastError());
fbi = new FILE_BASIC_INFO(p);
assertTrue((fbi.FileAttributes & WinNT.FILE_ATTRIBUTE_TEMPORARY) != 0);
} finally {
Kernel32.INSTANCE.CloseHandle(hFile);
}
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Kernel32Test method testSetFileInformationByHandleFileDispositionInfo.
public void testSetFileInformationByHandleFileDispositionInfo() throws IOException, InterruptedException {
File tmp = File.createTempFile("testSetFileInformationByHandleFileDispositionInfo", "jna");
HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_WRITE | WinNT.DELETE, WinNT.FILE_SHARE_WRITE, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(hFile));
try {
FILE_DISPOSITION_INFO fdi = new FILE_DISPOSITION_INFO(true);
if (false == Kernel32.INSTANCE.SetFileInformationByHandle(hFile, WinBase.FileDispositionInfo, fdi.getPointer(), new DWORD(FILE_DISPOSITION_INFO.sizeOf())))
fail("SetFileInformationByHandle failed with " + Kernel32.INSTANCE.GetLastError());
} finally {
Kernel32.INSTANCE.CloseHandle(hFile);
}
assertFalse(Files.exists(Paths.get(tmp.getAbsolutePath())));
}
Aggregations