push 149f0a5527ac85057a8ef03858d34d91c36f97e8
[wine/hacks.git] / dlls / setupapi / tests / install.c
blob4b718fc8da6e5aeef94bb20b4a92c1e7ffcfd5ea
1 /*
2 * Unit test for setupapi.dll install functions
4 * Copyright 2007 Misha Koshelev
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <assert.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "winsvc.h"
32 #include "setupapi.h"
33 #include "shlobj.h"
35 #include "wine/test.h"
37 static const char inffile[] = "test.inf";
38 static const WCHAR inffileW[] = {'t','e','s','t','.','i','n','f',0};
39 static char CURR_DIR[MAX_PATH];
41 /* Notes on InstallHinfSectionA/W:
42 * - InstallHinfSectionW on Win98 and InstallHinfSectionA on WinXP seem to be stubs - they do not do anything
43 * and simply return without displaying any error message or setting last error. We test whether
44 * InstallHinfSectionA sets last error, and if it doesn't we set it to NULL and use the W version if available.
45 * - These functions do not return a value and do not always set last error to ERROR_SUCCESS when installation still
46 * occurs (e.g., unquoted inf file with spaces, registry keys are written but last error is 6). Also, on Win98 last error
47 * is set to ERROR_SUCCESS even if install fails (e.g., quoted inf file with spaces, no registry keys set, MessageBox with
48 * "Installation Error" displayed). Thus, we must use functional tests (e.g., is registry key created) to determine whether
49 * or not installation occurred.
50 * - On installation problems, a MessageBox() is displayed and a Beep() is issued. The MessageBox() is disabled with a
51 * CBT hook.
54 static void (WINAPI *pInstallHinfSectionA)(HWND, HINSTANCE, LPCSTR, INT);
55 static void (WINAPI *pInstallHinfSectionW)(HWND, HINSTANCE, LPCWSTR, INT);
56 static BOOL (WINAPI *pSetupGetInfFileListW)(PCWSTR, DWORD, PWSTR, DWORD, PDWORD);
59 * Helpers
62 static void create_inf_file(LPCSTR filename, const char *data)
64 DWORD res;
65 HANDLE handle = CreateFile(filename, GENERIC_WRITE, 0, NULL,
66 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
67 assert(handle != INVALID_HANDLE_VALUE);
68 assert(WriteFile(handle, data, strlen(data), &res, NULL));
69 CloseHandle(handle);
72 /* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
73 static HHOOK hhook;
74 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
76 return nCode == HCBT_CREATEWND ? 1: CallNextHookEx(hhook, nCode, wParam, lParam);
80 * Tests
83 static const char *cmdline_inf = "[Version]\n"
84 "Signature=\"$Chicago$\"\n"
85 "[DefaultInstall]\n"
86 "AddReg=Add.Settings\n"
87 "[Add.Settings]\n"
88 "HKCU,Software\\Wine\\setupapitest,,\n";
90 static void run_cmdline(LPCSTR section, int mode, LPCSTR path)
92 CHAR cmdline[MAX_PATH * 2];
94 sprintf(cmdline, "%s %d %s", section, mode, path);
95 if (pInstallHinfSectionA) pInstallHinfSectionA(NULL, NULL, cmdline, 0);
96 else
98 WCHAR cmdlinew[MAX_PATH * 2];
99 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, cmdlinew, MAX_PATH*2);
100 pInstallHinfSectionW(NULL, NULL, cmdlinew, 0);
104 static void ok_registry(BOOL expectsuccess)
106 LONG ret;
108 /* Functional tests for success of install and clean up */
109 ret = RegDeleteKey(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
110 ok((expectsuccess && ret == ERROR_SUCCESS) ||
111 (!expectsuccess && ret == ERROR_FILE_NOT_FOUND),
112 "Expected registry key Software\\Wine\\setupapitest to %s, RegDeleteKey returned %d\n",
113 expectsuccess ? "exist" : "not exist",
114 ret);
117 /* Test command line processing */
118 static void test_cmdline(void)
120 static const char infwithspaces[] = "test file.inf";
121 char path[MAX_PATH];
123 create_inf_file(inffile, cmdline_inf);
124 sprintf(path, "%s\\%s", CURR_DIR, inffile);
125 run_cmdline("DefaultInstall", 128, path);
126 ok_registry(TRUE);
127 ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
129 /* Test handling of spaces in path, unquoted and quoted */
130 create_inf_file(infwithspaces, cmdline_inf);
132 sprintf(path, "%s\\%s", CURR_DIR, infwithspaces);
133 run_cmdline("DefaultInstall", 128, path);
134 ok_registry(TRUE);
136 sprintf(path, "\"%s\\%s\"", CURR_DIR, infwithspaces);
137 run_cmdline("DefaultInstall", 128, path);
138 ok_registry(FALSE);
140 ok(DeleteFile(infwithspaces), "Expected source inf to exist, last error was %d\n", GetLastError());
143 static const char *cmdline_inf_reg = "[Version]\n"
144 "Signature=\"$Chicago$\"\n"
145 "[DefaultInstall]\n"
146 "DelReg=Del.Settings\n"
147 "[Del.Settings]\n"
148 "HKCU,Software\\Wine\\setupapitest\n";
150 static void test_registry(void)
152 HKEY key;
153 LONG res;
154 char path[MAX_PATH];
156 /* First create a registry structure we would like to be deleted */
157 ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
158 "Expected RegCreateKeyA to succeed\n");
160 /* Doublecheck if the registry key is present */
161 ok(!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
162 "Expected registry key to exist\n");
164 create_inf_file(inffile, cmdline_inf_reg);
165 sprintf(path, "%s\\%s", CURR_DIR, inffile);
166 run_cmdline("DefaultInstall", 128, path);
168 /* Check if the registry key is recursively deleted */
169 res = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key);
170 todo_wine
171 ok(res == ERROR_FILE_NOT_FOUND, "Didn't expect the registry key to exist\n");
172 /* Just in case */
173 if (res == ERROR_SUCCESS)
175 RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest");
176 RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
178 ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
181 static void test_install_svc_from(void)
183 char inf[2048];
184 char path[MAX_PATH];
185 HINF infhandle;
186 BOOL ret;
187 SC_HANDLE scm_handle, svc_handle;
189 /* Bail out if we are on win98 */
190 SetLastError(0xdeadbeef);
191 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
193 if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
195 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
196 return;
198 CloseServiceHandle(scm_handle);
200 /* Basic inf file to satisfy SetupOpenInfFileA */
201 strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
202 create_inf_file(inffile, inf);
203 sprintf(path, "%s\\%s", CURR_DIR, inffile);
204 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
206 /* Nothing but the Version section */
207 SetLastError(0xdeadbeef);
208 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
209 ok(!ret, "Expected failure\n");
210 ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
211 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
212 SetupCloseInfFile(infhandle);
213 DeleteFile(inffile);
215 /* Add the section */
216 strcat(inf, "[Winetest.Services]\n");
217 create_inf_file(inffile, inf);
218 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
219 SetLastError(0xdeadbeef);
220 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
221 ok(!ret, "Expected failure\n");
222 ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
223 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
224 SetupCloseInfFile(infhandle);
225 DeleteFile(inffile);
227 /* Add a reference */
228 strcat(inf, "AddService=Winetest,,Winetest.Service\n");
229 create_inf_file(inffile, inf);
230 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
231 SetLastError(0xdeadbeef);
232 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
233 ok(!ret, "Expected failure\n");
234 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
235 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
236 SetupCloseInfFile(infhandle);
237 DeleteFile(inffile);
239 /* Add the section */
240 strcat(inf, "[Winetest.Service]\n");
241 create_inf_file(inffile, inf);
242 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
243 SetLastError(0xdeadbeef);
244 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
245 ok(!ret, "Expected failure\n");
246 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
247 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
248 SetupCloseInfFile(infhandle);
249 DeleteFile(inffile);
251 /* Just the ServiceBinary */
252 strcat(inf, "ServiceBinary=%12%\\winetest.sys\n");
253 create_inf_file(inffile, inf);
254 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
255 SetLastError(0xdeadbeef);
256 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
257 ok(!ret, "Expected failure\n");
258 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
259 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
260 SetupCloseInfFile(infhandle);
261 DeleteFile(inffile);
263 /* Add the ServiceType */
264 strcat(inf, "ServiceType=1\n");
265 create_inf_file(inffile, inf);
266 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
267 SetLastError(0xdeadbeef);
268 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
269 ok(!ret, "Expected failure\n");
270 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
271 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
272 SetupCloseInfFile(infhandle);
273 DeleteFile(inffile);
275 /* Add the StartType */
276 strcat(inf, "StartType=4\n");
277 create_inf_file(inffile, inf);
278 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
279 SetLastError(0xdeadbeef);
280 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
281 ok(!ret, "Expected failure\n");
282 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
283 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
284 SetupCloseInfFile(infhandle);
285 DeleteFile(inffile);
287 /* This should be it, the minimal entries to install a service */
288 strcat(inf, "ErrorControl=1");
289 create_inf_file(inffile, inf);
290 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
291 SetLastError(0xdeadbeef);
292 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
293 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
295 skip("Not enough rights to install the service\n");
296 SetupCloseInfFile(infhandle);
297 DeleteFile(inffile);
298 return;
300 ok(ret, "Expected success\n");
301 ok(GetLastError() == ERROR_SUCCESS,
302 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
303 SetupCloseInfFile(infhandle);
304 DeleteFile(inffile);
306 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
308 /* Open the service to see if it's really there */
309 svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
310 ok(svc_handle != NULL, "Service was not created\n");
312 SetLastError(0xdeadbeef);
313 ret = DeleteService(svc_handle);
314 ok(ret, "Service could not be deleted : %d\n", GetLastError());
316 CloseServiceHandle(svc_handle);
317 CloseServiceHandle(scm_handle);
319 /* TODO: Test the Flags */
322 static void test_driver_install(void)
324 HANDLE handle;
325 SC_HANDLE scm_handle, svc_handle;
326 BOOL ret;
327 char path[MAX_PATH], windir[MAX_PATH], driver[MAX_PATH];
328 DWORD attrs;
329 /* Minimal stuff needed */
330 static const char *inf =
331 "[Version]\n"
332 "Signature=\"$Chicago$\"\n"
333 "[DestinationDirs]\n"
334 "Winetest.DriverFiles=12\n"
335 "[DefaultInstall]\n"
336 "CopyFiles=Winetest.DriverFiles\n"
337 "[DefaultInstall.Services]\n"
338 "AddService=Winetest,,Winetest.Service\n"
339 "[Winetest.Service]\n"
340 "ServiceBinary=%12%\\winetest.sys\n"
341 "ServiceType=1\n"
342 "StartType=4\n"
343 "ErrorControl=1\n"
344 "[Winetest.DriverFiles]\n"
345 "winetest.sys";
347 /* Bail out if we are on win98 */
348 SetLastError(0xdeadbeef);
349 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
351 if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
353 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
354 return;
356 else if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
358 skip("Not enough rights to install the service\n");
359 return;
361 CloseServiceHandle(scm_handle);
363 /* Place where we expect the driver to be installed */
364 GetWindowsDirectoryA(windir, MAX_PATH);
365 lstrcpyA(driver, windir);
366 lstrcatA(driver, "\\system32\\drivers\\winetest.sys");
368 /* Create a dummy driver file */
369 handle = CreateFileA("winetest.sys", GENERIC_WRITE, 0, NULL,
370 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
371 CloseHandle(handle);
373 create_inf_file(inffile, inf);
374 sprintf(path, "%s\\%s", CURR_DIR, inffile);
375 run_cmdline("DefaultInstall", 128, path);
377 /* Driver should have been installed */
378 attrs = GetFileAttributes(driver);
379 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected driver to exist\n");
381 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
383 /* Open the service to see if it's really there */
384 svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
385 ok(svc_handle != NULL, "Service was not created\n");
387 SetLastError(0xdeadbeef);
388 ret = DeleteService(svc_handle);
389 ok(ret, "Service could not be deleted : %d\n", GetLastError());
391 CloseServiceHandle(svc_handle);
392 CloseServiceHandle(scm_handle);
394 /* File cleanup */
395 DeleteFile(inffile);
396 DeleteFile("winetest.sys");
397 DeleteFile(driver);
400 static void test_profile_items(void)
402 char path[MAX_PATH], commonprogs[MAX_PATH];
403 HMODULE hShell32;
404 BOOL (WINAPI *pSHGetFolderPathA)(HWND hwnd, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
406 static const char *inf =
407 "[Version]\n"
408 "Signature=\"$Chicago$\"\n"
409 "[DefaultInstall]\n"
410 "ProfileItems=TestItem,TestItem2,TestGroup\n"
411 "[TestItem]\n"
412 "Name=TestItem\n"
413 "CmdLine=11,,notepad.exe\n"
414 "[TestItem2]\n"
415 "Name=TestItem2\n"
416 "CmdLine=11,,notepad.exe\n"
417 "SubDir=TestDir\n"
418 "[TestGroup]\n"
419 "Name=TestGroup,4\n"
422 hShell32 = LoadLibraryA("shell32");
423 pSHGetFolderPathA = (void*)GetProcAddress(hShell32, "SHGetFolderPathA");
424 if (!pSHGetFolderPathA)
426 win_skip("SHGetFolderPathA is not available\n");
427 goto cleanup;
430 if (S_OK != pSHGetFolderPathA(NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, commonprogs))
432 skip("No common program files directory exists\n");
433 goto cleanup;
436 create_inf_file(inffile, inf);
437 sprintf(path, "%s\\%s", CURR_DIR, inffile);
438 run_cmdline("DefaultInstall", 128, path);
440 snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
441 if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(path))
443 win_skip("ProfileItems not implemented on this system\n");
445 else
447 snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
448 ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "directory not created\n");
449 snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
450 ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "link not created\n");
451 snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
452 ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "group not created\n");
455 snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
456 DeleteFile(path);
457 snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
458 DeleteFile(path);
459 snprintf(path, MAX_PATH, "%s\\TestItem2.lnk", commonprogs);
460 DeleteFile(path);
461 snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
462 RemoveDirectory(path);
463 snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
464 RemoveDirectory(path);
466 cleanup:
467 if (hShell32) FreeLibrary(hShell32);
468 DeleteFile(inffile);
471 static void test_inffilelist(void)
473 static const char inffile2[] = "test2.inf";
474 static const WCHAR inffile2W[] = {'t','e','s','t','2','.','i','n','f',0};
475 static const char invalid_inf[] = "invalid.inf";
476 static const char *inf =
477 "[Version]\n"
478 "Signature=\"$Chicago$\"";
480 WCHAR *p, *ptr;
481 char dirA[MAX_PATH];
482 WCHAR dir[MAX_PATH] = { 0 };
483 WCHAR buffer[MAX_PATH] = { 0 };
484 DWORD expected, outsize;
485 BOOL ret;
487 if(!pSetupGetInfFileListW)
489 win_skip("SetupGetInfFileListW not present\n");
490 return;
493 /* NULL means %windir%\\inf
494 * get the value as reference
496 expected = 0;
497 SetLastError(0xdeadbeef);
498 ret = pSetupGetInfFileListW(NULL, INF_STYLE_WIN4, NULL, 0, &expected);
499 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
501 win_skip("SetupGetInfFileListW not implemented\n");
502 return;
504 ok(ret, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
505 ok(expected > 0, "expected required buffersize to be at least 1\n");
507 /* check if an empty string doesn't behaves like NULL */
508 outsize = 0;
509 SetLastError(0xdeadbeef);
510 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
511 todo_wine
512 ok(!ret, "expected SetupGetInfFileListW to fail!\n");
514 /* create a private directory, the temp directory may contain some
515 * inf files left over from old installations
517 if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dirA))
519 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
520 return;
522 if (!CreateDirectoryA(dirA, NULL ))
524 win_skip("CreateDirectoryA failed with error %d\n", GetLastError());
525 return;
527 if (!SetCurrentDirectoryA(dirA))
529 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
530 RemoveDirectoryA(dirA);
531 return;
534 MultiByteToWideChar(CP_ACP, 0, dirA, -1, dir, MAX_PATH);
535 /* check a not existing directory
537 ptr = dir + lstrlenW(dir);
538 MultiByteToWideChar(CP_ACP, 0, "\\not_existent", -1, ptr, MAX_PATH - lstrlenW(dir));
539 outsize = 0xffffffff;
540 SetLastError(0xdeadbeef);
541 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
542 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
543 ok(outsize == 1, "expected required buffersize to be 1, got %d\n", outsize);
544 todo_wine
545 ok(ERROR_PATH_NOT_FOUND == GetLastError(),
546 "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
548 create_inf_file(inffile, inf);
549 create_inf_file(inffile2, inf);
550 create_inf_file(invalid_inf, "This content does not match the inf file format");
552 /* pass a filename instead of a directory
554 *ptr = '\\';
555 MultiByteToWideChar(CP_ACP, 0, invalid_inf, -1, ptr+1, MAX_PATH - lstrlenW(dir));
556 outsize = 0xffffffff;
557 SetLastError(0xdeadbeef);
558 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
559 todo_wine
560 ok(!ret, "expected SetupGetInfFileListW to fail!\n");
561 todo_wine
562 ok(ERROR_DIRECTORY == GetLastError(),
563 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
565 /* make the filename look like directory
567 dir[1 + lstrlenW(dir)] = 0;
568 dir[lstrlenW(dir)] = '\\';
569 SetLastError(0xdeadbeef);
570 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
571 todo_wine
572 ok(!ret, "expected SetupGetInfFileListW to fail!\n");
573 todo_wine
574 ok(ERROR_DIRECTORY == GetLastError(),
575 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
577 /* now check the buffer content of a vaild call
579 *ptr = 0;
580 expected = 3 + strlen(inffile) + strlen(inffile2);
581 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
582 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
583 todo_wine
584 ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
585 expected, outsize);
586 for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
587 ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
588 "unexpected filename %s\n",wine_dbgstr_w(p));
590 DeleteFile(inffile);
591 DeleteFile(inffile2);
592 DeleteFile(invalid_inf);
593 SetCurrentDirectoryA(CURR_DIR);
594 RemoveDirectoryA(dirA);
597 START_TEST(install)
599 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
600 char temp_path[MAX_PATH], prev_path[MAX_PATH];
601 DWORD len;
603 GetCurrentDirectory(MAX_PATH, prev_path);
604 GetTempPath(MAX_PATH, temp_path);
605 SetCurrentDirectory(temp_path);
607 strcpy(CURR_DIR, temp_path);
608 len = strlen(CURR_DIR);
609 if(len && (CURR_DIR[len - 1] == '\\'))
610 CURR_DIR[len - 1] = 0;
612 pInstallHinfSectionA = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionA");
613 pInstallHinfSectionW = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionW");
614 pSetupGetInfFileListW = (void *)GetProcAddress(hsetupapi, "SetupGetInfFileListW");
616 if (pInstallHinfSectionA)
618 /* Check if pInstallHinfSectionA sets last error or is a stub (as on WinXP) */
619 static const char *minimal_inf = "[Version]\nSignature=\"$Chicago$\"\n";
620 char cmdline[MAX_PATH*2];
621 create_inf_file(inffile, minimal_inf);
622 sprintf(cmdline, "DefaultInstall 128 %s\\%s", CURR_DIR, inffile);
623 SetLastError(0xdeadbeef);
624 pInstallHinfSectionA(NULL, NULL, cmdline, 0);
625 if (GetLastError() == 0xdeadbeef)
627 skip("InstallHinfSectionA is broken (stub)\n");
628 pInstallHinfSectionA = NULL;
630 ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
632 if (!pInstallHinfSectionW && !pInstallHinfSectionA)
633 win_skip("InstallHinfSectionA and InstallHinfSectionW are not available\n");
634 else
636 /* Set CBT hook to disallow MessageBox creation in current thread */
637 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
638 assert(hhook != 0);
640 test_cmdline();
641 test_registry();
642 test_install_svc_from();
643 test_driver_install();
645 UnhookWindowsHookEx(hhook);
647 /* We have to run this test after the CBT hook is disabled because
648 ProfileItems needs to create a window on Windows XP. */
649 test_profile_items();
652 test_inffilelist();
654 SetCurrentDirectory(prev_path);