include: Add asynot.idl.
[wine] / dlls / setupapi / tests / install.c
1 /*
2  * Unit test for setupapi.dll install functions
3  *
4  * Copyright 2007 Misha Koshelev
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <assert.h>
25
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"
34
35 #include "wine/test.h"
36
37 static const char inffile[] = "test.inf";
38 static char CURR_DIR[MAX_PATH];
39
40 /* Notes on InstallHinfSectionA/W:
41  * - InstallHinfSectionW on Win98 and InstallHinfSectionA on WinXP seem to be stubs - they do not do anything
42  *   and simply return without displaying any error message or setting last error. We test whether
43  *   InstallHinfSectionA sets last error, and if it doesn't we set it to NULL and use the W version if available.
44  * - These functions do not return a value and do not always set last error to ERROR_SUCCESS when installation still
45  *   occurs (e.g., unquoted inf file with spaces, registry keys are written but last error is 6). Also, on Win98 last error
46  *   is set to ERROR_SUCCESS even if install fails (e.g., quoted inf file with spaces, no registry keys set, MessageBox with
47  *   "Installation Error" displayed). Thus, we must use functional tests (e.g., is registry key created) to determine whether
48  *   or not installation occurred.
49  * - On installation problems, a MessageBox() is displayed and a Beep() is issued. The MessageBox() is disabled with a
50  *   CBT hook.
51  */
52
53 static void (WINAPI *pInstallHinfSectionA)(HWND, HINSTANCE, LPCSTR, INT);
54 static void (WINAPI *pInstallHinfSectionW)(HWND, HINSTANCE, LPCWSTR, INT);
55 static BOOL (WINAPI *pSetupGetInfFileListW)(PCWSTR, DWORD, PWSTR, DWORD, PDWORD);
56
57 /*
58  * Helpers
59  */
60
61 static void create_inf_file(LPCSTR filename, const char *data)
62 {
63     DWORD res;
64     HANDLE handle = CreateFile(filename, GENERIC_WRITE, 0, NULL,
65                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
66     assert(handle != INVALID_HANDLE_VALUE);
67     assert(WriteFile(handle, data, strlen(data), &res, NULL));
68     CloseHandle(handle);
69 }
70
71 /* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
72 static HHOOK hhook;
73 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
74 {
75     return nCode == HCBT_CREATEWND ? 1: CallNextHookEx(hhook, nCode, wParam, lParam);
76 }
77
78 /*
79  * Tests
80  */
81
82 static const char *cmdline_inf = "[Version]\n"
83     "Signature=\"$Chicago$\"\n"
84     "[DefaultInstall]\n"
85     "AddReg=Add.Settings\n"
86     "[Add.Settings]\n"
87     "HKCU,Software\\Wine\\setupapitest,,\n";
88
89 static void run_cmdline(LPCSTR section, int mode, LPCSTR path)
90 {
91     CHAR cmdline[MAX_PATH * 2];
92
93     sprintf(cmdline, "%s %d %s", section, mode, path);
94     if (pInstallHinfSectionA) pInstallHinfSectionA(NULL, NULL, cmdline, 0);
95     else
96     {
97         WCHAR cmdlinew[MAX_PATH * 2];
98         MultiByteToWideChar(CP_ACP, 0, cmdline, -1, cmdlinew, MAX_PATH*2);
99         pInstallHinfSectionW(NULL, NULL, cmdlinew, 0);
100     }
101 }
102
103 static void ok_registry(BOOL expectsuccess)
104 {
105     LONG ret;
106
107     /* Functional tests for success of install and clean up */
108     ret = RegDeleteKey(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
109     ok((expectsuccess && ret == ERROR_SUCCESS) ||
110        (!expectsuccess && ret == ERROR_FILE_NOT_FOUND),
111        "Expected registry key Software\\Wine\\setupapitest to %s, RegDeleteKey returned %d\n",
112        expectsuccess ? "exist" : "not exist",
113        ret);
114 }
115
116 /* Test command line processing */
117 static void test_cmdline(void)
118 {
119     static const char infwithspaces[] = "test file.inf";
120     char path[MAX_PATH];
121
122     create_inf_file(inffile, cmdline_inf);
123     sprintf(path, "%s\\%s", CURR_DIR, inffile);
124     run_cmdline("DefaultInstall", 128, path);
125     ok_registry(TRUE);
126     ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
127
128     /* Test handling of spaces in path, unquoted and quoted */
129     create_inf_file(infwithspaces, cmdline_inf);
130
131     sprintf(path, "%s\\%s", CURR_DIR, infwithspaces);
132     run_cmdline("DefaultInstall", 128, path);
133     ok_registry(TRUE);
134
135     sprintf(path, "\"%s\\%s\"", CURR_DIR, infwithspaces);
136     run_cmdline("DefaultInstall", 128, path);
137     ok_registry(FALSE);
138
139     ok(DeleteFile(infwithspaces), "Expected source inf to exist, last error was %d\n", GetLastError());
140 }
141
142 static const char *cmdline_inf_reg = "[Version]\n"
143     "Signature=\"$Chicago$\"\n"
144     "[DefaultInstall]\n"
145     "DelReg=Del.Settings\n"
146     "[Del.Settings]\n"
147     "HKCU,Software\\Wine\\setupapitest\n";
148
149 static void test_registry(void)
150 {
151     HKEY key;
152     LONG res;
153     char path[MAX_PATH];
154
155     /* First create a registry structure we would like to be deleted */
156     ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
157         "Expected RegCreateKeyA to succeed\n");
158
159     /* Doublecheck if the registry key is present */
160     ok(!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
161         "Expected registry key to exist\n");
162
163     create_inf_file(inffile, cmdline_inf_reg);
164     sprintf(path, "%s\\%s", CURR_DIR, inffile);
165     run_cmdline("DefaultInstall", 128, path);
166
167     /* Check if the registry key is recursively deleted */
168     res = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key);
169     todo_wine
170     ok(res == ERROR_FILE_NOT_FOUND, "Didn't expect the registry key to exist\n");
171     /* Just in case */
172     if (res == ERROR_SUCCESS)
173     {
174         RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest");
175         RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
176     }
177     ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
178 }
179
180 static void test_install_svc_from(void)
181 {
182     char inf[2048];
183     char path[MAX_PATH];
184     HINF infhandle;
185     BOOL ret;
186     SC_HANDLE scm_handle, svc_handle;
187
188     /* Bail out if we are on win98 */
189     SetLastError(0xdeadbeef);
190     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
191
192     if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
193     {
194         win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
195         return;
196     }
197     CloseServiceHandle(scm_handle);
198
199     /* Basic inf file to satisfy SetupOpenInfFileA */
200     strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
201     create_inf_file(inffile, inf);
202     sprintf(path, "%s\\%s", CURR_DIR, inffile);
203     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
204
205     /* Nothing but the Version section */
206     SetLastError(0xdeadbeef);
207     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
208     ok(!ret, "Expected failure\n");
209     ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
210         "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
211     SetupCloseInfFile(infhandle);
212     DeleteFile(inffile);
213
214     /* Add the section */
215     strcat(inf, "[Winetest.Services]\n");
216     create_inf_file(inffile, inf);
217     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
218     SetLastError(0xdeadbeef);
219     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
220     ok(!ret, "Expected failure\n");
221     ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
222         "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
223     SetupCloseInfFile(infhandle);
224     DeleteFile(inffile);
225
226     /* Add a reference */
227     strcat(inf, "AddService=Winetest,,Winetest.Service\n");
228     create_inf_file(inffile, inf);
229     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
230     SetLastError(0xdeadbeef);
231     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
232     ok(!ret, "Expected failure\n");
233     ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
234         "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
235     SetupCloseInfFile(infhandle);
236     DeleteFile(inffile);
237
238     /* Add the section */
239     strcat(inf, "[Winetest.Service]\n");
240     create_inf_file(inffile, inf);
241     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
242     SetLastError(0xdeadbeef);
243     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
244     ok(!ret, "Expected failure\n");
245     ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
246         "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
247     SetupCloseInfFile(infhandle);
248     DeleteFile(inffile);
249
250     /* Just the ServiceBinary */
251     strcat(inf, "ServiceBinary=%12%\\winetest.sys\n");
252     create_inf_file(inffile, inf);
253     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
254     SetLastError(0xdeadbeef);
255     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
256     ok(!ret, "Expected failure\n");
257     ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
258         "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
259     SetupCloseInfFile(infhandle);
260     DeleteFile(inffile);
261
262     /* Add the ServiceType */
263     strcat(inf, "ServiceType=1\n");
264     create_inf_file(inffile, inf);
265     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
266     SetLastError(0xdeadbeef);
267     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
268     ok(!ret, "Expected failure\n");
269     ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
270         "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
271     SetupCloseInfFile(infhandle);
272     DeleteFile(inffile);
273
274     /* Add the StartType */
275     strcat(inf, "StartType=4\n");
276     create_inf_file(inffile, inf);
277     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
278     SetLastError(0xdeadbeef);
279     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
280     ok(!ret, "Expected failure\n");
281     ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
282         "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
283     SetupCloseInfFile(infhandle);
284     DeleteFile(inffile);
285
286     /* This should be it, the minimal entries to install a service */
287     strcat(inf, "ErrorControl=1");
288     create_inf_file(inffile, inf);
289     infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
290     SetLastError(0xdeadbeef);
291     ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
292     if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
293     {
294         skip("Not enough rights to install the service\n");
295         SetupCloseInfFile(infhandle);
296         DeleteFile(inffile);
297         return;
298     }
299     ok(ret, "Expected success\n");
300     ok(GetLastError() == ERROR_SUCCESS,
301         "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
302     SetupCloseInfFile(infhandle);
303     DeleteFile(inffile);
304
305     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
306
307     /* Open the service to see if it's really there */
308     svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
309     ok(svc_handle != NULL, "Service was not created\n");
310
311     SetLastError(0xdeadbeef);
312     ret = DeleteService(svc_handle);
313     ok(ret, "Service could not be deleted : %d\n", GetLastError());
314
315     CloseServiceHandle(svc_handle);
316     CloseServiceHandle(scm_handle);
317
318     /* TODO: Test the Flags */
319 }
320
321 static void test_driver_install(void)
322 {
323     HANDLE handle;
324     SC_HANDLE scm_handle, svc_handle;
325     BOOL ret;
326     char path[MAX_PATH], windir[MAX_PATH], driver[MAX_PATH];
327     DWORD attrs;
328     /* Minimal stuff needed */
329     static const char *inf =
330         "[Version]\n"
331         "Signature=\"$Chicago$\"\n"
332         "[DestinationDirs]\n"
333         "Winetest.DriverFiles=12\n"
334         "[DefaultInstall]\n"
335         "CopyFiles=Winetest.DriverFiles\n"
336         "[DefaultInstall.Services]\n"
337         "AddService=Winetest,,Winetest.Service\n"
338         "[Winetest.Service]\n"
339         "ServiceBinary=%12%\\winetest.sys\n"
340         "ServiceType=1\n"
341         "StartType=4\n"
342         "ErrorControl=1\n"
343         "[Winetest.DriverFiles]\n"
344         "winetest.sys";
345
346     /* Bail out if we are on win98 */
347     SetLastError(0xdeadbeef);
348     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
349
350     if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
351     {
352         win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
353         return;
354     }
355     else if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
356     {
357         skip("Not enough rights to install the service\n");
358         return;
359     }
360     CloseServiceHandle(scm_handle);
361
362     /* Place where we expect the driver to be installed */
363     GetWindowsDirectoryA(windir, MAX_PATH);
364     lstrcpyA(driver, windir);
365     lstrcatA(driver, "\\system32\\drivers\\winetest.sys");
366
367     /* Create a dummy driver file */
368     handle = CreateFileA("winetest.sys", GENERIC_WRITE, 0, NULL,
369                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
370     CloseHandle(handle);
371
372     create_inf_file(inffile, inf);
373     sprintf(path, "%s\\%s", CURR_DIR, inffile);
374     run_cmdline("DefaultInstall", 128, path);
375
376     /* Driver should have been installed */
377     attrs = GetFileAttributes(driver);
378     ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected driver to exist\n");
379
380     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
381
382     /* Open the service to see if it's really there */
383     svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
384     ok(svc_handle != NULL, "Service was not created\n");
385
386     SetLastError(0xdeadbeef);
387     ret = DeleteService(svc_handle);
388     ok(ret, "Service could not be deleted : %d\n", GetLastError());
389
390     CloseServiceHandle(svc_handle);
391     CloseServiceHandle(scm_handle);
392
393     /* File cleanup */
394     DeleteFile(inffile);
395     DeleteFile("winetest.sys");
396     DeleteFile(driver);
397 }
398
399 static void test_profile_items(void)
400 {
401     char path[MAX_PATH], commonprogs[MAX_PATH];
402     HMODULE hShell32;
403     BOOL (WINAPI *pSHGetFolderPathA)(HWND hwnd, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
404
405     static const char *inf =
406         "[Version]\n"
407         "Signature=\"$Chicago$\"\n"
408         "[DefaultInstall]\n"
409         "ProfileItems=TestItem,TestItem2,TestGroup\n"
410         "[TestItem]\n"
411         "Name=TestItem\n"
412         "CmdLine=11,,notepad.exe\n"
413         "[TestItem2]\n"
414         "Name=TestItem2\n"
415         "CmdLine=11,,notepad.exe\n"
416         "SubDir=TestDir\n"
417         "[TestGroup]\n"
418         "Name=TestGroup,4\n"
419         ;
420
421     hShell32 = LoadLibraryA("shell32");
422     pSHGetFolderPathA = (void*)GetProcAddress(hShell32, "SHGetFolderPathA");
423     if (!pSHGetFolderPathA)
424     {
425         win_skip("SHGetFolderPathA is not available\n");
426         goto cleanup;
427     }
428
429     if (S_OK != pSHGetFolderPathA(NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, commonprogs))
430     {
431         skip("No common program files directory exists\n");
432         goto cleanup;
433     }
434
435     create_inf_file(inffile, inf);
436     sprintf(path, "%s\\%s", CURR_DIR, inffile);
437     run_cmdline("DefaultInstall", 128, path);
438
439     snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
440     if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(path))
441     {
442         win_skip("ProfileItems not implemented on this system\n");
443     }
444     else
445     {
446         snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
447         ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "directory not created\n");
448         snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
449         ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "link not created\n");
450         snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
451         ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "group not created\n");
452     }
453
454     snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
455     DeleteFile(path);
456     snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
457     DeleteFile(path);
458     snprintf(path, MAX_PATH, "%s\\TestItem2.lnk", commonprogs);
459     DeleteFile(path);
460     snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
461     RemoveDirectory(path);
462     snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
463     RemoveDirectory(path);
464
465 cleanup:
466     if (hShell32) FreeLibrary(hShell32);
467     DeleteFile(inffile);
468 }
469
470 static void test_inffilelist(void)
471 {
472     static const char inffile2[] = "test2.inf";
473     static const char invalid_inf[] = "invalid.inf";
474     static const char *inf =
475         "[Version]\n"
476         "Signature=\"$Chicago$\"";
477
478     WCHAR *ptr;
479     WCHAR dir[MAX_PATH] = { 0 };
480     WCHAR buffer[MAX_PATH] = { 0 };
481     DWORD expected, outsize;
482     BOOL ret;
483
484     if(!pSetupGetInfFileListW)
485     {
486         win_skip("SetupGetInfFileListW not present\n");
487         return;
488     }
489
490     /* NULL means %windir%\\inf
491      * get the value as reference
492      */
493     expected = 0;
494     ret = pSetupGetInfFileListW(NULL, INF_STYLE_WIN4, NULL, 0, &expected);
495     ok(ret, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
496     ok(expected > 0, "expected required buffersize to be at least 1\n");
497
498     /* check if an empty string doesn't behaves like NULL */
499     outsize = 0;
500     SetLastError(0xdeadbeef);
501     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
502     todo_wine
503     ok(!ret, "expected SetupGetInfFileListW to fail!\n");
504
505     /* check a not existing directory
506      */
507     MultiByteToWideChar(CP_ACP, 0, CURR_DIR, -1, dir, MAX_PATH);
508     ptr = dir + lstrlenW(dir);
509     MultiByteToWideChar(CP_ACP, 0, "\\not_existent", -1, ptr, MAX_PATH - lstrlenW(dir));
510     outsize = 0xffffffff;
511     SetLastError(0xdeadbeef);
512     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
513     ok(ret, "expected SetupGetInfFileListW to succeed!\n");
514     ok(outsize == 1, "expected required buffersize to be 1, got %d\n", outsize);
515     todo_wine
516     ok(ERROR_PATH_NOT_FOUND == GetLastError(),
517        "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
518     
519     create_inf_file(inffile, inf);
520     create_inf_file(inffile2, inf);
521     create_inf_file(invalid_inf, "This content does not match the inf file format");
522
523     /* pass a filename instead of a directory
524      */
525     *ptr = '\\';
526     MultiByteToWideChar(CP_ACP, 0, invalid_inf, -1, ptr+1, MAX_PATH - lstrlenW(dir));
527     outsize = 0xffffffff;
528     SetLastError(0xdeadbeef);
529     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
530     todo_wine
531     ok(!ret, "expected SetupGetInfFileListW to fail!\n");
532     todo_wine
533     ok(ERROR_DIRECTORY == GetLastError(),
534        "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
535
536     /* make the filename look like directory
537      */
538     dir[1 + lstrlenW(dir)] = 0;
539     dir[lstrlenW(dir)] = '\\';
540     SetLastError(0xdeadbeef);
541     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
542     todo_wine
543     ok(!ret, "expected SetupGetInfFileListW to fail!\n");
544     todo_wine
545     ok(ERROR_DIRECTORY == GetLastError(),
546        "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
547
548     /* now check the buffer content of a vaild call
549      */
550     *ptr = 0;
551     expected = 3 + strlen(inffile) + strlen(inffile2);
552     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
553     ok(ret, "expected SetupGetInfFileListW to succeed!\n");
554     todo_wine
555     ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
556          expected, outsize);
557     
558
559     DeleteFile(inffile);
560     DeleteFile(inffile2);
561     DeleteFile(invalid_inf);
562 }
563
564 START_TEST(install)
565 {
566     HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
567     char temp_path[MAX_PATH], prev_path[MAX_PATH];
568     DWORD len;
569
570     GetCurrentDirectory(MAX_PATH, prev_path);
571     GetTempPath(MAX_PATH, temp_path);
572     SetCurrentDirectory(temp_path);
573
574     strcpy(CURR_DIR, temp_path);
575     len = strlen(CURR_DIR);
576     if(len && (CURR_DIR[len - 1] == '\\'))
577         CURR_DIR[len - 1] = 0;
578
579     pInstallHinfSectionA = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionA");
580     pInstallHinfSectionW = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionW");
581     pSetupGetInfFileListW = (void *)GetProcAddress(hsetupapi, "SetupGetInfFileListW");
582
583     if (pInstallHinfSectionA)
584     {
585         /* Check if pInstallHinfSectionA sets last error or is a stub (as on WinXP) */
586         static const char *minimal_inf = "[Version]\nSignature=\"$Chicago$\"\n";
587         char cmdline[MAX_PATH*2];
588         create_inf_file(inffile, minimal_inf);
589         sprintf(cmdline, "DefaultInstall 128 %s\\%s", CURR_DIR, inffile);
590         SetLastError(0xdeadbeef);
591         pInstallHinfSectionA(NULL, NULL, cmdline, 0);
592         if (GetLastError() == 0xdeadbeef)
593         {
594             skip("InstallHinfSectionA is broken (stub)\n");
595             pInstallHinfSectionA = NULL;
596         }
597         ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
598     }
599     if (!pInstallHinfSectionW && !pInstallHinfSectionA)
600         win_skip("InstallHinfSectionA and InstallHinfSectionW are not available\n");
601     else
602     {
603         /* Set CBT hook to disallow MessageBox creation in current thread */
604         hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
605         assert(hhook != 0);
606
607         test_cmdline();
608         test_registry();
609         test_install_svc_from();
610         test_driver_install();
611
612         UnhookWindowsHookEx(hhook);
613
614         /* We have to run this test after the CBT hook is disabled because
615             ProfileItems needs to create a window on Windows XP. */
616         test_profile_items();
617     }
618
619     test_inffilelist();
620
621     SetCurrentDirectory(prev_path);
622 }