[1/3] kernel32/tests: Test K32GetProcessImageFileNameA() and improve the QueryFullProcessImageNameA() tests.
Francois Gouget
fgouget at codeweavers.com
Mon Oct 3 22:11:40 CDT 2011
---
I moved a variable but as Dan pointed out I forgot to remove it from
where it was first.
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 61e3069..85e119d 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -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();
--
Francois Gouget <fgouget at codeweavers.com>
More information about the wine-patches
mailing list