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 * - InstallHinfSectionA on WinXP seems to be a stub - it does not do anything
43 * and simply returns without displaying any error message or setting last
45 * - These functions do not return a value and do not always set last error to
46 * ERROR_SUCCESS when installation still occurs (e.g., unquoted inf file with
47 * spaces, registry keys are written but last error is 6).
48 * - On installation problems, a MessageBox() is displayed and a Beep() is
49 * issued. The MessageBox() is disabled with a CBT hook.
56 static void create_inf_file(LPCSTR filename
, const char *data
)
60 HANDLE handle
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
,
61 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
62 assert(handle
!= INVALID_HANDLE_VALUE
);
63 ret
= WriteFile(handle
, data
, strlen(data
), &res
, NULL
);
68 /* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
70 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
72 return nCode
== HCBT_CREATEWND
? 1: CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
79 static const char *cmdline_inf
= "[Version]\n"
80 "Signature=\"$Chicago$\"\n"
82 "AddReg=Add.Settings\n"
84 "HKCU,Software\\Wine\\setupapitest,,\n";
86 static void run_cmdline(LPCSTR section
, int mode
, LPCSTR path
)
88 CHAR cmdline
[MAX_PATH
* 2];
89 WCHAR cmdlinew
[MAX_PATH
* 2];
91 sprintf(cmdline
, "%s %d %s", section
, mode
, path
);
92 MultiByteToWideChar(CP_ACP
, 0, cmdline
, -1, cmdlinew
, MAX_PATH
*2);
93 InstallHinfSectionW(NULL
, NULL
, cmdlinew
, 0);
96 static void ok_registry(BOOL expectsuccess
)
100 /* Functional tests for success of install and clean up */
101 ret
= RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest");
102 ok((expectsuccess
&& ret
== ERROR_SUCCESS
) ||
103 (!expectsuccess
&& ret
== ERROR_FILE_NOT_FOUND
),
104 "Expected registry key Software\\Wine\\setupapitest to %s, RegDeleteKey returned %d\n",
105 expectsuccess
? "exist" : "not exist",
109 /* Test command line processing */
110 static void test_cmdline(void)
112 static const char infwithspaces
[] = "test file.inf";
116 create_inf_file(inffile
, cmdline_inf
);
117 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
118 run_cmdline("DefaultInstall", 128, path
);
120 ret
= DeleteFileA(inffile
);
121 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
123 /* Test handling of spaces in path, unquoted and quoted */
124 create_inf_file(infwithspaces
, cmdline_inf
);
126 sprintf(path
, "%s\\%s", CURR_DIR
, infwithspaces
);
127 run_cmdline("DefaultInstall", 128, path
);
130 sprintf(path
, "\"%s\\%s\"", CURR_DIR
, infwithspaces
);
131 run_cmdline("DefaultInstall", 128, path
);
134 ret
= DeleteFileA(infwithspaces
);
135 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
138 static const char *cmdline_inf_reg
= "[Version]\n"
139 "Signature=\"$Chicago$\"\n"
141 "DelReg=Del.Settings\n"
143 "HKCU,Software\\Wine\\setupapitest\n";
145 static void test_registry(void)
152 /* First create a registry structure we would like to be deleted */
153 ok(!RegCreateKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
154 "Expected RegCreateKeyA to succeed\n");
156 /* Doublecheck if the registry key is present */
157 ok(!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
158 "Expected registry key to exist\n");
160 create_inf_file(inffile
, cmdline_inf_reg
);
161 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
162 run_cmdline("DefaultInstall", 128, path
);
164 /* Check if the registry key is recursively deleted */
165 res
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest", &key
);
166 ok(res
== ERROR_FILE_NOT_FOUND
, "Didn't expect the registry key to exist\n");
168 if (res
== ERROR_SUCCESS
)
170 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest");
171 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest");
173 ret
= DeleteFileA(inffile
);
174 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
177 static void test_install_from(void)
185 /* First create a registry structure we would like to be deleted */
186 ok(!RegCreateKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
187 "Expected RegCreateKeyA to succeed\n");
189 /* Doublecheck if the registry key is present */
190 ok(!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest", &key
),
191 "Expected registry key to exist\n");
193 create_inf_file(inffile
, cmdline_inf_reg
);
194 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
195 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
196 SetLastError(0xdeadbeef);
197 ret
= SetupInstallFromInfSectionA(NULL
, infhandle
, "DefaultInstall", SPINST_REGISTRY
, key
,
198 "A:\\", 0, NULL
, NULL
, NULL
, NULL
);
199 ok(ret
, "Unexpected failure\n");
200 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
202 /* Check if the registry key is recursively deleted */
203 res
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest", &key
);
204 ok(res
== ERROR_FILE_NOT_FOUND
, "Didn't expect the registry key to exist\n");
206 if (res
== ERROR_SUCCESS
)
208 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest\\setupapitest");
209 RegDeleteKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest");
212 SetupCloseInfFile(infhandle
);
213 DeleteFileA(inffile
);
216 static void test_install_svc_from(void)
222 SC_HANDLE scm_handle
, svc_handle
;
224 /* Basic inf file to satisfy SetupOpenInfFileA */
225 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
226 create_inf_file(inffile
, inf
);
227 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
228 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
230 /* Nothing but the Version section */
231 SetLastError(0xdeadbeef);
232 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
233 ok(!ret
, "Expected failure\n");
234 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
235 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
236 SetupCloseInfFile(infhandle
);
237 DeleteFileA(inffile
);
239 /* Add the section */
240 strcat(inf
, "[Winetest.Services]\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_SECTION_NOT_FOUND
,
247 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
248 SetupCloseInfFile(infhandle
);
249 DeleteFileA(inffile
);
251 /* Add a reference */
252 strcat(inf
, "AddService=Winetest,,Winetest.Service\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 DeleteFileA(inffile
);
263 /* Add the section */
264 strcat(inf
, "[Winetest.Service]\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 DeleteFileA(inffile
);
275 /* Just the ServiceBinary */
276 strcat(inf
, "ServiceBinary=%12%\\winetest.sys\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 DeleteFileA(inffile
);
287 /* Add the ServiceType */
288 strcat(inf
, "ServiceType=1\n");
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 ok(!ret
, "Expected failure\n");
294 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
295 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
296 SetupCloseInfFile(infhandle
);
297 DeleteFileA(inffile
);
299 /* Add the StartType */
300 strcat(inf
, "StartType=4\n");
301 create_inf_file(inffile
, inf
);
302 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
303 SetLastError(0xdeadbeef);
304 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
305 ok(!ret
, "Expected failure\n");
306 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
307 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
308 SetupCloseInfFile(infhandle
);
309 DeleteFileA(inffile
);
311 /* This should be it, the minimal entries to install a service */
312 strcat(inf
, "ErrorControl=1");
313 create_inf_file(inffile
, inf
);
314 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
315 SetLastError(0xdeadbeef);
316 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
317 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
319 skip("Not enough rights to install the service\n");
320 SetupCloseInfFile(infhandle
);
321 DeleteFileA(inffile
);
324 ok(ret
, "Expected success\n");
325 ok(GetLastError() == ERROR_SUCCESS
,
326 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
327 SetupCloseInfFile(infhandle
);
328 DeleteFileA(inffile
);
330 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
332 /* Open the service to see if it's really there */
333 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
334 ok(svc_handle
!= NULL
, "Service was not created\n");
336 SetLastError(0xdeadbeef);
337 ret
= DeleteService(svc_handle
);
338 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
340 CloseServiceHandle(svc_handle
);
341 CloseServiceHandle(scm_handle
);
343 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
344 strcat(inf
, "[XSP.InstallPerVer]\n");
345 strcat(inf
, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
346 create_inf_file(inffile
, inf
);
347 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
348 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
350 SetLastError(0xdeadbeef);
351 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "XSP.InstallPerVer", 0);
352 ok(ret
, "Expected success\n");
353 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
354 SetupCloseInfFile(infhandle
);
355 DeleteFileA(inffile
);
357 /* TODO: Test the Flags */
360 static void test_driver_install(void)
363 SC_HANDLE scm_handle
, svc_handle
;
365 char path
[MAX_PATH
], windir
[MAX_PATH
], driver
[MAX_PATH
];
367 /* Minimal stuff needed */
368 static const char *inf
=
370 "Signature=\"$Chicago$\"\n"
371 "[DestinationDirs]\n"
372 "Winetest.DriverFiles=12\n"
374 "CopyFiles=Winetest.DriverFiles\n"
375 "[DefaultInstall.Services]\n"
376 "AddService=Winetest,,Winetest.Service\n"
377 "[Winetest.Service]\n"
378 "ServiceBinary=%12%\\winetest.sys\n"
382 "[Winetest.DriverFiles]\n"
385 /* Bail out if we don't have enough rights */
386 SetLastError(0xdeadbeef);
387 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
388 if (!scm_handle
&& (GetLastError() == ERROR_ACCESS_DENIED
))
390 skip("Not enough rights to install the service\n");
393 CloseServiceHandle(scm_handle
);
395 /* Place where we expect the driver to be installed */
396 GetWindowsDirectoryA(windir
, MAX_PATH
);
397 lstrcpyA(driver
, windir
);
398 lstrcatA(driver
, "\\system32\\drivers\\winetest.sys");
400 /* Create a dummy driver file */
401 handle
= CreateFileA("winetest.sys", GENERIC_WRITE
, 0, NULL
,
402 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
405 create_inf_file(inffile
, inf
);
406 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
407 run_cmdline("DefaultInstall", 128, path
);
409 /* Driver should have been installed */
410 attrs
= GetFileAttributesA(driver
);
411 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected driver to exist\n");
413 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
415 /* Open the service to see if it's really there */
416 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
417 ok(svc_handle
!= NULL
, "Service was not created\n");
419 SetLastError(0xdeadbeef);
420 ret
= DeleteService(svc_handle
);
421 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
423 CloseServiceHandle(svc_handle
);
424 CloseServiceHandle(scm_handle
);
427 DeleteFileA(inffile
);
428 DeleteFileA("winetest.sys");
432 static void test_profile_items(void)
434 char path
[MAX_PATH
], commonprogs
[MAX_PATH
];
436 static const char *inf
=
438 "Signature=\"$Chicago$\"\n"
440 "ProfileItems=TestItem,TestItem2,TestGroup\n"
443 "CmdLine=11,,notepad.exe\n"
446 "CmdLine=11,,notepad.exe\n"
452 if (S_OK
!= SHGetFolderPathA(NULL
, CSIDL_COMMON_PROGRAMS
, NULL
, SHGFP_TYPE_CURRENT
, commonprogs
))
454 skip("No common program files directory exists\n");
458 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
459 if (!CreateDirectoryA(path
, NULL
) && GetLastError() == ERROR_ACCESS_DENIED
)
461 skip("need admin rights\n");
464 RemoveDirectoryA(path
);
466 create_inf_file(inffile
, inf
);
467 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
468 run_cmdline("DefaultInstall", 128, path
);
470 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
471 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
472 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "directory not created\n");
473 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
474 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "link not created\n");
475 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
476 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "group not created\n");
478 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
480 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
482 snprintf(path
, MAX_PATH
, "%s\\TestItem2.lnk", commonprogs
);
484 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
485 RemoveDirectoryA(path
);
486 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
487 RemoveDirectoryA(path
);
490 DeleteFileA(inffile
);
493 static void test_inffilelistA(void)
495 static const char inffile2
[] = "test2.inf";
496 static const char *inf
=
498 "Signature=\"$Chicago$\"";
500 char buffer
[MAX_PATH
] = { 0 };
501 char dir
[MAX_PATH
], *p
;
502 DWORD expected
, outsize
;
505 /* create a private directory, the temp directory may contain some
506 * inf files left over from old installations
508 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dir
))
510 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
513 if (!CreateDirectoryA(dir
, NULL
))
515 win_skip("CreateDirectoryA(%s) failed with error %d\n", dir
, GetLastError());
518 if (!SetCurrentDirectoryA(dir
))
520 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
521 RemoveDirectoryA(dir
);
525 create_inf_file(inffile
, inf
);
526 create_inf_file(inffile2
, inf
);
530 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
531 ret
= SetupGetInfFileListA(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
533 ok(ret
, "expected SetupGetInfFileListA to succeed!\n");
534 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
536 for(p
= buffer
; lstrlenA(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenA(p
) + 1)
537 ok(!lstrcmpA(p
,inffile2
) || !lstrcmpA(p
,inffile
),
538 "unexpected filename %s\n",p
);
540 DeleteFileA(inffile
);
541 DeleteFileA(inffile2
);
542 SetCurrentDirectoryA(CURR_DIR
);
543 RemoveDirectoryA(dir
);
546 static void test_inffilelist(void)
548 static const char inffile2
[] = "test2.inf";
549 static const WCHAR inffile2W
[] = {'t','e','s','t','2','.','i','n','f',0};
550 static const char invalid_inf
[] = "invalid.inf";
551 static const WCHAR invalid_infW
[] = {'i','n','v','a','l','i','d','.','i','n','f',0};
552 static const char *inf
=
554 "Signature=\"$Chicago$\"";
555 static const char *inf2
=
557 "Signature=\"$CHICAGO$\"";
558 static const char *infNT
=
560 "Signature=\"$WINDOWS NT$\"";
564 WCHAR dir
[MAX_PATH
] = { 0 };
565 WCHAR buffer
[MAX_PATH
] = { 0 };
566 DWORD expected
, outsize
;
569 /* NULL means %windir%\\inf
570 * get the value as reference
573 SetLastError(0xdeadbeef);
574 ret
= SetupGetInfFileListW(NULL
, INF_STYLE_WIN4
, NULL
, 0, &expected
);
575 ok(ret
, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
576 ok(expected
> 0, "expected required buffersize to be at least 1\n");
578 /* check if an empty string doesn't behaves like NULL */
580 SetLastError(0xdeadbeef);
581 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
582 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
584 /* create a private directory, the temp directory may contain some
585 * inf files left over from old installations
587 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dirA
))
589 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
592 if (!CreateDirectoryA(dirA
, NULL
))
594 win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA
, GetLastError());
597 if (!SetCurrentDirectoryA(dirA
))
599 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
600 RemoveDirectoryA(dirA
);
604 MultiByteToWideChar(CP_ACP
, 0, dirA
, -1, dir
, MAX_PATH
);
605 /* check a not existing directory
607 ptr
= dir
+ lstrlenW(dir
);
608 MultiByteToWideChar(CP_ACP
, 0, "\\not_existent", -1, ptr
, MAX_PATH
- lstrlenW(dir
));
609 outsize
= 0xffffffff;
610 SetLastError(0xdeadbeef);
611 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
612 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
613 ok(outsize
== 1, "expected required buffersize to be 1, got %d\n", outsize
);
614 ok(ERROR_PATH_NOT_FOUND
== GetLastError(),
615 "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
617 create_inf_file(inffile
, inf
);
618 create_inf_file(inffile2
, inf
);
619 create_inf_file(invalid_inf
, "This content does not match the inf file format");
621 /* pass a filename instead of a directory
624 MultiByteToWideChar(CP_ACP
, 0, invalid_inf
, -1, ptr
+1, MAX_PATH
- lstrlenW(dir
));
625 outsize
= 0xffffffff;
626 SetLastError(0xdeadbeef);
627 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
628 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
629 ok(ERROR_DIRECTORY
== GetLastError(),
630 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
632 /* make the filename look like directory
634 dir
[1 + lstrlenW(dir
)] = 0;
635 dir
[lstrlenW(dir
)] = '\\';
636 SetLastError(0xdeadbeef);
637 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
638 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
639 ok(ERROR_DIRECTORY
== GetLastError(),
640 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
642 /* now check the buffer contents of a valid call
645 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
646 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
647 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
648 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
650 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
651 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
652 "unexpected filename %s\n",wine_dbgstr_w(p
));
656 create_inf_file(inffile2
, inf2
);
657 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
658 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
659 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
661 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
662 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
663 "unexpected filename %s\n",wine_dbgstr_w(p
));
665 /* signature Windows NT is also inf style win4
667 create_inf_file(inffile2
, infNT
);
668 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
669 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
670 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
671 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
673 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
674 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
675 "unexpected filename %s\n",wine_dbgstr_w(p
));
679 expected
= 2 + strlen(invalid_inf
);
680 ret
= SetupGetInfFileListW(dir
, INF_STYLE_OLDNT
, buffer
, MAX_PATH
, &outsize
);
681 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
682 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
684 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
685 ok(!lstrcmpW(p
,invalid_infW
), "unexpected filename %s\n",wine_dbgstr_w(p
));
689 expected
= 4 + strlen(inffile
) + strlen(inffile2
) + strlen(invalid_inf
);
690 ret
= SetupGetInfFileListW(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
692 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
693 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
695 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
696 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
) || !lstrcmpW(p
,invalid_infW
),
697 "unexpected filename %s\n",wine_dbgstr_w(p
));
699 DeleteFileA(inffile
);
700 DeleteFileA(inffile2
);
701 DeleteFileA(invalid_inf
);
702 SetCurrentDirectoryA(CURR_DIR
);
703 RemoveDirectoryA(dirA
);
706 static const char dirid_inf
[] = "[Version]\n"
707 "Signature=\"$Chicago$\"\n"
709 "AddReg=Add.Settings\n"
711 "HKCU,Software\\Wine\\setupapitest,dirid,,%%%i%%\n";
713 static void check_dirid(int dirid
, LPCSTR expected
)
715 char buffer
[sizeof(dirid_inf
)+11];
716 char path
[MAX_PATH
], actual
[MAX_PATH
];
721 sprintf(buffer
, dirid_inf
, dirid
);
723 create_inf_file(inffile
, buffer
);
725 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
726 run_cmdline("DefaultInstall", 128, path
);
728 size
= sizeof(actual
);
730 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest", &key
);
731 if (ret
== ERROR_SUCCESS
)
733 ret
= RegQueryValueExA(key
, "dirid", NULL
, &type
, (BYTE
*)&actual
, &size
);
736 ret
= ERROR_FILE_NOT_FOUND
;
739 ok(ret
== ERROR_SUCCESS
, "Failed getting value for dirid %i, err=%d\n", dirid
, ret
);
740 ok(!strcmp(actual
, expected
), "Expected path for dirid %i was \"%s\", got \"%s\"\n", dirid
, expected
, actual
);
743 ret
= DeleteFileA(inffile
);
744 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
747 /* Test dirid values */
748 static void test_dirid(void)
750 char expected
[MAX_PATH
];
752 check_dirid(DIRID_NULL
, "");
754 GetWindowsDirectoryA(expected
, MAX_PATH
);
755 check_dirid(DIRID_WINDOWS
, expected
);
757 GetSystemDirectoryA(expected
, MAX_PATH
);
758 check_dirid(DIRID_SYSTEM
, expected
);
760 strcat(expected
, "\\unknown");
761 check_dirid(40, expected
);
766 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
769 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
770 GetTempPathA(MAX_PATH
, temp_path
);
771 SetCurrentDirectoryA(temp_path
);
773 strcpy(CURR_DIR
, temp_path
);
774 len
= strlen(CURR_DIR
);
775 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
776 CURR_DIR
[len
- 1] = 0;
778 /* Set CBT hook to disallow MessageBox creation in current thread */
779 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
785 test_install_svc_from();
786 test_driver_install();
789 UnhookWindowsHookEx(hhook
);
791 /* We have to run this test after the CBT hook is disabled because
792 ProfileItems needs to create a window on Windows XP. */
793 test_profile_items();
798 SetCurrentDirectoryA(prev_path
);