Commit 80ba9f35 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

kernel32/tests: Test K32GetProcessImageFileNameA() and improve the…

kernel32/tests: Test K32GetProcessImageFileNameA() and improve the QueryFullProcessImageNameA() tests.
parent 1533965e
......@@ -62,6 +62,7 @@ static LPVOID (WINAPI *pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
static BOOL (WINAPI *pVirtualFreeEx)(HANDLE, LPVOID, SIZE_T, DWORD);
static BOOL (WINAPI *pQueryFullProcessImageNameA)(HANDLE hProcess, DWORD dwFlags, LPSTR lpExeName, PDWORD lpdwSize);
static BOOL (WINAPI *pQueryFullProcessImageNameW)(HANDLE hProcess, DWORD dwFlags, LPWSTR lpExeName, PDWORD lpdwSize);
static DWORD (WINAPI *pK32GetProcessImageFileNameA)(HANDLE,LPSTR,DWORD);
/* ############################### */
static char base[MAX_PATH];
......@@ -204,6 +205,7 @@ static int init(void)
pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
pQueryFullProcessImageNameA = (void *) GetProcAddress(hkernel32, "QueryFullProcessImageNameA");
pQueryFullProcessImageNameW = (void *) GetProcAddress(hkernel32, "QueryFullProcessImageNameW");
pK32GetProcessImageFileNameA = (void *) GetProcAddress(hkernel32, "K32GetProcessImageFileNameA");
return 1;
}
......@@ -1638,21 +1640,70 @@ static void test_GetProcessVersion(void)
CloseHandle(pi.hThread);
}
static void test_ProcessNameA(void)
static void test_GetProcessImageFileNameA(void)
{
DWORD rc;
CHAR process[MAX_PATH];
static const char harddisk[] = "\\Device\\HarddiskVolume";
if (!pK32GetProcessImageFileNameA)
{
win_skip("K32GetProcessImageFileNameA is unavailable\n");
return;
}
/* callers must guess the buffer size */
SetLastError(0xdeadbeef);
rc = pK32GetProcessImageFileNameA(GetCurrentProcess(), NULL, 0);
ok(!rc && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"K32GetProcessImageFileNameA(no buffer): returned %u, le=%u\n", rc, GetLastError());
*process = '\0';
rc = pK32GetProcessImageFileNameA(GetCurrentProcess(), process, sizeof(process));
expect_eq_d(rc, lstrlenA(process));
if (strncmp(process, harddisk, lstrlenA(harddisk)))
{
todo_wine win_skip("%s is probably on a network share, skipping tests\n", process);
return;
}
if (!pQueryFullProcessImageNameA)
win_skip("QueryFullProcessImageNameA unavailable (added in Windows Vista)\n");
else
{
CHAR image[MAX_PATH];
DWORD length;
length = sizeof(image);
expect_eq_d(TRUE, pQueryFullProcessImageNameA(GetCurrentProcess(), PROCESS_NAME_NATIVE, image, &length));
expect_eq_d(length, lstrlenA(image));
ok(lstrcmpi(process, image) == 0, "expected '%s' to be equal to '%s'\n", process, image);
}
}
static void test_QueryFullProcessImageNameA(void)
{
#define INIT_STR "Just some words"
DWORD length, size;
CHAR buf[1024];
CHAR buf[MAX_PATH], module[MAX_PATH];
if (!pQueryFullProcessImageNameA)
{
win_skip("QueryFullProcessImageNameA unavailable (added in Windows Vista)\n");
return;
}
*module = '\0';
SetLastError(0); /* old Windows don't reset it on success */
size = GetModuleFileNameA(NULL, module, sizeof(module));
ok(size && GetLastError() != ERROR_INSUFFICIENT_BUFFER, "GetModuleFileName failed: %u le=%u\n", size, GetLastError());
/* get the buffer length without \0 terminator */
length = 1024;
length = sizeof(buf);
expect_eq_d(TRUE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &length));
expect_eq_d(length, lstrlenA(buf));
ok((buf[0] == '\\' && buf[1] == '\\') ||
lstrcmpi(buf, module) == 0, "expected %s to match %s\n", buf, module);
/* when the buffer is too small
* - function fail with error ERROR_INSUFFICIENT_BUFFER
......@@ -1685,7 +1736,7 @@ static void test_ProcessNameA(void)
expect_eq_d(ERROR_INVALID_PARAMETER, GetLastError());
}
static void test_ProcessName(void)
static void test_QueryFullProcessImageNameW(void)
{
HANDLE hSelf;
WCHAR module_name[1024];
......@@ -1888,8 +1939,9 @@ START_TEST(process)
test_ExitCode();
test_OpenProcess();
test_GetProcessVersion();
test_ProcessNameA();
test_ProcessName();
test_GetProcessImageFileNameA();
test_QueryFullProcessImageNameA();
test_QueryFullProcessImageNameW();
test_Handles();
test_SystemInfo();
test_RegistryQuota();
......
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