From 519f640982d755f4c544db23512e2cca6bc8a6e4 Mon Sep 17 00:00:00 2001 From: dEajL3kA Date: Fri, 11 Aug 2023 10:43:18 +0200 Subject: [PATCH] Added test cases for Kernel32.SetPriorityClass() and Kernel32.SetThreadPriority(). Also added Kernel32Util.setCurrentProcessPriority(), Kernel32Util.setCurrentThreadPriority(), Kernel32Util.setProcessPriority() and Kernel32Util.setThreadPriority() tests. --- .../sun/jna/platform/win32/Kernel32Test.java | 10 ++++++ .../jna/platform/win32/Kernel32UtilTest.java | 34 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java index d964c70dec..877782886a 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java @@ -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); + } } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java index cdb5c373f4..66844a362a 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java @@ -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()); + } + } }