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
)
67 HANDLE handle
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
,
68 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
69 assert(handle
!= INVALID_HANDLE_VALUE
);
70 ret
= WriteFile(handle
, data
, strlen(data
), &res
, NULL
);
75 /* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
77 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
79 return nCode
== HCBT_CREATEWND
? 1: CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
86 static const char *cmdline_inf
= "[Version]\n"
87 "Signature=\"$Chicago$\"\n"
89 "AddReg=Add.Settings\n"
91 "HKCU,Software\\Wine\\setupapitest,,\n";
93 static void run_cmdline(LPCSTR section
, int mode
, LPCSTR path
)
95 CHAR cmdline
[MAX_PATH
* 2];
97 sprintf(cmdline
, "%s %d %s", section
, mode
, path
);
98 if (pInstallHinfSectionA
) pInstallHinfSectionA(NULL
, NULL
, cmdline
, 0);
101 WCHAR cmdlinew
[MAX_PATH
* 2];
102 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, cmdlinew
, MAX_PATH
*2);
103 pInstallHinfSectionW(NULL
, NULL
, cmdlinew
, 0);
107 static void ok_registry(BOOL expectsuccess
)
111 /* Functional tests for success of install and clean up */
112 ret
= RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest");
113 ok((expectsuccess
&& ret
== ERROR_SUCCESS
) ||
114 (!expectsuccess
&& ret
== ERROR_FILE_NOT_FOUND
),
115 "Expected registry key Software\\Wine\\setupapitest to %s, RegDeleteKey returned %d\n",
116 expectsuccess
? "exist" : "not exist",
120 /* Test command line processing */
121 static void test_cmdline(void)
123 static const char infwithspaces
[] = "test file.inf";
127 create_inf_file(inffile
, cmdline_inf
);
128 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
129 run_cmdline("DefaultInstall", 128, path
);
131 ret
= DeleteFileA(inffile
);
132 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
134 /* Test handling of spaces in path, unquoted and quoted */
135 create_inf_file(infwithspaces
, cmdline_inf
);
137 sprintf(path
, "%s\\%s", CURR_DIR
, infwithspaces
);
138 run_cmdline("DefaultInstall", 128, path
);
141 sprintf(path
, "\"%s\\%s\"", CURR_DIR
, infwithspaces
);
142 run_cmdline("DefaultInstall", 128, path
);
145 ret
= DeleteFileA(infwithspaces
);
146 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
149 static const char *cmdline_inf_reg
= "[Version]\n"
150 "Signature=\"$Chicago$\"\n"
152 "DelReg=Del.Settings\n"
154 "HKCU,Software\\Wine\\setupapitest\n";
156 static void test_registry(void)
163 /* First create a registry structure we would like to be deleted */
164 ok(!RegCreateKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
165 "Expected RegCreateKeyA to succeed\n");
167 /* Doublecheck if the registry key is present */
168 ok(!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
169 "Expected registry key to exist\n");
171 create_inf_file(inffile
, cmdline_inf_reg
);
172 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
173 run_cmdline("DefaultInstall", 128, path
);
175 /* Check if the registry key is recursively deleted */
176 res
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest", &key
);
177 ok(res
== ERROR_FILE_NOT_FOUND
, "Didn't expect the registry key to exist\n");
179 if (res
== ERROR_SUCCESS
)
181 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest");
182 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest");
184 ret
= DeleteFileA(inffile
);
185 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
188 static void test_install_svc_from(void)
194 SC_HANDLE scm_handle
, svc_handle
;
196 /* Bail out if we are on win98 */
197 SetLastError(0xdeadbeef);
198 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
200 if (!scm_handle
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
202 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
205 CloseServiceHandle(scm_handle
);
207 /* Basic inf file to satisfy SetupOpenInfFileA */
208 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
209 create_inf_file(inffile
, inf
);
210 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
211 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
213 /* Nothing but the Version section */
214 SetLastError(0xdeadbeef);
215 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
216 ok(!ret
, "Expected failure\n");
217 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
218 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
219 SetupCloseInfFile(infhandle
);
220 DeleteFileA(inffile
);
222 /* Add the section */
223 strcat(inf
, "[Winetest.Services]\n");
224 create_inf_file(inffile
, inf
);
225 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
226 SetLastError(0xdeadbeef);
227 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
228 ok(!ret
, "Expected failure\n");
229 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
230 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
231 SetupCloseInfFile(infhandle
);
232 DeleteFileA(inffile
);
234 /* Add a reference */
235 strcat(inf
, "AddService=Winetest,,Winetest.Service\n");
236 create_inf_file(inffile
, inf
);
237 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
238 SetLastError(0xdeadbeef);
239 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
240 ok(!ret
, "Expected failure\n");
241 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
242 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
243 SetupCloseInfFile(infhandle
);
244 DeleteFileA(inffile
);
246 /* Add the section */
247 strcat(inf
, "[Winetest.Service]\n");
248 create_inf_file(inffile
, inf
);
249 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
250 SetLastError(0xdeadbeef);
251 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
252 ok(!ret
, "Expected failure\n");
253 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
254 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
255 SetupCloseInfFile(infhandle
);
256 DeleteFileA(inffile
);
258 /* Just the ServiceBinary */
259 strcat(inf
, "ServiceBinary=%12%\\winetest.sys\n");
260 create_inf_file(inffile
, inf
);
261 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
262 SetLastError(0xdeadbeef);
263 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
264 ok(!ret
, "Expected failure\n");
265 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
266 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
267 SetupCloseInfFile(infhandle
);
268 DeleteFileA(inffile
);
270 /* Add the ServiceType */
271 strcat(inf
, "ServiceType=1\n");
272 create_inf_file(inffile
, inf
);
273 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
274 SetLastError(0xdeadbeef);
275 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
276 ok(!ret
, "Expected failure\n");
277 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
278 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
279 SetupCloseInfFile(infhandle
);
280 DeleteFileA(inffile
);
282 /* Add the StartType */
283 strcat(inf
, "StartType=4\n");
284 create_inf_file(inffile
, inf
);
285 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
286 SetLastError(0xdeadbeef);
287 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
288 ok(!ret
, "Expected failure\n");
289 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
290 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
291 SetupCloseInfFile(infhandle
);
292 DeleteFileA(inffile
);
294 /* This should be it, the minimal entries to install a service */
295 strcat(inf
, "ErrorControl=1");
296 create_inf_file(inffile
, inf
);
297 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
298 SetLastError(0xdeadbeef);
299 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
300 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
302 skip("Not enough rights to install the service\n");
303 SetupCloseInfFile(infhandle
);
304 DeleteFileA(inffile
);
307 ok(ret
, "Expected success\n");
308 ok(GetLastError() == ERROR_SUCCESS
,
309 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
310 SetupCloseInfFile(infhandle
);
311 DeleteFileA(inffile
);
313 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
315 /* Open the service to see if it's really there */
316 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
317 ok(svc_handle
!= NULL
, "Service was not created\n");
319 SetLastError(0xdeadbeef);
320 ret
= DeleteService(svc_handle
);
321 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
323 CloseServiceHandle(svc_handle
);
324 CloseServiceHandle(scm_handle
);
326 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
327 strcat(inf
, "[XSP.InstallPerVer]\n");
328 strcat(inf
, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
329 create_inf_file(inffile
, inf
);
330 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
331 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
333 SetLastError(0xdeadbeef);
334 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "XSP.InstallPerVer", 0);
335 ok(ret
, "Expected success\n");
336 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
337 SetupCloseInfFile(infhandle
);
338 DeleteFileA(inffile
);
340 /* TODO: Test the Flags */
343 static void test_driver_install(void)
346 SC_HANDLE scm_handle
, svc_handle
;
348 char path
[MAX_PATH
], windir
[MAX_PATH
], driver
[MAX_PATH
];
350 /* Minimal stuff needed */
351 static const char *inf
=
353 "Signature=\"$Chicago$\"\n"
354 "[DestinationDirs]\n"
355 "Winetest.DriverFiles=12\n"
357 "CopyFiles=Winetest.DriverFiles\n"
358 "[DefaultInstall.Services]\n"
359 "AddService=Winetest,,Winetest.Service\n"
360 "[Winetest.Service]\n"
361 "ServiceBinary=%12%\\winetest.sys\n"
365 "[Winetest.DriverFiles]\n"
368 /* Bail out if we are on win98 */
369 SetLastError(0xdeadbeef);
370 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
372 if (!scm_handle
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
374 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
377 else if (!scm_handle
&& (GetLastError() == ERROR_ACCESS_DENIED
))
379 skip("Not enough rights to install the service\n");
382 CloseServiceHandle(scm_handle
);
384 /* Place where we expect the driver to be installed */
385 GetWindowsDirectoryA(windir
, MAX_PATH
);
386 lstrcpyA(driver
, windir
);
387 lstrcatA(driver
, "\\system32\\drivers\\winetest.sys");
389 /* Create a dummy driver file */
390 handle
= CreateFileA("winetest.sys", GENERIC_WRITE
, 0, NULL
,
391 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
394 create_inf_file(inffile
, inf
);
395 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
396 run_cmdline("DefaultInstall", 128, path
);
398 /* Driver should have been installed */
399 attrs
= GetFileAttributesA(driver
);
400 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected driver to exist\n");
402 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
404 /* Open the service to see if it's really there */
405 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
406 ok(svc_handle
!= NULL
, "Service was not created\n");
408 SetLastError(0xdeadbeef);
409 ret
= DeleteService(svc_handle
);
410 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
412 CloseServiceHandle(svc_handle
);
413 CloseServiceHandle(scm_handle
);
416 DeleteFileA(inffile
);
417 DeleteFileA("winetest.sys");
421 static void test_profile_items(void)
423 char path
[MAX_PATH
], commonprogs
[MAX_PATH
];
425 BOOL (WINAPI
*pSHGetFolderPathA
)(HWND hwnd
, int nFolder
, HANDLE hToken
, DWORD dwFlags
, LPSTR pszPath
);
427 static const char *inf
=
429 "Signature=\"$Chicago$\"\n"
431 "ProfileItems=TestItem,TestItem2,TestGroup\n"
434 "CmdLine=11,,notepad.exe\n"
437 "CmdLine=11,,notepad.exe\n"
443 hShell32
= LoadLibraryA("shell32");
444 pSHGetFolderPathA
= (void*)GetProcAddress(hShell32
, "SHGetFolderPathA");
445 if (!pSHGetFolderPathA
)
447 win_skip("SHGetFolderPathA is not available\n");
451 if (S_OK
!= pSHGetFolderPathA(NULL
, CSIDL_COMMON_PROGRAMS
, NULL
, SHGFP_TYPE_CURRENT
, commonprogs
))
453 skip("No common program files directory exists\n");
457 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
458 if (!CreateDirectoryA(path
, NULL
) && GetLastError() == ERROR_ACCESS_DENIED
)
460 skip("need admin rights\n");
463 RemoveDirectoryA(path
);
465 create_inf_file(inffile
, inf
);
466 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
467 run_cmdline("DefaultInstall", 128, path
);
469 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
470 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesA(path
))
472 win_skip("ProfileItems not implemented on this system\n");
476 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
477 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "directory not created\n");
478 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
479 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "link not created\n");
480 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
481 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "group not created\n");
484 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
486 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
488 snprintf(path
, MAX_PATH
, "%s\\TestItem2.lnk", commonprogs
);
490 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
491 RemoveDirectoryA(path
);
492 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
493 RemoveDirectoryA(path
);
496 if (hShell32
) FreeLibrary(hShell32
);
497 DeleteFileA(inffile
);
500 static void test_inffilelistA(void)
502 static const char inffile2
[] = "test2.inf";
503 static const char *inf
=
505 "Signature=\"$Chicago$\"";
507 char buffer
[MAX_PATH
] = { 0 };
508 char dir
[MAX_PATH
], *p
;
509 DWORD expected
, outsize
;
512 if(!pSetupGetInfFileListA
)
514 win_skip("SetupGetInfFileListA not present\n");
518 /* create a private directory, the temp directory may contain some
519 * inf files left over from old installations
521 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dir
))
523 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
526 if (!CreateDirectoryA(dir
, NULL
))
528 win_skip("CreateDirectoryA(%s) failed with error %d\n", dir
, GetLastError());
531 if (!SetCurrentDirectoryA(dir
))
533 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
534 RemoveDirectoryA(dir
);
538 create_inf_file(inffile
, inf
);
539 create_inf_file(inffile2
, inf
);
543 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
544 ret
= pSetupGetInfFileListA(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
546 ok(ret
, "expected SetupGetInfFileListA to succeed!\n");
547 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
549 for(p
= buffer
; lstrlenA(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenA(p
) + 1)
550 ok(!lstrcmpA(p
,inffile2
) || !lstrcmpA(p
,inffile
),
551 "unexpected filename %s\n",p
);
553 DeleteFileA(inffile
);
554 DeleteFileA(inffile2
);
555 SetCurrentDirectoryA(CURR_DIR
);
556 RemoveDirectoryA(dir
);
559 static void test_inffilelist(void)
561 static const char inffile2
[] = "test2.inf";
562 static const WCHAR inffile2W
[] = {'t','e','s','t','2','.','i','n','f',0};
563 static const char invalid_inf
[] = "invalid.inf";
564 static const WCHAR invalid_infW
[] = {'i','n','v','a','l','i','d','.','i','n','f',0};
565 static const char *inf
=
567 "Signature=\"$Chicago$\"";
568 static const char *inf2
=
570 "Signature=\"$CHICAGO$\"";
571 static const char *infNT
=
573 "Signature=\"$WINDOWS NT$\"";
577 WCHAR dir
[MAX_PATH
] = { 0 };
578 WCHAR buffer
[MAX_PATH
] = { 0 };
579 DWORD expected
, outsize
;
582 if(!pSetupGetInfFileListW
)
584 win_skip("SetupGetInfFileListW not present\n");
588 /* NULL means %windir%\\inf
589 * get the value as reference
592 SetLastError(0xdeadbeef);
593 ret
= pSetupGetInfFileListW(NULL
, INF_STYLE_WIN4
, NULL
, 0, &expected
);
594 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
596 win_skip("SetupGetInfFileListW not implemented\n");
599 ok(ret
, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
600 ok(expected
> 0, "expected required buffersize to be at least 1\n");
602 /* check if an empty string doesn't behaves like NULL */
604 SetLastError(0xdeadbeef);
605 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
606 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
608 /* create a private directory, the temp directory may contain some
609 * inf files left over from old installations
611 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dirA
))
613 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
616 if (!CreateDirectoryA(dirA
, NULL
))
618 win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA
, GetLastError());
621 if (!SetCurrentDirectoryA(dirA
))
623 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
624 RemoveDirectoryA(dirA
);
628 MultiByteToWideChar(CP_ACP
, 0, dirA
, -1, dir
, MAX_PATH
);
629 /* check a not existing directory
631 ptr
= dir
+ lstrlenW(dir
);
632 MultiByteToWideChar(CP_ACP
, 0, "\\not_existent", -1, ptr
, MAX_PATH
- lstrlenW(dir
));
633 outsize
= 0xffffffff;
634 SetLastError(0xdeadbeef);
635 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
636 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
637 ok(outsize
== 1, "expected required buffersize to be 1, got %d\n", outsize
);
638 ok(ERROR_PATH_NOT_FOUND
== GetLastError(),
639 "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
641 create_inf_file(inffile
, inf
);
642 create_inf_file(inffile2
, inf
);
643 create_inf_file(invalid_inf
, "This content does not match the inf file format");
645 /* pass a filename instead of a directory
648 MultiByteToWideChar(CP_ACP
, 0, invalid_inf
, -1, ptr
+1, MAX_PATH
- lstrlenW(dir
));
649 outsize
= 0xffffffff;
650 SetLastError(0xdeadbeef);
651 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
652 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
653 ok(ERROR_DIRECTORY
== GetLastError(),
654 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
656 /* make the filename look like directory
658 dir
[1 + lstrlenW(dir
)] = 0;
659 dir
[lstrlenW(dir
)] = '\\';
660 SetLastError(0xdeadbeef);
661 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
662 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
663 ok(ERROR_DIRECTORY
== GetLastError(),
664 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
666 /* now check the buffer contents of a valid call
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 create_inf_file(inffile2
, inf2
);
681 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, 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
,inffile2W
) || !lstrcmpW(p
,inffileW
),
687 "unexpected filename %s\n",wine_dbgstr_w(p
));
689 /* signature Windows NT is also inf style win4
691 create_inf_file(inffile2
, infNT
);
692 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
693 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
694 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
695 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
697 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
698 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
699 "unexpected filename %s\n",wine_dbgstr_w(p
));
703 expected
= 2 + strlen(invalid_inf
);
704 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_OLDNT
, buffer
, MAX_PATH
, &outsize
);
705 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
706 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
708 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
709 ok(!lstrcmpW(p
,invalid_infW
), "unexpected filename %s\n",wine_dbgstr_w(p
));
713 expected
= 4 + strlen(inffile
) + strlen(inffile2
) + strlen(invalid_inf
);
714 ret
= pSetupGetInfFileListW(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
716 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
717 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
719 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
720 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
) || !lstrcmpW(p
,invalid_infW
),
721 "unexpected filename %s\n",wine_dbgstr_w(p
));
723 DeleteFileA(inffile
);
724 DeleteFileA(inffile2
);
725 DeleteFileA(invalid_inf
);
726 SetCurrentDirectoryA(CURR_DIR
);
727 RemoveDirectoryA(dirA
);
730 static const char dirid_inf
[] = "[Version]\n"
731 "Signature=\"$Chicago$\"\n"
733 "AddReg=Add.Settings\n"
735 "HKCU,Software\\Wine\\setupapitest,dirid,,%%%i%%\n";
737 static void check_dirid(int dirid
, LPCSTR expected
)
739 char buffer
[sizeof(dirid_inf
)+11];
740 char path
[MAX_PATH
], actual
[MAX_PATH
];
745 sprintf(buffer
, dirid_inf
, dirid
);
747 create_inf_file(inffile
, buffer
);
749 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
750 run_cmdline("DefaultInstall", 128, path
);
752 size
= sizeof(actual
);
754 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest", &key
);
755 if (ret
== ERROR_SUCCESS
)
757 ret
= RegQueryValueExA(key
, "dirid", NULL
, &type
, (BYTE
*)&actual
, &size
);
760 ret
= ERROR_FILE_NOT_FOUND
;
763 ok(ret
== ERROR_SUCCESS
, "Failed getting value for dirid %i, err=%d\n", dirid
, ret
);
764 ok(!strcmp(actual
, expected
), "Expected path for dirid %i was \"%s\", got \"%s\"\n", dirid
, expected
, actual
);
767 ret
= DeleteFileA(inffile
);
768 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
771 /* Test dirid values */
772 static void test_dirid(void)
774 char expected
[MAX_PATH
];
776 check_dirid(DIRID_NULL
, "");
778 GetWindowsDirectoryA(expected
, MAX_PATH
);
779 check_dirid(DIRID_WINDOWS
, expected
);
781 GetSystemDirectoryA(expected
, MAX_PATH
);
782 check_dirid(DIRID_SYSTEM
, expected
);
784 strcat(expected
, "\\unknown");
785 check_dirid(40, expected
);
790 HMODULE hsetupapi
= GetModuleHandleA("setupapi.dll");
791 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
794 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
795 GetTempPathA(MAX_PATH
, temp_path
);
796 SetCurrentDirectoryA(temp_path
);
798 strcpy(CURR_DIR
, temp_path
);
799 len
= strlen(CURR_DIR
);
800 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
801 CURR_DIR
[len
- 1] = 0;
803 pInstallHinfSectionA
= (void *)GetProcAddress(hsetupapi
, "InstallHinfSectionA");
804 pInstallHinfSectionW
= (void *)GetProcAddress(hsetupapi
, "InstallHinfSectionW");
805 pSetupGetInfFileListA
= (void *)GetProcAddress(hsetupapi
, "SetupGetInfFileListA");
806 pSetupGetInfFileListW
= (void *)GetProcAddress(hsetupapi
, "SetupGetInfFileListW");
808 if (pInstallHinfSectionA
)
810 /* Check if pInstallHinfSectionA sets last error or is a stub (as on WinXP) */
811 static const char *minimal_inf
= "[Version]\nSignature=\"$Chicago$\"\n";
812 char cmdline
[MAX_PATH
*2];
814 create_inf_file(inffile
, minimal_inf
);
815 sprintf(cmdline
, "DefaultInstall 128 %s\\%s", CURR_DIR
, inffile
);
816 SetLastError(0xdeadbeef);
817 pInstallHinfSectionA(NULL
, NULL
, cmdline
, 0);
818 if (GetLastError() == 0xdeadbeef)
820 skip("InstallHinfSectionA is broken (stub)\n");
821 pInstallHinfSectionA
= NULL
;
823 ret
= DeleteFileA(inffile
);
824 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
826 if (!pInstallHinfSectionW
&& !pInstallHinfSectionA
)
827 win_skip("InstallHinfSectionA and InstallHinfSectionW are not available\n");
830 /* Set CBT hook to disallow MessageBox creation in current thread */
831 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
836 test_install_svc_from();
837 test_driver_install();
840 UnhookWindowsHookEx(hhook
);
842 /* We have to run this test after the CBT hook is disabled because
843 ProfileItems needs to create a window on Windows XP. */
844 test_profile_items();
850 SetCurrentDirectoryA(prev_path
);