Skip to content

Commit 519f640

Browse files
committed
Added test cases for Kernel32.SetPriorityClass() and Kernel32.SetThreadPriority().
Also added Kernel32Util.setCurrentProcessPriority(), Kernel32Util.setCurrentThreadPriority(), Kernel32Util.setProcessPriority() and Kernel32Util.setThreadPriority() tests.
1 parent c2ecd67 commit 519f640

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java

+10
Original file line numberDiff line numberDiff line change
@@ -2099,4 +2099,14 @@ public void testVirtualLockUnlock() {
20992099
// Unlocking an unlocked region should fail
21002100
assertFalse(Kernel32.INSTANCE.VirtualUnlock(mem, new SIZE_T(4096)));
21012101
}
2102+
2103+
public void testSetPriorityClass() {
2104+
HANDLE selfHandle = Kernel32.INSTANCE.GetCurrentProcess();
2105+
assertTrue(Kernel32.INSTANCE.SetPriorityClass(selfHandle, Kernel32.HIGH_PRIORITY_CLASS);
2106+
}
2107+
2108+
public void testSetPriorityClass() {
2109+
HANDLE selfHandle = Kernel32.INSTANCE.GetCurrentThread();
2110+
assertTrue(Kernel32.INSTANCE.SetThreadPriority(selfHandle, Kernel32.THREAD_PRIORITY_ABOVE_NORMAL);
2111+
}
21022112
}

contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,38 @@ public void testGetLogicalProcessorInformationEx() {
513513
assertTrue(cache.associativity == WinNT.CACHE_FULLY_ASSOCIATIVE || cache.associativity > 0);
514514
}
515515
}
516+
517+
public void testSetCurrentProcessPriority() {
518+
try {
519+
Kernel32Util.setCurrentProcessPriority(Kernel32.HIGH_PRIORITY_CLASS);
520+
} catch (Win32Exception e) {
521+
fail("setCurrentProcessPriority() failed: " + e.getMessage());
522+
}
523+
}
524+
525+
public void testSetCurrentThreadPriority() {
526+
try {
527+
Kernel32Util.setCurrentThreadPriority(Kernel32.THREAD_PRIORITY_ABOVE_NORMAL);
528+
} catch (Win32Exception e) {
529+
fail("setCurrentThreadPriority() failed: " + e.getMessage());
530+
}
531+
}
532+
533+
public void testSetProcessPriority() {
534+
final int pid = Kernel32.INSTANCE.GetCurrentProcessId();
535+
try {
536+
Kernel32Util.setProcessPriority(pid, Kernel32.HIGH_PRIORITY_CLASS);
537+
} catch (Win32Exception e) {
538+
fail("setProcessPriority() failed: " + e.getMessage());
539+
}
540+
}
541+
542+
public void testSetThreadPriority() {
543+
final int tid = Kernel32.INSTANCE.GetCurrentThreadId();
544+
try {
545+
Kernel32Util.setThreadPriority(tid, Kernel32.HIGH_PRIORITY_CLASS);
546+
} catch (Win32Exception e) {
547+
fail("setThreadPriority() failed: " + e.getMessage());
548+
}
549+
}
516550
}

0 commit comments

Comments
 (0)