Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/tests/misc.c | 298 ++++++++++++++++++------------------- 1 file changed, 142 insertions(+), 156 deletions(-)
diff --git a/dlls/setupapi/tests/misc.c b/dlls/setupapi/tests/misc.c index 9143cd4bd33..157edd82a7c 100644 --- a/dlls/setupapi/tests/misc.c +++ b/dlls/setupapi/tests/misc.c @@ -45,27 +45,19 @@ static CHAR CURR_DIR[MAX_PATH]; */
static BOOL (WINAPI *pSetupGetFileCompressionInfoExA)(PCSTR, PSTR, DWORD, PDWORD, PDWORD, PDWORD, PUINT); -static BOOL (WINAPI *pSetupCopyOEMInfA)(PCSTR, PCSTR, DWORD, DWORD, PSTR, DWORD, PDWORD, PSTR *); static BOOL (WINAPI *pSetupQueryInfOriginalFileInformationA)(PSP_INF_INFORMATION, UINT, PSP_ALTPLATFORM_INFO, PSP_ORIGINAL_FILE_INFO_A); -static BOOL (WINAPI *pSetupUninstallOEMInfA)(PCSTR, DWORD, PVOID);
-static void create_inf_file(LPCSTR filename) +static void create_file(const char *name, const char *data) { - DWORD dwNumberOfBytesWritten; - HANDLE hf = CreateFileA(filename, GENERIC_WRITE, 0, NULL, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE file; + DWORD size; + BOOL ret;
- static const char data[] = - "[Version]\n" - "Signature="$Chicago$"\n" - "AdvancedINF=2.5\n" - "[DefaultInstall]\n" - "RegisterOCXs=RegisterOCXsSection\n" - "[RegisterOCXsSection]\n" - "%%11%%\ole32.dll\n"; - - WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL); - CloseHandle(hf); + file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); + ok(file != INVALID_HANDLE_VALUE, "Failed to create %s, error %u.\n", name, GetLastError()); + ret = WriteFile(file, data, strlen(data), &size, NULL); + ok(ret && size == strlen(data), "Failed to write %s, error %u.\n", name, GetLastError()); + CloseHandle(file); }
static void get_temp_filename(LPSTR path) @@ -84,19 +76,13 @@ static BOOL file_exists(LPSTR path) return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES; }
-static BOOL check_format(LPSTR path, LPSTR inf) +static BOOL is_in_inf_dir(const char *path) { - CHAR check[MAX_PATH]; - BOOL res; - - static const CHAR format[] = "\INF\oem"; - - GetWindowsDirectoryA(check, MAX_PATH); - strcat(check, format); - res = CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, check, -1, path, strlen(check)) == CSTR_EQUAL && - path[strlen(check)] != '\'; + char expect[MAX_PATH];
- return (!inf) ? res : res && (inf == path + strlen(check) - 3); + GetWindowsDirectoryA(expect, sizeof(expect)); + strcat(expect, "\inf\"); + return !strncasecmp(path, expect, strrchr(path, '\') - path); }
static void test_original_file_name(LPCSTR original, LPCSTR dest) @@ -143,32 +129,39 @@ static void test_original_file_name(LPCSTR original, LPCSTR dest)
static void test_SetupCopyOEMInf(void) { - CHAR toolong[MAX_PATH * 2]; - CHAR path[MAX_PATH], dest[MAX_PATH]; - CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH]; - LPSTR inf = NULL; + char path[MAX_PATH * 2], dest[MAX_PATH], tmpfile[MAX_PATH], orig_dest[MAX_PATH]; + char *filepart, pnf[MAX_PATH]; DWORD size; BOOL res;
+ static const char inf_data1[] = + "[Version]\n" + "Signature="$Chicago$"\n" + "; This is a WINE test INF file\n"; + + static const char inf_data2[] = + "[Version]\n" + "Signature="$Chicago$"\n" + "; This is another WINE test INF file\n"; + /* try NULL SourceInfFileName */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
/* try empty SourceInfFileName */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_NOT_FOUND || - GetLastError() == ERROR_BAD_PATHNAME || /* Win98 */ GetLastError() == ERROR_INVALID_PARAMETER, /* Vista, W2K8 */ "Unexpected error : %d\n", GetLastError());
/* try a relative nonexistent SourceInfFileName */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); @@ -177,30 +170,18 @@ static void test_SetupCopyOEMInf(void) strcpy(path, CURR_DIR); strcat(path, "\nonexistent"); SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); 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); - toolong[MAX_PATH * 2 - 1] = '\0'; - SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); - ok(res == FALSE, "Expected FALSE, got %d\n", res); - ok(GetLastError() == ERROR_FILE_NOT_FOUND || - GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Win98 */ - "Expected ERROR_FILE_NOT_FOUND or ERROR_FILENAME_EXCED_RANGE, got %d\n", GetLastError()); - get_temp_filename(tmpfile); - create_inf_file(tmpfile); + create_file(tmpfile, inf_data1);
/* try a relative SourceInfFileName */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); - ok(res == FALSE || - broken(res == TRUE), /* Win98 */ - "Expected FALSE, got %d\n", res); + res = SetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); + ok(res == FALSE, "Expected FALSE, got %d\n", res); if (GetLastError() == ERROR_WRONG_INF_TYPE || GetLastError() == ERROR_UNSUPPORTED_TYPE /* Win7 */) { /* FIXME: @@ -212,152 +193,169 @@ static void test_SetupCopyOEMInf(void) return; }
- ok(GetLastError() == ERROR_FILE_NOT_FOUND || - broken(GetLastError() == ERROR_SUCCESS), /* Win98 */ - "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 tmpfile to exist\n");
/* try SP_COPY_REPLACEONLY, dest does not exist */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); 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 */ + /* Test a successful call. */ strcpy(path, CURR_DIR); strcat(path, "\"); strcat(path, tmpfile); SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, NULL); if (!res && GetLastError() == ERROR_ACCESS_DENIED) { skip("SetupCopyOEMInfA() failed on insufficient permissions\n"); + DeleteFileA(tmpfile); return; } 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"); + ok(file_exists(path), "Expected source inf to exist.\n"); + ok(file_exists(dest), "Expected dest file to exist.\n"); + ok(is_in_inf_dir(dest), "Got unexpected path '%s'.\n", dest); + strcpy(orig_dest, dest); + + /* Existing INF files are checked for a match. */ + SetLastError(0xdeadbeef); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, NULL); + 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"); + ok(file_exists(dest), "Expected dest file to exist.\n"); +todo_wine + ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest);
/* try SP_COPY_REPLACEONLY, dest exists */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, dest, sizeof(dest), NULL, NULL); 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"); + ok(file_exists(path), "Expected source inf to exist.\n"); + ok(file_exists(dest), "Expected dest file to exist.\n"); +todo_wine + ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest);
- /* try SP_COPY_NOOVERWRITE */ + strcpy(dest, "aaa"); SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, dest, sizeof(dest), NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_EXISTS, "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError()); +todo_wine + ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest);
- /* get the DestinationInfFileName */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); - ok(strlen(dest) != 0, "Expected a non-zero length string\n"); - ok(file_exists(dest), "Expected destination inf to exist\n"); - 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(file_exists(path), "Expected source inf to exist.\n"); + ok(file_exists(orig_dest), "Expected dest file to exist.\n");
- strcpy(dest_save, dest); - DeleteFileA(dest_save); - - /* get the DestinationInfFileName, DestinationInfFileNameSize is too small - * - inf is still copied - */ strcpy(dest, "aaa"); size = 0; SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL); + res = SetupCopyOEMInfA(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(file_exists(orig_dest), "Expected dest inf to exist\n"); ok(!strcmp(dest, "aaa"), "Expected dest to be unchanged\n"); - ok(size == strlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); +todo_wine + ok(size == strlen(orig_dest) + 1, "Expected size %d, got %d.\n", strlen(orig_dest) + 1, size);
- /* get the DestinationInfFileName and DestinationInfFileNameSize */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), &size, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); - ok(lstrlenA(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlenA(dest), size); - ok(file_exists(dest), "Expected destination inf to exist\n"); - 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 == lstrlenA(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); +todo_wine + ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest); + ok(size == strlen(dest) + 1, "Expected size %d, got %d.\n", strlen(dest) + 1, size);
test_original_file_name(strrchr(path, '\') + 1, dest);
- /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, &filepart); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); - ok(lstrlenA(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlenA(dest), size); - ok(file_exists(dest), "Expected destination inf to exist\n"); - ok((inf && inf[0] != 0) || - broken(!inf), /* Win98 */ - "Expected inf to point to the filename\n"); - 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 == lstrlenA(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); +todo_wine + ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest); + ok(filepart == strrchr(dest, '\') + 1, "Got unexpected file part %s.\n", filepart);
- /* try SP_COPY_DELETESOURCE */ SetLastError(0xdeadbeef); - res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL); 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");
- if (pSetupUninstallOEMInfA) - { - char pnf[MAX_PATH]; - char *pnffile; - char *destfile = strrchr(dest, '\') + 1; - - strcpy(pnf, dest); - *(strrchr(pnf, '.') + 1) = 'p'; - pnffile = strrchr(pnf, '\') + 1; - - SetLastError(0xdeadbeef); - res = pSetupUninstallOEMInfA(destfile, 0, NULL); - if(!res) - res = pSetupUninstallOEMInfA(pnffile, 0, NULL); - ok(res, "Failed to uninstall '%s'/'%s' : %d\n", destfile, - pnffile, GetLastError()); - todo_wine ok(!file_exists(dest), "Expected inf '%s' to not exist\n", dest); - if(file_exists(dest)) - { - SetLastError(0xdeadbeef); - res = DeleteFileA(dest); - ok(res, "Failed to delete file '%s' : %d\n", dest, GetLastError()); - } - ok(!file_exists(pnf), "Expected pnf '%s' to not exist\n", pnf); - if(file_exists(pnf)) - { - SetLastError(0xdeadbeef); - res = DeleteFileA(pnf); - ok(res, "Failed to delete file '%s' : %d\n", pnf, GetLastError()); - } - } - else - { - /* Win9x/WinMe */ - SetLastError(0xdeadbeef); - res = DeleteFileA(dest); - ok(res, "Failed to delete file '%s' : %d\n", dest, GetLastError()); - - /* On WinMe we also need to remove the .pnf file */ - *(strrchr(dest, '.') + 1) = 'p'; - DeleteFileA(dest); - } + strcpy(pnf, dest); + *(strrchr(pnf, '.') + 1) = 'p'; + + res = SetupUninstallOEMInfA(strrchr(dest, '\') + 1, 0, NULL); + ok(res, "Failed to uninstall '%s', error %u.\n", dest, GetLastError()); + todo_wine ok(!file_exists(dest), "Expected inf '%s' to not exist\n", dest); + DeleteFileA(dest); + ok(!file_exists(pnf), "Expected pnf '%s' to not exist\n", pnf); + + create_file(tmpfile, inf_data1); + SetLastError(0xdeadbeef); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, NULL); + ok(res == TRUE, "Expected TRUE, got %d\n", res); + ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); + ok(is_in_inf_dir(dest), "Got unexpected path '%s'.\n", dest); + strcpy(orig_dest, dest); + + create_file(tmpfile, inf_data2); + SetLastError(0xdeadbeef); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, NULL); + ok(res == TRUE, "Expected TRUE, got %d\n", res); + ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); + ok(is_in_inf_dir(dest), "Got unexpected path '%s'.\n", dest); + ok(strcmp(dest, orig_dest), "Expected INF files to be copied to differnet paths.\n"); + + res = SetupUninstallOEMInfA(strrchr(dest, '\') + 1, 0, NULL); + ok(res, "Failed to uninstall '%s', error %u.\n", dest, GetLastError()); + todo_wine ok(!file_exists(dest), "Expected inf '%s' to not exist\n", dest); + DeleteFileA(dest); + strcpy(pnf, dest); + *(strrchr(pnf, '.') + 1) = 'p'; + ok(!file_exists(pnf), "Expected pnf '%s' to not exist\n", pnf); + + res = SetupUninstallOEMInfA(strrchr(orig_dest, '\') + 1, 0, NULL); + ok(res, "Failed to uninstall '%s', error %u.\n", orig_dest, GetLastError()); + todo_wine ok(!file_exists(orig_dest), "Expected inf '%s' to not exist\n", dest); + DeleteFileA(orig_dest); + strcpy(pnf, dest); + *(strrchr(pnf, '.') + 1) = 'p'; + ok(!file_exists(pnf), "Expected pnf '%s' to not exist\n", pnf); + + GetWindowsDirectoryA(orig_dest, sizeof(orig_dest)); + strcat(orig_dest, "\inf\"); + strcat(orig_dest, tmpfile); + res = CopyFileA(tmpfile, orig_dest, TRUE); +todo_wine + ok(res, "Failed to copy file, error %u.\n", GetLastError()); + SetLastError(0xdeadbeef); + res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, NULL); + ok(res == TRUE, "Expected TRUE, got %d\n", res); + ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); +todo_wine + ok(!strcasecmp(dest, orig_dest), "Expected '%s', got '%s'.\n", orig_dest, dest); + + /* Since it wasn't actually installed, SetupUninstallOEMInf would fail here. */ + res = DeleteFileA(dest); + ok(res, "Failed to delete '%s', error %u.\n", tmpfile, GetLastError()); + + res = DeleteFileA(tmpfile); + ok(res, "Failed to delete '%s', error %u.\n", tmpfile, GetLastError()); }
static void create_source_file(LPSTR filename, const BYTE *data, DWORD size) @@ -716,12 +714,12 @@ static void test_SetupUninstallOEMInf(void) BOOL ret;
SetLastError(0xdeadbeef); - ret = pSetupUninstallOEMInfA(NULL, 0, NULL); + ret = SetupUninstallOEMInfA(NULL, 0, NULL); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
SetLastError(0xdeadbeef); - ret = pSetupUninstallOEMInfA("", 0, NULL); + ret = SetupUninstallOEMInfA("", 0, NULL); todo_wine { ok(!ret, "Expected failure\n"); @@ -729,7 +727,7 @@ static void test_SetupUninstallOEMInf(void) }
SetLastError(0xdeadbeef); - ret = pSetupUninstallOEMInfA("nonexistent.inf", 0, NULL); + ret = SetupUninstallOEMInfA("nonexistent.inf", 0, NULL); todo_wine { ok(!ret, "Expected failure\n"); @@ -835,17 +833,11 @@ START_TEST(misc) HMODULE hsetupapi = GetModuleHandleA("setupapi.dll");
pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA"); - pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA"); pSetupQueryInfOriginalFileInformationA = (void*)GetProcAddress(hsetupapi, "SetupQueryInfOriginalFileInformationA"); - pSetupUninstallOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupUninstallOEMInfA");
GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
- if (pSetupCopyOEMInfA) - test_SetupCopyOEMInf(); - else - win_skip("SetupCopyOEMInfA is not available\n"); - + test_SetupCopyOEMInf(); test_SetupGetFileCompressionInfo();
if (pSetupGetFileCompressionInfoExA) @@ -854,14 +846,8 @@ START_TEST(misc) win_skip("SetupGetFileCompressionInfoExA is not available\n");
test_SetupDecompressOrCopyFile(); - - if (pSetupUninstallOEMInfA) - test_SetupUninstallOEMInf(); - else - win_skip("SetupUninstallOEMInfA is not available\n"); - + test_SetupUninstallOEMInf(); test_defaultcallback(); - test_SetupLogError(); test_CM_Get_Version(); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/misc.c | 138 ++++++++++++++++++++++--------------- dlls/setupapi/tests/misc.c | 8 --- 2 files changed, 83 insertions(+), 63 deletions(-)
diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c index c83df698adf..7298ac65b62 100644 --- a/dlls/setupapi/misc.c +++ b/dlls/setupapi/misc.c @@ -903,23 +903,80 @@ static int compare_files( HANDLE file1, HANDLE file2 ) return 0; }
+static BOOL find_existing_inf(const WCHAR *source, WCHAR *target) +{ + static const WCHAR infW[] = {'\','i','n','f','\',0}; + static const WCHAR wildcardW[] = {'*',0}; + + LARGE_INTEGER source_file_size, dest_file_size; + HANDLE source_file, dest_file; + WIN32_FIND_DATAW find_data; + HANDLE find_handle; + + source_file = CreateFileW( source, FILE_READ_DATA | FILE_READ_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, OPEN_EXISTING, 0, NULL ); + if (source_file == INVALID_HANDLE_VALUE) + return FALSE; + + if (!GetFileSizeEx( source_file, &source_file_size )) + { + CloseHandle( source_file ); + return FALSE; + } + + GetWindowsDirectoryW( target, MAX_PATH ); + strcatW( target, infW ); + strcatW( target, wildcardW ); + if ((find_handle = FindFirstFileW( target, &find_data )) != INVALID_HANDLE_VALUE) + { + do { + GetWindowsDirectoryW( target, MAX_PATH ); + strcatW( target, infW ); + strcatW( target, find_data.cFileName ); + dest_file = CreateFileW( target, FILE_READ_DATA | FILE_READ_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, OPEN_EXISTING, 0, NULL ); + if (dest_file == INVALID_HANDLE_VALUE) + continue; + + if (GetFileSizeEx( dest_file, &dest_file_size ) + && dest_file_size.QuadPart == source_file_size.QuadPart + && !compare_files( source_file, dest_file )) + { + CloseHandle( dest_file ); + CloseHandle( source_file ); + FindClose( find_handle ); + return TRUE; + } + CloseHandle( dest_file ); + } while (FindNextFileW( find_handle, &find_data )); + + FindClose( find_handle ); + } + + CloseHandle( source_file ); + return FALSE; +} + /*********************************************************************** * SetupCopyOEMInfW (SETUPAPI.@) */ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location, DWORD media_type, DWORD style, PWSTR dest, - DWORD buffer_size, PDWORD required_size, PWSTR *component ) + DWORD buffer_size, DWORD *required_size, WCHAR **filepart ) { BOOL ret = FALSE; WCHAR target[MAX_PATH], catalog_file[MAX_PATH], *p; static const WCHAR inf[] = { '\','i','n','f','\',0 }; static const WCHAR wszVersion[] = { 'V','e','r','s','i','o','n',0 }; static const WCHAR wszCatalogFile[] = { 'C','a','t','a','l','o','g','F','i','l','e',0 }; + unsigned int i; DWORD size; HINF hinf;
TRACE("%s, %s, %d, %d, %p, %d, %p, %p\n", debugstr_w(source), debugstr_w(location), - media_type, style, dest, buffer_size, required_size, component); + media_type, style, dest, buffer_size, required_size, filepart);
if (!source) { @@ -934,65 +991,35 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location, return FALSE; }
- if (!GetWindowsDirectoryW( target, ARRAY_SIZE( target ))) return FALSE; - - strcatW( target, inf ); - if ((p = strrchrW( source, '\' ))) - strcatW( target, p + 1 ); - - /* does the file exist already? */ - if ((GetFileAttributesW( target ) != INVALID_FILE_ATTRIBUTES) && - !(style & SP_COPY_NOOVERWRITE)) - { - static const WCHAR oem[] = { 'o','e','m',0 }; - unsigned int i; - LARGE_INTEGER source_file_size; - HANDLE source_file; - - source_file = CreateFileW( source, FILE_READ_DATA | FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, OPEN_EXISTING, 0, NULL ); - if (source_file == INVALID_HANDLE_VALUE) - return FALSE; - - if (!GetFileSizeEx( source_file, &source_file_size )) + if (find_existing_inf( source, target )) + { + TRACE("Found existing INF %s.\n", debugstr_w(target)); + if (style & SP_COPY_NOOVERWRITE) { - CloseHandle( source_file ); - return FALSE; + SetLastError( ERROR_FILE_EXISTS ); + ret = FALSE; } + else + ret = TRUE; + goto done; + }
- p = strrchrW( target, '\' ) + 1; - memcpy( p, oem, sizeof(oem) ); - p += ARRAY_SIZE( oem ) - 1; - - /* generate OEMnnn.inf ending */ + GetWindowsDirectoryW( target, ARRAY_SIZE(target) ); + strcatW( target, inf ); + strcatW( target, strrchrW( source, '\' ) + 1 ); + if (GetFileAttributesW( target ) != INVALID_FILE_ATTRIBUTES) + { for (i = 0; i < OEM_INDEX_LIMIT; i++) { - static const WCHAR format[] = { '%','u','.','i','n','f',0 }; - HANDLE dest_file; - LARGE_INTEGER dest_file_size; + static const WCHAR formatW[] = {'o','e','m','%','u','.','i','n','f',0};
- wsprintfW( p, format, i ); - dest_file = CreateFileW( target, FILE_READ_DATA | FILE_READ_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, OPEN_EXISTING, 0, NULL ); - /* if we found a file name that doesn't exist then we're done */ - if (dest_file == INVALID_HANDLE_VALUE) + GetWindowsDirectoryW( target, ARRAY_SIZE(target) ); + strcatW( target, inf ); + sprintfW( target + strlenW(target), formatW, i ); + + if (GetFileAttributesW( target ) == INVALID_FILE_ATTRIBUTES) break; - /* now check if the same inf file has already been copied to the inf - * directory. if so, use that file and don't create a new one */ - if (!GetFileSizeEx( dest_file, &dest_file_size ) || - (dest_file_size.QuadPart != source_file_size.QuadPart) || - compare_files( source_file, dest_file )) - { - CloseHandle( dest_file ); - continue; - } - CloseHandle( dest_file ); - break; } - - CloseHandle( source_file ); if (i == OEM_INDEX_LIMIT) { SetLastError( ERROR_FILENAME_EXCED_RANGE ); @@ -1040,9 +1067,10 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location, else SetupCloseInfFile( hinf );
- if (!(ret = CopyFileW( source, target, (style & SP_COPY_NOOVERWRITE) != 0 ))) + if (!(ret = CopyFileW( source, target, TRUE ))) return ret;
+done: if (style & SP_COPY_DELETESOURCE) DeleteFileW( source );
@@ -1060,7 +1088,7 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location, } }
- if (component) *component = p + 1; + if (filepart) *filepart = strrchrW( target, '\' ) + 1; if (required_size) *required_size = size; if (ret) SetLastError(ERROR_SUCCESS);
diff --git a/dlls/setupapi/tests/misc.c b/dlls/setupapi/tests/misc.c index 157edd82a7c..e2dd12fa3f6 100644 --- a/dlls/setupapi/tests/misc.c +++ b/dlls/setupapi/tests/misc.c @@ -119,7 +119,6 @@ static void test_original_file_name(LPCSTR original, LPCSTR dest) res = pSetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi); ok(res, "SetupQueryInfOriginalFileInformationA failed with error %d\n", GetLastError()); ok(!spofi.OriginalCatalogName[0], "spofi.OriginalCatalogName should have been "" instead of "%s"\n", spofi.OriginalCatalogName); - todo_wine ok(!strcmp(original, spofi.OriginalInfName), "spofi.OriginalInfName of %s didn't match real original name %s\n", spofi.OriginalInfName, original);
HeapFree(GetProcessHeap(), 0, pspii); @@ -230,7 +229,6 @@ static void test_SetupCopyOEMInf(void) ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(file_exists(path), "Expected source inf to exist.\n"); ok(file_exists(dest), "Expected dest file to exist.\n"); -todo_wine ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest);
/* try SP_COPY_REPLACEONLY, dest exists */ @@ -240,7 +238,6 @@ todo_wine ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(file_exists(path), "Expected source inf to exist.\n"); ok(file_exists(dest), "Expected dest file to exist.\n"); -todo_wine ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest);
strcpy(dest, "aaa"); @@ -269,14 +266,12 @@ todo_wine ok(file_exists(path), "Expected source inf to exist\n"); ok(file_exists(orig_dest), "Expected dest inf to exist\n"); ok(!strcmp(dest, "aaa"), "Expected dest to be unchanged\n"); -todo_wine ok(size == strlen(orig_dest) + 1, "Expected size %d, got %d.\n", strlen(orig_dest) + 1, size);
SetLastError(0xdeadbeef); res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), &size, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); -todo_wine ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest); ok(size == strlen(dest) + 1, "Expected size %d, got %d.\n", strlen(dest) + 1, size);
@@ -286,7 +281,6 @@ todo_wine res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, &filepart); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); -todo_wine ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest); ok(filepart == strrchr(dest, '\') + 1, "Got unexpected file part %s.\n", filepart);
@@ -341,13 +335,11 @@ todo_wine strcat(orig_dest, "\inf\"); strcat(orig_dest, tmpfile); res = CopyFileA(tmpfile, orig_dest, TRUE); -todo_wine ok(res, "Failed to copy file, error %u.\n", GetLastError()); SetLastError(0xdeadbeef); res = SetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, sizeof(dest), NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); -todo_wine ok(!strcasecmp(dest, orig_dest), "Expected '%s', got '%s'.\n", orig_dest, dest);
/* Since it wasn't actually installed, SetupUninstallOEMInf would fail here. */
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/misc.c | 12 +++--------- dlls/setupapi/tests/misc.c | 1 - 2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c index 7298ac65b62..67e2eafa41e 100644 --- a/dlls/setupapi/misc.c +++ b/dlls/setupapi/misc.c @@ -851,12 +851,9 @@ BOOL WINAPI SetupCopyOEMInfA( PCSTR source, PCSTR location, if (source && !(sourceW = strdupAtoW( source ))) goto done; if (location && !(locationW = strdupAtoW( location ))) goto done;
- if (!(ret = SetupCopyOEMInfW( sourceW, locationW, media_type, style, destW, - buffer_size, &size, NULL ))) - { - if (required_size) *required_size = size; - goto done; - } + ret = SetupCopyOEMInfW( sourceW, locationW, media_type, style, destW, buffer_size, &size, NULL ); + + if (required_size) *required_size = size;
if (dest) { @@ -866,10 +863,7 @@ BOOL WINAPI SetupCopyOEMInfA( PCSTR source, PCSTR location, if (component) *component = strrchr( dest, '\' ) + 1; } else - { SetLastError( ERROR_INSUFFICIENT_BUFFER ); - goto done; - } }
done: diff --git a/dlls/setupapi/tests/misc.c b/dlls/setupapi/tests/misc.c index e2dd12fa3f6..7e597708f07 100644 --- a/dlls/setupapi/tests/misc.c +++ b/dlls/setupapi/tests/misc.c @@ -246,7 +246,6 @@ static void test_SetupCopyOEMInf(void) ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_EXISTS, "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError()); -todo_wine ok(!strcmp(orig_dest, dest), "Expected '%s', got '%s'.\n", orig_dest, dest);
SetLastError(0xdeadbeef);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/install.c | 40 ++++++++++++++++++----------------- dlls/setupapi/tests/install.c | 14 ++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/dlls/setupapi/install.c b/dlls/setupapi/install.c index 6a3213ce7c3..dae0bc13de0 100644 --- a/dlls/setupapi/install.c +++ b/dlls/setupapi/install.c @@ -1458,36 +1458,38 @@ BOOL WINAPI SetupInstallServicesFromInfSectionW( HINF hinf, PCWSTR section, DWOR SC_HANDLE scm; INFCONTEXT context; INT section_flags; - BOOL ok, ret = TRUE; + BOOL ret = TRUE;
- if (!(ok = SetupFindFirstLineW( hinf, section, NULL, &context ))) + if (!SetupFindFirstLineW( hinf, section, NULL, &context )) { SetLastError( ERROR_SECTION_NOT_FOUND ); return FALSE; } if (!(scm = OpenSCManagerW( NULL, NULL, SC_MANAGER_ALL_ACCESS ))) return FALSE;
- ok = SetupFindFirstLineW( hinf, section, AddService, &context ); - while (ok) + if (SetupFindFirstLineW( hinf, section, AddService, &context )) { - if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL )) - continue; - if (!SetupGetIntField( &context, 2, §ion_flags )) section_flags = 0; - if (!SetupGetStringFieldW( &context, 3, service_section, MAX_INF_STRING_LENGTH, NULL )) - continue; - if (!(ret = add_service( scm, hinf, service_name, service_section, section_flags | flags ))) - goto done; - ok = SetupFindNextMatchLineW( &context, AddService, &context ); + do + { + if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL )) + continue; + if (!SetupGetIntField( &context, 2, §ion_flags )) section_flags = 0; + if (!SetupGetStringFieldW( &context, 3, service_section, MAX_INF_STRING_LENGTH, NULL )) + continue; + if (!(ret = add_service( scm, hinf, service_name, service_section, section_flags | flags ))) + goto done; + } while (SetupFindNextMatchLineW( &context, AddService, &context )); }
- ok = SetupFindFirstLineW( hinf, section, DelService, &context ); - while (ok) + if (SetupFindFirstLineW( hinf, section, DelService, &context )) { - if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL )) - continue; - if (!SetupGetIntField( &context, 2, §ion_flags )) section_flags = 0; - if (!(ret = del_service( scm, hinf, service_name, section_flags | flags ))) goto done; - ok = SetupFindNextMatchLineW( &context, AddService, &context ); + do + { + if (!SetupGetStringFieldW( &context, 1, service_name, MAX_INF_STRING_LENGTH, NULL )) + continue; + if (!SetupGetIntField( &context, 2, §ion_flags )) section_flags = 0; + if (!(ret = del_service( scm, hinf, service_name, section_flags | flags ))) goto done; + } while (SetupFindNextMatchLineW( &context, AddService, &context )); } if (ret) SetLastError( ERROR_SUCCESS ); done: diff --git a/dlls/setupapi/tests/install.c b/dlls/setupapi/tests/install.c index a0a45969a42..f9e55929f2e 100644 --- a/dlls/setupapi/tests/install.c +++ b/dlls/setupapi/tests/install.c @@ -574,6 +574,20 @@ static void test_install_svc_from(void) SetupCloseInfFile(infhandle); DeleteFileA(inffile);
+ strcpy(inf, "[Version]\nSignature="$Chicago$"\n"); + strcat(inf, "[Winetest.Services]\n"); + strcat(inf, "AddService=,2\n"); + create_inf_file(inffile, inf); + sprintf(path, "%s\%s", CURR_DIR, inffile); + infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); + + SetLastError(0xdeadbeef); + ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); + ok(ret, "Expected success\n"); + ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", GetLastError()); + SetupCloseInfFile(infhandle); + DeleteFileA(inffile); + /* TODO: Test the Flags */ }