1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: Tests for the NtSetInformationProcess API 5 * COPYRIGHT: Copyright 2020 Bișoc George <fraizeraust99 at gmail dot com> 6 */ 7 8 #include "precomp.h" 9 10 static 11 void 12 Test_ProcForegroundBackgroundClass(void) 13 { 14 NTSTATUS Status; 15 PPROCESS_FOREGROUND_BACKGROUND ProcForeground; 16 17 ProcForeground = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROCESS_FOREGROUND_BACKGROUND)); 18 if (ProcForeground == NULL) 19 { 20 skip("Failed to allocate memory block from heap for PROCESS_FOREGROUND_BACKGROUND!\n"); 21 return; 22 } 23 24 /* As a test, set the foreground of the retrieved current process to FALSE */ 25 ProcForeground->Foreground = FALSE; 26 27 /* Set everything NULL for the caller */ 28 Status = NtSetInformationProcess(NULL, 29 ProcessForegroundInformation, 30 NULL, 31 0); 32 ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); 33 34 /* Give an invalid process handle (but the input buffer and length are correct) */ 35 Status = NtSetInformationProcess(NULL, 36 ProcessForegroundInformation, 37 ProcForeground, 38 sizeof(PROCESS_FOREGROUND_BACKGROUND)); 39 ok_hex(Status, STATUS_INVALID_HANDLE); 40 41 /* Give a buffer data to the argument input as NULL */ 42 Status = NtSetInformationProcess(NtCurrentProcess(), 43 ProcessForegroundInformation, 44 NULL, 45 sizeof(PROCESS_FOREGROUND_BACKGROUND)); 46 ok_hex(Status, STATUS_ACCESS_VIOLATION); 47 48 /* Set the information process foreground with an incorrect buffer alignment and zero buffer length */ 49 Status = NtSetInformationProcess(NtCurrentProcess(), 50 ProcessForegroundInformation, 51 (PVOID)1, 52 0); 53 ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); 54 55 /* 56 * Set the information process foreground with an incorrect buffer alignment but correct size length. 57 * The function will return STATUS_ACCESS_VIOLATION as the alignment probe requirement is not performed 58 * in this class. 59 */ 60 Status = NtSetInformationProcess(NtCurrentProcess(), 61 ProcessForegroundInformation, 62 (PVOID)1, 63 sizeof(PROCESS_FOREGROUND_BACKGROUND)); 64 ok_hex(Status, STATUS_ACCESS_VIOLATION); 65 66 /* Set the foreground information to the current given process, we must expect the function should succeed */ 67 Status = NtSetInformationProcess(NtCurrentProcess(), 68 ProcessForegroundInformation, 69 ProcForeground, 70 sizeof(PROCESS_FOREGROUND_BACKGROUND)); 71 ok_hex(Status, STATUS_SUCCESS); 72 73 /* Clear all the stuff */ 74 HeapFree(GetProcessHeap(), 0, ProcForeground); 75 } 76 77 START_TEST(NtSetInformationProcess) 78 { 79 Test_ProcForegroundBackgroundClass(); 80 } 81