Skip to content

Commit

Permalink
Added test cases for Kernel32.SetPriorityClass() and Kernel32.SetThre…
Browse files Browse the repository at this point in the history
…adPriority().

Also added Kernel32Util.setCurrentProcessPriority(), Kernel32Util.setCurrentThreadPriority(), Kernel32Util.setProcessPriority() and Kernel32Util.setThreadPriority() tests.
  • Loading branch information
dEajL3kA committed Aug 11, 2023
1 parent c2ecd67 commit 519f640
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2099,4 +2099,14 @@ public void testVirtualLockUnlock() {
// Unlocking an unlocked region should fail
assertFalse(Kernel32.INSTANCE.VirtualUnlock(mem, new SIZE_T(4096)));
}

public void testSetPriorityClass() {
HANDLE selfHandle = Kernel32.INSTANCE.GetCurrentProcess();
assertTrue(Kernel32.INSTANCE.SetPriorityClass(selfHandle, Kernel32.HIGH_PRIORITY_CLASS);
}

public void testSetPriorityClass() {
HANDLE selfHandle = Kernel32.INSTANCE.GetCurrentThread();
assertTrue(Kernel32.INSTANCE.SetThreadPriority(selfHandle, Kernel32.THREAD_PRIORITY_ABOVE_NORMAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,38 @@ public void testGetLogicalProcessorInformationEx() {
assertTrue(cache.associativity == WinNT.CACHE_FULLY_ASSOCIATIVE || cache.associativity > 0);
}
}

public void testSetCurrentProcessPriority() {
try {
Kernel32Util.setCurrentProcessPriority(Kernel32.HIGH_PRIORITY_CLASS);
} catch (Win32Exception e) {
fail("setCurrentProcessPriority() failed: " + e.getMessage());
}
}

public void testSetCurrentThreadPriority() {
try {
Kernel32Util.setCurrentThreadPriority(Kernel32.THREAD_PRIORITY_ABOVE_NORMAL);
} catch (Win32Exception e) {
fail("setCurrentThreadPriority() failed: " + e.getMessage());
}
}

public void testSetProcessPriority() {
final int pid = Kernel32.INSTANCE.GetCurrentProcessId();
try {
Kernel32Util.setProcessPriority(pid, Kernel32.HIGH_PRIORITY_CLASS);
} catch (Win32Exception e) {
fail("setProcessPriority() failed: " + e.getMessage());
}
}

public void testSetThreadPriority() {
final int tid = Kernel32.INSTANCE.GetCurrentThreadId();
try {
Kernel32Util.setThreadPriority(tid, Kernel32.HIGH_PRIORITY_CLASS);
} catch (Win32Exception e) {
fail("setThreadPriority() failed: " + e.getMessage());
}
}
}

0 comments on commit 519f640

Please sign in to comment.