push 38a8c0aff9170390b5a3ded41e7cf5b02f3a73d8
[wine/hacks.git] / dlls / setupapi / tests / install.c
blob9aed163f2ba83ced9cae3e6617f781296aee64e9
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <assert.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "winsvc.h"
32 #include "setupapi.h"
33 #include "shlobj.h"
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
51 * CBT hook.
54 static void (WINAPI *pInstallHinfSectionA)(HWND, HINSTANCE, LPCSTR, INT);
55 static void (WINAPI *pInstallHinfSectionW)(HWND, HINSTANCE, LPCWSTR, INT);
56 static BOOL (WINAPI *pSetupGetInfFileListW)(PCWSTR, DWORD, PWSTR, DWORD, PDWORD);
59 * Helpers
62 static void create_inf_file(LPCSTR filename, const char *data)
64 DWORD res;
65 HANDLE handle = CreateFile(filename, GENERIC_WRITE, 0, NULL,
66 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
67 assert(handle != INVALID_HANDLE_VALUE);
68 assert(WriteFile(handle, data, strlen(data), &res, NULL));
69 CloseHandle(handle);
72 /* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
73 static HHOOK hhook;
74 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
76 return nCode == HCBT_CREATEWND ? 1: CallNextHookEx(hhook, nCode, wParam, lParam);
80 * Tests
83 static const char *cmdline_inf = "[Version]\n"
84 "Signature=\"$Chicago$\"\n"
85 "[DefaultInstall]\n"
86 "AddReg=Add.Settings\n"
87 "[Add.Settings]\n"
88 "HKCU,Software\\Wine\\setupapitest,,\n";
90 static void run_cmdline(LPCSTR section, int mode, LPCSTR path)
92 CHAR cmdline[MAX_PATH * 2];
94 sprintf(cmdline, "%s %d %s", section, mode, path);
95 if (pInstallHinfSectionA) pInstallHinfSectionA(NULL, NULL, cmdline, 0);
96 else
98 WCHAR cmdlinew[MAX_PATH * 2];
99 MultiByteToWideChar(CP_ACP, 0, cmdline, -1, cmdlinew, MAX_PATH*2);
100 pInstallHinfSectionW(NULL, NULL, cmdlinew, 0);
104 static void ok_registry(BOOL expectsuccess)
106 LONG ret;
108 /* Functional tests for success of install and clean up */
109 ret = RegDeleteKey(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
110 ok((expectsuccess && ret == ERROR_SUCCESS) ||
111 (!expectsuccess && ret == ERROR_FILE_NOT_FOUND),
112 "Expected registry key Software\\Wine\\setupapitest to %s, RegDeleteKey returned %d\n",
113 expectsuccess ? "exist" : "not exist",
114 ret);
117 /* Test command line processing */
118 static void test_cmdline(void)
120 static const char infwithspaces[] = "test file.inf";
121 char path[MAX_PATH];
123 create_inf_file(inffile, cmdline_inf);
124 sprintf(path, "%s\\%s", CURR_DIR, inffile);
125 run_cmdline("DefaultInstall", 128, path);
126 ok_registry(TRUE);
127 ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
129 /* Test handling of spaces in path, unquoted and quoted */
130 create_inf_file(infwithspaces, cmdline_inf);
132 sprintf(path, "%s\\%s", CURR_DIR, infwithspaces);
133 run_cmdline("DefaultInstall", 128, path);
134 ok_registry(TRUE);
136 sprintf(path, "\"%s\\%s\"", CURR_DIR, infwithspaces);
137 run_cmdline("DefaultInstall", 128, path);
138 ok_registry(FALSE);
140 ok(DeleteFile(infwithspaces), "Expected source inf to exist, last error was %d\n", GetLastError());
143 static const char *cmdline_inf_reg = "[Version]\n"
144 "Signature=\"$Chicago$\"\n"
145 "[DefaultInstall]\n"
146 "DelReg=Del.Settings\n"
147 "[Del.Settings]\n"
148 "HKCU,Software\\Wine\\setupapitest\n";
150 static void test_registry(void)
152 HKEY key;
153 LONG res;
154 char path[MAX_PATH];
156 /* First create a registry structure we would like to be deleted */
157 ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
158 "Expected RegCreateKeyA to succeed\n");
160 /* Doublecheck if the registry key is present */
161 ok(!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
162 "Expected registry key to exist\n");
164 create_inf_file(inffile, cmdline_inf_reg);
165 sprintf(path, "%s\\%s", CURR_DIR, inffile);
166 run_cmdline("DefaultInstall", 128, path);
168 /* Check if the registry key is recursively deleted */
169 res = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key);
170 todo_wine
171 ok(res == ERROR_FILE_NOT_FOUND, "Didn't expect the registry key to exist\n");
172 /* Just in case */
173 if (res == ERROR_SUCCESS)
175 RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest");
176 RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
178 ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
181 static void test_install_svc_from(void)
183 char inf[2048];
184 char path[MAX_PATH];
185 HINF infhandle;
186 BOOL ret;
187 SC_HANDLE scm_handle, svc_handle;
189 /* Bail out if we are on win98 */
190 SetLastError(0xdeadbeef);
191 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
193 if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
195 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
196 return;
198 CloseServiceHandle(scm_handle);
200 /* Basic inf file to satisfy SetupOpenInfFileA */
201 strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
202 create_inf_file(inffile, inf);
203 sprintf(path, "%s\\%s", CURR_DIR, inffile);
204 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
206 /* Nothing but the Version section */
207 SetLastError(0xdeadbeef);
208 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
209 ok(!ret, "Expected failure\n");
210 ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
211 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
212 SetupCloseInfFile(infhandle);
213 DeleteFile(inffile);
215 /* Add the section */
216 strcat(inf, "[Winetest.Services]\n");
217 create_inf_file(inffile, inf);
218 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
219 SetLastError(0xdeadbeef);
220 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
221 ok(!ret, "Expected failure\n");
222 ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
223 "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
224 SetupCloseInfFile(infhandle);
225 DeleteFile(inffile);
227 /* Add a reference */
228 strcat(inf, "AddService=Winetest,,Winetest.Service\n");
229 create_inf_file(inffile, inf);
230 infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
231 SetLastError(0xdeadbeef);
232 ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
233 ok(!ret, "Expected failure\n");
234 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
235 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
236 SetupCloseInfFile(infhandle);
237 DeleteFile(inffile);
239 /* Add the section */
240 strcat(inf, "[Winetest.Service]\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_BAD_SERVICE_INSTALLSECT,
247 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
248 SetupCloseInfFile(infhandle);
249 DeleteFile(inffile);
251 /* Just the ServiceBinary */
252 strcat(inf, "ServiceBinary=%12%\\winetest.sys\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 DeleteFile(inffile);
263 /* Add the ServiceType */
264 strcat(inf, "ServiceType=1\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 DeleteFile(inffile);
275 /* Add the StartType */
276 strcat(inf, "StartType=4\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 DeleteFile(inffile);
287 /* This should be it, the minimal entries to install a service */
288 strcat(inf, "ErrorControl=1");
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 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
295 skip("Not enough rights to install the service\n");
296 SetupCloseInfFile(infhandle);
297 DeleteFile(inffile);
298 return;
300 ok(ret, "Expected success\n");
301 ok(GetLastError() == ERROR_SUCCESS,
302 "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
303 SetupCloseInfFile(infhandle);
304 DeleteFile(inffile);
306 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
308 /* Open the service to see if it's really there */
309 svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
310 ok(svc_handle != NULL, "Service was not created\n");
312 SetLastError(0xdeadbeef);
313 ret = DeleteService(svc_handle);
314 ok(ret, "Service could not be deleted : %d\n", GetLastError());
316 CloseServiceHandle(svc_handle);
317 CloseServiceHandle(scm_handle);
319 /* TODO: Test the Flags */
322 static void test_driver_install(void)
324 HANDLE handle;
325 SC_HANDLE scm_handle, svc_handle;
326 BOOL ret;
327 char path[MAX_PATH], windir[MAX_PATH], driver[MAX_PATH];
328 DWORD attrs;
329 /* Minimal stuff needed */
330 static const char *inf =
331 "[Version]\n"
332 "Signature=\"$Chicago$\"\n"
333 "[DestinationDirs]\n"
334 "Winetest.DriverFiles=12\n"
335 "[DefaultInstall]\n"
336 "CopyFiles=Winetest.DriverFiles\n"
337 "[DefaultInstall.Services]\n"
338 "AddService=Winetest,,Winetest.Service\n"
339 "[Winetest.Service]\n"
340 "ServiceBinary=%12%\\winetest.sys\n"
341 "ServiceType=1\n"
342 "StartType=4\n"
343 "ErrorControl=1\n"
344 "[Winetest.DriverFiles]\n"
345 "winetest.sys";
347 /* Bail out if we are on win98 */
348 SetLastError(0xdeadbeef);
349 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
351 if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
353 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
354 return;
356 else if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
358 skip("Not enough rights to install the service\n");
359 return;
361 CloseServiceHandle(scm_handle);
363 /* Place where we expect the driver to be installed */
364 GetWindowsDirectoryA(windir, MAX_PATH);
365 lstrcpyA(driver, windir);
366 lstrcatA(driver, "\\system32\\drivers\\winetest.sys");
368 /* Create a dummy driver file */
369 handle = CreateFileA("winetest.sys", GENERIC_WRITE, 0, NULL,
370 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
371 CloseHandle(handle);
373 create_inf_file(inffile, inf);
374 sprintf(path, "%s\\%s", CURR_DIR, inffile);
375 run_cmdline("DefaultInstall", 128, path);
377 /* Driver should have been installed */
378 attrs = GetFileAttributes(driver);
379 ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected driver to exist\n");
381 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
383 /* Open the service to see if it's really there */
384 svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
385 ok(svc_handle != NULL, "Service was not created\n");
387 SetLastError(0xdeadbeef);
388 ret = DeleteService(svc_handle);
389 ok(ret, "Service could not be deleted : %d\n", GetLastError());
391 CloseServiceHandle(svc_handle);
392 CloseServiceHandle(scm_handle);
394 /* File cleanup */
395 DeleteFile(inffile);
396 DeleteFile("winetest.sys");
397 DeleteFile(driver);
400 static void test_profile_items(void)
402 char path[MAX_PATH], commonprogs[MAX_PATH];
403 HMODULE hShell32;
404 BOOL (WINAPI *pSHGetFolderPathA)(HWND hwnd, int nFolder, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
406 static const char *inf =
407 "[Version]\n"
408 "Signature=\"$Chicago$\"\n"
409 "[DefaultInstall]\n"
410 "ProfileItems=TestItem,TestItem2,TestGroup\n"
411 "[TestItem]\n"
412 "Name=TestItem\n"
413 "CmdLine=11,,notepad.exe\n"
414 "[TestItem2]\n"
415 "Name=TestItem2\n"
416 "CmdLine=11,,notepad.exe\n"
417 "SubDir=TestDir\n"
418 "[TestGroup]\n"
419 "Name=TestGroup,4\n"
422 hShell32 = LoadLibraryA("shell32");
423 pSHGetFolderPathA = (void*)GetProcAddress(hShell32, "SHGetFolderPathA");
424 if (!pSHGetFolderPathA)
426 win_skip("SHGetFolderPathA is not available\n");
427 goto cleanup;
430 if (S_OK != pSHGetFolderPathA(NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, commonprogs))
432 skip("No common program files directory exists\n");
433 goto cleanup;
436 create_inf_file(inffile, inf);
437 sprintf(path, "%s\\%s", CURR_DIR, inffile);
438 run_cmdline("DefaultInstall", 128, path);
440 snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
441 if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(path))
443 win_skip("ProfileItems not implemented on this system\n");
445 else
447 snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
448 ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "directory not created\n");
449 snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
450 ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "link not created\n");
451 snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
452 ok(INVALID_FILE_ATTRIBUTES != GetFileAttributes(path), "group not created\n");
455 snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
456 DeleteFile(path);
457 snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
458 DeleteFile(path);
459 snprintf(path, MAX_PATH, "%s\\TestItem2.lnk", commonprogs);
460 DeleteFile(path);
461 snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
462 RemoveDirectory(path);
463 snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
464 RemoveDirectory(path);
466 cleanup:
467 if (hShell32) FreeLibrary(hShell32);
468 DeleteFile(inffile);
471 static void test_inffilelist(void)
473 static const char inffile2[] = "test2.inf";
474 static const WCHAR inffile2W[] = {'t','e','s','t','2','.','i','n','f',0};
475 static const char invalid_inf[] = "invalid.inf";
476 static const WCHAR invalid_infW[] = {'i','n','v','a','l','i','d','.','i','n','f',0};
477 static const char *inf =
478 "[Version]\n"
479 "Signature=\"$Chicago$\"";
480 static const char *inf2 =
481 "[Version]\n"
482 "Signature=\"$CHICAGO$\"";
483 static const char *infNT =
484 "[Version]\n"
485 "Signature=\"$WINDOWS NT$\"";
487 WCHAR *p, *ptr;
488 char dirA[MAX_PATH];
489 WCHAR dir[MAX_PATH] = { 0 };
490 WCHAR buffer[MAX_PATH] = { 0 };
491 DWORD expected, outsize;
492 BOOL ret;
494 if(!pSetupGetInfFileListW)
496 win_skip("SetupGetInfFileListW not present\n");
497 return;
500 /* NULL means %windir%\\inf
501 * get the value as reference
503 expected = 0;
504 SetLastError(0xdeadbeef);
505 ret = pSetupGetInfFileListW(NULL, INF_STYLE_WIN4, NULL, 0, &expected);
506 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
508 win_skip("SetupGetInfFileListW not implemented\n");
509 return;
511 ok(ret, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
512 ok(expected > 0, "expected required buffersize to be at least 1\n");
514 /* check if an empty string doesn't behaves like NULL */
515 outsize = 0;
516 SetLastError(0xdeadbeef);
517 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
518 todo_wine
519 ok(!ret, "expected SetupGetInfFileListW to fail!\n");
521 /* create a private directory, the temp directory may contain some
522 * inf files left over from old installations
524 if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dirA))
526 win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
527 return;
529 if (!CreateDirectoryA(dirA, NULL ))
531 win_skip("CreateDirectoryA failed with error %d\n", GetLastError());
532 return;
534 if (!SetCurrentDirectoryA(dirA))
536 win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
537 RemoveDirectoryA(dirA);
538 return;
541 MultiByteToWideChar(CP_ACP, 0, dirA, -1, dir, MAX_PATH);
542 /* check a not existing directory
544 ptr = dir + lstrlenW(dir);
545 MultiByteToWideChar(CP_ACP, 0, "\\not_existent", -1, ptr, MAX_PATH - lstrlenW(dir));
546 outsize = 0xffffffff;
547 SetLastError(0xdeadbeef);
548 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
549 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
550 ok(outsize == 1, "expected required buffersize to be 1, got %d\n", outsize);
551 todo_wine
552 ok(ERROR_PATH_NOT_FOUND == GetLastError(),
553 "expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
555 create_inf_file(inffile, inf);
556 create_inf_file(inffile2, inf);
557 create_inf_file(invalid_inf, "This content does not match the inf file format");
559 /* pass a filename instead of a directory
561 *ptr = '\\';
562 MultiByteToWideChar(CP_ACP, 0, invalid_inf, -1, ptr+1, MAX_PATH - lstrlenW(dir));
563 outsize = 0xffffffff;
564 SetLastError(0xdeadbeef);
565 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
566 todo_wine
567 ok(!ret, "expected SetupGetInfFileListW to fail!\n");
568 todo_wine
569 ok(ERROR_DIRECTORY == GetLastError(),
570 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
572 /* make the filename look like directory
574 dir[1 + lstrlenW(dir)] = 0;
575 dir[lstrlenW(dir)] = '\\';
576 SetLastError(0xdeadbeef);
577 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
578 todo_wine
579 ok(!ret, "expected SetupGetInfFileListW to fail!\n");
580 todo_wine
581 ok(ERROR_DIRECTORY == GetLastError(),
582 "expected error ERROR_DIRECTORY, got %d\n", GetLastError());
584 /* now check the buffer content of a vaild call
586 *ptr = 0;
587 expected = 3 + strlen(inffile) + strlen(inffile2);
588 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
589 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
590 todo_wine
591 ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
592 expected, outsize);
593 for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
594 ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
595 "unexpected filename %s\n",wine_dbgstr_w(p));
597 /* upper case value
599 create_inf_file(inffile2, inf2);
600 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
601 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
602 todo_wine
603 ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
604 expected, outsize);
605 for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
606 ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
607 "unexpected filename %s\n",wine_dbgstr_w(p));
609 /* signature Windows NT is also inf style win4
611 create_inf_file(inffile2, infNT);
612 expected = 3 + strlen(inffile) + strlen(inffile2);
613 ret = pSetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
614 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
615 todo_wine
616 ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
617 expected, outsize);
618 for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
619 ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
620 "unexpected filename %s\n",wine_dbgstr_w(p));
622 /* old style
624 expected = 2 + strlen(invalid_inf);
625 ret = pSetupGetInfFileListW(dir, INF_STYLE_OLDNT, buffer, MAX_PATH, &outsize);
626 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
627 todo_wine
628 ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
629 expected, outsize);
630 for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
631 ok(!lstrcmpW(p,invalid_infW), "unexpected filename %s\n",wine_dbgstr_w(p));
633 /* mixed style
635 expected = 4 + strlen(inffile) + strlen(inffile2) + strlen(invalid_inf);
636 ret = pSetupGetInfFileListW(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer,
637 MAX_PATH, &outsize);
638 ok(ret, "expected SetupGetInfFileListW to succeed!\n");
639 todo_wine
640 ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
641 expected, outsize);
642 for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
643 ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW) || !lstrcmpW(p,invalid_infW),
644 "unexpected filename %s\n",wine_dbgstr_w(p));
646 DeleteFile(inffile);
647 DeleteFile(inffile2);
648 DeleteFile(invalid_inf);
649 SetCurrentDirectoryA(CURR_DIR);
650 RemoveDirectoryA(dirA);
653 START_TEST(install)
655 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
656 char temp_path[MAX_PATH], prev_path[MAX_PATH];
657 DWORD len;
659 GetCurrentDirectory(MAX_PATH, prev_path);
660 GetTempPath(MAX_PATH, temp_path);
661 SetCurrentDirectory(temp_path);
663 strcpy(CURR_DIR, temp_path);
664 len = strlen(CURR_DIR);
665 if(len && (CURR_DIR[len - 1] == '\\'))
666 CURR_DIR[len - 1] = 0;
668 pInstallHinfSectionA = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionA");
669 pInstallHinfSectionW = (void *)GetProcAddress(hsetupapi, "InstallHinfSectionW");
670 pSetupGetInfFileListW = (void *)GetProcAddress(hsetupapi, "SetupGetInfFileListW");
672 if (pInstallHinfSectionA)
674 /* Check if pInstallHinfSectionA sets last error or is a stub (as on WinXP) */
675 static const char *minimal_inf = "[Version]\nSignature=\"$Chicago$\"\n";
676 char cmdline[MAX_PATH*2];
677 create_inf_file(inffile, minimal_inf);
678 sprintf(cmdline, "DefaultInstall 128 %s\\%s", CURR_DIR, inffile);
679 SetLastError(0xdeadbeef);
680 pInstallHinfSectionA(NULL, NULL, cmdline, 0);
681 if (GetLastError() == 0xdeadbeef)
683 skip("InstallHinfSectionA is broken (stub)\n");
684 pInstallHinfSectionA = NULL;
686 ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
688 if (!pInstallHinfSectionW && !pInstallHinfSectionA)
689 win_skip("InstallHinfSectionA and InstallHinfSectionW are not available\n");
690 else
692 /* Set CBT hook to disallow MessageBox creation in current thread */
693 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
694 assert(hhook != 0);
696 test_cmdline();
697 test_registry();
698 test_install_svc_from();
699 test_driver_install();
701 UnhookWindowsHookEx(hhook);
703 /* We have to run this test after the CBT hook is disabled because
704 ProfileItems needs to create a window on Windows XP. */
705 test_profile_items();
708 test_inffilelist();
710 SetCurrentDirectory(prev_path);