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 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
326 strcat(inf
, "[XSP.InstallPerVer]\n");
327 strcat(inf
, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
328 create_inf_file(inffile
, inf
);
329 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
330 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
332 SetLastError(0xdeadbeef);
333 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "XSP.InstallPerVer", 0);
334 ok(ret
, "Expected success\n");
335 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
336 SetupCloseInfFile(infhandle
);
339 /* TODO: Test the Flags */
342 static void test_driver_install(void)
345 SC_HANDLE scm_handle
, svc_handle
;
347 char path
[MAX_PATH
], windir
[MAX_PATH
], driver
[MAX_PATH
];
349 /* Minimal stuff needed */
350 static const char *inf
=
352 "Signature=\"$Chicago$\"\n"
353 "[DestinationDirs]\n"
354 "Winetest.DriverFiles=12\n"
356 "CopyFiles=Winetest.DriverFiles\n"
357 "[DefaultInstall.Services]\n"
358 "AddService=Winetest,,Winetest.Service\n"
359 "[Winetest.Service]\n"
360 "ServiceBinary=%12%\\winetest.sys\n"
364 "[Winetest.DriverFiles]\n"
367 /* Bail out if we are on win98 */
368 SetLastError(0xdeadbeef);
369 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
371 if (!scm_handle
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
373 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
376 else if (!scm_handle
&& (GetLastError() == ERROR_ACCESS_DENIED
))
378 skip("Not enough rights to install the service\n");
381 CloseServiceHandle(scm_handle
);
383 /* Place where we expect the driver to be installed */
384 GetWindowsDirectoryA(windir
, MAX_PATH
);
385 lstrcpyA(driver
, windir
);
386 lstrcatA(driver
, "\\system32\\drivers\\winetest.sys");
388 /* Create a dummy driver file */
389 handle
= CreateFileA("winetest.sys", GENERIC_WRITE
, 0, NULL
,
390 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
393 create_inf_file(inffile
, inf
);
394 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
395 run_cmdline("DefaultInstall", 128, path
);
397 /* Driver should have been installed */
398 attrs
= GetFileAttributes(driver
);
399 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected driver to exist\n");
401 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
403 /* Open the service to see if it's really there */
404 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
405 ok(svc_handle
!= NULL
, "Service was not created\n");
407 SetLastError(0xdeadbeef);
408 ret
= DeleteService(svc_handle
);
409 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
411 CloseServiceHandle(svc_handle
);
412 CloseServiceHandle(scm_handle
);
416 DeleteFile("winetest.sys");
420 static void test_profile_items(void)
422 char path
[MAX_PATH
], commonprogs
[MAX_PATH
];
424 BOOL (WINAPI
*pSHGetFolderPathA
)(HWND hwnd
, int nFolder
, HANDLE hToken
, DWORD dwFlags
, LPSTR pszPath
);
426 static const char *inf
=
428 "Signature=\"$Chicago$\"\n"
430 "ProfileItems=TestItem,TestItem2,TestGroup\n"
433 "CmdLine=11,,notepad.exe\n"
436 "CmdLine=11,,notepad.exe\n"
442 hShell32
= LoadLibraryA("shell32");
443 pSHGetFolderPathA
= (void*)GetProcAddress(hShell32
, "SHGetFolderPathA");
444 if (!pSHGetFolderPathA
)
446 win_skip("SHGetFolderPathA is not available\n");
450 if (S_OK
!= pSHGetFolderPathA(NULL
, CSIDL_COMMON_PROGRAMS
, NULL
, SHGFP_TYPE_CURRENT
, commonprogs
))
452 skip("No common program files directory exists\n");
456 create_inf_file(inffile
, inf
);
457 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
458 run_cmdline("DefaultInstall", 128, path
);
460 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
461 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributes(path
))
463 win_skip("ProfileItems not implemented on this system\n");
467 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
468 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributes(path
), "directory not created\n");
469 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
470 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributes(path
), "link not created\n");
471 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
472 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributes(path
), "group not created\n");
475 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
477 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
479 snprintf(path
, MAX_PATH
, "%s\\TestItem2.lnk", commonprogs
);
481 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
482 RemoveDirectory(path
);
483 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
484 RemoveDirectory(path
);
487 if (hShell32
) FreeLibrary(hShell32
);
491 static void test_inffilelistA(void)
493 static const char inffile2
[] = "test2.inf";
494 static const char *inf
=
496 "Signature=\"$Chicago$\"";
498 char buffer
[MAX_PATH
] = { 0 };
499 char dir
[MAX_PATH
], *p
;
500 DWORD expected
, outsize
;
503 if(!pSetupGetInfFileListA
)
505 win_skip("SetupGetInfFileListA not present\n");
509 /* create a private directory, the temp directory may contain some
510 * inf files left over from old installations
512 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dir
))
514 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
517 if (!CreateDirectoryA(dir
, NULL
))
519 win_skip("CreateDirectoryA(%s) failed with error %d\n", dir
, GetLastError());
522 if (!SetCurrentDirectoryA(dir
))
524 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
525 RemoveDirectoryA(dir
);
529 create_inf_file(inffile
, inf
);
530 create_inf_file(inffile2
, inf
);
534 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
535 ret
= pSetupGetInfFileListA(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
537 ok(ret
, "expected SetupGetInfFileListA to succeed!\n");
538 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
540 for(p
= buffer
; lstrlenA(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenA(p
) + 1)
541 ok(!lstrcmpA(p
,inffile2
) || !lstrcmpA(p
,inffile
),
542 "unexpected filename %s\n",p
);
545 DeleteFile(inffile2
);
546 SetCurrentDirectoryA(CURR_DIR
);
547 RemoveDirectoryA(dir
);
550 static void test_inffilelist(void)
552 static const char inffile2
[] = "test2.inf";
553 static const WCHAR inffile2W
[] = {'t','e','s','t','2','.','i','n','f',0};
554 static const char invalid_inf
[] = "invalid.inf";
555 static const WCHAR invalid_infW
[] = {'i','n','v','a','l','i','d','.','i','n','f',0};
556 static const char *inf
=
558 "Signature=\"$Chicago$\"";
559 static const char *inf2
=
561 "Signature=\"$CHICAGO$\"";
562 static const char *infNT
=
564 "Signature=\"$WINDOWS NT$\"";
568 WCHAR dir
[MAX_PATH
] = { 0 };
569 WCHAR buffer
[MAX_PATH
] = { 0 };
570 DWORD expected
, outsize
;
573 if(!pSetupGetInfFileListW
)
575 win_skip("SetupGetInfFileListW not present\n");
579 /* NULL means %windir%\\inf
580 * get the value as reference
583 SetLastError(0xdeadbeef);
584 ret
= pSetupGetInfFileListW(NULL
, INF_STYLE_WIN4
, NULL
, 0, &expected
);
585 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
587 win_skip("SetupGetInfFileListW not implemented\n");
590 ok(ret
, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
591 ok(expected
> 0, "expected required buffersize to be at least 1\n");
593 /* check if an empty string doesn't behaves like NULL */
595 SetLastError(0xdeadbeef);
596 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
597 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
599 /* create a private directory, the temp directory may contain some
600 * inf files left over from old installations
602 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dirA
))
604 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
607 if (!CreateDirectoryA(dirA
, NULL
))
609 win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA
, GetLastError());
612 if (!SetCurrentDirectoryA(dirA
))
614 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
615 RemoveDirectoryA(dirA
);
619 MultiByteToWideChar(CP_ACP
, 0, dirA
, -1, dir
, MAX_PATH
);
620 /* check a not existing directory
622 ptr
= dir
+ lstrlenW(dir
);
623 MultiByteToWideChar(CP_ACP
, 0, "\\not_existent", -1, ptr
, MAX_PATH
- lstrlenW(dir
));
624 outsize
= 0xffffffff;
625 SetLastError(0xdeadbeef);
626 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
627 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
628 ok(outsize
== 1, "expected required buffersize to be 1, got %d\n", outsize
);
629 ok(ERROR_PATH_NOT_FOUND
== GetLastError(),
630 "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
632 create_inf_file(inffile
, inf
);
633 create_inf_file(inffile2
, inf
);
634 create_inf_file(invalid_inf
, "This content does not match the inf file format");
636 /* pass a filename instead of a directory
639 MultiByteToWideChar(CP_ACP
, 0, invalid_inf
, -1, ptr
+1, MAX_PATH
- lstrlenW(dir
));
640 outsize
= 0xffffffff;
641 SetLastError(0xdeadbeef);
642 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
643 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
644 ok(ERROR_DIRECTORY
== GetLastError(),
645 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
647 /* make the filename look like directory
649 dir
[1 + lstrlenW(dir
)] = 0;
650 dir
[lstrlenW(dir
)] = '\\';
651 SetLastError(0xdeadbeef);
652 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
653 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
654 ok(ERROR_DIRECTORY
== GetLastError(),
655 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
657 /* now check the buffer content of a vaild call
660 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
661 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
662 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
663 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
665 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
666 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
667 "unexpected filename %s\n",wine_dbgstr_w(p
));
671 create_inf_file(inffile2
, inf2
);
672 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
673 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
674 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
676 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
677 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
678 "unexpected filename %s\n",wine_dbgstr_w(p
));
680 /* signature Windows NT is also inf style win4
682 create_inf_file(inffile2
, infNT
);
683 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
684 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
685 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
686 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
688 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
689 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
690 "unexpected filename %s\n",wine_dbgstr_w(p
));
694 expected
= 2 + strlen(invalid_inf
);
695 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_OLDNT
, buffer
, MAX_PATH
, &outsize
);
696 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
697 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
699 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
700 ok(!lstrcmpW(p
,invalid_infW
), "unexpected filename %s\n",wine_dbgstr_w(p
));
704 expected
= 4 + strlen(inffile
) + strlen(inffile2
) + strlen(invalid_inf
);
705 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
707 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
708 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
710 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
711 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
) || !lstrcmpW(p
,invalid_infW
),
712 "unexpected filename %s\n",wine_dbgstr_w(p
));
715 DeleteFile(inffile2
);
716 DeleteFile(invalid_inf
);
717 SetCurrentDirectoryA(CURR_DIR
);
718 RemoveDirectoryA(dirA
);
723 HMODULE hsetupapi
= GetModuleHandle("setupapi.dll");
724 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
727 GetCurrentDirectory(MAX_PATH
, prev_path
);
728 GetTempPath(MAX_PATH
, temp_path
);
729 SetCurrentDirectory(temp_path
);
731 strcpy(CURR_DIR
, temp_path
);
732 len
= strlen(CURR_DIR
);
733 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
734 CURR_DIR
[len
- 1] = 0;
736 pInstallHinfSectionA
= (void *)GetProcAddress(hsetupapi
, "InstallHinfSectionA");
737 pInstallHinfSectionW
= (void *)GetProcAddress(hsetupapi
, "InstallHinfSectionW");
738 pSetupGetInfFileListA
= (void *)GetProcAddress(hsetupapi
, "SetupGetInfFileListA");
739 pSetupGetInfFileListW
= (void *)GetProcAddress(hsetupapi
, "SetupGetInfFileListW");
741 if (pInstallHinfSectionA
)
743 /* Check if pInstallHinfSectionA sets last error or is a stub (as on WinXP) */
744 static const char *minimal_inf
= "[Version]\nSignature=\"$Chicago$\"\n";
745 char cmdline
[MAX_PATH
*2];
747 create_inf_file(inffile
, minimal_inf
);
748 sprintf(cmdline
, "DefaultInstall 128 %s\\%s", CURR_DIR
, inffile
);
749 SetLastError(0xdeadbeef);
750 pInstallHinfSectionA(NULL
, NULL
, cmdline
, 0);
751 if (GetLastError() == 0xdeadbeef)
753 skip("InstallHinfSectionA is broken (stub)\n");
754 pInstallHinfSectionA
= NULL
;
756 ret
= DeleteFile(inffile
);
757 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
759 if (!pInstallHinfSectionW
&& !pInstallHinfSectionA
)
760 win_skip("InstallHinfSectionA and InstallHinfSectionW are not available\n");
763 /* Set CBT hook to disallow MessageBox creation in current thread */
764 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
769 test_install_svc_from();
770 test_driver_install();
772 UnhookWindowsHookEx(hhook
);
774 /* We have to run this test after the CBT hook is disabled because
775 ProfileItems needs to create a window on Windows XP. */
776 test_profile_items();
782 SetCurrentDirectory(prev_path
);