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 append_str(char **str
, const char *data
)
52 static void create_inf_file(LPSTR filename
)
56 DWORD dwNumberOfBytesWritten
;
57 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
58 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
60 append_str(&ptr
, "[Version]\n");
61 append_str(&ptr
, "Signature=\"$Chicago$\"\n");
62 append_str(&ptr
, "AdvancedINF=2.5\n");
63 append_str(&ptr
, "[SourceDisksNames]\n");
64 append_str(&ptr
, "2 = %%SrcDiskName%%, LANCOM\\LANtools\\lanconf.cab\n");
65 append_str(&ptr
, "[SourceDisksFiles]\n");
66 append_str(&ptr
, "lanconf.exe = 2\n");
67 append_str(&ptr
, "[DestinationDirs]\n");
68 append_str(&ptr
, "DefaultDestDir = 24, %%DefaultDest%%\n");
69 append_str(&ptr
, "[Strings]\n");
70 append_str(&ptr
, "LangDir = english\n");
71 append_str(&ptr
, "DefaultDest = LANCOM\n");
72 append_str(&ptr
, "SrcDiskName = \"LANCOM Software CD\"\n");
74 WriteFile(hf
, data
, ptr
- data
, &dwNumberOfBytesWritten
, NULL
);
78 static void create_inf_file2(LPSTR filename
)
82 DWORD dwNumberOfBytesWritten
;
83 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
84 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
86 append_str(&ptr
, "[SourceFileInfo]\n");
87 append_str(&ptr
, "sp1qfe\\bitsinst.exe=250B3702C7CCD7C2F9E4DAA1555C933E,000600060A28062C,27136,SP1QFE\n");
88 append_str(&ptr
, "sp1qfe\\bitsprx2.dll=4EBEA67F4BB4EB402E725CA7CA2857AE,000600060A280621,7680,SP1QFE\n");
89 append_str(&ptr
, "sp1qfe\\bitsprx3.dll=C788A1D9330DA011EF25E95D3BC7BDE5,000600060A280621,7168,SP1QFE\n");
90 append_str(&ptr
, "sp1qfe\\qmgr.dll=696AC82FB290A03F205901442E0E9589,000600060A280621,361984,SP1QFE\n");
91 append_str(&ptr
, "sp1qfe\\qmgrprxy.dll=8B5848144829E1BC985EA4C3D8CA7E3F,000600060A280621,17408,SP1QFE\n");
92 append_str(&ptr
, "sp1qfe\\winhttp.dll=3EC6F518114606CA59D4160322077437,000500010A280615,331776,SP1QFE\n");
93 append_str(&ptr
, "sp1qfe\\xpob2res.dll=DB83156B9F496F20D1EA70E4ABEC0166,000500010A280622,158720,SP1QFE\n");
95 WriteFile(hf
, data
, ptr
- data
, &dwNumberOfBytesWritten
, NULL
);
99 static BOOL
check_info_filename(PSP_INF_INFORMATION info
, LPSTR test
)
105 if (!SetupQueryInfFileInformationA(info
, 0, NULL
, 0, &size
))
108 filename
= HeapAlloc(GetProcessHeap(), 0, size
);
112 SetupQueryInfFileInformationA(info
, 0, filename
, size
, &size
);
114 if (!lstrcmpiA(test
, filename
))
117 HeapFree(GetProcessHeap(), 0, filename
);
121 static PSP_INF_INFORMATION
alloc_inf_info(LPCSTR filename
, DWORD search
, PDWORD size
)
123 PSP_INF_INFORMATION info
;
126 ret
= SetupGetInfInformationA(filename
, search
, NULL
, 0, size
);
130 info
= HeapAlloc(GetProcessHeap(), 0, *size
);
134 static void test_SetupGetInfInformation(void)
136 PSP_INF_INFORMATION info
;
137 CHAR inf_filename
[MAX_PATH
];
138 CHAR inf_one
[MAX_PATH
], inf_two
[MAX_PATH
];
143 lstrcpyA(inf_filename
, CURR_DIR
);
144 lstrcatA(inf_filename
, "\\");
145 lstrcatA(inf_filename
, "test.inf");
147 /* try an invalid inf handle */
149 SetLastError(0xbeefcafe);
150 ret
= SetupGetInfInformationA(NULL
, INFINFO_INF_SPEC_IS_HINF
, NULL
, 0, &size
);
151 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
152 ok(GetLastError() == ERROR_INVALID_HANDLE
,
153 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
154 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
156 /* try an invalid inf filename */
158 SetLastError(0xbeefcafe);
159 ret
= SetupGetInfInformationA(NULL
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
160 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
161 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
162 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
163 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
165 create_inf_file(inf_filename
);
167 /* try an invalid search flag */
169 SetLastError(0xbeefcafe);
170 ret
= SetupGetInfInformationA(inf_filename
, -1, NULL
, 0, &size
);
171 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
172 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
173 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
174 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
176 /* try a nonexistent inf file */
178 SetLastError(0xbeefcafe);
179 ret
= SetupGetInfInformationA("idontexist", INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
180 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
181 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
182 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
183 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
185 /* successfully open the inf file */
187 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
188 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
189 ok(size
!= 0xdeadbeef, "Expected a valid size on return\n");
191 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */
192 SetLastError(0xbeefcafe);
193 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, &size
);
194 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
195 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
196 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
198 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */
199 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
-1, &size
);
200 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
202 /* some tests for behaviour with a NULL RequiredSize pointer */
203 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, NULL
);
204 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
205 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
- 1, NULL
);
206 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
207 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, NULL
);
208 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
210 info
= HeapAlloc(GetProcessHeap(), 0, size
);
212 /* try valid ReturnBuffer but too small size */
213 SetLastError(0xbeefcafe);
214 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
- 1, &size
);
215 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
216 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
217 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
219 /* successfully get the inf information */
220 ret
= SetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
, &size
);
221 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
222 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
224 HeapFree(GetProcessHeap(), 0, info
);
226 /* try the INFINFO_INF_SPEC_IS_HINF search flag */
227 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
228 info
= alloc_inf_info(hinf
, INFINFO_INF_SPEC_IS_HINF
, &size
);
229 ret
= SetupGetInfInformationA(hinf
, INFINFO_INF_SPEC_IS_HINF
, info
, size
, &size
);
230 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
231 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
232 SetupCloseInfFile(hinf
);
234 lstrcpyA(inf_one
, WIN_DIR
);
235 lstrcatA(inf_one
, "\\inf\\");
236 lstrcatA(inf_one
, "test.inf");
237 create_inf_file(inf_one
);
239 lstrcpyA(inf_two
, WIN_DIR
);
240 lstrcatA(inf_two
, "\\system32\\");
241 lstrcatA(inf_two
, "test.inf");
242 create_inf_file(inf_two
);
244 HeapFree(GetProcessHeap(), 0, info
);
245 info
= alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH
, &size
);
247 /* test the INFINFO_DEFAULT_SEARCH search flag */
248 ret
= SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH
, info
, size
, &size
);
249 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
250 ok(check_info_filename(info
, inf_one
), "Expected returned filename to be equal\n");
252 HeapFree(GetProcessHeap(), 0, info
);
253 info
= alloc_inf_info("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, &size
);
255 /* test the INFINFO_REVERSE_DEFAULT_SEARCH search flag */
256 ret
= SetupGetInfInformationA("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, info
, size
, &size
);
257 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
258 ok(check_info_filename(info
, inf_two
), "Expected returned filename to be equal\n");
260 DeleteFileA(inf_filename
);
261 DeleteFileA(inf_one
);
262 DeleteFileA(inf_two
);
265 static void test_SetupGetSourceFileLocation(void)
267 char buffer
[MAX_PATH
] = "not empty", inf_filename
[MAX_PATH
];
269 DWORD required
, error
;
273 lstrcpyA(inf_filename
, CURR_DIR
);
274 lstrcatA(inf_filename
, "\\");
275 lstrcatA(inf_filename
, "test.inf");
277 create_inf_file(inf_filename
);
279 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
280 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
285 ret
= SetupGetSourceFileLocationA(hinf
, NULL
, "lanconf.exe", &source_id
, buffer
, sizeof(buffer
), &required
);
286 ok(ret
, "SetupGetSourceFileLocation failed\n");
288 ok(required
== 1, "unexpected required size: %d\n", required
);
289 ok(source_id
== 2, "unexpected source id: %d\n", source_id
);
290 ok(!lstrcmpA("", buffer
), "unexpected result string: %s\n", buffer
);
292 SetupCloseInfFile(hinf
);
293 DeleteFileA(inf_filename
);
295 create_inf_file2(inf_filename
);
297 SetLastError(0xdeadbeef);
298 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
299 error
= GetLastError();
300 ok(hinf
== INVALID_HANDLE_VALUE
, "could open inf file\n");
301 ok(error
== ERROR_WRONG_INF_STYLE
, "got wrong error: %d\n", error
);
303 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_OLDNT
, NULL
);
304 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
306 ret
= SetupGetSourceFileLocationA(hinf
, NULL
, "", &source_id
, buffer
, sizeof(buffer
), &required
);
307 ok(!ret
, "SetupGetSourceFileLocation succeeded\n");
309 SetupCloseInfFile(hinf
);
310 DeleteFileA(inf_filename
);
313 static void test_SetupGetSourceInfo(void)
315 char buffer
[MAX_PATH
], inf_filename
[MAX_PATH
];
320 lstrcpyA(inf_filename
, CURR_DIR
);
321 lstrcatA(inf_filename
, "\\");
322 lstrcatA(inf_filename
, "test.inf");
324 create_inf_file(inf_filename
);
326 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
327 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
331 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_PATH
, buffer
, sizeof(buffer
), &required
);
332 ok(ret
, "SetupGetSourceInfoA failed\n");
334 ok(required
== 1, "unexpected required size: %d\n", required
);
335 ok(!lstrcmpA("", buffer
), "unexpected result string: %s\n", buffer
);
340 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_TAGFILE
, buffer
, sizeof(buffer
), &required
);
341 ok(ret
, "SetupGetSourceInfoA failed\n");
343 ok(required
== 28, "unexpected required size: %d\n", required
);
344 ok(!lstrcmpA("LANCOM\\LANtools\\lanconf.cab", buffer
), "unexpected result string: %s\n", buffer
);
349 ret
= SetupGetSourceInfoA(hinf
, 2, SRCINFO_DESCRIPTION
, buffer
, sizeof(buffer
), &required
);
350 ok(ret
, "SetupGetSourceInfoA failed\n");
352 ok(required
== 19, "unexpected required size: %d\n", required
);
353 ok(!lstrcmpA("LANCOM Software CD", buffer
), "unexpected result string: %s\n", buffer
);
355 SetupCloseInfFile(hinf
);
356 DeleteFileA(inf_filename
);
359 static void test_SetupGetTargetPath(void)
361 char buffer
[MAX_PATH
], inf_filename
[MAX_PATH
];
367 lstrcpyA(inf_filename
, CURR_DIR
);
368 lstrcatA(inf_filename
, "\\");
369 lstrcatA(inf_filename
, "test.inf");
371 create_inf_file(inf_filename
);
373 hinf
= SetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
374 ok(hinf
!= INVALID_HANDLE_VALUE
, "could not open inf file\n");
377 ctx
.CurrentInf
= hinf
;
383 ret
= SetupGetTargetPathA(hinf
, &ctx
, NULL
, buffer
, sizeof(buffer
), &required
);
384 ok(ret
, "SetupGetTargetPathA failed\n");
386 ok(required
== 10, "unexpected required size: %d\n", required
);
387 ok(!lstrcmpiA("C:\\LANCOM", buffer
), "unexpected result string: %s\n", buffer
);
389 SetupCloseInfFile(hinf
);
390 DeleteFileA(inf_filename
);
397 test_SetupGetInfInformation();
398 test_SetupGetSourceFileLocation();
399 test_SetupGetSourceInfo();
400 test_SetupGetTargetPath();