diff --git a/dlls/psapi/tests/psapi_main.c b/dlls/psapi/tests/psapi_main.c index 7696d89ee56..b8552507447 100644 --- a/dlls/psapi/tests/psapi_main.c +++ b/dlls/psapi/tests/psapi_main.c @@ -33,17 +33,6 @@ return FALSE; \ } -/* All PSAPI functions return non-zero and call SetLastError() - * on failure so we can use some macros for convenience */ - -#define w32_suc(x) \ - (SetLastError(0xdeadbeef), \ - (x) \ - ? (ok(1, "succeeded\n"), 1) \ - : GetLastError() == 0xdeadbeef \ - ? (ok(0, "failed without error code\n"), 0) \ - : (ok(0, "failed with %d\n", GetLastError()), 0)) - static BOOL (WINAPI *pEmptyWorkingSet)(HANDLE); static BOOL (WINAPI *pEnumProcesses)(DWORD*, DWORD, DWORD*); static BOOL (WINAPI *pEnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD); @@ -84,18 +73,23 @@ static const HANDLE hBad = (HANDLE)0xdeadbeef; static void test_EnumProcesses(void) { - DWORD pid, cbUsed = 0xdeadbeef; + DWORD pid, ret, cbUsed = 0xdeadbeef; - if(w32_suc(pEnumProcesses(NULL, 0, &cbUsed))) - ok(cbUsed == 0, "cbUsed=%d\n", cbUsed); - if(w32_suc(pEnumProcesses(&pid, 4, &cbUsed))) - ok(cbUsed == 4, "cbUsed=%d\n", cbUsed); + SetLastError(0xdeadbeef); + ret = pEnumProcesses(NULL, 0, &cbUsed); + ok(ret == 1, "failed with %d\n", GetLastError()); + ok(cbUsed == 0, "cbUsed=%d\n", cbUsed); + + SetLastError(0xdeadbeef); + ret = pEnumProcesses(&pid, 4, &cbUsed); + ok(ret == 1, "failed with %d\n", GetLastError()); + ok(cbUsed == 4, "cbUsed=%d\n", cbUsed); } static void test_EnumProcessModules(void) { HMODULE hMod = GetModuleHandle(NULL); - DWORD cbNeeded = 0xdeadbeef; + DWORD ret, cbNeeded = 0xdeadbeef; SetLastError(0xdeadbeef); pEnumProcessModules(NULL, NULL, 0, &cbNeeded); @@ -105,8 +99,13 @@ static void test_EnumProcessModules(void) pEnumProcessModules(hpQI, NULL, 0, &cbNeeded); ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError()); - w32_suc(pEnumProcessModules(hpQV, NULL, 0, &cbNeeded)); - if(!w32_suc(pEnumProcessModules(hpQV, &hMod, sizeof(HMODULE), &cbNeeded))) + SetLastError(0xdeadbeef); + ret = pEnumProcessModules(hpQV, NULL, 0, &cbNeeded); + ok(ret == 1, "failed with %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = pEnumProcessModules(hpQV, &hMod, sizeof(HMODULE), &cbNeeded); + if(ret != 1) return; ok(cbNeeded / sizeof(HMODULE) >= 3 && cbNeeded / sizeof(HMODULE) <= 5 * sizeof(HMODULE), "cbNeeded=%d\n", cbNeeded); @@ -118,7 +117,8 @@ static void test_GetModuleInformation(void) { HMODULE hMod = GetModuleHandle(NULL); MODULEINFO info; - + DWORD ret; + SetLastError(0xdeadbeef); pGetModuleInformation(NULL, hMod, &info, sizeof(info)); ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError()); @@ -135,13 +135,16 @@ static void test_GetModuleInformation(void) pGetModuleInformation(hpQV, hMod, &info, sizeof(info)-1); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError()); - if(w32_suc(pGetModuleInformation(hpQV, hMod, &info, sizeof(info)))) - ok(info.lpBaseOfDll == hMod, "lpBaseOfDll=%p hMod=%p\n", info.lpBaseOfDll, hMod); + SetLastError(0xdeadbeef); + ret = pGetModuleInformation(hpQV, hMod, &info, sizeof(info)); + ok(ret == 1, "failed with %d\n", GetLastError()); + ok(info.lpBaseOfDll == hMod, "lpBaseOfDll=%p hMod=%p\n", info.lpBaseOfDll, hMod); } static void test_GetProcessMemoryInfo(void) { PROCESS_MEMORY_COUNTERS pmc; + DWORD ret; SetLastError(0xdeadbeef); pGetProcessMemoryInfo(NULL, &pmc, sizeof(pmc)); @@ -155,7 +158,9 @@ static void test_GetProcessMemoryInfo(void) pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)-1); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError()); - w32_suc(pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc))); + SetLastError(0xdeadbeef); + ret = pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)); + ok(ret == 1, "failed with %d\n", GetLastError()); } static void test_GetMappedFileName(void) @@ -195,7 +200,7 @@ static void test_GetProcessImageFileName(void) HMODULE hMod = GetModuleHandle(NULL); char szImgPath[MAX_PATH], szMapPath[MAX_PATH]; WCHAR szImgPathW[MAX_PATH]; - DWORD ret; + DWORD ret, ret1; if(pGetProcessImageFileNameA == NULL) return; @@ -227,13 +232,13 @@ static void test_GetProcessImageFileName(void) pGetProcessImageFileNameA(hpQI, szImgPath, 0); todo_wine ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError()); - todo_wine - if(w32_suc(ret = pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath))) && - w32_suc(pGetMappedFileNameA(hpQV, hMod, szMapPath, sizeof(szMapPath)))) { + ret = pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath)); + ret1 = pGetMappedFileNameA(hpQV, hMod, szMapPath, sizeof(szMapPath)); + if(ret && ret1) + { /* Windows returns 2*strlen-1 */ - ok(ret >= strlen(szImgPath), "szImgPath=\"%s\" ret=%d\n", szImgPath, ret); - ok(!strcmp(szImgPath, szMapPath), - "szImgPath=\"%s\" szMapPath=\"%s\"\n", szImgPath, szMapPath); + todo_wine ok(ret >= strlen(szImgPath), "szImgPath=\"%s\" ret=%d\n", szImgPath, ret); + todo_wine ok(!strcmp(szImgPath, szMapPath), "szImgPath=\"%s\" szMapPath=\"%s\"\n", szImgPath, szMapPath); } SetLastError(0xdeadbeef); @@ -286,8 +291,9 @@ static void test_GetModuleFileNameEx(void) pGetModuleFileNameExA(hpQV, hBad, szModExPath, sizeof(szModExPath)); ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError()); - if(!w32_suc(ret = pGetModuleFileNameExA(hpQV, NULL, szModExPath, sizeof(szModExPath)))) - return; + ret = pGetModuleFileNameExA(hpQV, NULL, szModExPath, sizeof(szModExPath)); + if(!ret) + return; ok(ret == strlen(szModExPath), "szModExPath=\"%s\" ret=%d\n", szModExPath, ret); GetModuleFileNameA(NULL, szModPath, sizeof(szModPath)); ok(!strncmp(szModExPath, szModPath, MAX_PATH), @@ -312,7 +318,8 @@ static void test_GetModuleBaseName(void) pGetModuleBaseNameA(hpQV, hBad, szModBaseName, sizeof(szModBaseName)); ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError()); - if(!w32_suc(ret = pGetModuleBaseNameA(hpQV, NULL, szModBaseName, sizeof(szModBaseName)))) + ret = pGetModuleBaseNameA(hpQV, NULL, szModBaseName, sizeof(szModBaseName)); + if(!ret) return; ok(ret == strlen(szModBaseName), "szModBaseName=\"%s\" ret=%d\n", szModBaseName, ret); GetModuleFileNameA(NULL, szModPath, sizeof(szModPath)); @@ -336,7 +343,9 @@ static void test_ws_functions(void) pEmptyWorkingSet(hpSR); todo_wine ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError()); - w32_suc(pEmptyWorkingSet(hpAA)); + SetLastError(0xdeadbeef); + ret = pEmptyWorkingSet(hpAA); + ok(ret == 1, "failed with %d\n", GetLastError()); SetLastError( 0xdeadbeef ); ret = pInitializeProcessForWsWatch( NULL ); @@ -350,9 +359,12 @@ static void test_ws_functions(void) } ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() ); } - w32_suc(pInitializeProcessForWsWatch(hpAA)); + SetLastError(0xdeadbeef); + ret = pInitializeProcessForWsWatch(hpAA); + ok(ret == 1, "failed with %d\n", GetLastError()); - if(!w32_suc(addr = VirtualAlloc(NULL, 1, MEM_COMMIT, PAGE_READWRITE))) + addr = VirtualAlloc(NULL, 1, MEM_COMMIT, PAGE_READWRITE); + if(!addr) return; *addr = 0; /* make sure it's paged in (needed on wow64) */ @@ -362,29 +374,35 @@ static void test_ws_functions(void) goto free_page; } - todo_wine if(w32_suc(pQueryWorkingSet(hpQI, pages, 4096 * sizeof(ULONG_PTR)))) + SetLastError(0xdeadbeef); + ret = pQueryWorkingSet(hpQI, pages, 4096 * sizeof(ULONG_PTR)); + todo_wine ok(ret == 1, "failed with %d\n", GetLastError()); + if(ret == 1) { for(i = 0; i < pages[0]; i++) if((pages[i+1] & ~0xfffL) == (ULONG_PTR)addr) { - ok(1, "QueryWorkingSet found our page\n"); + todo_wine ok(ret == 1, "QueryWorkingSet found our page\n"); goto test_gwsc; } - ok(0, "QueryWorkingSet didn't find our page\n"); + todo_wine ok(0, "QueryWorkingSet didn't find our page\n"); } test_gwsc: - todo_wine if(w32_suc(pGetWsChanges(hpQI, wswi, sizeof(wswi)))) + SetLastError(0xdeadbeef); + ret = pGetWsChanges(hpQI, wswi, sizeof(wswi)); + todo_wine ok(ret == 1, "failed with %d\n", GetLastError()); + if(ret == 1) { for(i = 0; wswi[i].FaultingVa; i++) if(((ULONG_PTR)wswi[i].FaultingVa & ~0xfffL) == (ULONG_PTR)addr) { - ok(1, "GetWsChanges found our page\n"); + todo_wine ok(ret == 1, "GetWsChanges found our page\n"); goto free_page; } - ok(0, "GetWsChanges didn't find our page\n"); + todo_wine ok(0, "GetWsChanges didn't find our page\n"); } free_page: @@ -394,7 +412,7 @@ free_page: START_TEST(psapi_main) { HMODULE hpsapi = LoadLibraryA("psapi.dll"); - + if(!hpsapi) { trace("Could not load psapi.dll\n"); @@ -405,12 +423,13 @@ START_TEST(psapi_main) { DWORD pid = GetCurrentProcessId(); - w32_suc(hpSR = OpenProcess(STANDARD_RIGHTS_REQUIRED, FALSE, pid)); - w32_suc(hpQI = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid)); - w32_suc(hpVR = OpenProcess(PROCESS_VM_READ, FALSE, pid)); - w32_suc(hpQV = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); - w32_suc(hpAA = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid)); - if(hpSR && hpQI && hpVR && hpQV && hpAA) + hpSR = OpenProcess(STANDARD_RIGHTS_REQUIRED, FALSE, pid); + hpQI = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); + hpVR = OpenProcess(PROCESS_VM_READ, FALSE, pid); + hpQV = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); + hpAA = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); + + if(hpSR && hpQI && hpVR && hpQV && hpAA) { test_EnumProcesses(); test_EnumProcessModules();