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 CHAR CURR_DIR
[MAX_PATH
];
27 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 void create_inf_file(LPSTR filename
)
48 DWORD dwNumberOfBytesWritten
;
49 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
50 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
52 static const char data
[] =
54 "Signature=\"$Chicago$\"\n"
56 "[SourceDisksNames]\n"
57 "2 = %SrcDiskName%, LANCOM\\LANtools\\lanconf.cab\n"
58 "[SourceDisksFiles]\n"
61 "DefaultDestDir = 24, %DefaultDest%\n"
64 "DefaultDest = LANCOM\n"
65 "SrcDiskName = \"LANCOM Software CD\"\n";
67 WriteFile(hf
, data
, sizeof(data
) - 1, &dwNumberOfBytesWritten
, NULL
);
71 static void create_inf_file2(LPSTR filename
)
73 DWORD dwNumberOfBytesWritten
;
74 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
75 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
77 static const char data
[] =
79 "sp1qfe\\bitsinst.exe=250B3702C7CCD7C2F9E4DAA1555C933E,000600060A28062C,27136,SP1QFE\n"
80 "sp1qfe\\bitsprx2.dll=4EBEA67F4BB4EB402E725CA7CA2857AE,000600060A280621,7680,SP1QFE\n"
81 "sp1qfe\\bitsprx3.dll=C788A1D9330DA011EF25E95D3BC7BDE5,000600060A280621,7168,SP1QFE\n"
82 "sp1qfe\\qmgr.dll=696AC82FB290A03F205901442E0E9589,000600060A280621,361984,SP1QFE\n"
83 "sp1qfe\\qmgrprxy.dll=8B5848144829E1BC985EA4C3D8CA7E3F,000600060A280621,17408,SP1QFE\n"
84 "sp1qfe\\winhttp.dll=3EC6F518114606CA59D4160322077437,000500010A280615,331776,SP1QFE\n"
85 "sp1qfe\\xpob2res.dll=DB83156B9F496F20D1EA70E4ABEC0166,000500010A280622,158720,SP1QFE\n";
87 WriteFile(hf
, data
, sizeof(data
) - 1, &dwNumberOfBytesWritten
, NULL
);
91 static BOOL
check_info_filename(PSP_INF_INFORMATION info
, LPSTR test
)
97 if (!SetupQueryInfFileInformationA(info
, 0, NULL
, 0, &size
))
100 filename
= HeapAlloc(GetProcessHeap(), 0, size
);
104 SetupQueryInfFileInformationA(info
, 0, filename
, size
, &size
);
106 if (!lstrcmpiA(test
, filename
))
109 HeapFree(GetProcessHeap(), 0, filename
);
113 static PSP_INF_INFORMATION
alloc_inf_info(LPCSTR filename
, DWORD search
, PDWORD size
)
115 PSP_INF_INFORMATION info
;
118 ret
= SetupGetInfInformationA(filename
, search
, NULL
, 0, size
);
122 info
= HeapAlloc(GetProcessHeap(), 0, *size
);
126 static void test_SetupGetInfInformation(void)
128 PSP_INF_INFORMATION info
;
129 CHAR inf_filename
[MAX_PATH
];
130 CHAR inf_one
[MAX_PATH
], inf_two
[MAX_PATH
];
136 lstrcpyA(inf_filename
, CURR_DIR
);
137 lstrcatA(inf_filename
, "\\");
138 lstrcatA(inf_filename
, "test.inf");
140 /* try an invalid inf handle */
142 SetLastError(0xbeefcafe);
143 ret
= SetupGetInfInformationA(NULL
, INFINFO_INF_SPEC_IS_HINF
, NULL
, 0, &size
);
144 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
145 ok(GetLastError() == ERROR_INVALID_HANDLE
||
146 broken(GetLastError() == ERROR_BAD_PATHNAME
) || /* win95 */
147 broken(GetLastError() == ERROR_FILE_NOT_FOUND
) || /* win98 */
148 broken(GetLastError() == ERROR_PATH_NOT_FOUND
) || /* NT4 */
149 broken(GetLastError() == ERROR_INVALID_NAME
) || /* win2k */
150 broken(GetLastError() == ERROR_GENERAL_SYNTAX
), /* another win2k */
151 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
152 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
154 /* try an invalid inf filename */
155 /* do not use NULL as absolute inf filename on win9x (crash) */
156 if ((GetLastError() != ERROR_BAD_PATHNAME
) && /* win95 */
157 (GetLastError() != ERROR_FILE_NOT_FOUND
)) /* win98 */
160 SetLastError(0xbeefcafe);
161 ret
= SetupGetInfInformationA(NULL
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
162 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
163 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
164 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
165 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
168 create_inf_file(inf_filename
);
170 /* try an invalid search flag */
172 SetLastError(0xbeefcafe);
173 ret
= SetupGetInfInformationA(inf_filename
, -1, NULL
, 0, &size
);
174 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
175 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
176 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
177 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
179 /* try a nonexistent inf file */
181 SetLastError(0xbeefcafe);
182 ret
= SetupGetInfInformationA("idontexist", INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
183 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
184 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
185 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
186 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
188 /* successfully open the inf file */
190 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
191 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
192 ok(size
!= 0xdeadbeef, "Expected a valid size on return\n");
194 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */
195 SetLastError(0xbeefcafe);
196 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, &size
);
197 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
198 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
199 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
201 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */
202 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
-1, &size
);
203 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
205 /* some tests for behaviour with a NULL RequiredSize pointer */
206 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, NULL
);
207 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
208 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
- 1, NULL
);
209 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
210 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, NULL
);
211 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
213 info
= HeapAlloc(GetProcessHeap(), 0, size
);
215 /* try valid ReturnBuffer but too small size */
216 SetLastError(0xbeefcafe);
217 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
- 1, &size
);
218 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
219 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
220 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
222 /* successfully get the inf information */
223 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
, &size
);
224 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
225 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
227 HeapFree(GetProcessHeap(), 0, info
);
229 /* try the INFINFO_INF_SPEC_IS_HINF search flag */
230 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
231 info
= alloc_inf_info(hinf
, INFINFO_INF_SPEC_IS_HINF
, &size
);
232 ret
= SetupGetInfInformationA(hinf
, INFINFO_INF_SPEC_IS_HINF
, info
, size
, &size
);
233 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
234 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
235 SetupCloseInfFile(hinf
);
237 lstrcpyA(inf_two
, WIN_DIR
);
238 lstrcatA(inf_two
, "\\system32\\");
239 lstrcatA(inf_two
, "test.inf");
240 create_inf_file(inf_two
);
242 HeapFree(GetProcessHeap(), 0, info
);
243 info
= alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH
, &size
);
245 /* check if system32 is searched for inf */
246 ret
= SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH
, info
, size
, &size
);
247 if (!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
)
248 revfile
= inf_one
; /* Vista */
252 lstrcpyA(inf_one
, WIN_DIR
);
253 lstrcatA(inf_one
, "\\inf\\");
254 lstrcatA(inf_one
, "test.inf");
255 create_inf_file(inf_one
);
257 HeapFree(GetProcessHeap(), 0, info
);
258 info
= alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH
, &size
);
260 /* test the INFINFO_DEFAULT_SEARCH search flag */
261 ret
= SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH
, info
, size
, &size
);
262 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed: %d\n", GetLastError());
263 ok(check_info_filename(info
, inf_one
), "Expected returned filename to be equal\n");
265 HeapFree(GetProcessHeap(), 0, info
);
266 info
= alloc_inf_info("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, &size
);
268 /* test the INFINFO_REVERSE_DEFAULT_SEARCH search flag */
269 ret
= SetupGetInfInformationA("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, info
, size
, &size
);
270 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
271 ok(check_info_filename(info
, revfile
), "Expected returned filename to be equal\n");
273 HeapFree(GetProcessHeap(), 0, info
);
275 DeleteFileA(inf_filename
);
276 DeleteFileA(inf_one
);
277 DeleteFileA(inf_two
);
280 static void test_SetupGetSourceFileLocation(void)
282 char buffer
[MAX_PATH
] = "not empty", inf_filename
[MAX_PATH
];
284 DWORD required
, error
;
288 lstrcpyA(inf_filename
, CURR_DIR
);
289 lstrcatA(inf_filename
, "\\");
290 lstrcatA(inf_filename
, "test.inf");
292 create_inf_file(inf_filename
);
294 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
295 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
300 ret
= SetupGetSourceFileLocationA(hinf
, NULL
, "lanconf.exe", &source_id
, buffer
, sizeof(buffer
), &required
);
301 ok(ret
, "SetupGetSourceFileLocation failed\n");
303 ok(required
== 1, "unexpected required size: %d\n", required
);
304 ok(source_id
== 2, "unexpected source id: %d\n", source_id
);
305 ok(!lstrcmpA("", buffer
), "unexpected result string: %s\n", buffer
);
307 SetupCloseInfFile(hinf
);
308 DeleteFileA(inf_filename
);
310 create_inf_file2(inf_filename
);
312 SetLastError(0xdeadbeef);
313 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
314 error
= GetLastError();
315 ok(hinf
== INVALID_HANDLE_VALUE
, "could open inf file\n");
316 ok(error
== ERROR_WRONG_INF_STYLE
, "got wrong error: %d\n", error
);
318 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_OLDNT
, NULL
);
319 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
321 ret
= SetupGetSourceFileLocationA(hinf
, NULL
, "", &source_id
, buffer
, sizeof(buffer
), &required
);
322 ok(!ret
, "SetupGetSourceFileLocation succeeded\n");
324 SetupCloseInfFile(hinf
);
325 DeleteFileA(inf_filename
);
328 static void test_SetupGetSourceInfo(void)
330 char buffer
[MAX_PATH
], inf_filename
[MAX_PATH
];
335 lstrcpyA(inf_filename
, CURR_DIR
);
336 lstrcatA(inf_filename
, "\\");
337 lstrcatA(inf_filename
, "test.inf");
339 create_inf_file(inf_filename
);
341 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
342 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
346 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_PATH
, buffer
, sizeof(buffer
), &required
);
347 ok(ret
, "SetupGetSourceInfoA failed\n");
349 ok(required
== 1, "unexpected required size: %d\n", required
);
350 ok(!lstrcmpA("", buffer
), "unexpected result string: %s\n", buffer
);
355 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_TAGFILE
, buffer
, sizeof(buffer
), &required
);
356 ok(ret
, "SetupGetSourceInfoA failed\n");
358 ok(required
== 28, "unexpected required size: %d\n", required
);
359 ok(!lstrcmpA("LANCOM\\LANtools\\lanconf.cab", buffer
), "unexpected result string: %s\n", buffer
);
364 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_DESCRIPTION
, buffer
, sizeof(buffer
), &required
);
365 ok(ret
, "SetupGetSourceInfoA failed\n");
367 ok(required
== 19, "unexpected required size: %d\n", required
);
368 ok(!lstrcmpA("LANCOM Software CD", buffer
), "unexpected result string: %s\n", buffer
);
370 SetupCloseInfFile(hinf
);
371 DeleteFileA(inf_filename
);
374 static void test_SetupGetTargetPath(void)
376 char buffer
[MAX_PATH
], inf_filename
[MAX_PATH
];
377 char destfile
[MAX_PATH
];
383 lstrcpyA(inf_filename
, CURR_DIR
);
384 lstrcatA(inf_filename
, "\\");
385 lstrcatA(inf_filename
, "test.inf");
387 create_inf_file(inf_filename
);
389 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
390 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
393 ctx
.CurrentInf
= hinf
;
399 ret
= SetupGetTargetPathA(hinf
, &ctx
, NULL
, buffer
, sizeof(buffer
), &required
);
400 ok(ret
, "SetupGetTargetPathA failed\n");
401 ok(required
== 10, "unexpected required size: %d\n", required
);
402 /* Retrieve the system drive from the windows directory.
403 * (%SystemDrive% is not available on Win9x)
405 lstrcpyA(destfile
, WIN_DIR
);
407 lstrcatA(destfile
, "LANCOM");
408 ok(!lstrcmpiA(destfile
, buffer
), "unexpected result string: %s\n", buffer
);
410 SetupCloseInfFile(hinf
);
411 DeleteFileA(inf_filename
);
418 test_SetupGetInfInformation();
419 test_SetupGetSourceFileLocation();
420 test_SetupGetSourceInfo();
421 test_SetupGetTargetPath();