2 * Unit tests for setupapi.dll query functions
4 * Copyright (C) 2006 James Hawkins
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
24 #include "wine/test.h"
26 static CHAR CURR_DIR
[MAX_PATH
];
27 static CHAR WIN_DIR
[MAX_PATH
];
29 static void get_directories(void)
33 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
34 len
= lstrlenA(CURR_DIR
);
36 if(len
&& (CURR_DIR
[len
-1] == '\\'))
39 GetWindowsDirectoryA(WIN_DIR
, MAX_PATH
);
40 len
= lstrlenA(WIN_DIR
);
42 if (len
&& (WIN_DIR
[len
-1] == '\\'))
46 static const char inf_data1
[] =
48 "Signature=\"$Chicago$\"\n"
50 "[SourceDisksNames]\n"
51 "2 = %SrcDiskName%, LANCOM\\LANtools\\lanconf.cab\n"
52 "[SourceDisksFiles]\n"
55 "DefaultDestDir = 24, %DefaultDest%\n"
58 "DefaultDest = LANCOM\n"
59 "SrcDiskName = \"LANCOM Software CD\"\n";
61 static const char inf_data2
[] =
63 "sp1qfe\\bitsinst.exe=250B3702C7CCD7C2F9E4DAA1555C933E,000600060A28062C,27136,SP1QFE\n"
64 "sp1qfe\\bitsprx2.dll=4EBEA67F4BB4EB402E725CA7CA2857AE,000600060A280621,7680,SP1QFE\n"
65 "sp1qfe\\bitsprx3.dll=C788A1D9330DA011EF25E95D3BC7BDE5,000600060A280621,7168,SP1QFE\n"
66 "sp1qfe\\qmgr.dll=696AC82FB290A03F205901442E0E9589,000600060A280621,361984,SP1QFE\n"
67 "sp1qfe\\qmgrprxy.dll=8B5848144829E1BC985EA4C3D8CA7E3F,000600060A280621,17408,SP1QFE\n"
68 "sp1qfe\\winhttp.dll=3EC6F518114606CA59D4160322077437,000500010A280615,331776,SP1QFE\n"
69 "sp1qfe\\xpob2res.dll=DB83156B9F496F20D1EA70E4ABEC0166,000500010A280622,158720,SP1QFE\n";
71 static const char inf_data3
[] =
73 "Signature = \"$Windows NT$\"\n"
75 "CopyAlways.Windir.files = 10\n"
76 "[CopyAlways.Windir.Files]\n"
77 "WindowsCodecs.dll\n";
79 static const char inf_data4
[] =
81 "Signature = \"$Windows NT$\"\n"
82 "[CopyAlways.System32.Files]\n"
83 "WindowsCodecs.dll\n";
85 static const char inf_data5
[] =
87 "Signature = \"$Windows NT$\"\n"
89 "DefaultDestDir = 11\n"
90 "CopyAlways.Windir.files = 10\n"
91 "[CopyAlways.Windir.Files]\n"
92 "WindowsCodecs.dll\n";
94 static const char inf_data6
[] =
96 "Signature = \"$Windows NT$\"\n"
98 "DefaultDestDir = 10\n"
99 "[CopyAlways.Windir.Files]\n"
100 "WindowsCodecs.dll\n";
102 static void create_inf_file(LPSTR filename
, const char *data
, DWORD size
)
104 DWORD dwNumberOfBytesWritten
;
105 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
106 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
107 WriteFile(hf
, data
, size
, &dwNumberOfBytesWritten
, NULL
);
111 static BOOL
check_info_filename(PSP_INF_INFORMATION info
, LPSTR test
)
117 if (!SetupQueryInfFileInformationA(info
, 0, NULL
, 0, &size
))
120 filename
= HeapAlloc(GetProcessHeap(), 0, size
);
124 SetupQueryInfFileInformationA(info
, 0, filename
, size
, &size
);
126 if (!lstrcmpiA(test
, filename
))
129 HeapFree(GetProcessHeap(), 0, filename
);
133 static PSP_INF_INFORMATION
alloc_inf_info(LPCSTR filename
, DWORD search
, PDWORD size
)
135 PSP_INF_INFORMATION info
;
138 ret
= SetupGetInfInformationA(filename
, search
, NULL
, 0, size
);
142 info
= HeapAlloc(GetProcessHeap(), 0, *size
);
146 static void test_SetupGetInfInformation(void)
148 PSP_INF_INFORMATION info
;
149 CHAR inf_filename
[MAX_PATH
];
150 CHAR inf_one
[MAX_PATH
], inf_two
[MAX_PATH
];
156 lstrcpyA(inf_filename
, CURR_DIR
);
157 lstrcatA(inf_filename
, "\\");
158 lstrcatA(inf_filename
, "test.inf");
160 /* try an invalid inf handle */
162 SetLastError(0xbeefcafe);
163 ret
= SetupGetInfInformationA(NULL
, INFINFO_INF_SPEC_IS_HINF
, NULL
, 0, &size
);
164 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
165 ok(GetLastError() == ERROR_INVALID_HANDLE
||
166 broken(GetLastError() == ERROR_BAD_PATHNAME
) || /* win95 */
167 broken(GetLastError() == ERROR_FILE_NOT_FOUND
) || /* win98 */
168 broken(GetLastError() == ERROR_PATH_NOT_FOUND
) || /* NT4 */
169 broken(GetLastError() == ERROR_INVALID_NAME
) || /* win2k */
170 broken(GetLastError() == ERROR_GENERAL_SYNTAX
), /* another win2k / winMe */
171 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
172 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
174 /* try an invalid inf filename */
175 /* do not use NULL as absolute inf filename on win9x/winMe (crash) */
176 if ((GetLastError() != ERROR_BAD_PATHNAME
) && /* win95 */
177 (GetLastError() != ERROR_FILE_NOT_FOUND
) && /* win98 */
178 (GetLastError() != ERROR_GENERAL_SYNTAX
)) /* winMe */
181 SetLastError(0xbeefcafe);
182 ret
= SetupGetInfInformationA(NULL
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
183 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
184 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
185 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
186 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
189 create_inf_file(inf_filename
, inf_data1
, sizeof(inf_data1
) - 1);
191 /* try an invalid search flag */
193 SetLastError(0xbeefcafe);
194 ret
= SetupGetInfInformationA(inf_filename
, -1, NULL
, 0, &size
);
195 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
196 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
197 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
198 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
200 /* try a nonexistent inf file */
202 SetLastError(0xbeefcafe);
203 ret
= SetupGetInfInformationA("idontexist", INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
204 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
205 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
206 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
207 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
209 /* successfully open the inf file */
211 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
212 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
213 ok(size
!= 0xdeadbeef, "Expected a valid size on return\n");
215 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */
216 SetLastError(0xbeefcafe);
217 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, &size
);
218 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
219 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
220 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
222 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */
223 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
-1, &size
);
224 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
226 /* some tests for behaviour with a NULL RequiredSize pointer */
227 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, NULL
);
228 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
229 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
- 1, NULL
);
230 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
231 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, NULL
);
232 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
234 info
= HeapAlloc(GetProcessHeap(), 0, size
);
236 /* try valid ReturnBuffer but too small size */
237 SetLastError(0xbeefcafe);
238 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
- 1, &size
);
239 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
240 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
241 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
243 /* successfully get the inf information */
244 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
, &size
);
245 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
246 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
248 HeapFree(GetProcessHeap(), 0, info
);
250 /* try the INFINFO_INF_SPEC_IS_HINF search flag */
251 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
252 info
= alloc_inf_info(hinf
, INFINFO_INF_SPEC_IS_HINF
, &size
);
253 ret
= SetupGetInfInformationA(hinf
, INFINFO_INF_SPEC_IS_HINF
, info
, size
, &size
);
254 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
255 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
256 SetupCloseInfFile(hinf
);
258 lstrcpyA(inf_two
, WIN_DIR
);
259 lstrcatA(inf_two
, "\\system32\\");
260 lstrcatA(inf_two
, "test.inf");
261 create_inf_file(inf_two
, inf_data1
, sizeof(inf_data1
) - 1);
263 HeapFree(GetProcessHeap(), 0, info
);
264 info
= alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH
, &size
);
266 /* check if system32 is searched for inf */
267 ret
= SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH
, info
, size
, &size
);
268 if (!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
269 revfile
= inf_one
; /* Vista */
273 lstrcpyA(inf_one
, WIN_DIR
);
274 lstrcatA(inf_one
, "\\inf\\");
275 lstrcatA(inf_one
, "test.inf");
276 create_inf_file(inf_one
, inf_data1
, sizeof(inf_data1
) - 1);
278 HeapFree(GetProcessHeap(), 0, info
);
279 info
= alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH
, &size
);
281 /* test the INFINFO_DEFAULT_SEARCH search flag */
282 ret
= SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH
, info
, size
, &size
);
283 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed: %d\n", GetLastError());
284 ok(check_info_filename(info
, inf_one
), "Expected returned filename to be equal\n");
286 HeapFree(GetProcessHeap(), 0, info
);
287 info
= alloc_inf_info("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, &size
);
289 /* test the INFINFO_REVERSE_DEFAULT_SEARCH search flag */
290 ret
= SetupGetInfInformationA("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, info
, size
, &size
);
291 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
292 ok(check_info_filename(info
, revfile
), "Expected returned filename to be equal\n");
294 HeapFree(GetProcessHeap(), 0, info
);
296 DeleteFileA(inf_filename
);
297 DeleteFileA(inf_one
);
298 DeleteFileA(inf_two
);
301 static void test_SetupGetSourceFileLocation(void)
303 char buffer
[MAX_PATH
] = "not empty", inf_filename
[MAX_PATH
];
305 DWORD required
, error
;
309 lstrcpyA(inf_filename
, CURR_DIR
);
310 lstrcatA(inf_filename
, "\\");
311 lstrcatA(inf_filename
, "test.inf");
313 create_inf_file(inf_filename
, inf_data1
, sizeof(inf_data1
) - 1);
315 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
316 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
321 ret
= SetupGetSourceFileLocationA(hinf
, NULL
, "lanconf.exe", &source_id
, buffer
, sizeof(buffer
), &required
);
322 ok(ret
, "SetupGetSourceFileLocation failed\n");
324 ok(required
== 1, "unexpected required size: %d\n", required
);
325 ok(source_id
== 2, "unexpected source id: %d\n", source_id
);
326 ok(!lstrcmpA("", buffer
), "unexpected result string: %s\n", buffer
);
328 SetupCloseInfFile(hinf
);
329 DeleteFileA(inf_filename
);
331 create_inf_file(inf_filename
, inf_data2
, sizeof(inf_data2
) - 1);
333 SetLastError(0xdeadbeef);
334 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
335 error
= GetLastError();
336 ok(hinf
== INVALID_HANDLE_VALUE
, "could open inf file\n");
337 ok(error
== ERROR_WRONG_INF_STYLE
, "got wrong error: %d\n", error
);
339 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_OLDNT
, NULL
);
340 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
342 ret
= SetupGetSourceFileLocationA(hinf
, NULL
, "", &source_id
, buffer
, sizeof(buffer
), &required
);
343 ok(!ret
, "SetupGetSourceFileLocation succeeded\n");
345 SetupCloseInfFile(hinf
);
346 DeleteFileA(inf_filename
);
349 static void test_SetupGetSourceInfo(void)
351 char buffer
[MAX_PATH
], inf_filename
[MAX_PATH
];
356 lstrcpyA(inf_filename
, CURR_DIR
);
357 lstrcatA(inf_filename
, "\\");
358 lstrcatA(inf_filename
, "test.inf");
360 create_inf_file(inf_filename
, inf_data1
, sizeof(inf_data1
) - 1);
362 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
363 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
367 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_PATH
, buffer
, sizeof(buffer
), &required
);
368 ok(ret
, "SetupGetSourceInfoA failed\n");
370 ok(required
== 1, "unexpected required size: %d\n", required
);
371 ok(!lstrcmpA("", buffer
), "unexpected result string: %s\n", buffer
);
376 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_TAGFILE
, buffer
, sizeof(buffer
), &required
);
377 ok(ret
, "SetupGetSourceInfoA failed\n");
379 ok(required
== 28, "unexpected required size: %d\n", required
);
380 ok(!lstrcmpA("LANCOM\\LANtools\\lanconf.cab", buffer
), "unexpected result string: %s\n", buffer
);
385 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_DESCRIPTION
, buffer
, sizeof(buffer
), &required
);
386 ok(ret
, "SetupGetSourceInfoA failed\n");
388 ok(required
== 19, "unexpected required size: %d\n", required
);
389 ok(!lstrcmpA("LANCOM Software CD", buffer
), "unexpected result string: %s\n", buffer
);
391 SetupCloseInfFile(hinf
);
392 DeleteFileA(inf_filename
);
395 static void test_SetupGetTargetPath(void)
397 char buffer
[MAX_PATH
], inf_filename
[MAX_PATH
];
398 char destfile
[MAX_PATH
];
404 lstrcpyA(inf_filename
, CURR_DIR
);
405 lstrcatA(inf_filename
, "\\");
406 lstrcatA(inf_filename
, "test.inf");
408 create_inf_file(inf_filename
, inf_data1
, sizeof(inf_data1
) - 1);
410 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
411 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
414 ctx
.CurrentInf
= hinf
;
420 ret
= SetupGetTargetPathA(hinf
, &ctx
, NULL
, buffer
, sizeof(buffer
), &required
);
421 ok(ret
, "SetupGetTargetPathA failed\n");
422 ok(required
== 10, "unexpected required size: %d\n", required
);
423 /* Retrieve the system drive from the windows directory.
424 * (%SystemDrive% is not available on Win9x)
426 lstrcpyA(destfile
, WIN_DIR
);
428 lstrcatA(destfile
, "LANCOM");
429 ok(!lstrcmpiA(destfile
, buffer
), "unexpected result string: %s\n", buffer
);
431 SetupCloseInfFile(hinf
);
432 DeleteFileA(inf_filename
);
434 create_inf_file(inf_filename
, inf_data3
, sizeof(inf_data3
) - 1);
436 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
437 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
441 ret
= SetupGetTargetPathA(hinf
, NULL
, "CopyAlways.Windir.Files", buffer
, sizeof(buffer
), &required
);
442 ok(ret
, "SetupGetTargetPathA failed\n");
444 lstrcpyA(destfile
, WIN_DIR
);
446 ok(required
== lstrlenA(destfile
) + 1, "unexpected required size: %d\n", required
);
447 ok(!lstrcmpiA(buffer
, destfile
), "unexpected path: %s\n", buffer
);
449 SetupCloseInfFile(hinf
);
450 DeleteFileA(inf_filename
);
452 create_inf_file(inf_filename
, inf_data4
, sizeof(inf_data4
) - 1);
454 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
455 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
459 ret
= SetupGetTargetPathA(hinf
, NULL
, "CopyAlways.System32.Files", buffer
, sizeof(buffer
), &required
);
460 ok(ret
, "SetupGetTargetPathA failed\n");
462 GetSystemDirectoryA(destfile
, MAX_PATH
);
464 ok(required
== lstrlenA(destfile
) + 1, "unexpected required size: %d\n", required
);
465 ok(!lstrcmpiA(buffer
, destfile
), "unexpected path: %s\n", buffer
);
467 SetupCloseInfFile(hinf
);
468 DeleteFileA(inf_filename
);
470 create_inf_file(inf_filename
, inf_data5
, sizeof(inf_data5
) - 1);
472 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
473 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
477 ret
= SetupGetTargetPathA(hinf
, NULL
, "CopyAlways.Windir.Files", buffer
, sizeof(buffer
), &required
);
478 ok(ret
, "SetupGetTargetPathA failed\n");
480 lstrcpyA(destfile
, WIN_DIR
);
482 ok(required
== lstrlenA(destfile
) + 1, "unexpected required size: %d\n", required
);
483 ok(!lstrcmpiA(buffer
, destfile
), "unexpected path: %s\n", buffer
);
485 SetupCloseInfFile(hinf
);
486 DeleteFileA(inf_filename
);
488 create_inf_file(inf_filename
, inf_data6
, sizeof(inf_data6
) - 1);
490 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
491 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
495 ret
= SetupGetTargetPathA(hinf
, NULL
, "CopyAlways.Windir.Files", buffer
, sizeof(buffer
), &required
);
496 ok(ret
, "SetupGetTargetPathA failed\n");
498 lstrcpyA(destfile
, WIN_DIR
);
500 ok(required
== lstrlenA(destfile
) + 1, "unexpected required size: %d\n", required
);
501 ok(!lstrcmpiA(buffer
, destfile
), "unexpected path: %s\n", buffer
);
503 SetupCloseInfFile(hinf
);
504 DeleteFileA(inf_filename
);
511 test_SetupGetInfInformation();
512 test_SetupGetSourceFileLocation();
513 test_SetupGetSourceInfo();
514 test_SetupGetTargetPath();