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 /* function pointers */
27 static HMODULE hSetupAPI;
28 static void (WINAPI *pSetupCloseInfFile)(HINF);
29 static BOOL (WINAPI *pSetupGetInfInformationA)(LPCVOID,DWORD,PSP_INF_INFORMATION,DWORD,PDWORD);
30 static HINF (WINAPI *pSetupOpenInfFileA)(PCSTR,PCSTR,DWORD,PUINT);
31 static BOOL (WINAPI *pSetupQueryInfFileInformationA)(PSP_INF_INFORMATION,UINT,PSTR,DWORD,PDWORD);
32 static BOOL (WINAPI *pSetupGetSourceFileLocationA)(HINF,PINFCONTEXT,PCSTR,PUINT,PSTR,DWORD,PDWORD);
33 static BOOL (WINAPI *pSetupGetSourceInfoA)(HINF,UINT,UINT,PSTR,DWORD,PDWORD);
34 static BOOL (WINAPI *pSetupGetTargetPathA)(HINF,PINFCONTEXT,PCSTR,PSTR,DWORD,PDWORD);
36 CHAR CURR_DIR[MAX_PATH];
37 CHAR WIN_DIR[MAX_PATH];
39 static void init_function_pointers(void)
41 hSetupAPI = LoadLibraryA("setupapi.dll");
45 pSetupCloseInfFile = (void *)GetProcAddress(hSetupAPI, "SetupCloseInfFile");
46 pSetupGetInfInformationA = (void *)GetProcAddress(hSetupAPI, "SetupGetInfInformationA");
47 pSetupOpenInfFileA = (void *)GetProcAddress(hSetupAPI, "SetupOpenInfFileA");
48 pSetupQueryInfFileInformationA = (void *)GetProcAddress(hSetupAPI, "SetupQueryInfFileInformationA");
49 pSetupGetSourceFileLocationA = (void *)GetProcAddress(hSetupAPI, "SetupGetSourceFileLocationA");
50 pSetupGetSourceInfoA = (void *)GetProcAddress(hSetupAPI, "SetupGetSourceInfoA");
51 pSetupGetTargetPathA = (void *)GetProcAddress(hSetupAPI, "SetupGetTargetPathA");
55 static void get_directories(void)
59 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
60 len = lstrlenA(CURR_DIR);
62 if(len && (CURR_DIR[len-1] == '\\'))
65 GetWindowsDirectoryA(WIN_DIR, MAX_PATH);
66 len = lstrlenA(WIN_DIR);
68 if (len && (WIN_DIR[len-1] == '\\'))
72 static void append_str(char **str, const char *data)
78 static void create_inf_file(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, "[Version]\n");
87 append_str(&ptr, "Signature=\"$Chicago$\"\n");
88 append_str(&ptr, "AdvancedINF=2.5\n");
89 append_str(&ptr, "[SourceDisksNames]\n");
90 append_str(&ptr, "2 = %%SrcDiskName%%, LANCOM\\LANtools\\lanconf.cab\n");
91 append_str(&ptr, "[SourceDisksFiles]\n");
92 append_str(&ptr, "lanconf.exe = 2\n");
93 append_str(&ptr, "[DestinationDirs]\n");
94 append_str(&ptr, "DefaultDestDir = 24, %%DefaultDest%%\n");
95 append_str(&ptr, "[Strings]\n");
96 append_str(&ptr, "LangDir = english\n");
97 append_str(&ptr, "DefaultDest = LANCOM\n");
98 append_str(&ptr, "SrcDiskName = \"LANCOM Software CD\"\n");
100 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
104 static void create_inf_file2(LPSTR filename)
108 DWORD dwNumberOfBytesWritten;
109 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
110 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
112 append_str(&ptr, "[SourceFileInfo]\n");
113 append_str(&ptr, "sp1qfe\\bitsinst.exe=250B3702C7CCD7C2F9E4DAA1555C933E,000600060A28062C,27136,SP1QFE\n");
114 append_str(&ptr, "sp1qfe\\bitsprx2.dll=4EBEA67F4BB4EB402E725CA7CA2857AE,000600060A280621,7680,SP1QFE\n");
115 append_str(&ptr, "sp1qfe\\bitsprx3.dll=C788A1D9330DA011EF25E95D3BC7BDE5,000600060A280621,7168,SP1QFE\n");
116 append_str(&ptr, "sp1qfe\\qmgr.dll=696AC82FB290A03F205901442E0E9589,000600060A280621,361984,SP1QFE\n");
117 append_str(&ptr, "sp1qfe\\qmgrprxy.dll=8B5848144829E1BC985EA4C3D8CA7E3F,000600060A280621,17408,SP1QFE\n");
118 append_str(&ptr, "sp1qfe\\winhttp.dll=3EC6F518114606CA59D4160322077437,000500010A280615,331776,SP1QFE\n");
119 append_str(&ptr, "sp1qfe\\xpob2res.dll=DB83156B9F496F20D1EA70E4ABEC0166,000500010A280622,158720,SP1QFE\n");
121 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
125 static BOOL check_info_filename(PSP_INF_INFORMATION info, LPSTR test)
131 if (!pSetupQueryInfFileInformationA(info, 0, NULL, 0, &size))
134 filename = HeapAlloc(GetProcessHeap(), 0, size);
138 pSetupQueryInfFileInformationA(info, 0, filename, size, &size);
140 if (!lstrcmpiA(test, filename))
143 HeapFree(GetProcessHeap(), 0, filename);
147 static PSP_INF_INFORMATION alloc_inf_info(LPCSTR filename, DWORD search, PDWORD size)
149 PSP_INF_INFORMATION info;
152 ret = pSetupGetInfInformationA(filename, search, NULL, 0, size);
156 info = HeapAlloc(GetProcessHeap(), 0, *size);
160 static void test_SetupGetInfInformation(void)
162 PSP_INF_INFORMATION info;
163 CHAR inf_filename[MAX_PATH];
164 CHAR inf_one[MAX_PATH], inf_two[MAX_PATH];
169 lstrcpyA(inf_filename, CURR_DIR);
170 lstrcatA(inf_filename, "\\");
171 lstrcatA(inf_filename, "test.inf");
173 /* try an invalid inf handle */
175 SetLastError(0xbeefcafe);
176 ret = pSetupGetInfInformationA(NULL, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
177 ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
178 ok(GetLastError() == ERROR_INVALID_HANDLE,
179 "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
180 ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
182 /* try an invalid inf filename */
184 SetLastError(0xbeefcafe);
185 ret = pSetupGetInfInformationA(NULL, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size);
186 ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
187 ok(GetLastError() == ERROR_INVALID_PARAMETER,
188 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
189 ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
191 create_inf_file(inf_filename);
193 /* try an invalid search flag */
195 SetLastError(0xbeefcafe);
196 ret = pSetupGetInfInformationA(inf_filename, -1, NULL, 0, &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());
200 ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
202 /* try a nonexistent inf file */
204 SetLastError(0xbeefcafe);
205 ret = pSetupGetInfInformationA("idontexist", INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size);
206 ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
207 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
208 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
209 ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
211 /* successfully open the inf file */
213 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size);
214 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
215 ok(size != 0xdeadbeef, "Expected a valid size on return\n");
217 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */
218 SetLastError(0xbeefcafe);
219 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, &size);
220 ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
221 ok(GetLastError() == ERROR_INVALID_PARAMETER,
222 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
224 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */
225 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size-1, &size);
226 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
228 /* some tests for behaviour with a NULL RequiredSize pointer */
229 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, NULL);
230 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
231 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size - 1, NULL);
232 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
233 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, NULL);
234 ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
236 info = HeapAlloc(GetProcessHeap(), 0, size);
238 /* try valid ReturnBuffer but too small size */
239 SetLastError(0xbeefcafe);
240 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, info, size - 1, &size);
241 ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
242 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
243 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
245 /* successfully get the inf information */
246 ret = pSetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, info, size, &size);
247 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
248 ok(check_info_filename(info, inf_filename), "Expected returned filename to be equal\n");
250 HeapFree(GetProcessHeap(), 0, info);
252 /* try the INFINFO_INF_SPEC_IS_HINF search flag */
253 hinf = pSetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
254 info = alloc_inf_info(hinf, INFINFO_INF_SPEC_IS_HINF, &size);
255 ret = pSetupGetInfInformationA(hinf, INFINFO_INF_SPEC_IS_HINF, info, size, &size);
256 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
257 ok(check_info_filename(info, inf_filename), "Expected returned filename to be equal\n");
258 pSetupCloseInfFile(hinf);
260 lstrcpyA(inf_one, WIN_DIR);
261 lstrcatA(inf_one, "\\inf\\");
262 lstrcatA(inf_one, "test.inf");
263 create_inf_file(inf_one);
265 lstrcpyA(inf_two, WIN_DIR);
266 lstrcatA(inf_two, "\\system32\\");
267 lstrcatA(inf_two, "test.inf");
268 create_inf_file(inf_two);
270 HeapFree(GetProcessHeap(), 0, info);
271 info = alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH, &size);
273 /* test the INFINFO_DEFAULT_SEARCH search flag */
274 ret = pSetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH, info, size, &size);
275 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
276 ok(check_info_filename(info, inf_one), "Expected returned filename to be equal\n");
278 HeapFree(GetProcessHeap(), 0, info);
279 info = alloc_inf_info("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH, &size);
281 /* test the INFINFO_REVERSE_DEFAULT_SEARCH search flag */
282 ret = pSetupGetInfInformationA("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH, info, size, &size);
283 ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
284 ok(check_info_filename(info, inf_two), "Expected returned filename to be equal\n");
286 DeleteFileA(inf_filename);
287 DeleteFileA(inf_one);
288 DeleteFileA(inf_two);
291 static void test_SetupGetSourceFileLocation(void)
293 char buffer[MAX_PATH] = "not empty", inf_filename[MAX_PATH];
295 DWORD required, error;
299 lstrcpyA(inf_filename, CURR_DIR);
300 lstrcatA(inf_filename, "\\");
301 lstrcatA(inf_filename, "test.inf");
303 create_inf_file(inf_filename);
305 hinf = pSetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
306 ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
311 ret = pSetupGetSourceFileLocationA(hinf, NULL, "lanconf.exe", &source_id, buffer, sizeof(buffer), &required);
312 ok(ret, "SetupGetSourceFileLocation failed\n");
314 ok(required == 1, "unexpected required size: %d\n", required);
315 ok(source_id == 2, "unexpected source id: %d\n", source_id);
316 ok(!lstrcmpA("", buffer), "unexpected result string: %s\n", buffer);
318 pSetupCloseInfFile(hinf);
319 DeleteFileA(inf_filename);
321 create_inf_file2(inf_filename);
323 SetLastError(0xdeadbeef);
324 hinf = pSetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
325 error = GetLastError();
326 ok(hinf == INVALID_HANDLE_VALUE, "could open inf file\n");
327 ok(error == ERROR_WRONG_INF_STYLE, "got wrong error: %d\n", error);
329 hinf = pSetupOpenInfFileA(inf_filename, NULL, INF_STYLE_OLDNT, NULL);
330 ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
332 ret = pSetupGetSourceFileLocationA(hinf, NULL, "", &source_id, buffer, sizeof(buffer), &required);
333 ok(!ret, "SetupGetSourceFileLocation succeeded\n");
335 pSetupCloseInfFile(hinf);
336 DeleteFileA(inf_filename);
339 static void test_SetupGetSourceInfo(void)
341 char buffer[MAX_PATH], inf_filename[MAX_PATH];
346 lstrcpyA(inf_filename, CURR_DIR);
347 lstrcatA(inf_filename, "\\");
348 lstrcatA(inf_filename, "test.inf");
350 create_inf_file(inf_filename);
352 hinf = pSetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
353 ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
357 ret = pSetupGetSourceInfoA(hinf, 2, SRCINFO_PATH, buffer, sizeof(buffer), &required);
358 ok(ret, "SetupGetSourceInfoA failed\n");
360 ok(required == 1, "unexpected required size: %d\n", required);
361 ok(!lstrcmpA("", buffer), "unexpected result string: %s\n", buffer);
366 ret = pSetupGetSourceInfoA(hinf, 2, SRCINFO_TAGFILE, buffer, sizeof(buffer), &required);
367 ok(ret, "SetupGetSourceInfoA failed\n");
369 ok(required == 28, "unexpected required size: %d\n", required);
370 ok(!lstrcmpA("LANCOM\\LANtools\\lanconf.cab", buffer), "unexpected result string: %s\n", buffer);
375 ret = pSetupGetSourceInfoA(hinf, 2, SRCINFO_DESCRIPTION, buffer, sizeof(buffer), &required);
376 ok(ret, "SetupGetSourceInfoA failed\n");
378 ok(required == 19, "unexpected required size: %d\n", required);
379 ok(!lstrcmpA("LANCOM Software CD", buffer), "unexpected result string: %s\n", buffer);
381 pSetupCloseInfFile(hinf);
382 DeleteFileA(inf_filename);
385 static void test_SetupGetTargetPath(void)
387 char buffer[MAX_PATH], inf_filename[MAX_PATH];
393 lstrcpyA(inf_filename, CURR_DIR);
394 lstrcatA(inf_filename, "\\");
395 lstrcatA(inf_filename, "test.inf");
397 create_inf_file(inf_filename);
399 hinf = pSetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
400 ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
403 ctx.CurrentInf = hinf;
409 ret = pSetupGetTargetPathA(hinf, &ctx, NULL, buffer, sizeof(buffer), &required);
410 ok(ret, "SetupGetTargetPathA failed\n");
412 ok(required == 10, "unexpected required size: %d\n", required);
413 ok(!lstrcmpiA("C:\\LANCOM", buffer), "unexpected result string: %s\n", buffer);
415 pSetupCloseInfFile(hinf);
416 DeleteFileA(inf_filename);
421 init_function_pointers();
424 test_SetupGetInfInformation();
425 test_SetupGetSourceFileLocation();
426 test_SetupGetSourceInfo();
427 test_SetupGetTargetPath();