[2/3] kernel32/tests: Test K32GetProcessImageFileNameA() and improve the QueryFullProcessImageNameA() tests.

Francois Gouget fgouget at codeweavers.com
Thu Sep 29 19:19:06 CDT 2011


---

At some point the test assumes that GetModuleFileName() resets LastError 
so it depends on the previous patch. Initially this was to be 
accompanied by a fix for K32GetProcessImageFileNameA() but that part 
is not ready yet. At least with this part in I'll see if there are 
issues with older Windows versions.

 dlls/kernel32/tests/process.c |   81 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 73 insertions(+), 8 deletions(-)

diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 1ee30dc..f0447ec 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,84 @@ static void test_GetProcessVersion(void)
     CloseHandle(pi.hThread);
 }
 
-static void test_ProcessNameA(void)
+static void test_GetProcessNameA(void)
+{
+    DWORD rc, size;
+    CHAR process[MAX_PATH], module[MAX_PATH], device[1024];
+    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';
+    size = sizeof(process);
+    rc = pK32GetProcessImageFileNameA(GetCurrentProcess(), process, size);
+    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;
+    }
+
+    *module = '\0';
+    size = sizeof(module);
+    rc = GetModuleFileName(NULL, module, size);
+    ok(rc && GetLastError() != ERROR_INSUFFICIENT_BUFFER, "GetModuleFileName failed: %u le=%u\n", rc, GetLastError());
+    expect_eq_d(rc, lstrlenA(module));
+
+    module[2] = '\0';
+    *device = '\0';
+    size = sizeof(device);
+    rc = QueryDosDeviceA(module, device, size);
+    ok(rc, "QueryDosDeviceA failed: le=%u\n", GetLastError());
+    size = lstrlenA(device);
+    ok(rc >= size+2, "expected %d to be greater than %d+2 = strlen(%s)\n", rc, size, device);
+
+    if (size >= lstrlenA(process))
+    {
+        ok(0, "expected '%s\\' to match the start of '%s'\n", device, process);
+    }
+    else
+    {
+        ok(process[size] == '\\', "expected '%c' to be a '\\' in %s\n", process[size], module);
+        process[size] = '\0';
+        ok(lstrcmpiA(device, process) == 0, "expected '%s' to match '%s'\n", device, process);
+        ok(lstrcmpiA(module+3, process+size+1) == 0, "expected '%s' to match '%s'\n", module+3, process+size+1);
+    }
+}
+
+static void test_QueryProcessNameA(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';
+    length = sizeof(module);
+    size = GetModuleFileName(NULL, module, length);
+    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
@@ -1666,8 +1731,7 @@ static void test_ProcessNameA(void)
     expect_eq_d(length, size);
     expect_eq_s(INIT_STR, buf);
 
-    /* retest with smaller buffer size
-     */
+    /* retest with smaller buffer size */
     size = 4;
     sprintf(buf,INIT_STR);
     expect_eq_d(FALSE, pQueryFullProcessImageNameA(GetCurrentProcess(), 0, buf, &size));
@@ -1685,7 +1749,7 @@ static void test_ProcessNameA(void)
     expect_eq_d(ERROR_INVALID_PARAMETER, GetLastError());
 }
 
-static void test_ProcessName(void)
+static void test_QueryProcessNameW(void)
 {
     HANDLE hSelf;
     WCHAR module_name[1024];
@@ -1888,8 +1952,9 @@ START_TEST(process)
     test_ExitCode();
     test_OpenProcess();
     test_GetProcessVersion();
-    test_ProcessNameA();
-    test_ProcessName();
+    test_GetProcessNameA();
+    test_QueryProcessNameA();
+    test_QueryProcessNameW();
     test_Handles();
     test_SystemInfo();
     test_RegistryQuota();
-- 
1.7.6.3




More information about the wine-patches mailing list