From 88bdfac0f88e250975181edc251b7f527217224a Mon Sep 17 00:00:00 2001
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
Date: Sat, 3 Jan 2015 20:24:07 -0700
Subject: kernel32: Add SearchPath test demonstrating the priority of the
 working directory.

---
 dlls/kernel32/tests/path.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/tests/path.c b/dlls/kernel32/tests/path.c
index 836d7ec..079820f 100644
--- a/dlls/kernel32/tests/path.c
+++ b/dlls/kernel32/tests/path.c
@@ -1790,10 +1790,11 @@ static void test_SearchPathA(void)
     static const CHAR testdeprelA[] = "./testdep.dll";
     static const CHAR kernel32A[] = "kernel32.dll";
     static const CHAR fileA[] = "";
-    CHAR pathA[MAX_PATH], buffA[MAX_PATH], path2A[MAX_PATH];
-    CHAR *ptrA = NULL;
+    CHAR pathA[MAX_PATH], buffA[MAX_PATH], path2A[MAX_PATH], path3A[MAX_PATH], curdirA[MAX_PATH];
+    CHAR tmpdirA[MAX_PATH], *ptrA = NULL;
     ULONG_PTR cookie;
     HANDLE handle;
+    BOOL bret;
     DWORD ret;
 
     if (!pSearchPathA)
@@ -1867,6 +1868,28 @@ static void test_SearchPathA(void)
     ret = pDeactivateActCtx(0, cookie);
     ok(ret, "failed to deactivate context, %u\n", GetLastError());
     pReleaseActCtx(handle);
+
+    /* test the search path priority of the working directory */
+    GetTempPathA(sizeof(tmpdirA), tmpdirA);
+    ret = GetCurrentDirectoryA(MAX_PATH, curdirA);
+    ok(ret, "failed to obtain working directory.\n");
+    sprintf(pathA, "%s\\%s", tmpdirA, kernel32A);
+    ret = pSearchPathA(NULL, kernel32A, NULL, sizeof(path2A)/sizeof(CHAR), path2A, NULL);
+    ok(ret && ret == strlen(path2A), "got %d\n", ret);
+    bret = CopyFileA(path2A, pathA, FALSE);
+    ok(bret != 0, "failed to copy test executable to temp directory, %u\n", GetLastError());
+    sprintf(path3A, "%s%s%s", curdirA, curdirA[strlen(curdirA)-1] != '\\' ? "\\" : "", kernel32A);
+    bret = CopyFileA(path2A, path3A, FALSE);
+    ok(bret != 0, "failed to copy test executable to launch directory, %u\n", GetLastError());
+    bret = SetCurrentDirectoryA(tmpdirA);
+    ok(bret, "failed to change working directory\n");
+    ret = pSearchPathA(NULL, kernel32A, ".exe", sizeof(buffA), buffA, NULL);
+    ok(ret && ret == strlen(buffA), "got %d\n", ret);
+    ok(strcmp(buffA, path3A) == 0, "expected %s, got %s\n", path3A, buffA);
+    bret = SetCurrentDirectoryA(curdirA);
+    ok(bret, "failed to reset working directory\n");
+    DeleteFileA(path3A);
+    DeleteFileA(pathA);
 }
 
 static void test_SearchPathW(void)
-- 
2.7.1

