Commit db27d9af authored by Austin English's avatar Austin English Committed by Alexandre Julliard

psapi/tests: Get rid of an ugly test macro.

parent 47d2a00a
...@@ -33,17 +33,6 @@ ...@@ -33,17 +33,6 @@
return FALSE; \ 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 *pEmptyWorkingSet)(HANDLE);
static BOOL (WINAPI *pEnumProcesses)(DWORD*, DWORD, DWORD*); static BOOL (WINAPI *pEnumProcesses)(DWORD*, DWORD, DWORD*);
static BOOL (WINAPI *pEnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD); static BOOL (WINAPI *pEnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD);
...@@ -84,18 +73,23 @@ static const HANDLE hBad = (HANDLE)0xdeadbeef; ...@@ -84,18 +73,23 @@ static const HANDLE hBad = (HANDLE)0xdeadbeef;
static void test_EnumProcesses(void) static void test_EnumProcesses(void)
{ {
DWORD pid, cbUsed = 0xdeadbeef; DWORD pid, ret, cbUsed = 0xdeadbeef;
if(w32_suc(pEnumProcesses(NULL, 0, &cbUsed))) SetLastError(0xdeadbeef);
ret = pEnumProcesses(NULL, 0, &cbUsed);
ok(ret == 1, "failed with %d\n", GetLastError());
ok(cbUsed == 0, "cbUsed=%d\n", cbUsed); ok(cbUsed == 0, "cbUsed=%d\n", cbUsed);
if(w32_suc(pEnumProcesses(&pid, 4, &cbUsed)))
SetLastError(0xdeadbeef);
ret = pEnumProcesses(&pid, 4, &cbUsed);
ok(ret == 1, "failed with %d\n", GetLastError());
ok(cbUsed == 4, "cbUsed=%d\n", cbUsed); ok(cbUsed == 4, "cbUsed=%d\n", cbUsed);
} }
static void test_EnumProcessModules(void) static void test_EnumProcessModules(void)
{ {
HMODULE hMod = GetModuleHandle(NULL); HMODULE hMod = GetModuleHandle(NULL);
DWORD cbNeeded = 0xdeadbeef; DWORD ret, cbNeeded = 0xdeadbeef;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
pEnumProcessModules(NULL, NULL, 0, &cbNeeded); pEnumProcessModules(NULL, NULL, 0, &cbNeeded);
...@@ -105,8 +99,13 @@ static void test_EnumProcessModules(void) ...@@ -105,8 +99,13 @@ static void test_EnumProcessModules(void)
pEnumProcessModules(hpQI, NULL, 0, &cbNeeded); pEnumProcessModules(hpQI, NULL, 0, &cbNeeded);
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError()); ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
w32_suc(pEnumProcessModules(hpQV, NULL, 0, &cbNeeded)); SetLastError(0xdeadbeef);
if(!w32_suc(pEnumProcessModules(hpQV, &hMod, sizeof(HMODULE), &cbNeeded))) 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; return;
ok(cbNeeded / sizeof(HMODULE) >= 3 && cbNeeded / sizeof(HMODULE) <= 5 * sizeof(HMODULE), ok(cbNeeded / sizeof(HMODULE) >= 3 && cbNeeded / sizeof(HMODULE) <= 5 * sizeof(HMODULE),
"cbNeeded=%d\n", cbNeeded); "cbNeeded=%d\n", cbNeeded);
...@@ -118,6 +117,7 @@ static void test_GetModuleInformation(void) ...@@ -118,6 +117,7 @@ static void test_GetModuleInformation(void)
{ {
HMODULE hMod = GetModuleHandle(NULL); HMODULE hMod = GetModuleHandle(NULL);
MODULEINFO info; MODULEINFO info;
DWORD ret;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
pGetModuleInformation(NULL, hMod, &info, sizeof(info)); pGetModuleInformation(NULL, hMod, &info, sizeof(info));
...@@ -135,13 +135,16 @@ static void test_GetModuleInformation(void) ...@@ -135,13 +135,16 @@ static void test_GetModuleInformation(void)
pGetModuleInformation(hpQV, hMod, &info, sizeof(info)-1); pGetModuleInformation(hpQV, hMod, &info, sizeof(info)-1);
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError()); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
if(w32_suc(pGetModuleInformation(hpQV, hMod, &info, sizeof(info)))) 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); ok(info.lpBaseOfDll == hMod, "lpBaseOfDll=%p hMod=%p\n", info.lpBaseOfDll, hMod);
} }
static void test_GetProcessMemoryInfo(void) static void test_GetProcessMemoryInfo(void)
{ {
PROCESS_MEMORY_COUNTERS pmc; PROCESS_MEMORY_COUNTERS pmc;
DWORD ret;
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
pGetProcessMemoryInfo(NULL, &pmc, sizeof(pmc)); pGetProcessMemoryInfo(NULL, &pmc, sizeof(pmc));
...@@ -155,7 +158,9 @@ static void test_GetProcessMemoryInfo(void) ...@@ -155,7 +158,9 @@ static void test_GetProcessMemoryInfo(void)
pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)-1); pGetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)-1);
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError()); 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) static void test_GetMappedFileName(void)
...@@ -195,7 +200,7 @@ static void test_GetProcessImageFileName(void) ...@@ -195,7 +200,7 @@ static void test_GetProcessImageFileName(void)
HMODULE hMod = GetModuleHandle(NULL); HMODULE hMod = GetModuleHandle(NULL);
char szImgPath[MAX_PATH], szMapPath[MAX_PATH]; char szImgPath[MAX_PATH], szMapPath[MAX_PATH];
WCHAR szImgPathW[MAX_PATH]; WCHAR szImgPathW[MAX_PATH];
DWORD ret; DWORD ret, ret1;
if(pGetProcessImageFileNameA == NULL) if(pGetProcessImageFileNameA == NULL)
return; return;
...@@ -227,13 +232,13 @@ static void test_GetProcessImageFileName(void) ...@@ -227,13 +232,13 @@ static void test_GetProcessImageFileName(void)
pGetProcessImageFileNameA(hpQI, szImgPath, 0); pGetProcessImageFileNameA(hpQI, szImgPath, 0);
todo_wine ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError()); todo_wine ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
todo_wine ret = pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath));
if(w32_suc(ret = pGetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath))) && ret1 = pGetMappedFileNameA(hpQV, hMod, szMapPath, sizeof(szMapPath));
w32_suc(pGetMappedFileNameA(hpQV, hMod, szMapPath, sizeof(szMapPath)))) { if(ret && ret1)
{
/* Windows returns 2*strlen-1 */ /* Windows returns 2*strlen-1 */
ok(ret >= strlen(szImgPath), "szImgPath=\"%s\" ret=%d\n", szImgPath, ret); todo_wine ok(ret >= strlen(szImgPath), "szImgPath=\"%s\" ret=%d\n", szImgPath, ret);
ok(!strcmp(szImgPath, szMapPath), todo_wine ok(!strcmp(szImgPath, szMapPath), "szImgPath=\"%s\" szMapPath=\"%s\"\n", szImgPath, szMapPath);
"szImgPath=\"%s\" szMapPath=\"%s\"\n", szImgPath, szMapPath);
} }
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
...@@ -286,7 +291,8 @@ static void test_GetModuleFileNameEx(void) ...@@ -286,7 +291,8 @@ static void test_GetModuleFileNameEx(void)
pGetModuleFileNameExA(hpQV, hBad, szModExPath, sizeof(szModExPath)); pGetModuleFileNameExA(hpQV, hBad, szModExPath, sizeof(szModExPath));
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError()); 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)))) ret = pGetModuleFileNameExA(hpQV, NULL, szModExPath, sizeof(szModExPath));
if(!ret)
return; return;
ok(ret == strlen(szModExPath), "szModExPath=\"%s\" ret=%d\n", szModExPath, ret); ok(ret == strlen(szModExPath), "szModExPath=\"%s\" ret=%d\n", szModExPath, ret);
GetModuleFileNameA(NULL, szModPath, sizeof(szModPath)); GetModuleFileNameA(NULL, szModPath, sizeof(szModPath));
...@@ -312,7 +318,8 @@ static void test_GetModuleBaseName(void) ...@@ -312,7 +318,8 @@ static void test_GetModuleBaseName(void)
pGetModuleBaseNameA(hpQV, hBad, szModBaseName, sizeof(szModBaseName)); pGetModuleBaseNameA(hpQV, hBad, szModBaseName, sizeof(szModBaseName));
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError()); 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; return;
ok(ret == strlen(szModBaseName), "szModBaseName=\"%s\" ret=%d\n", szModBaseName, ret); ok(ret == strlen(szModBaseName), "szModBaseName=\"%s\" ret=%d\n", szModBaseName, ret);
GetModuleFileNameA(NULL, szModPath, sizeof(szModPath)); GetModuleFileNameA(NULL, szModPath, sizeof(szModPath));
...@@ -336,7 +343,9 @@ static void test_ws_functions(void) ...@@ -336,7 +343,9 @@ static void test_ws_functions(void)
pEmptyWorkingSet(hpSR); pEmptyWorkingSet(hpSR);
todo_wine ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError()); 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 ); SetLastError( 0xdeadbeef );
ret = pInitializeProcessForWsWatch( NULL ); ret = pInitializeProcessForWsWatch( NULL );
...@@ -350,9 +359,12 @@ static void test_ws_functions(void) ...@@ -350,9 +359,12 @@ static void test_ws_functions(void)
} }
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() ); 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; return;
*addr = 0; /* make sure it's paged in (needed on wow64) */ *addr = 0; /* make sure it's paged in (needed on wow64) */
...@@ -362,29 +374,35 @@ static void test_ws_functions(void) ...@@ -362,29 +374,35 @@ static void test_ws_functions(void)
goto free_page; 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++) for(i = 0; i < pages[0]; i++)
if((pages[i+1] & ~0xfffL) == (ULONG_PTR)addr) 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; 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: 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++) for(i = 0; wswi[i].FaultingVa; i++)
if(((ULONG_PTR)wswi[i].FaultingVa & ~0xfffL) == (ULONG_PTR)addr) 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; 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: free_page:
...@@ -405,11 +423,12 @@ START_TEST(psapi_main) ...@@ -405,11 +423,12 @@ START_TEST(psapi_main)
{ {
DWORD pid = GetCurrentProcessId(); DWORD pid = GetCurrentProcessId();
w32_suc(hpSR = OpenProcess(STANDARD_RIGHTS_REQUIRED, FALSE, pid)); hpSR = OpenProcess(STANDARD_RIGHTS_REQUIRED, FALSE, pid);
w32_suc(hpQI = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid)); hpQI = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
w32_suc(hpVR = OpenProcess(PROCESS_VM_READ, FALSE, pid)); hpVR = OpenProcess(PROCESS_VM_READ, FALSE, pid);
w32_suc(hpQV = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)); hpQV = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
w32_suc(hpAA = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid)); hpAA = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(hpSR && hpQI && hpVR && hpQV && hpAA) if(hpSR && hpQI && hpVR && hpQV && hpAA)
{ {
test_EnumProcesses(); test_EnumProcesses();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment