version: VerFindFile: Add some tests & fixes.
Florian Tobias Schandinat
FlorianSchandinat at gmx.de
Wed Feb 4 03:56:42 CST 2009
---
dlls/version/install.c | 62 +++++++++++++++++++++++++++++++++++++----
dlls/version/tests/install.c | 33 +++++++++++++++++++++-
2 files changed, 87 insertions(+), 8 deletions(-)
diff --git a/dlls/version/install.c b/dlls/version/install.c
index 2ecfeb9..f416cfc 100644
--- a/dlls/version/install.c
+++ b/dlls/version/install.c
@@ -40,6 +40,46 @@ WINE_DEFAULT_DEBUG_CHANNEL(ver);
/******************************************************************************
+ * IsDirA
+ *
+ * Tests whether a given string exists and is a directory.
+ * If it is, the return value is non-zero.
+ */
+static int IsDirA(const char *path)
+{
+ DWORD attr;
+
+ if (!path)
+ return 0;
+
+ attr = GetFileAttributesA(path);
+ if (attr!=INVALID_FILE_ATTRIBUTES && attr&FILE_ATTRIBUTE_DIRECTORY)
+ return 1;
+
+ return 0;
+}
+
+/******************************************************************************
+ * IsDirW
+ *
+ * Tests whether a given string exists and is a directory.
+ * If it is, the return value is non-zero.
+ */
+static int IsDirW(const WCHAR *path)
+{
+ DWORD attr;
+
+ if (!path)
+ return 0;
+
+ attr = GetFileAttributesW(path);
+ if (attr!=INVALID_FILE_ATTRIBUTES && attr&FILE_ATTRIBUTE_DIRECTORY)
+ return 1;
+
+ return 0;
+}
+
+/******************************************************************************
* testFileExistenceA
*
* Tests whether a given path/file combination exists. If the file does
@@ -163,23 +203,28 @@ DWORD WINAPI VerFindFileA(
curDir = lpszAppDir;
retval |= VFF_CURNEDEST;
}
+ else if (IsDirA(lpszWinDir) || IsDirA(lpszAppDir))
+ retval |= VFF_CURNEDEST;
}
}
else /* not a shared file */
{
- if(lpszAppDir)
+ if(IsDirA(lpszAppDir))
{
destDir = lpszAppDir;
if(lpszFilename)
{
if(testFileExistenceA(destDir, lpszFilename, FALSE)) curDir = destDir;
- else if(testFileExistenceA(systemDir, lpszFilename, FALSE))
+ else
{
- curDir = systemDir;
retval |= VFF_CURNEDEST;
+ if(testFileExistenceA(systemDir, lpszFilename, FALSE))
+ curDir = systemDir;
}
}
}
+ else if (lpszWinDir && lpszFilename && testFileExistenceA(lpszWinDir, lpszFilename, FALSE))
+ destDir = curDir = systemDir;
}
/* Check to see if the file exists and is inuse by another application */
@@ -257,23 +302,28 @@ DWORD WINAPI VerFindFileW( DWORD flags,LPCWSTR lpszFilename,LPCWSTR lpszWinDir,
curDir = lpszAppDir;
retval |= VFF_CURNEDEST;
}
+ else if (IsDirW(lpszWinDir) || IsDirW(lpszAppDir))
+ retval |= VFF_CURNEDEST;
}
}
else /* not a shared file */
{
- if(lpszAppDir)
+ if(IsDirW(lpszAppDir))
{
destDir = lpszAppDir;
if(lpszFilename)
{
if(testFileExistenceW(destDir, lpszFilename, FALSE)) curDir = destDir;
- else if(testFileExistenceW(systemDir, lpszFilename, FALSE))
+ else
{
- curDir = systemDir;
retval |= VFF_CURNEDEST;
+ if(testFileExistenceW(systemDir, lpszFilename, FALSE))
+ curDir = systemDir;
}
}
}
+ else if (lpszWinDir && lpszFilename && testFileExistenceW(lpszWinDir, lpszFilename, FALSE))
+ destDir = curDir = systemDir;
}
if (lpszFilename && !testFileExistenceW(curDir, lpszFilename, TRUE))
diff --git a/dlls/version/tests/install.c b/dlls/version/tests/install.c
index 6fc19bb..6dccaa8 100644
--- a/dlls/version/tests/install.c
+++ b/dlls/version/tests/install.c
@@ -114,6 +114,35 @@ static void test_find_file(void)
todo_wine ok(0, "Got unexpected return value %x\n", ret);
}
}
+
+ /* test the behaviour for nonexistent shared files */
+ dwCur=MAX_PATH;
+ dwOut=MAX_PATH;
+ memset(curdir, 0, MAX_PATH);
+ memset(outBuf, 0, MAX_PATH);
+ ret = VerFindFileA(0, "NoWINE.dll", windir, empty, curdir, &dwCur, outBuf, &dwOut);
+ ok(!ret || ret==VFF_BUFFTOOSMALL, "Unexpected result: %x, %s, %d, %s, %d\n", ret, curdir, dwCur, outBuf, dwOut);
+
+ dwCur=MAX_PATH;
+ dwOut=MAX_PATH;
+ memset(curdir, 0, MAX_PATH);
+ memset(outBuf, 0, MAX_PATH);
+ ret = VerFindFileA(VFFF_ISSHAREDFILE, "NoWINE.dll", windir, empty, curdir, &dwCur, outBuf, &dwOut);
+ ok(ret==VFF_CURNEDEST || ret==VFF_BUFFTOOSMALL, "Unexpected result: %x, %s, %d, %s, %d\n", ret, curdir, dwCur, outBuf, dwOut);
+
+ dwCur=MAX_PATH;
+ dwOut=MAX_PATH;
+ memset(curdir, 0, MAX_PATH);
+ memset(outBuf, 0, MAX_PATH);
+ ret = VerFindFileA(0, "NoWINE.dll", windir, windir, curdir, &dwCur, outBuf, &dwOut);
+ ok(ret==VFF_CURNEDEST, "Unexpected result: %x, %s, %d, %s, %d\n", ret, curdir, dwCur, outBuf, dwOut);
+
+ dwCur=MAX_PATH;
+ dwOut=MAX_PATH;
+ memset(curdir, 0, MAX_PATH);
+ memset(outBuf, 0, MAX_PATH);
+ ret = VerFindFileA(VFFF_ISSHAREDFILE, "NoWINE.dll", windir, windir, curdir, &dwCur, outBuf, &dwOut);
+ ok(ret==VFF_CURNEDEST, "Unexpected result: %x, %s, %d, %s, %d\n", ret, curdir, dwCur, outBuf, dwOut);
}
if(!GetModuleFileNameA(NULL, filename, MAX_PATH) ||
!GetSystemDirectoryA(windir, MAX_PATH) ||
@@ -150,7 +179,7 @@ static void test_find_file(void)
memset(outBuf, 0, MAX_PATH);
memset(curdir, 0, MAX_PATH);
ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
- todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
+ ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
ok(dwOut == 1 + strlen(windir), "Wrong length of buffer for current location: "
"got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(windir)+1);
@@ -159,7 +188,7 @@ static void test_find_file(void)
memset(outBuf, 0, MAX_PATH);
memset(curdir, 0, MAX_PATH);
ret = VerFindFileA(0, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
- todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
+ ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
ok(dwOut == 1 + strlen(appdir), "Wrong length of buffer for current location: "
"got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(appdir)+1);
}
--
1.4.4.4
--------------060605020205000106040307--
More information about the wine-patches
mailing list