James Hawkins : setupapi:
The Inf file should be copied regardless of the destination buffer,
with tests.
Alexandre Julliard
julliard at wine.codeweavers.com
Wed Mar 28 06:42:11 CDT 2007
Module: wine
Branch: master
Commit: ff326fd0ffd4ad017634d6d068781d8a0736d4a2
URL: http://source.winehq.org/git/wine.git/?a=commit;h=ff326fd0ffd4ad017634d6d068781d8a0736d4a2
Author: James Hawkins <truiken at gmail.com>
Date: Wed Mar 28 01:55:46 2007 -0500
setupapi: The Inf file should be copied regardless of the destination buffer, with tests.
---
dlls/setupapi/misc.c | 26 ++++++++++--------
dlls/setupapi/tests/misc.c | 61 +++++++++++++++++++++++--------------------
2 files changed, 47 insertions(+), 40 deletions(-)
diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c
index 8257828..eb3c3a1 100644
--- a/dlls/setupapi/misc.c
+++ b/dlls/setupapi/misc.c
@@ -887,20 +887,21 @@ BOOL WINAPI SetupCopyOEMInfA( PCSTR source, PCSTR location,
{
BOOL ret = FALSE;
LPWSTR destW = NULL, sourceW = NULL, locationW = NULL;
- INT size = MAX_PATH;
+ DWORD size;
TRACE("%s, %s, %d, %d, %p, %d, %p, %p\n", debugstr_a(source), debugstr_a(location),
media_type, style, dest, buffer_size, required_size, component);
- if (dest && !(destW = MyMalloc( MAX_PATH * sizeof(WCHAR) ))) return FALSE;
+ if (dest && !(destW = MyMalloc( buffer_size * sizeof(WCHAR) ))) return FALSE;
if (source && !(sourceW = strdupAtoW( source ))) goto done;
if (location && !(locationW = strdupAtoW( location ))) goto done;
- if (!(ret = SetupCopyOEMInfW( sourceW, locationW, media_type, style, destW, size, NULL, NULL )))
+ if (!(ret = SetupCopyOEMInfW( sourceW, locationW, media_type, style, destW,
+ buffer_size, &size, NULL )))
+ {
+ if (required_size) *required_size = size;
goto done;
-
- size = WideCharToMultiByte( CP_ACP, 0, destW, -1, NULL, 0, NULL, NULL );
- if (required_size) *required_size = size;
+ }
if (dest)
{
@@ -957,17 +958,18 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location,
if ((p = strrchrW( source, '\\' )))
strcatW( target, p + 1 );
+ if (!(ret = CopyFileW( source, target, (style & SP_COPY_NOOVERWRITE) != 0 )))
+ return ret;
+
+ if (style & SP_COPY_DELETESOURCE)
+ DeleteFileW( source );
+
size = strlenW( target ) + 1;
if (dest)
{
if (buffer_size >= size)
{
- /* FIXME: honour style flags */
- if ((ret = CopyFileW( source, target, (style & SP_COPY_NOOVERWRITE) != 0 )))
- {
- if (style & SP_COPY_DELETESOURCE) DeleteFileW( source );
- strcpyW( dest, target );
- }
+ strcpyW( dest, target );
}
else
{
diff --git a/dlls/setupapi/tests/misc.c b/dlls/setupapi/tests/misc.c
index ea11a6c..27dcc77 100644
--- a/dlls/setupapi/tests/misc.c
+++ b/dlls/setupapi/tests/misc.c
@@ -102,7 +102,7 @@ static void test_SetupCopyOEMInf(void)
{
CHAR toolong[MAX_PATH * 2];
CHAR path[MAX_PATH], dest[MAX_PATH];
- CHAR tmpfile[MAX_PATH];
+ CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
LPSTR inf;
DWORD size;
BOOL res;
@@ -134,11 +134,8 @@ static void test_SetupCopyOEMInf(void)
SetLastError(0xdeadbeef);
res = SetupCopyOEMInf(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
ok(res == FALSE, "Expected FALSE, got %d\n", res);
- todo_wine
- {
- ok(GetLastError() == ERROR_FILE_NOT_FOUND,
- "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
- }
+ ok(GetLastError() == ERROR_FILE_NOT_FOUND,
+ "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
/* try a long SourceInfFileName */
memset(toolong, 'a', MAX_PATH * 2);
@@ -164,11 +161,8 @@ static void test_SetupCopyOEMInf(void)
SetLastError(0xdeadbeef);
res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
ok(res == FALSE, "Expected FALSE, got %d\n", res);
- todo_wine
- {
- ok(GetLastError() == ERROR_FILE_NOT_FOUND,
- "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
- }
+ ok(GetLastError() == ERROR_FILE_NOT_FOUND,
+ "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
ok(file_exists(tmpfile), "Expected source inf to exist\n");
/* try an absolute SourceInfFileName, without DestinationInfFileName */
@@ -177,32 +171,23 @@ static void test_SetupCopyOEMInf(void)
lstrcat(path, tmpfile);
SetLastError(0xdeadbeef);
res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
- todo_wine
- {
- ok(res == TRUE, "Expected TRUE, got %d\n", res);
- ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
- }
+ ok(res == TRUE, "Expected TRUE, got %d\n", res);
+ ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
ok(file_exists(path), "Expected source inf to exist\n");
/* try SP_COPY_REPLACEONLY, dest exists */
SetLastError(0xdeadbeef);
res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
- todo_wine
- {
- ok(res == TRUE, "Expected TRUE, got %d\n", res);
- ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
- }
+ ok(res == TRUE, "Expected TRUE, got %d\n", res);
+ ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
ok(file_exists(path), "Expected source inf to exist\n");
/* try SP_COPY_NOOVERWRITE */
SetLastError(0xdeadbeef);
res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
ok(res == FALSE, "Expected FALSE, got %d\n", res);
- todo_wine
- {
- ok(GetLastError() == ERROR_FILE_EXISTS,
- "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
- }
+ ok(GetLastError() == ERROR_FILE_EXISTS,
+ "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
/* get the DestinationInfFileName */
SetLastError(0xdeadbeef);
@@ -217,6 +202,24 @@ static void test_SetupCopyOEMInf(void)
}
ok(file_exists(path), "Expected source inf to exist\n");
+ lstrcpy(dest_save, dest);
+ DeleteFile(dest_save);
+
+ /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
+ * - inf is still copied
+ */
+ lstrcpy(dest, "aaa");
+ size = 0;
+ SetLastError(0xdeadbeef);
+ res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
+ ok(res == FALSE, "Expected FALSE, got %d\n", res);
+ ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
+ "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+ ok(file_exists(path), "Expected source inf to exist\n");
+ ok(file_exists(dest_save), "Expected dest inf to exist\n");
+ ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
+ ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
+
/* get the DestinationInfFileName and DestinationInfFileNameSize */
SetLastError(0xdeadbeef);
res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
@@ -229,6 +232,7 @@ static void test_SetupCopyOEMInf(void)
ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
}
ok(file_exists(path), "Expected source inf to exist\n");
+ ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
/* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
SetLastError(0xdeadbeef);
@@ -242,15 +246,16 @@ static void test_SetupCopyOEMInf(void)
ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
}
ok(file_exists(path), "Expected source inf to exist\n");
+ ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
/* try SP_COPY_DELETESOURCE */
SetLastError(0xdeadbeef);
res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
+ ok(res == TRUE, "Expected TRUE, got %d\n", res);
+ ok(!file_exists(path), "Expected source inf to not exist\n");
todo_wine
{
- ok(res == TRUE, "Expected TRUE, got %d\n", res);
ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
- ok(!file_exists(path), "Expected source inf to not exist\n");
}
}
More information about the wine-cvs
mailing list