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
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
54 static void (WINAPI
*pInstallHinfSectionA
)(HWND
, HINSTANCE
, LPCSTR
, INT
);
55 static void (WINAPI
*pInstallHinfSectionW
)(HWND
, HINSTANCE
, LPCWSTR
, INT
);
56 static BOOL (WINAPI
*pSetupGetInfFileListA
)(PCSTR
, DWORD
, PSTR
, DWORD
, PDWORD
);
57 static BOOL (WINAPI
*pSetupGetInfFileListW
)(PCWSTR
, DWORD
, PWSTR
, DWORD
, PDWORD
);
63 static void create_inf_file(LPCSTR filename
, const char *data
)
66 HANDLE handle
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
67 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
68 assert(handle
!= INVALID_HANDLE_VALUE
);
69 assert(WriteFile(handle
, data
, strlen(data
), &res
, NULL
));
73 /* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
75 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
77 return nCode
== HCBT_CREATEWND
? 1: CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
84 static const char *cmdline_inf
= "[Version]\n"
85 "Signature=\"$Chicago$\"\n"
87 "AddReg=Add.Settings\n"
89 "HKCU,Software\\Wine\\setupapitest,,\n";
91 static void run_cmdline(LPCSTR section
, int mode
, LPCSTR path
)
93 CHAR cmdline
[MAX_PATH
* 2];
95 sprintf(cmdline
, "%s %d %s", section
, mode
, path
);
96 if (pInstallHinfSectionA
) pInstallHinfSectionA(NULL
, NULL
, cmdline
, 0);
99 WCHAR cmdlinew
[MAX_PATH
* 2];
100 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, cmdlinew
, MAX_PATH
*2);
101 pInstallHinfSectionW(NULL
, NULL
, cmdlinew
, 0);
105 static void ok_registry(BOOL expectsuccess
)
109 /* Functional tests for success of install and clean up */
110 ret
= RegDeleteKey(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest");
111 ok((expectsuccess
&& ret
== ERROR_SUCCESS
) ||
112 (!expectsuccess
&& ret
== ERROR_FILE_NOT_FOUND
),
113 "Expected registry key Software\\Wine\\setupapitest to %s, RegDeleteKey returned %d\n",
114 expectsuccess
? "exist" : "not exist",
118 /* Test command line processing */
119 static void test_cmdline(void)
121 static const char infwithspaces
[] = "test file.inf";
125 create_inf_file(inffile
, cmdline_inf
);
126 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
127 run_cmdline("DefaultInstall", 128, path
);
129 ret
= DeleteFile(inffile
);
130 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
132 /* Test handling of spaces in path, unquoted and quoted */
133 create_inf_file(infwithspaces
, cmdline_inf
);
135 sprintf(path
, "%s\\%s", CURR_DIR
, infwithspaces
);
136 run_cmdline("DefaultInstall", 128, path
);
139 sprintf(path
, "\"%s\\%s\"", CURR_DIR
, infwithspaces
);
140 run_cmdline("DefaultInstall", 128, path
);
143 ret
= DeleteFile(infwithspaces
);
144 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
147 static const char *cmdline_inf_reg
= "[Version]\n"
148 "Signature=\"$Chicago$\"\n"
150 "DelReg=Del.Settings\n"
152 "HKCU,Software\\Wine\\setupapitest\n";
154 static void test_registry(void)
161 /* First create a registry structure we would like to be deleted */
162 ok(!RegCreateKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
163 "Expected RegCreateKeyA to succeed\n");
165 /* Doublecheck if the registry key is present */
166 ok(!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
167 "Expected registry key to exist\n");
169 create_inf_file(inffile
, cmdline_inf_reg
);
170 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
171 run_cmdline("DefaultInstall", 128, path
);
173 /* Check if the registry key is recursively deleted */
174 res
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest", &key
);
176 ok(res
== ERROR_FILE_NOT_FOUND
, "Didn't expect the registry key to exist\n");
178 if (res
== ERROR_SUCCESS
)
180 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest");
181 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest");
183 ret
= DeleteFile(inffile
);
184 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
187 static void test_install_svc_from(void)
193 SC_HANDLE scm_handle
, svc_handle
;
195 /* Bail out if we are on win98 */
196 SetLastError(0xdeadbeef);
197 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
199 if (!scm_handle
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
201 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
204 CloseServiceHandle(scm_handle
);
206 /* Basic inf file to satisfy SetupOpenInfFileA */
207 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
208 create_inf_file(inffile
, inf
);
209 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
210 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
212 /* Nothing but the Version section */
213 SetLastError(0xdeadbeef);
214 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
215 ok(!ret
, "Expected failure\n");
216 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
217 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
218 SetupCloseInfFile(infhandle
);
221 /* Add the section */
222 strcat(inf
, "[Winetest.Services]\n");
223 create_inf_file(inffile
, inf
);
224 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
225 SetLastError(0xdeadbeef);
226 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
227 ok(!ret
, "Expected failure\n");
228 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
229 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
230 SetupCloseInfFile(infhandle
);
233 /* Add a reference */
234 strcat(inf
, "AddService=Winetest,,Winetest.Service\n");
235 create_inf_file(inffile
, inf
);
236 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
237 SetLastError(0xdeadbeef);
238 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
239 ok(!ret
, "Expected failure\n");
240 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
241 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
242 SetupCloseInfFile(infhandle
);
245 /* Add the section */
246 strcat(inf
, "[Winetest.Service]\n");
247 create_inf_file(inffile
, inf
);
248 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
249 SetLastError(0xdeadbeef);
250 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
251 ok(!ret
, "Expected failure\n");
252 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
253 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
254 SetupCloseInfFile(infhandle
);
257 /* Just the ServiceBinary */
258 strcat(inf
, "ServiceBinary=%12%\\winetest.sys\n");
259 create_inf_file(inffile
, inf
);
260 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
261 SetLastError(0xdeadbeef);
262 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
263 ok(!ret
, "Expected failure\n");
264 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
265 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
266 SetupCloseInfFile(infhandle
);
269 /* Add the ServiceType */
270 strcat(inf
, "ServiceType=1\n");
271 create_inf_file(inffile
, inf
);
272 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
273 SetLastError(0xdeadbeef);
274 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
275 ok(!ret
, "Expected failure\n");
276 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
277 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
278 SetupCloseInfFile(infhandle
);
281 /* Add the StartType */
282 strcat(inf
, "StartType=4\n");
283 create_inf_file(inffile
, inf
);
284 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
285 SetLastError(0xdeadbeef);
286 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
287 ok(!ret
, "Expected failure\n");
288 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
289 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
290 SetupCloseInfFile(infhandle
);
293 /* This should be it, the minimal entries to install a service */
294 strcat(inf
, "ErrorControl=1");
295 create_inf_file(inffile
, inf
);
296 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
297 SetLastError(0xdeadbeef);
298 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
299 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
301 skip("Not enough rights to install the service\n");
302 SetupCloseInfFile(infhandle
);
306 ok(ret
, "Expected success\n");
307 ok(GetLastError() == ERROR_SUCCESS
,
308 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
309 SetupCloseInfFile(infhandle
);
312 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
314 /* Open the service to see if it's really there */
315 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
316 ok(svc_handle
!= NULL
, "Service was not created\n");
318 SetLastError(0xdeadbeef);
319 ret
= DeleteService(svc_handle
);
320 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
322 CloseServiceHandle(svc_handle
);
323 CloseServiceHandle(scm_handle
);
325 /* TODO: Test the Flags */
328 static void test_driver_install(void)
331 SC_HANDLE scm_handle
, svc_handle
;
333 char path
[MAX_PATH
], windir
[MAX_PATH
], driver
[MAX_PATH
];
335 /* Minimal stuff needed */
336 static const char *inf
=
338 "Signature=\"$Chicago$\"\n"
339 "[DestinationDirs]\n"
340 "Winetest.DriverFiles=12\n"
342 "CopyFiles=Winetest.DriverFiles\n"
343 "[DefaultInstall.Services]\n"
344 "AddService=Winetest,,Winetest.Service\n"
345 "[Winetest.Service]\n"
346 "ServiceBinary=%12%\\winetest.sys\n"
350 "[Winetest.DriverFiles]\n"
353 /* Bail out if we are on win98 */
354 SetLastError(0xdeadbeef);
355 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
357 if (!scm_handle
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
359 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
362 else if (!scm_handle
&& (GetLastError() == ERROR_ACCESS_DENIED
))
364 skip("Not enough rights to install the service\n");
367 CloseServiceHandle(scm_handle
);
369 /* Place where we expect the driver to be installed */
370 GetWindowsDirectoryA(windir
, MAX_PATH
);
371 lstrcpyA(driver
, windir
);
372 lstrcatA(driver
, "\\system32\\drivers\\winetest.sys");
374 /* Create a dummy driver file */
375 handle
= CreateFileA("winetest.sys", GENERIC_WRITE
, 0, NULL
,
376 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
379 create_inf_file(inffile
, inf
);
380 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
381 run_cmdline("DefaultInstall", 128, path
);
383 /* Driver should have been installed */
384 attrs
= GetFileAttributes(driver
);
385 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected driver to exist\n");
387 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
389 /* Open the service to see if it's really there */
390 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
391 ok(svc_handle
!= NULL
, "Service was not created\n");
393 SetLastError(0xdeadbeef);
394 ret
= DeleteService(svc_handle
);
395 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
397 CloseServiceHandle(svc_handle
);
398 CloseServiceHandle(scm_handle
);
402 DeleteFile("winetest.sys");
406 static void test_profile_items(void)
408 char path
[MAX_PATH
], commonprogs
[MAX_PATH
];
410 BOOL (WINAPI
*pSHGetFolderPathA
)(HWND hwnd
, int nFolder
, HANDLE hToken
, DWORD dwFlags
, LPSTR pszPath
);
412 static const char *inf
=
414 "Signature=\"$Chicago$\"\n"
416 "ProfileItems=TestItem,TestItem2,TestGroup\n"
419 "CmdLine=11,,notepad.exe\n"
422 "CmdLine=11,,notepad.exe\n"
428 hShell32
= LoadLibraryA("shell32");
429 pSHGetFolderPathA
= (void*)GetProcAddress(hShell32
, "SHGetFolderPathA");
430 if (!pSHGetFolderPathA
)
432 win_skip("SHGetFolderPathA is not available\n");
436 if (S_OK
!= pSHGetFolderPathA(NULL
, CSIDL_COMMON_PROGRAMS
, NULL
, SHGFP_TYPE_CURRENT
, commonprogs
))
438 skip("No common program files directory exists\n");
442 create_inf_file(inffile
, inf
);
443 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
444 run_cmdline("DefaultInstall", 128, path
);
446 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
447 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributes(path
))
449 win_skip("ProfileItems not implemented on this system\n");
453 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
454 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributes(path
), "directory not created\n");
455 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
456 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributes(path
), "link not created\n");
457 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
458 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributes(path
), "group not created\n");
461 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
463 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
465 snprintf(path
, MAX_PATH
, "%s\\TestItem2.lnk", commonprogs
);
467 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
468 RemoveDirectory(path
);
469 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
470 RemoveDirectory(path
);
473 if (hShell32
) FreeLibrary(hShell32
);
477 static void test_inffilelistA(void)
479 static const char inffile2
[] = "test2.inf";
480 static const char *inf
=
482 "Signature=\"$Chicago$\"";
484 char buffer
[MAX_PATH
] = { 0 };
485 char dir
[MAX_PATH
], *p
;
486 DWORD expected
, outsize
;
489 if(!pSetupGetInfFileListA
)
491 win_skip("SetupGetInfFileListA not present\n");
495 /* create a private directory, the temp directory may contain some
496 * inf files left over from old installations
498 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dir
))
500 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
503 if (!CreateDirectoryA(dir
, NULL
))
505 win_skip("CreateDirectoryA(%s) failed with error %d\n", dir
, GetLastError());
508 if (!SetCurrentDirectoryA(dir
))
510 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
511 RemoveDirectoryA(dir
);
515 create_inf_file(inffile
, inf
);
516 create_inf_file(inffile2
, inf
);
520 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
521 ret
= pSetupGetInfFileListA(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
523 ok(ret
, "expected SetupGetInfFileListA to succeed!\n");
524 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
526 for(p
= buffer
; lstrlenA(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenA(p
) + 1)
527 ok(!lstrcmpA(p
,inffile2
) || !lstrcmpA(p
,inffile
),
528 "unexpected filename %s\n",p
);
531 DeleteFile(inffile2
);
532 SetCurrentDirectoryA(CURR_DIR
);
533 RemoveDirectoryA(dir
);
536 static void test_inffilelist(void)
538 static const char inffile2
[] = "test2.inf";
539 static const WCHAR inffile2W
[] = {'t','e','s','t','2','.','i','n','f',0};
540 static const char invalid_inf
[] = "invalid.inf";
541 static const WCHAR invalid_infW
[] = {'i','n','v','a','l','i','d','.','i','n','f',0};
542 static const char *inf
=
544 "Signature=\"$Chicago$\"";
545 static const char *inf2
=
547 "Signature=\"$CHICAGO$\"";
548 static const char *infNT
=
550 "Signature=\"$WINDOWS NT$\"";
554 WCHAR dir
[MAX_PATH
] = { 0 };
555 WCHAR buffer
[MAX_PATH
] = { 0 };
556 DWORD expected
, outsize
;
559 if(!pSetupGetInfFileListW
)
561 win_skip("SetupGetInfFileListW not present\n");
565 /* NULL means %windir%\\inf
566 * get the value as reference
569 SetLastError(0xdeadbeef);
570 ret
= pSetupGetInfFileListW(NULL
, INF_STYLE_WIN4
, NULL
, 0, &expected
);
571 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
573 win_skip("SetupGetInfFileListW not implemented\n");
576 ok(ret
, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
577 ok(expected
> 0, "expected required buffersize to be at least 1\n");
579 /* check if an empty string doesn't behaves like NULL */
581 SetLastError(0xdeadbeef);
582 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
583 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
585 /* create a private directory, the temp directory may contain some
586 * inf files left over from old installations
588 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dirA
))
590 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
593 if (!CreateDirectoryA(dirA
, NULL
))
595 win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA
, GetLastError());
598 if (!SetCurrentDirectoryA(dirA
))
600 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
601 RemoveDirectoryA(dirA
);
605 MultiByteToWideChar(CP_ACP
, 0, dirA
, -1, dir
, MAX_PATH
);
606 /* check a not existing directory
608 ptr
= dir
+ lstrlenW(dir
);
609 MultiByteToWideChar(CP_ACP
, 0, "\\not_existent", -1, ptr
, MAX_PATH
- lstrlenW(dir
));
610 outsize
= 0xffffffff;
611 SetLastError(0xdeadbeef);
612 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
613 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
614 ok(outsize
== 1, "expected required buffersize to be 1, got %d\n", outsize
);
615 ok(ERROR_PATH_NOT_FOUND
== GetLastError(),
616 "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
618 create_inf_file(inffile
, inf
);
619 create_inf_file(inffile2
, inf
);
620 create_inf_file(invalid_inf
, "This content does not match the inf file format");
622 /* pass a filename instead of a directory
625 MultiByteToWideChar(CP_ACP
, 0, invalid_inf
, -1, ptr
+1, MAX_PATH
- lstrlenW(dir
));
626 outsize
= 0xffffffff;
627 SetLastError(0xdeadbeef);
628 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
629 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
630 ok(ERROR_DIRECTORY
== GetLastError(),
631 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
633 /* make the filename look like directory
635 dir
[1 + lstrlenW(dir
)] = 0;
636 dir
[lstrlenW(dir
)] = '\\';
637 SetLastError(0xdeadbeef);
638 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
639 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
640 ok(ERROR_DIRECTORY
== GetLastError(),
641 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
643 /* now check the buffer content of a vaild call
646 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
647 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
648 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
649 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
651 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
652 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
653 "unexpected filename %s\n",wine_dbgstr_w(p
));
657 create_inf_file(inffile2
, inf2
);
658 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
659 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
660 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
662 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
663 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
664 "unexpected filename %s\n",wine_dbgstr_w(p
));
666 /* signature Windows NT is also inf style win4
668 create_inf_file(inffile2
, infNT
);
669 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
670 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
671 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
672 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
674 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
675 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
676 "unexpected filename %s\n",wine_dbgstr_w(p
));
680 expected
= 2 + strlen(invalid_inf
);
681 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_OLDNT
, buffer
, MAX_PATH
, &outsize
);
682 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
683 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
685 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
686 ok(!lstrcmpW(p
,invalid_infW
), "unexpected filename %s\n",wine_dbgstr_w(p
));
690 expected
= 4 + strlen(inffile
) + strlen(inffile2
) + strlen(invalid_inf
);
691 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
693 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
694 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
696 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
697 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
) || !lstrcmpW(p
,invalid_infW
),
698 "unexpected filename %s\n",wine_dbgstr_w(p
));
701 DeleteFile(inffile2
);
702 DeleteFile(invalid_inf
);
703 SetCurrentDirectoryA(CURR_DIR
);
704 RemoveDirectoryA(dirA
);
709 HMODULE hsetupapi
= GetModuleHandle("setupapi.dll");
710 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
713 GetCurrentDirectory(MAX_PATH
, prev_path
);
714 GetTempPath(MAX_PATH
, temp_path
);
715 SetCurrentDirectory(temp_path
);
717 strcpy(CURR_DIR
, temp_path
);
718 len
= strlen(CURR_DIR
);
719 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
720 CURR_DIR
[len
- 1] = 0;
722 pInstallHinfSectionA
= (void *)GetProcAddress(hsetupapi
, "InstallHinfSectionA");
723 pInstallHinfSectionW
= (void *)GetProcAddress(hsetupapi
, "InstallHinfSectionW");
724 pSetupGetInfFileListA
= (void *)GetProcAddress(hsetupapi
, "SetupGetInfFileListA");
725 pSetupGetInfFileListW
= (void *)GetProcAddress(hsetupapi
, "SetupGetInfFileListW");
727 if (pInstallHinfSectionA
)
729 /* Check if pInstallHinfSectionA sets last error or is a stub (as on WinXP) */
730 static const char *minimal_inf
= "[Version]\nSignature=\"$Chicago$\"\n";
731 char cmdline
[MAX_PATH
*2];
733 create_inf_file(inffile
, minimal_inf
);
734 sprintf(cmdline
, "DefaultInstall 128 %s\\%s", CURR_DIR
, inffile
);
735 SetLastError(0xdeadbeef);
736 pInstallHinfSectionA(NULL
, NULL
, cmdline
, 0);
737 if (GetLastError() == 0xdeadbeef)
739 skip("InstallHinfSectionA is broken (stub)\n");
740 pInstallHinfSectionA
= NULL
;
742 ret
= DeleteFile(inffile
);
743 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
745 if (!pInstallHinfSectionW
&& !pInstallHinfSectionA
)
746 win_skip("InstallHinfSectionA and InstallHinfSectionW are not available\n");
749 /* Set CBT hook to disallow MessageBox creation in current thread */
750 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
755 test_install_svc_from();
756 test_driver_install();
758 UnhookWindowsHookEx(hhook
);
760 /* We have to run this test after the CBT hook is disabled because
761 ProfileItems needs to create a window on Windows XP. */
762 test_profile_items();
768 SetCurrentDirectory(prev_path
);