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_svc_from(void)
183 SC_HANDLE scm_handle
, svc_handle
;
185 /* Basic inf file to satisfy SetupOpenInfFileA */
186 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
187 create_inf_file(inffile
, inf
);
188 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
189 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
191 /* Nothing but the Version section */
192 SetLastError(0xdeadbeef);
193 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
194 ok(!ret
, "Expected failure\n");
195 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
196 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
197 SetupCloseInfFile(infhandle
);
198 DeleteFileA(inffile
);
200 /* Add the section */
201 strcat(inf
, "[Winetest.Services]\n");
202 create_inf_file(inffile
, inf
);
203 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
204 SetLastError(0xdeadbeef);
205 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
206 ok(!ret
, "Expected failure\n");
207 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
208 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
209 SetupCloseInfFile(infhandle
);
210 DeleteFileA(inffile
);
212 /* Add a reference */
213 strcat(inf
, "AddService=Winetest,,Winetest.Service\n");
214 create_inf_file(inffile
, inf
);
215 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
216 SetLastError(0xdeadbeef);
217 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
218 ok(!ret
, "Expected failure\n");
219 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
220 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
221 SetupCloseInfFile(infhandle
);
222 DeleteFileA(inffile
);
224 /* Add the section */
225 strcat(inf
, "[Winetest.Service]\n");
226 create_inf_file(inffile
, inf
);
227 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
228 SetLastError(0xdeadbeef);
229 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
230 ok(!ret
, "Expected failure\n");
231 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
232 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
233 SetupCloseInfFile(infhandle
);
234 DeleteFileA(inffile
);
236 /* Just the ServiceBinary */
237 strcat(inf
, "ServiceBinary=%12%\\winetest.sys\n");
238 create_inf_file(inffile
, inf
);
239 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
240 SetLastError(0xdeadbeef);
241 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
242 ok(!ret
, "Expected failure\n");
243 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
244 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
245 SetupCloseInfFile(infhandle
);
246 DeleteFileA(inffile
);
248 /* Add the ServiceType */
249 strcat(inf
, "ServiceType=1\n");
250 create_inf_file(inffile
, inf
);
251 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
252 SetLastError(0xdeadbeef);
253 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
254 ok(!ret
, "Expected failure\n");
255 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
256 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
257 SetupCloseInfFile(infhandle
);
258 DeleteFileA(inffile
);
260 /* Add the StartType */
261 strcat(inf
, "StartType=4\n");
262 create_inf_file(inffile
, inf
);
263 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
264 SetLastError(0xdeadbeef);
265 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
266 ok(!ret
, "Expected failure\n");
267 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
268 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
269 SetupCloseInfFile(infhandle
);
270 DeleteFileA(inffile
);
272 /* This should be it, the minimal entries to install a service */
273 strcat(inf
, "ErrorControl=1");
274 create_inf_file(inffile
, inf
);
275 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
276 SetLastError(0xdeadbeef);
277 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "Winetest.Services", 0);
278 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
280 skip("Not enough rights to install the service\n");
281 SetupCloseInfFile(infhandle
);
282 DeleteFileA(inffile
);
285 ok(ret
, "Expected success\n");
286 ok(GetLastError() == ERROR_SUCCESS
,
287 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
288 SetupCloseInfFile(infhandle
);
289 DeleteFileA(inffile
);
291 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
293 /* Open the service to see if it's really there */
294 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
295 ok(svc_handle
!= NULL
, "Service was not created\n");
297 SetLastError(0xdeadbeef);
298 ret
= DeleteService(svc_handle
);
299 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
301 CloseServiceHandle(svc_handle
);
302 CloseServiceHandle(scm_handle
);
304 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
305 strcat(inf
, "[XSP.InstallPerVer]\n");
306 strcat(inf
, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
307 create_inf_file(inffile
, inf
);
308 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
309 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
311 SetLastError(0xdeadbeef);
312 ret
= SetupInstallServicesFromInfSectionA(infhandle
, "XSP.InstallPerVer", 0);
313 ok(ret
, "Expected success\n");
314 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
315 SetupCloseInfFile(infhandle
);
316 DeleteFileA(inffile
);
318 /* TODO: Test the Flags */
321 static void test_driver_install(void)
324 SC_HANDLE scm_handle
, svc_handle
;
326 char path
[MAX_PATH
], windir
[MAX_PATH
], driver
[MAX_PATH
];
328 /* Minimal stuff needed */
329 static const char *inf
=
331 "Signature=\"$Chicago$\"\n"
332 "[DestinationDirs]\n"
333 "Winetest.DriverFiles=12\n"
335 "CopyFiles=Winetest.DriverFiles\n"
336 "[DefaultInstall.Services]\n"
337 "AddService=Winetest,,Winetest.Service\n"
338 "[Winetest.Service]\n"
339 "ServiceBinary=%12%\\winetest.sys\n"
343 "[Winetest.DriverFiles]\n"
346 /* Bail out if we don't have enough rights */
347 SetLastError(0xdeadbeef);
348 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
349 if (!scm_handle
&& (GetLastError() == ERROR_ACCESS_DENIED
))
351 skip("Not enough rights to install the service\n");
354 CloseServiceHandle(scm_handle
);
356 /* Place where we expect the driver to be installed */
357 GetWindowsDirectoryA(windir
, MAX_PATH
);
358 lstrcpyA(driver
, windir
);
359 lstrcatA(driver
, "\\system32\\drivers\\winetest.sys");
361 /* Create a dummy driver file */
362 handle
= CreateFileA("winetest.sys", GENERIC_WRITE
, 0, NULL
,
363 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
366 create_inf_file(inffile
, inf
);
367 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
368 run_cmdline("DefaultInstall", 128, path
);
370 /* Driver should have been installed */
371 attrs
= GetFileAttributesA(driver
);
372 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Expected driver to exist\n");
374 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
376 /* Open the service to see if it's really there */
377 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
378 ok(svc_handle
!= NULL
, "Service was not created\n");
380 SetLastError(0xdeadbeef);
381 ret
= DeleteService(svc_handle
);
382 ok(ret
, "Service could not be deleted : %d\n", GetLastError());
384 CloseServiceHandle(svc_handle
);
385 CloseServiceHandle(scm_handle
);
388 DeleteFileA(inffile
);
389 DeleteFileA("winetest.sys");
393 static void test_profile_items(void)
395 char path
[MAX_PATH
], commonprogs
[MAX_PATH
];
397 static const char *inf
=
399 "Signature=\"$Chicago$\"\n"
401 "ProfileItems=TestItem,TestItem2,TestGroup\n"
404 "CmdLine=11,,notepad.exe\n"
407 "CmdLine=11,,notepad.exe\n"
413 if (S_OK
!= SHGetFolderPathA(NULL
, CSIDL_COMMON_PROGRAMS
, NULL
, SHGFP_TYPE_CURRENT
, commonprogs
))
415 skip("No common program files directory exists\n");
419 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
420 if (!CreateDirectoryA(path
, NULL
) && GetLastError() == ERROR_ACCESS_DENIED
)
422 skip("need admin rights\n");
425 RemoveDirectoryA(path
);
427 create_inf_file(inffile
, inf
);
428 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
429 run_cmdline("DefaultInstall", 128, path
);
431 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
432 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
433 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "directory not created\n");
434 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
435 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "link not created\n");
436 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
437 ok(INVALID_FILE_ATTRIBUTES
!= GetFileAttributesA(path
), "group not created\n");
439 snprintf(path
, MAX_PATH
, "%s\\TestItem.lnk", commonprogs
);
441 snprintf(path
, MAX_PATH
, "%s\\TestDir\\TestItem2.lnk", commonprogs
);
443 snprintf(path
, MAX_PATH
, "%s\\TestItem2.lnk", commonprogs
);
445 snprintf(path
, MAX_PATH
, "%s\\TestDir", commonprogs
);
446 RemoveDirectoryA(path
);
447 snprintf(path
, MAX_PATH
, "%s\\TestGroup", commonprogs
);
448 RemoveDirectoryA(path
);
451 DeleteFileA(inffile
);
454 static void test_inffilelistA(void)
456 static const char inffile2
[] = "test2.inf";
457 static const char *inf
=
459 "Signature=\"$Chicago$\"";
461 char buffer
[MAX_PATH
] = { 0 };
462 char dir
[MAX_PATH
], *p
;
463 DWORD expected
, outsize
;
466 /* create a private directory, the temp directory may contain some
467 * inf files left over from old installations
469 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dir
))
471 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
474 if (!CreateDirectoryA(dir
, NULL
))
476 win_skip("CreateDirectoryA(%s) failed with error %d\n", dir
, GetLastError());
479 if (!SetCurrentDirectoryA(dir
))
481 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
482 RemoveDirectoryA(dir
);
486 create_inf_file(inffile
, inf
);
487 create_inf_file(inffile2
, inf
);
491 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
492 ret
= SetupGetInfFileListA(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
494 ok(ret
, "expected SetupGetInfFileListA to succeed!\n");
495 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
497 for(p
= buffer
; lstrlenA(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenA(p
) + 1)
498 ok(!lstrcmpA(p
,inffile2
) || !lstrcmpA(p
,inffile
),
499 "unexpected filename %s\n",p
);
501 DeleteFileA(inffile
);
502 DeleteFileA(inffile2
);
503 SetCurrentDirectoryA(CURR_DIR
);
504 RemoveDirectoryA(dir
);
507 static void test_inffilelist(void)
509 static const char inffile2
[] = "test2.inf";
510 static const WCHAR inffile2W
[] = {'t','e','s','t','2','.','i','n','f',0};
511 static const char invalid_inf
[] = "invalid.inf";
512 static const WCHAR invalid_infW
[] = {'i','n','v','a','l','i','d','.','i','n','f',0};
513 static const char *inf
=
515 "Signature=\"$Chicago$\"";
516 static const char *inf2
=
518 "Signature=\"$CHICAGO$\"";
519 static const char *infNT
=
521 "Signature=\"$WINDOWS NT$\"";
525 WCHAR dir
[MAX_PATH
] = { 0 };
526 WCHAR buffer
[MAX_PATH
] = { 0 };
527 DWORD expected
, outsize
;
530 /* NULL means %windir%\\inf
531 * get the value as reference
534 SetLastError(0xdeadbeef);
535 ret
= SetupGetInfFileListW(NULL
, INF_STYLE_WIN4
, NULL
, 0, &expected
);
536 ok(ret
, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
537 ok(expected
> 0, "expected required buffersize to be at least 1\n");
539 /* check if an empty string doesn't behaves like NULL */
541 SetLastError(0xdeadbeef);
542 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
543 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
545 /* create a private directory, the temp directory may contain some
546 * inf files left over from old installations
548 if (!GetTempFileNameA(CURR_DIR
, "inftest", 1, dirA
))
550 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
553 if (!CreateDirectoryA(dirA
, NULL
))
555 win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA
, GetLastError());
558 if (!SetCurrentDirectoryA(dirA
))
560 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
561 RemoveDirectoryA(dirA
);
565 MultiByteToWideChar(CP_ACP
, 0, dirA
, -1, dir
, MAX_PATH
);
566 /* check a not existing directory
568 ptr
= dir
+ lstrlenW(dir
);
569 MultiByteToWideChar(CP_ACP
, 0, "\\not_existent", -1, ptr
, MAX_PATH
- lstrlenW(dir
));
570 outsize
= 0xffffffff;
571 SetLastError(0xdeadbeef);
572 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
573 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
574 ok(outsize
== 1, "expected required buffersize to be 1, got %d\n", outsize
);
575 ok(ERROR_PATH_NOT_FOUND
== GetLastError(),
576 "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
578 create_inf_file(inffile
, inf
);
579 create_inf_file(inffile2
, inf
);
580 create_inf_file(invalid_inf
, "This content does not match the inf file format");
582 /* pass a filename instead of a directory
585 MultiByteToWideChar(CP_ACP
, 0, invalid_inf
, -1, ptr
+1, MAX_PATH
- lstrlenW(dir
));
586 outsize
= 0xffffffff;
587 SetLastError(0xdeadbeef);
588 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
589 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
590 ok(ERROR_DIRECTORY
== GetLastError(),
591 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
593 /* make the filename look like directory
595 dir
[1 + lstrlenW(dir
)] = 0;
596 dir
[lstrlenW(dir
)] = '\\';
597 SetLastError(0xdeadbeef);
598 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, NULL
, 0, &outsize
);
599 ok(!ret
, "expected SetupGetInfFileListW to fail!\n");
600 ok(ERROR_DIRECTORY
== GetLastError(),
601 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
603 /* now check the buffer contents of a valid call
606 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
607 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
608 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
609 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
611 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
612 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
613 "unexpected filename %s\n",wine_dbgstr_w(p
));
617 create_inf_file(inffile2
, inf2
);
618 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
619 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
620 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
622 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
623 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
624 "unexpected filename %s\n",wine_dbgstr_w(p
));
626 /* signature Windows NT is also inf style win4
628 create_inf_file(inffile2
, infNT
);
629 expected
= 3 + strlen(inffile
) + strlen(inffile2
);
630 ret
= SetupGetInfFileListW(dir
, INF_STYLE_WIN4
, buffer
, MAX_PATH
, &outsize
);
631 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
632 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
634 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
635 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
),
636 "unexpected filename %s\n",wine_dbgstr_w(p
));
640 expected
= 2 + strlen(invalid_inf
);
641 ret
= SetupGetInfFileListW(dir
, INF_STYLE_OLDNT
, buffer
, MAX_PATH
, &outsize
);
642 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
643 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
645 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
646 ok(!lstrcmpW(p
,invalid_infW
), "unexpected filename %s\n",wine_dbgstr_w(p
));
650 expected
= 4 + strlen(inffile
) + strlen(inffile2
) + strlen(invalid_inf
);
651 ret
= SetupGetInfFileListW(dir
, INF_STYLE_OLDNT
| INF_STYLE_WIN4
, buffer
,
653 ok(ret
, "expected SetupGetInfFileListW to succeed!\n");
654 ok(expected
== outsize
, "expected required buffersize to be %d, got %d\n",
656 for(p
= buffer
; lstrlenW(p
) && (outsize
> (p
- buffer
)); p
+=lstrlenW(p
) + 1)
657 ok(!lstrcmpW(p
,inffile2W
) || !lstrcmpW(p
,inffileW
) || !lstrcmpW(p
,invalid_infW
),
658 "unexpected filename %s\n",wine_dbgstr_w(p
));
660 DeleteFileA(inffile
);
661 DeleteFileA(inffile2
);
662 DeleteFileA(invalid_inf
);
663 SetCurrentDirectoryA(CURR_DIR
);
664 RemoveDirectoryA(dirA
);
667 static const char dirid_inf
[] = "[Version]\n"
668 "Signature=\"$Chicago$\"\n"
670 "AddReg=Add.Settings\n"
672 "HKCU,Software\\Wine\\setupapitest,dirid,,%%%i%%\n";
674 static void check_dirid(int dirid
, LPCSTR expected
)
676 char buffer
[sizeof(dirid_inf
)+11];
677 char path
[MAX_PATH
], actual
[MAX_PATH
];
682 sprintf(buffer
, dirid_inf
, dirid
);
684 create_inf_file(inffile
, buffer
);
686 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
687 run_cmdline("DefaultInstall", 128, path
);
689 size
= sizeof(actual
);
691 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\setupapitest", &key
);
692 if (ret
== ERROR_SUCCESS
)
694 ret
= RegQueryValueExA(key
, "dirid", NULL
, &type
, (BYTE
*)&actual
, &size
);
697 ret
= ERROR_FILE_NOT_FOUND
;
700 ok(ret
== ERROR_SUCCESS
, "Failed getting value for dirid %i, err=%d\n", dirid
, ret
);
701 ok(!strcmp(actual
, expected
), "Expected path for dirid %i was \"%s\", got \"%s\"\n", dirid
, expected
, actual
);
704 ret
= DeleteFileA(inffile
);
705 ok(ret
, "Expected source inf to exist, last error was %d\n", GetLastError());
708 /* Test dirid values */
709 static void test_dirid(void)
711 char expected
[MAX_PATH
];
713 check_dirid(DIRID_NULL
, "");
715 GetWindowsDirectoryA(expected
, MAX_PATH
);
716 check_dirid(DIRID_WINDOWS
, expected
);
718 GetSystemDirectoryA(expected
, MAX_PATH
);
719 check_dirid(DIRID_SYSTEM
, expected
);
721 strcat(expected
, "\\unknown");
722 check_dirid(40, expected
);
727 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
730 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
731 GetTempPathA(MAX_PATH
, temp_path
);
732 SetCurrentDirectoryA(temp_path
);
734 strcpy(CURR_DIR
, temp_path
);
735 len
= strlen(CURR_DIR
);
736 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
737 CURR_DIR
[len
- 1] = 0;
739 /* Set CBT hook to disallow MessageBox creation in current thread */
740 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
745 test_install_svc_from();
746 test_driver_install();
749 UnhookWindowsHookEx(hhook
);
751 /* We have to run this test after the CBT hook is disabled because
752 ProfileItems needs to create a window on Windows XP. */
753 test_profile_items();
758 SetCurrentDirectoryA(prev_path
);