/* Test command line processing */ static void test_cmdline(void) { static const char infwithspaces[] = "test file.inf"; char path[MAX_PATH]; BOOL ret; create_inf_file(inffile, cmdline_inf); sprintf(path, "%s\\%s", CURR_DIR, inffile); run_cmdline("DefaultInstall", 128, path); ok_registry(TRUE); ret = DeleteFileA(inffile); ok(ret, "Expected source inf to exist, last error was %d\n", GetLastError()); /* Test handling of spaces in path, unquoted and quoted */ create_inf_file(infwithspaces, cmdline_inf); sprintf(path, "%s\\%s", CURR_DIR, infwithspaces); run_cmdline("DefaultInstall", 128, path); ok_registry(TRUE); sprintf(path, "\"%s\\%s\"", CURR_DIR, infwithspaces); run_cmdline("DefaultInstall", 128, path); ok_registry(FALSE); ret = DeleteFileA(infwithspaces); ok(ret, "Expected source inf to exist, last error was %d\n", GetLastError()); }
static void test_inffilelistA(void) { static const char inffile2[] = "test2.inf"; static const char *inf = "[Version]\n" "Signature=\"$Chicago$\""; char buffer[MAX_PATH] = { 0 }; char dir[MAX_PATH], *p; DWORD expected, outsize; BOOL ret; if(!pSetupGetInfFileListA) { win_skip("SetupGetInfFileListA not present\n"); return; } /* create a private directory, the temp directory may contain some * inf files left over from old installations */ if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dir)) { win_skip("GetTempFileNameA failed with error %d\n", GetLastError()); return; } if (!CreateDirectoryA(dir, NULL )) { win_skip("CreateDirectoryA(%s) failed with error %d\n", dir, GetLastError()); return; } if (!SetCurrentDirectoryA(dir)) { win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError()); RemoveDirectoryA(dir); return; } create_inf_file(inffile, inf); create_inf_file(inffile2, inf); /* mixed style */ expected = 3 + strlen(inffile) + strlen(inffile2); ret = pSetupGetInfFileListA(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListA to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenA(p) && (outsize > (p - buffer)); p+=lstrlenA(p) + 1) ok(!lstrcmpA(p,inffile2) || !lstrcmpA(p,inffile), "unexpected filename %s\n",p); DeleteFileA(inffile); DeleteFileA(inffile2); SetCurrentDirectoryA(CURR_DIR); RemoveDirectoryA(dir); }
static void test_registry(void) { HKEY key; LONG res; char path[MAX_PATH]; BOOL ret; /* First create a registry structure we would like to be deleted */ ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key), "Expected RegCreateKeyA to succeed\n"); /* Doublecheck if the registry key is present */ ok(!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key), "Expected registry key to exist\n"); create_inf_file(inffile, cmdline_inf_reg); sprintf(path, "%s\\%s", CURR_DIR, inffile); run_cmdline("DefaultInstall", 128, path); /* Check if the registry key is recursively deleted */ res = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key); todo_wine ok(res == ERROR_FILE_NOT_FOUND, "Didn't expect the registry key to exist\n"); /* Just in case */ if (res == ERROR_SUCCESS) { RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest"); RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest"); } ret = DeleteFileA(inffile); ok(ret, "Expected source inf to exist, last error was %d\n", GetLastError()); }
static void test_LaunchINFSectionEx(void) { HRESULT hr; char cmdline[MAX_PATH]; create_inf_file("test.inf"); /* try an invalid CAB filename with an absolute INF name */ lstrcpyA(cmdline, CURR_DIR); lstrcatA(cmdline, "\\"); lstrcatA(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4"); hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0); ok(hr == 0, "Expected 0, got %d\n", hr); /* try quoting the parameters */ lstrcpyA(cmdline, "\""); lstrcatA(cmdline, CURR_DIR); lstrcatA(cmdline, "\\test.inf\",\"DefaultInstall\",\"c:,imacab.cab\",\"4\""); hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0); ok(hr == 0, "Expected 0, got %d\n", hr); /* The 'No UI' flag seems to have no effect whatsoever on Windows. * So only do this test in interactive mode. */ if (winetest_interactive) { /* try an invalid CAB filename with a relative INF name */ lstrcpyA(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4"); hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); } DeleteFileA("test.inf"); }
static void check_dirid(int dirid, LPCSTR expected) { char buffer[sizeof(dirid_inf)+11]; char path[MAX_PATH], actual[MAX_PATH]; LONG ret; DWORD size, type; HKEY key; sprintf(buffer, dirid_inf, dirid); create_inf_file(inffile, buffer); sprintf(path, "%s\\%s", CURR_DIR, inffile); run_cmdline("DefaultInstall", 128, path); size = sizeof(actual); actual[0] = '\0'; ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key); if (ret == ERROR_SUCCESS) { ret = RegQueryValueExA(key, "dirid", NULL, &type, (BYTE*)&actual, &size); RegCloseKey(key); if (type != REG_SZ) ret = ERROR_FILE_NOT_FOUND; } ok(ret == ERROR_SUCCESS, "Failed getting value for dirid %i, err=%d\n", dirid, ret); ok(!strcmp(actual, expected), "Expected path for dirid %i was \"%s\", got \"%s\"\n", dirid, expected, actual); ok_registry(TRUE); ret = DeleteFileA(inffile); ok(ret, "Expected source inf to exist, last error was %d\n", GetLastError()); }
static void test_SetupGetSourceFileLocation(void) { char buffer[MAX_PATH] = "not empty", inf_filename[MAX_PATH]; UINT source_id; DWORD required, error; HINF hinf; BOOL ret; lstrcpyA(inf_filename, CURR_DIR); lstrcatA(inf_filename, "\\"); lstrcatA(inf_filename, "test.inf"); create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); required = 0; source_id = 0; ret = SetupGetSourceFileLocationA(hinf, NULL, "lanconf.exe", &source_id, buffer, sizeof(buffer), &required); ok(ret, "SetupGetSourceFileLocation failed\n"); ok(required == 1, "unexpected required size: %d\n", required); ok(source_id == 2, "unexpected source id: %d\n", source_id); ok(!lstrcmpA("", buffer), "unexpected result string: %s\n", buffer); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); create_inf_file(inf_filename, inf_data2, sizeof(inf_data2) - 1); SetLastError(0xdeadbeef); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); error = GetLastError(); ok(hinf == INVALID_HANDLE_VALUE, "could open inf file\n"); ok(error == ERROR_WRONG_INF_STYLE, "got wrong error: %d\n", error); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_OLDNT, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); ret = SetupGetSourceFileLocationA(hinf, NULL, "", &source_id, buffer, sizeof(buffer), &required); ok(!ret, "SetupGetSourceFileLocation succeeded\n"); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); }
static void test_LaunchINFSection(void) { HRESULT hr; char cmdline[MAX_PATH]; static char file[] = "test.inf,DefaultInstall,4,0"; static char file2[] = "test.inf,,1,0"; /* The 'No UI' flag seems to have no effect whatsoever on Windows. * So only do this test in interactive mode. */ if (winetest_interactive) { /* try an invalid cmdline */ hr = pLaunchINFSection(NULL, NULL, NULL, 0); ok(hr == 1, "Expected 1, got %d\n", hr); } CreateDirectoryA("one", NULL); create_inf_file("one\\test.inf"); /* try a full path to the INF */ lstrcpyA(cmdline, CURR_DIR); lstrcatA(cmdline, "\\"); lstrcatA(cmdline, "one\\test.inf,DefaultInstall,,4"); hr = pLaunchINFSection(NULL, NULL, cmdline, 0); ok(hr == 0, "Expected 0, got %d\n", hr); DeleteFileA("one\\test.inf"); RemoveDirectoryA("one"); create_inf_file("test.inf"); /* try just the INF filename */ hr = pLaunchINFSection(NULL, NULL, file, 0); ok(hr == 0, "Expected 0, got %d\n", hr); hr = pLaunchINFSection(NULL, NULL, file2, 0); ok(hr == 0, "Expected 0, got %d\n", hr); DeleteFileA("test.inf"); }
static void test_SetupGetSourceInfo(void) { char buffer[MAX_PATH], inf_filename[MAX_PATH]; DWORD required; HINF hinf; BOOL ret; lstrcpyA(inf_filename, CURR_DIR); lstrcatA(inf_filename, "\\"); lstrcatA(inf_filename, "test.inf"); create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); required = 0; ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_PATH, buffer, sizeof(buffer), &required); ok(ret, "SetupGetSourceInfoA failed\n"); ok(required == 1, "unexpected required size: %d\n", required); ok(!lstrcmpA("", buffer), "unexpected result string: %s\n", buffer); required = 0; buffer[0] = 0; ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_TAGFILE, buffer, sizeof(buffer), &required); ok(ret, "SetupGetSourceInfoA failed\n"); ok(required == 28, "unexpected required size: %d\n", required); ok(!lstrcmpA("LANCOM\\LANtools\\lanconf.cab", buffer), "unexpected result string: %s\n", buffer); required = 0; buffer[0] = 0; ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_DESCRIPTION, buffer, sizeof(buffer), &required); ok(ret, "SetupGetSourceInfoA failed\n"); ok(required == 19, "unexpected required size: %d\n", required); ok(!lstrcmpA("LANCOM Software CD", buffer), "unexpected result string: %s\n", buffer); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); }
static void test_SetupGetInfInformation(void) { PSP_INF_INFORMATION info; CHAR inf_filename[MAX_PATH]; CHAR inf_one[MAX_PATH], inf_two[MAX_PATH]; LPSTR revfile; DWORD size; HINF hinf; BOOL ret; lstrcpyA(inf_filename, CURR_DIR); lstrcatA(inf_filename, "\\"); lstrcatA(inf_filename, "test.inf"); /* try an invalid inf handle */ size = 0xdeadbeef; SetLastError(0xbeefcafe); ret = SetupGetInfInformationA(NULL, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); ok(GetLastError() == ERROR_INVALID_HANDLE || broken(GetLastError() == ERROR_BAD_PATHNAME) || /* win95 */ broken(GetLastError() == ERROR_FILE_NOT_FOUND) || /* win98 */ broken(GetLastError() == ERROR_PATH_NOT_FOUND) || /* NT4 */ broken(GetLastError() == ERROR_INVALID_NAME) || /* win2k */ broken(GetLastError() == ERROR_GENERAL_SYNTAX), /* another win2k / winMe */ "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); ok(size == 0xdeadbeef, "Expected size to remain unchanged\n"); /* try an invalid inf filename */ /* do not use NULL as absolute inf filename on win9x/winMe (crash) */ if ((GetLastError() != ERROR_BAD_PATHNAME) && /* win95 */ (GetLastError() != ERROR_FILE_NOT_FOUND) && /* win98 */ (GetLastError() != ERROR_GENERAL_SYNTAX)) /* winMe */ { size = 0xdeadbeef; SetLastError(0xbeefcafe); ret = SetupGetInfInformationA(NULL, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); ok(size == 0xdeadbeef, "Expected size to remain unchanged\n"); } create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1); /* try an invalid search flag */ size = 0xdeadbeef; SetLastError(0xbeefcafe); ret = SetupGetInfInformationA(inf_filename, -1, NULL, 0, &size); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); ok(size == 0xdeadbeef, "Expected size to remain unchanged\n"); /* try a nonexistent inf file */ size = 0xdeadbeef; SetLastError(0xbeefcafe); ret = SetupGetInfInformationA("idontexist", INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); ok(size == 0xdeadbeef, "Expected size to remain unchanged\n"); /* successfully open the inf file */ size = 0xdeadbeef; ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); ok(size != 0xdeadbeef, "Expected a valid size on return\n"); /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */ SetLastError(0xbeefcafe); ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, &size); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */ ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size-1, &size); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); /* some tests for behaviour with a NULL RequiredSize pointer */ ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, NULL); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size - 1, NULL); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, NULL); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); info = HeapAlloc(GetProcessHeap(), 0, size); /* try valid ReturnBuffer but too small size */ SetLastError(0xbeefcafe); ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, info, size - 1, &size); ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError()); /* successfully get the inf information */ ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, info, size, &size); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); ok(check_info_filename(info, inf_filename), "Expected returned filename to be equal\n"); HeapFree(GetProcessHeap(), 0, info); /* try the INFINFO_INF_SPEC_IS_HINF search flag */ hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); info = alloc_inf_info(hinf, INFINFO_INF_SPEC_IS_HINF, &size); ret = SetupGetInfInformationA(hinf, INFINFO_INF_SPEC_IS_HINF, info, size, &size); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); ok(check_info_filename(info, inf_filename), "Expected returned filename to be equal\n"); SetupCloseInfFile(hinf); lstrcpyA(inf_two, WIN_DIR); lstrcatA(inf_two, "\\system32\\"); lstrcatA(inf_two, "test.inf"); create_inf_file(inf_two, inf_data1, sizeof(inf_data1) - 1); HeapFree(GetProcessHeap(), 0, info); info = alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH, &size); /* check if system32 is searched for inf */ ret = SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH, info, size, &size); if (!ret && GetLastError() == ERROR_FILE_NOT_FOUND) revfile = inf_one; /* Vista */ else revfile = inf_two; lstrcpyA(inf_one, WIN_DIR); lstrcatA(inf_one, "\\inf\\"); lstrcatA(inf_one, "test.inf"); create_inf_file(inf_one, inf_data1, sizeof(inf_data1) - 1); HeapFree(GetProcessHeap(), 0, info); info = alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH, &size); /* test the INFINFO_DEFAULT_SEARCH search flag */ ret = SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH, info, size, &size); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed: %d\n", GetLastError()); ok(check_info_filename(info, inf_one), "Expected returned filename to be equal\n"); HeapFree(GetProcessHeap(), 0, info); info = alloc_inf_info("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH, &size); /* test the INFINFO_REVERSE_DEFAULT_SEARCH search flag */ ret = SetupGetInfInformationA("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH, info, size, &size); ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n"); ok(check_info_filename(info, revfile), "Expected returned filename to be equal\n"); HeapFree(GetProcessHeap(), 0, info); DeleteFileA(inf_filename); DeleteFileA(inf_one); DeleteFileA(inf_two); }
static void translateinfstringex_test(void) { HINF hinf; HRESULT hr; char buffer[MAX_PATH]; DWORD size = MAX_PATH; hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); if (hr == E_UNEXPECTED) { win_skip("Skipping tests on win9x because of brokenness\n"); return; } create_inf_file(); /* need to see if there are any flags */ /* try a NULL filename */ hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ || hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */, "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08x\n", hr); /* try a NULL hinf */ hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* open the INF without the Install section specified */ hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* try a NULL hinf */ hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try a NULL filename */ hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL translate section */ hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate section */ hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* try a NULL translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL, buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* successfully translate the string */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL hinf */ hr = pCloseINFEngine(NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* successfully close the hinf */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* translate the string with the install section specified */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer); ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); { char drive[MAX_PATH]; lstrcpyA(drive, PROG_FILES_ROOT); drive[3] = 0x00; /* Just keep the system drive plus '\' */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, drive), "Expected %s, got %s\n", drive, buffer); ok(size == strlen(drive)+1, "Expected size %d, got %d\n", lstrlenA(drive)+1, size); } /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); /* Create another .inf file which is just here to trigger a wine bug */ { char data[1024]; char *ptr = data; DWORD dwNumberOfBytesWritten; HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); append_str(&ptr, "[Version]\n"); append_str(&ptr, "Signature=\"$Chicago$\"\n"); append_str(&ptr, "[section]\n"); append_str(&ptr, "NotACustomDestination=Version\n"); append_str(&ptr, "CustomDestination=CustInstDestSection\n"); append_str(&ptr, "[CustInstDestSection]\n"); append_str(&ptr, "49010=DestA,1\n"); append_str(&ptr, "49020=DestB\n"); append_str(&ptr, "49030=DestC\n"); append_str(&ptr, "49040=DestD\n"); append_str(&ptr, "[Options.NTx86]\n"); append_str(&ptr, "Result2=%%49030%%\n"); append_str(&ptr, "[DestA]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); /* The point of this test is to have HKCU just before the quoted HKLM */ append_str(&ptr, "[DestB]\n"); append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); append_str(&ptr, "[DestC]\n"); append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',"); append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n"); append_str(&ptr, "[DestD]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL); CloseHandle(hf); } /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); }
static void test_inffilelist(void) { static const char inffile2[] = "test2.inf"; static const WCHAR inffile2W[] = {'t','e','s','t','2','.','i','n','f',0}; static const char invalid_inf[] = "invalid.inf"; static const WCHAR invalid_infW[] = {'i','n','v','a','l','i','d','.','i','n','f',0}; static const char *inf = "[Version]\n" "Signature=\"$Chicago$\""; static const char *inf2 = "[Version]\n" "Signature=\"$CHICAGO$\""; static const char *infNT = "[Version]\n" "Signature=\"$WINDOWS NT$\""; WCHAR *p, *ptr; char dirA[MAX_PATH]; WCHAR dir[MAX_PATH] = { 0 }; WCHAR buffer[MAX_PATH] = { 0 }; DWORD expected, outsize; BOOL ret; if(!pSetupGetInfFileListW) { win_skip("SetupGetInfFileListW not present\n"); return; } /* NULL means %windir%\\inf * get the value as reference */ expected = 0; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(NULL, INF_STYLE_WIN4, NULL, 0, &expected); if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("SetupGetInfFileListW not implemented\n"); return; } ok(ret, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError()); ok(expected > 0, "expected required buffersize to be at least 1\n"); /* check if an empty string doesn't behaves like NULL */ outsize = 0; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(!ret, "expected SetupGetInfFileListW to fail!\n"); /* create a private directory, the temp directory may contain some * inf files left over from old installations */ if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dirA)) { win_skip("GetTempFileNameA failed with error %d\n", GetLastError()); return; } if (!CreateDirectoryA(dirA, NULL )) { win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA, GetLastError()); return; } if (!SetCurrentDirectoryA(dirA)) { win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError()); RemoveDirectoryA(dirA); return; } MultiByteToWideChar(CP_ACP, 0, dirA, -1, dir, MAX_PATH); /* check a not existing directory */ ptr = dir + lstrlenW(dir); MultiByteToWideChar(CP_ACP, 0, "\\not_existent", -1, ptr, MAX_PATH - lstrlenW(dir)); outsize = 0xffffffff; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(outsize == 1, "expected required buffersize to be 1, got %d\n", outsize); ok(ERROR_PATH_NOT_FOUND == GetLastError(), "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError()); create_inf_file(inffile, inf); create_inf_file(inffile2, inf); create_inf_file(invalid_inf, "This content does not match the inf file format"); /* pass a filename instead of a directory */ *ptr = '\\'; MultiByteToWideChar(CP_ACP, 0, invalid_inf, -1, ptr+1, MAX_PATH - lstrlenW(dir)); outsize = 0xffffffff; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(!ret, "expected SetupGetInfFileListW to fail!\n"); ok(ERROR_DIRECTORY == GetLastError(), "expected error ERROR_DIRECTORY, got %d\n", GetLastError()); /* make the filename look like directory */ dir[1 + lstrlenW(dir)] = 0; dir[lstrlenW(dir)] = '\\'; SetLastError(0xdeadbeef); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize); ok(!ret, "expected SetupGetInfFileListW to fail!\n"); ok(ERROR_DIRECTORY == GetLastError(), "expected error ERROR_DIRECTORY, got %d\n", GetLastError()); /* now check the buffer content of a vaild call */ *ptr = 0; expected = 3 + strlen(inffile) + strlen(inffile2); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* upper case value */ create_inf_file(inffile2, inf2); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* signature Windows NT is also inf style win4 */ create_inf_file(inffile2, infNT); expected = 3 + strlen(inffile) + strlen(inffile2); ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* old style */ expected = 2 + strlen(invalid_inf); ret = pSetupGetInfFileListW(dir, INF_STYLE_OLDNT, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,invalid_infW), "unexpected filename %s\n",wine_dbgstr_w(p)); /* mixed style */ expected = 4 + strlen(inffile) + strlen(inffile2) + strlen(invalid_inf); ret = pSetupGetInfFileListW(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer, MAX_PATH, &outsize); ok(ret, "expected SetupGetInfFileListW to succeed!\n"); ok(expected == outsize, "expected required buffersize to be %d, got %d\n", expected, outsize); for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1) ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW) || !lstrcmpW(p,invalid_infW), "unexpected filename %s\n",wine_dbgstr_w(p)); DeleteFileA(inffile); DeleteFileA(inffile2); DeleteFileA(invalid_inf); SetCurrentDirectoryA(CURR_DIR); RemoveDirectoryA(dirA); }
static void translateinfstring_test() { HRESULT hr; char buffer[MAX_PATH]; DWORD dwSize; create_inf_file(); /* pass in a couple invalid parameters */ hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr); /* try to open an inf file that doesn't exist */ hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND), "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr); if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND)) { trace("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n"); return; } /* try a nonexistent section */ buffer[0] = 0; hr = pTranslateInfString("c:\\test.inf", "idontexist", "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr); ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize); buffer[0] = 0; /* try other nonexistent section */ hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "idontexist", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr); buffer[0] = 0; /* try nonexistent key */ hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "Options.NTx86", "notvalid", buffer, MAX_PATH, &dwSize, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr); buffer[0] = 0; /* test the behavior of pszInstallSection */ hr = pTranslateInfString("c:\\test.inf", "section", "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == ERROR_SUCCESS || hr == E_FAIL, "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr); if(hr == ERROR_SUCCESS) { ok(!strcmp(buffer, PROG_FILES), "Expected '%s', got '%s'\n", PROG_FILES, buffer); ok(dwSize == PROG_FILES_LEN, "Expected size %ld, got %ld\n", PROG_FILES_LEN, dwSize); } buffer[0] = 0; /* try without a pszInstallSection */ hr = pTranslateInfString("c:\\test.inf", NULL, "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize); } DeleteFile("c:\\a.inf"); DeleteFile("c:\\test.inf"); }
static void test_install_svc_from(void) { char inf[2048]; char path[MAX_PATH]; HINF infhandle; BOOL ret; SC_HANDLE scm_handle, svc_handle; /* Bail out if we are on win98 */ SetLastError(0xdeadbeef); scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL); if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) { win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n"); return; } CloseServiceHandle(scm_handle); /* Basic inf file to satisfy SetupOpenInfFileA */ strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n"); create_inf_file(inffile, inf); sprintf(path, "%s\\%s", CURR_DIR, inffile); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); /* Nothing but the Version section */ SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_SECTION_NOT_FOUND, "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); /* Add the section */ strcat(inf, "[Winetest.Services]\n"); create_inf_file(inffile, inf); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_SECTION_NOT_FOUND, "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); /* Add a reference */ strcat(inf, "AddService=Winetest,,Winetest.Service\n"); create_inf_file(inffile, inf); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT, "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); /* Add the section */ strcat(inf, "[Winetest.Service]\n"); create_inf_file(inffile, inf); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT, "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); /* Just the ServiceBinary */ strcat(inf, "ServiceBinary=%12%\\winetest.sys\n"); create_inf_file(inffile, inf); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT, "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); /* Add the ServiceType */ strcat(inf, "ServiceType=1\n"); create_inf_file(inffile, inf); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT, "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); /* Add the StartType */ strcat(inf, "StartType=4\n"); create_inf_file(inffile, inf); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); ok(!ret, "Expected failure\n"); ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT, "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); /* This should be it, the minimal entries to install a service */ strcat(inf, "ErrorControl=1"); create_inf_file(inffile, inf); infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL); SetLastError(0xdeadbeef); ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0); if (!ret && GetLastError() == ERROR_ACCESS_DENIED) { skip("Not enough rights to install the service\n"); SetupCloseInfFile(infhandle); DeleteFileA(inffile); return; } ok(ret, "Expected success\n"); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", GetLastError()); SetupCloseInfFile(infhandle); DeleteFileA(inffile); scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL); /* Open the service to see if it's really there */ svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE); ok(svc_handle != NULL, "Service was not created\n"); SetLastError(0xdeadbeef); ret = DeleteService(svc_handle); ok(ret, "Service could not be deleted : %d\n", GetLastError()); CloseServiceHandle(svc_handle); CloseServiceHandle(scm_handle); strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n"); strcat(inf, "[XSP.InstallPerVer]\n"); strcat(inf, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\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, "XSP.InstallPerVer", 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 */ }
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; DWORD size; BOOL res; /* try NULL SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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); 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); 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 an absolute nonexistent SourceInfFileName */ lstrcpy(path, CURR_DIR); lstrcat(path, "\\nonexistent"); SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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); /* 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); if (GetLastError() == ERROR_WRONG_INF_TYPE || GetLastError() == ERROR_UNSUPPORTED_TYPE /* Win7 */) { /* FIXME: * Vista needs a [Manufacturer] entry in the inf file. Doing this will give some * popups during the installation though as it also needs a catalog file (signed?). */ win_skip("Needs a different inf file on Vista+\n"); DeleteFile(tmpfile); return; } ok(GetLastError() == ERROR_FILE_NOT_FOUND || broken(GetLastError() == ERROR_SUCCESS), /* Win98 */ "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); 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 */ lstrcpy(path, CURR_DIR); lstrcat(path, "\\"); lstrcat(path, tmpfile); SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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(file_exists(path), "Expected source inf to exist\n"); /* try SP_COPY_REPLACEONLY, dest exists */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, 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 exist\n"); /* try SP_COPY_NOOVERWRITE */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_EXISTS, "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError()); /* get the DestinationInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlen(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"); 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 = pSetupCopyOEMInfA(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 = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(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 == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); 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); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(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 == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); /* try SP_COPY_DELETESOURCE */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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 *destfile = strrchr(dest, '\\') + 1; SetLastError(0xdeadbeef); ok(pSetupUninstallOEMInfA(destfile, 0, NULL), "Failed to uninstall '%s' : %d\n", destfile, GetLastError()); } else { /* Win9x/WinMe */ SetLastError(0xdeadbeef); ok(DeleteFileA(dest), "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); } }
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; DWORD size; BOOL res; /* try NULL SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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); 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 relative nonexistent SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA("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()); /* try an absolute nonexistent SourceInfFileName */ lstrcpy(path, CURR_DIR); lstrcat(path, "\\nonexistent"); SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); get_temp_filename(tmpfile); create_inf_file(tmpfile); /* try a relative SourceInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(tmpfile, 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()); 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); 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 */ lstrcpy(path, CURR_DIR); lstrcat(path, "\\"); lstrcat(path, tmpfile); SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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(file_exists(path), "Expected source inf to exist\n"); /* try SP_COPY_REPLACEONLY, dest exists */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, 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 exist\n"); /* try SP_COPY_NOOVERWRITE */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL); ok(res == FALSE, "Expected FALSE, got %d\n", res); ok(GetLastError() == ERROR_FILE_EXISTS, "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError()); /* get the DestinationInfFileName */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlen(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"); 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 = pSetupCopyOEMInfA(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 = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(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 == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); 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); ok(res == TRUE, "Expected TRUE, got %d\n", res); ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size); ok(file_exists(dest), "Expected destination inf to exist\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 == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n"); /* try SP_COPY_DELETESOURCE */ SetLastError(0xdeadbeef); res = pSetupCopyOEMInfA(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"); }
static void test_RunSetupCommand(void) { HRESULT hr; HANDLE hexe; char path[MAX_PATH]; char dir[MAX_PATH]; char systemdir[MAX_PATH]; GetSystemDirectoryA(systemdir, sizeof(systemdir)); /* try an invalid cmd name */ hr = pRunSetupCommand(NULL, NULL, "Install", "Dir", "Title", NULL, 0, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); /* try an invalid directory */ hr = pRunSetupCommand(NULL, "winver.exe", "Install", NULL, "Title", NULL, 0, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr); /* try to run a nonexistent exe */ #ifdef __REACTOS__ hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull; #else hexe = (HANDLE)0xdeadbeef; #endif hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", systemdir, "Title", &hexe, 0, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr); ok(hexe == NULL, "Expected hexe to be NULL\n"); ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n"); /* try a bad directory */ #ifdef __REACTOS__ hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull; #else hexe = (HANDLE)0xdeadbeef; #endif hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %d\n", hr); ok(hexe == NULL, "Expected hexe to be NULL\n"); ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n"); /* try to run an exe with the RSC_FLAG_INF flag */ #ifdef __REACTOS__ hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull; #else hexe = (HANDLE)0xdeadbeef; #endif hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(is_spapi_err(hr), "Expected a setupapi error, got %d\n", hr); #ifdef __REACTOS__ ok(hexe == (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull, "Expected hexe to be 0xdeadbeef\n"); #else ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n"); #endif ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n"); /* run winver.exe */ #ifdef __REACTOS__ hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull; #else hexe = (HANDLE)0xdeadbeef; #endif hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, 0, NULL); ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %d\n", hr); ok(hexe != NULL, "Expected hexe to be non-NULL\n"); ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n"); CreateDirectoryA("one", NULL); create_inf_file("one\\test.inf"); /* try a full path to the INF, with working dir provided */ lstrcpyA(path, CURR_DIR); lstrcatA(path, "\\one\\test.inf"); lstrcpyA(dir, CURR_DIR); lstrcatA(dir, "\\one"); hr = pRunSetupCommand(NULL, path, "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr); /* try a full path to the INF, NULL working dir */ hr = pRunSetupCommand(NULL, path, "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr); /* try a full path to the INF, empty working dir */ hr = pRunSetupCommand(NULL, path, "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr); /* try a relative path to the INF, with working dir provided */ hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr); /* try a relative path to the INF, NULL working dir */ hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr); /* try a relative path to the INF, empty working dir */ hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr); /* try only the INF filename, with working dir provided */ hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr); /* try only the INF filename, NULL working dir */ hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr); /* try only the INF filename, empty working dir */ hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr); DeleteFileA("one\\test.inf"); RemoveDirectoryA("one"); create_inf_file("test.inf"); /* try INF file in the current directory, working directory provided */ hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr); /* try INF file in the current directory, NULL working directory */ hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr); /* try INF file in the current directory, empty working directory */ hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr); }
static void test_SetupGetTargetPath(void) { char buffer[MAX_PATH], inf_filename[MAX_PATH]; char destfile[MAX_PATH]; DWORD required; HINF hinf; INFCONTEXT ctx; BOOL ret; lstrcpyA(inf_filename, CURR_DIR); lstrcatA(inf_filename, "\\"); lstrcatA(inf_filename, "test.inf"); create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); ctx.Inf = hinf; ctx.CurrentInf = hinf; ctx.Section = 7; ctx.Line = 0; required = 0; ret = SetupGetTargetPathA(hinf, &ctx, NULL, buffer, sizeof(buffer), &required); ok(ret, "SetupGetTargetPathA failed\n"); ok(required == 10, "unexpected required size: %d\n", required); /* Retrieve the system drive from the windows directory. * (%SystemDrive% is not available on Win9x) */ lstrcpyA(destfile, WIN_DIR); destfile[3] = '\0'; lstrcatA(destfile, "LANCOM"); ok(!lstrcmpiA(destfile, buffer), "unexpected result string: %s\n", buffer); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); create_inf_file(inf_filename, inf_data3, sizeof(inf_data3) - 1); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); required = 0; ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required); ok(ret, "SetupGetTargetPathA failed\n"); lstrcpyA(destfile, WIN_DIR); ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required); ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); create_inf_file(inf_filename, inf_data4, sizeof(inf_data4) - 1); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); required = 0; ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.System32.Files", buffer, sizeof(buffer), &required); ok(ret, "SetupGetTargetPathA failed\n"); GetSystemDirectoryA(destfile, MAX_PATH); ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required); ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); create_inf_file(inf_filename, inf_data5, sizeof(inf_data5) - 1); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); required = 0; ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required); ok(ret, "SetupGetTargetPathA failed\n"); lstrcpyA(destfile, WIN_DIR); ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required); ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); create_inf_file(inf_filename, inf_data6, sizeof(inf_data6) - 1); hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL); ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n"); required = 0; ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required); ok(ret, "SetupGetTargetPathA failed\n"); lstrcpyA(destfile, WIN_DIR); ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required); ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer); SetupCloseInfFile(hinf); DeleteFileA(inf_filename); }
static void test_driver_install(void) { HANDLE handle; SC_HANDLE scm_handle, svc_handle; BOOL ret; char path[MAX_PATH], windir[MAX_PATH], driver[MAX_PATH]; DWORD attrs; /* Minimal stuff needed */ static const char *inf = "[Version]\n" "Signature=\"$Chicago$\"\n" "[DestinationDirs]\n" "Winetest.DriverFiles=12\n" "[DefaultInstall]\n" "CopyFiles=Winetest.DriverFiles\n" "[DefaultInstall.Services]\n" "AddService=Winetest,,Winetest.Service\n" "[Winetest.Service]\n" "ServiceBinary=%12%\\winetest.sys\n" "ServiceType=1\n" "StartType=4\n" "ErrorControl=1\n" "[Winetest.DriverFiles]\n" "winetest.sys"; /* Bail out if we are on win98 */ SetLastError(0xdeadbeef); scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL); if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) { win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n"); return; } else if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED)) { skip("Not enough rights to install the service\n"); return; } CloseServiceHandle(scm_handle); /* Place where we expect the driver to be installed */ GetWindowsDirectoryA(windir, MAX_PATH); lstrcpyA(driver, windir); lstrcatA(driver, "\\system32\\drivers\\winetest.sys"); /* Create a dummy driver file */ handle = CreateFileA("winetest.sys", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); CloseHandle(handle); create_inf_file(inffile, inf); sprintf(path, "%s\\%s", CURR_DIR, inffile); run_cmdline("DefaultInstall", 128, path); /* Driver should have been installed */ attrs = GetFileAttributesA(driver); ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected driver to exist\n"); scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL); /* Open the service to see if it's really there */ svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE); ok(svc_handle != NULL, "Service was not created\n"); SetLastError(0xdeadbeef); ret = DeleteService(svc_handle); ok(ret, "Service could not be deleted : %d\n", GetLastError()); CloseServiceHandle(svc_handle); CloseServiceHandle(scm_handle); /* File cleanup */ DeleteFileA(inffile); DeleteFileA("winetest.sys"); DeleteFileA(driver); }
static void translateinfstringex_test(void) { HINF hinf; HRESULT hr; char buffer[MAX_PATH]; DWORD size = MAX_PATH; create_inf_file(); /* need to see if there are any flags */ /* try a NULL filename */ hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty filename */ hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr); /* try a NULL hinf */ hr = pOpenINFEngine("c:\\test.inf", "Options.NTx86", 0, NULL, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* open the INF without the Install section specified */ hr = pOpenINFEngine("c:\\test.inf", NULL, 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); /* try a NULL hinf */ hr = pTranslateInfStringEx(NULL, "c:\\test.inf", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try a NULL filename */ hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty filename */ size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", (UINT)hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %ld\n", size); } /* try a NULL translate section */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", NULL, "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty translate section */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "", "InstallDir", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %ld\n", hr); /* try a NULL translate key */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", NULL, buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty translate key */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %ld\n", hr); /* successfully translate the string */ size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %ld\n", size); } /* try a NULL hinf */ hr = pCloseINFEngine(NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* successfully close the hinf */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); /* open the inf with the install section */ hr = pOpenINFEngine("c:\\test.inf", "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); /* translate the string with the install section specified */ size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); ok(!strcmp(buffer, PROG_FILES), "Expected %s, got %s\n", PROG_FILES, buffer); ok(size == PROG_FILES_LEN, "Expected size %ld, got %ld\n", PROG_FILES_LEN, size); /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); DeleteFileA("c:\\test.inf"); }
static void test_profile_items(void) { char path[MAX_PATH], commonprogs[MAX_PATH]; HMODULE hShell32; BOOL (WINAPI *pSHGetFolderPathA)(HWND hwnd, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath); static const char *inf = "[Version]\n" "Signature=\"$Chicago$\"\n" "[DefaultInstall]\n" "ProfileItems=TestItem,TestItem2,TestGroup\n" "[TestItem]\n" "Name=TestItem\n" "CmdLine=11,,notepad.exe\n" "[TestItem2]\n" "Name=TestItem2\n" "CmdLine=11,,notepad.exe\n" "SubDir=TestDir\n" "[TestGroup]\n" "Name=TestGroup,4\n" ; hShell32 = LoadLibraryA("shell32"); pSHGetFolderPathA = (void*)GetProcAddress(hShell32, "SHGetFolderPathA"); if (!pSHGetFolderPathA) { win_skip("SHGetFolderPathA is not available\n"); goto cleanup; } if (S_OK != pSHGetFolderPathA(NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, commonprogs)) { skip("No common program files directory exists\n"); goto cleanup; } create_inf_file(inffile, inf); sprintf(path, "%s\\%s", CURR_DIR, inffile); run_cmdline("DefaultInstall", 128, path); snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs); if (INVALID_FILE_ATTRIBUTES == GetFileAttributesA(path)) { win_skip("ProfileItems not implemented on this system\n"); } else { snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs); ok(INVALID_FILE_ATTRIBUTES != GetFileAttributesA(path), "directory not created\n"); snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs); ok(INVALID_FILE_ATTRIBUTES != GetFileAttributesA(path), "link not created\n"); snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs); ok(INVALID_FILE_ATTRIBUTES != GetFileAttributesA(path), "group not created\n"); } snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs); DeleteFileA(path); snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs); DeleteFileA(path); snprintf(path, MAX_PATH, "%s\\TestItem2.lnk", commonprogs); DeleteFileA(path); snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs); RemoveDirectoryA(path); snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs); RemoveDirectoryA(path); cleanup: if (hShell32) FreeLibrary(hShell32); DeleteFileA(inffile); }