setupapi/tests: Check the buffer content returned from SetupGetInfFileListW test.
[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 const WCHAR inffileW[] = {'t','e','s','t','.','i','n','f',0};
39 static char CURR_DIR[MAX_PATH];
40
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.
52  */
53
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);
57
58 /*
59  * Helpers
60  */
61
62 static void create_inf_file(LPCSTR filename, const char *data)
63 {
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);
70 }
71
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)
75 {
76     return nCode == HCBT_CREATEWND ? 1: CallNextHookEx(hhook, nCode, wParam, lParam);
77 }
78
79 /*
80  * Tests
81  */
82
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";
89
90 static void run_cmdline(LPCSTR section, int mode, LPCSTR path)
91 {
92     CHAR cmdline[MAX_PATH * 2];
93
94     sprintf(cmdline, "%s %d %s", section, mode, path);
95     if (pInstallHinfSectionA) pInstallHinfSectionA(NULL, NULL, cmdline, 0);
96     else
97     {
98         WCHAR cmdlinew[MAX_PATH * 2];
99         MultiByteToWideChar(CP_ACP, 0, cmdline, -1, cmdlinew, MAX_PATH*2);
100         pInstallHinfSectionW(NULL, NULL, cmdlinew, 0);
101     }
102 }
103
104 static void ok_registry(BOOL expectsuccess)
105 {
106     LONG ret;
107
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);
115 }
116
117 /* Test command line processing */
118 static void test_cmdline(void)
119 {
120     static const char infwithspaces[] = "test file.inf";
121     char path[MAX_PATH];
122
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());
128
129     /* Test handling of spaces in path, unquoted and quoted */
130     create_inf_file(infwithspaces, cmdline_inf);
131
132     sprintf(path, "%s\\%s", CURR_DIR, infwithspaces);
133     run_cmdline("DefaultInstall", 128, path);
134     ok_registry(TRUE);
135
136     sprintf(path, "\"%s\\%s\"", CURR_DIR, infwithspaces);
137     run_cmdline("DefaultInstall", 128, path);
138     ok_registry(FALSE);
139
140     ok(DeleteFile(infwithspaces), "Expected source inf to exist, last error was %d\n", GetLastError());
141 }
142
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";
149
150 static void test_registry(void)
151 {
152     HKEY key;
153     LONG res;
154     char path[MAX_PATH];
155
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");
159
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");
163
164     create_inf_file(inffile, cmdline_inf_reg);
165     sprintf(path, "%s\\%s", CURR_DIR, inffile);
166     run_cmdline("DefaultInstall", 128, path);
167
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)
174     {
175         RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest");
176         RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
177     }
178     ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
179 }
180
181 static void test_install_svc_from(void)
182 {
183     char inf[2048];
184     char path[MAX_PATH];
185     HINF infhandle;
186     BOOL ret;
187     SC_HANDLE scm_handle, svc_handle;
188
189     /* Bail out if we are on win98 */
190     SetLastError(0xdeadbeef);
191     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
192
193     if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
194     {
195         win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
196         return;
197     }
198     CloseServiceHandle(scm_handle);
199
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);
205
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);
214
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);
226
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);
238
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);
250
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);
262
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);
274
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);
286
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)
294     {
295         skip("Not enough rights to install the service\n");
296         SetupCloseInfFile(infhandle);
297         DeleteFile(inffile);
298         return;
299     }
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);
305
306     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
307
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");
311
312     SetLastError(0xdeadbeef);
313     ret = DeleteService(svc_handle);
314     ok(ret, "Service could not be deleted : %d\n", GetLastError());
315
316     CloseServiceHandle(svc_handle);
317     CloseServiceHandle(scm_handle);
318
319     /* TODO: Test the Flags */
320 }
321
322 static void test_driver_install(void)
323 {
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";
346
347     /* Bail out if we are on win98 */
348     SetLastError(0xdeadbeef);
349     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
350
351     if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
352     {
353         win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
354         return;
355     }
356     else if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
357     {
358         skip("Not enough rights to install the service\n");
359         return;
360     }
361     CloseServiceHandle(scm_handle);
362
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");
367
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);
372
373     create_inf_file(inffile, inf);
374     sprintf(path, "%s\\%s", CURR_DIR, inffile);
375     run_cmdline("DefaultInstall", 128, path);
376
377     /* Driver should have been installed */
378     attrs = GetFileAttributes(driver);
379     ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected driver to exist\n");
380
381     scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
382
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");
386
387     SetLastError(0xdeadbeef);
388     ret = DeleteService(svc_handle);
389     ok(ret, "Service could not be deleted : %d\n", GetLastError());
390
391     CloseServiceHandle(svc_handle);
392     CloseServiceHandle(scm_handle);
393
394     /* File cleanup */
395     DeleteFile(inffile);
396     DeleteFile("winetest.sys");
397     DeleteFile(driver);
398 }
399
400 static void test_profile_items(void)
401 {
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);
405
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"
420         ;
421
422     hShell32 = LoadLibraryA("shell32");
423     pSHGetFolderPathA = (void*)GetProcAddress(hShell32, "SHGetFolderPathA");
424     if (!pSHGetFolderPathA)
425     {
426         win_skip("SHGetFolderPathA is not available\n");
427         goto cleanup;
428     }
429
430     if (S_OK != pSHGetFolderPathA(NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, commonprogs))
431     {
432         skip("No common program files directory exists\n");
433         goto cleanup;
434     }
435
436     create_inf_file(inffile, inf);
437     sprintf(path, "%s\\%s", CURR_DIR, inffile);
438     run_cmdline("DefaultInstall", 128, path);
439
440     snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
441     if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(path))
442     {
443         win_skip("ProfileItems not implemented on this system\n");
444     }
445     else
446     {
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");
453     }
454
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);
465
466 cleanup:
467     if (hShell32) FreeLibrary(hShell32);
468     DeleteFile(inffile);
469 }
470
471 static void test_inffilelist(void)
472 {
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$\"";
479
480     WCHAR *p, *ptr;
481     WCHAR dir[MAX_PATH] = { 0 };
482     WCHAR buffer[MAX_PATH] = { 0 };
483     DWORD expected, outsize;
484     BOOL ret;
485
486     if(!pSetupGetInfFileListW)
487     {
488         win_skip("SetupGetInfFileListW not present\n");
489         return;
490     }
491
492     /* NULL means %windir%\\inf
493      * get the value as reference
494      */
495     expected = 0;
496     SetLastError(0xdeadbeef);
497     ret = pSetupGetInfFileListW(NULL, INF_STYLE_WIN4, NULL, 0, &expected);
498     if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
499     {
500         win_skip("SetupGetInfFileListW not implemented\n");
501         return;
502     }
503     ok(ret, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
504     ok(expected > 0, "expected required buffersize to be at least 1\n");
505
506     /* check if an empty string doesn't behaves like NULL */
507     outsize = 0;
508     SetLastError(0xdeadbeef);
509     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
510     todo_wine
511     ok(!ret, "expected SetupGetInfFileListW to fail!\n");
512
513     /* check a not existing directory
514      */
515     MultiByteToWideChar(CP_ACP, 0, CURR_DIR, -1, dir, MAX_PATH);
516     ptr = dir + lstrlenW(dir);
517     MultiByteToWideChar(CP_ACP, 0, "\\not_existent", -1, ptr, MAX_PATH - lstrlenW(dir));
518     outsize = 0xffffffff;
519     SetLastError(0xdeadbeef);
520     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
521     ok(ret, "expected SetupGetInfFileListW to succeed!\n");
522     ok(outsize == 1, "expected required buffersize to be 1, got %d\n", outsize);
523     todo_wine
524     ok(ERROR_PATH_NOT_FOUND == GetLastError(),
525        "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
526     
527     create_inf_file(inffile, inf);
528     create_inf_file(inffile2, inf);
529     create_inf_file(invalid_inf, "This content does not match the inf file format");
530
531     /* pass a filename instead of a directory
532      */
533     *ptr = '\\';
534     MultiByteToWideChar(CP_ACP, 0, invalid_inf, -1, ptr+1, MAX_PATH - lstrlenW(dir));
535     outsize = 0xffffffff;
536     SetLastError(0xdeadbeef);
537     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
538     todo_wine
539     ok(!ret, "expected SetupGetInfFileListW to fail!\n");
540     todo_wine
541     ok(ERROR_DIRECTORY == GetLastError(),
542        "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
543
544     /* make the filename look like directory
545      */
546     dir[1 + lstrlenW(dir)] = 0;
547     dir[lstrlenW(dir)] = '\\';
548     SetLastError(0xdeadbeef);
549     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
550     todo_wine
551     ok(!ret, "expected SetupGetInfFileListW to fail!\n");
552     todo_wine
553     ok(ERROR_DIRECTORY == GetLastError(),
554        "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
555
556     /* now check the buffer content of a vaild call
557      */
558     *ptr = 0;
559     expected = 3 + strlen(inffile) + strlen(inffile2);
560     ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
561     ok(ret, "expected SetupGetInfFileListW to succeed!\n");
562     todo_wine
563     ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
564          expected, outsize);
565     for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
566         ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
567             "unexpected filename %s\n",wine_dbgstr_w(p));
568
569     DeleteFile(inffile);
570     DeleteFile(inffile2);
571     DeleteFile(invalid_inf);
572 }
573
574 START_TEST(install)
575 {
576     HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
577     char temp_path[MAX_PATH], prev_path[MAX_PATH];
578     DWORD len;
579
580     GetCurrentDirectory(MAX_PATH, prev_path);
581     GetTempPath(MAX_PATH, temp_path);
582     SetCurrentDirectory(temp_path);
583
584     strcpy(CURR_DIR, temp_path);
585     len = strlen(CURR_DIR);
586     if(len && (CURR_DIR[len - 1] == '\\'))
587         CURR_DIR[len - 1] = 0;
588
589     pInstallHinfSectionA = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionA");
590     pInstallHinfSectionW = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionW");
591     pSetupGetInfFileListW = (void *)GetProcAddress(hsetupapi, "SetupGetInfFileListW");
592
593     if (pInstallHinfSectionA)
594     {
595         /* Check if pInstallHinfSectionA sets last error or is a stub (as on WinXP) */
596         static const char *minimal_inf = "[Version]\nSignature=\"$Chicago$\"\n";
597         char cmdline[MAX_PATH*2];
598         create_inf_file(inffile, minimal_inf);
599         sprintf(cmdline, "DefaultInstall 128 %s\\%s", CURR_DIR, inffile);
600         SetLastError(0xdeadbeef);
601         pInstallHinfSectionA(NULL, NULL, cmdline, 0);
602         if (GetLastError() == 0xdeadbeef)
603         {
604             skip("InstallHinfSectionA is broken (stub)\n");
605             pInstallHinfSectionA = NULL;
606         }
607         ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
608     }
609     if (!pInstallHinfSectionW && !pInstallHinfSectionA)
610         win_skip("InstallHinfSectionA and InstallHinfSectionW are not available\n");
611     else
612     {
613         /* Set CBT hook to disallow MessageBox creation in current thread */
614         hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
615         assert(hhook != 0);
616
617         test_cmdline();
618         test_registry();
619         test_install_svc_from();
620         test_driver_install();
621
622         UnhookWindowsHookEx(hhook);
623
624         /* We have to run this test after the CBT hook is disabled because
625             ProfileItems needs to create a window on Windows XP. */
626         test_profile_items();
627     }
628
629     test_inffilelist();
630
631     SetCurrentDirectory(prev_path);
632 }