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
);
33 CHAR CURR_DIR
[MAX_PATH
];
34 CHAR WIN_DIR
[MAX_PATH
];
36 static void init_function_pointers(void)
38 hSetupAPI
= LoadLibraryA("setupapi.dll");
42 pSetupCloseInfFile
= (void *)GetProcAddress(hSetupAPI
, "SetupCloseInfFile");
43 pSetupGetInfInformationA
= (void *)GetProcAddress(hSetupAPI
, "SetupGetInfInformationA");
44 pSetupOpenInfFileA
= (void *)GetProcAddress(hSetupAPI
, "SetupOpenInfFileA");
45 pSetupQueryInfFileInformationA
= (void *)GetProcAddress(hSetupAPI
, "SetupQueryInfFileInformationA");
49 static void get_directories(void)
53 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
54 len
= lstrlenA(CURR_DIR
);
56 if(len
&& (CURR_DIR
[len
-1] == '\\'))
59 GetWindowsDirectoryA(WIN_DIR
, MAX_PATH
);
60 len
= lstrlenA(WIN_DIR
);
62 if (len
&& (WIN_DIR
[len
-1] == '\\'))
66 static void append_str(char **str
, const char *data
)
72 static void create_inf_file(LPSTR filename
)
76 DWORD dwNumberOfBytesWritten
;
77 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
78 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
80 append_str(&ptr
, "[Version]\n");
81 append_str(&ptr
, "Signature=\"$Chicago$\"\n");
82 append_str(&ptr
, "AdvancedINF=2.5\n");
84 WriteFile(hf
, data
, ptr
- data
, &dwNumberOfBytesWritten
, NULL
);
88 static BOOL
check_info_filename(PSP_INF_INFORMATION info
, LPSTR test
)
94 if (!pSetupQueryInfFileInformationA(info
, 0, NULL
, 0, &size
))
97 filename
= HeapAlloc(GetProcessHeap(), 0, size
);
101 pSetupQueryInfFileInformationA(info
, 0, filename
, size
, &size
);
103 if (!lstrcmpiA(test
, filename
))
106 HeapFree(GetProcessHeap(), 0, filename
);
110 static PSP_INF_INFORMATION
alloc_inf_info(LPCSTR filename
, DWORD search
, PDWORD size
)
112 PSP_INF_INFORMATION info
;
115 ret
= pSetupGetInfInformationA(filename
, search
, NULL
, 0, size
);
119 info
= HeapAlloc(GetProcessHeap(), 0, *size
);
123 static void test_SetupGetInfInformation(void)
125 PSP_INF_INFORMATION info
;
126 CHAR inf_filename
[MAX_PATH
];
127 CHAR inf_one
[MAX_PATH
], inf_two
[MAX_PATH
];
132 lstrcpyA(inf_filename
, CURR_DIR
);
133 lstrcatA(inf_filename
, "\\");
134 lstrcatA(inf_filename
, "test.inf");
136 /* try an invalid inf handle */
138 SetLastError(0xbeefcafe);
139 ret
= pSetupGetInfInformationA(NULL
, INFINFO_INF_SPEC_IS_HINF
, NULL
, 0, &size
);
140 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
141 ok(GetLastError() == ERROR_INVALID_HANDLE
,
142 "Expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
143 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
145 /* try an invalid inf filename */
147 SetLastError(0xbeefcafe);
148 ret
= pSetupGetInfInformationA(NULL
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
149 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
150 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
151 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
152 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
154 create_inf_file(inf_filename
);
156 /* try an invalid search flag */
158 SetLastError(0xbeefcafe);
159 ret
= pSetupGetInfInformationA(inf_filename
, -1, NULL
, 0, &size
);
160 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
161 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
162 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
163 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
165 /* try a nonexistent inf file */
167 SetLastError(0xbeefcafe);
168 ret
= pSetupGetInfInformationA("idontexist", INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
169 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
170 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
171 "Expected ERROR_FILE_NOT_FOUND, got %ld\n", GetLastError());
172 ok(size
== 0xdeadbeef, "Expected size to remain unchanged\n");
174 /* successfully open the inf file */
176 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, &size
);
177 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
178 ok(size
!= 0xdeadbeef, "Expected a valid size on return\n");
180 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */
181 SetLastError(0xbeefcafe);
182 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, &size
);
183 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
184 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
185 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
187 /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */
188 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
-1, &size
);
189 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
191 /* some tests for behaviour with a NULL RequiredSize pointer */
192 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, 0, NULL
);
193 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
194 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
- 1, NULL
);
195 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
196 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, NULL
, size
, NULL
);
197 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
199 info
= HeapAlloc(GetProcessHeap(), 0, size
);
201 /* try valid ReturnBuffer but too small size */
202 SetLastError(0xbeefcafe);
203 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
- 1, &size
);
204 ok(ret
== FALSE
, "Expected SetupGetInfInformation to fail\n");
205 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
206 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
208 /* successfully get the inf information */
209 ret
= pSetupGetInfInformationA(inf_filename
, INFINFO_INF_NAME_IS_ABSOLUTE
, info
, size
, &size
);
210 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
211 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
213 HeapFree(GetProcessHeap(), 0, info
);
215 /* try the INFINFO_INF_SPEC_IS_HINF search flag */
216 hinf
= pSetupOpenInfFileA(inf_filename
, NULL
, INF_STYLE_WIN4
, NULL
);
217 info
= alloc_inf_info(hinf
, INFINFO_INF_SPEC_IS_HINF
, &size
);
218 ret
= pSetupGetInfInformationA(hinf
, INFINFO_INF_SPEC_IS_HINF
, info
, size
, &size
);
219 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
220 ok(check_info_filename(info
, inf_filename
), "Expected returned filename to be equal\n");
221 pSetupCloseInfFile(hinf
);
223 lstrcpyA(inf_one
, WIN_DIR
);
224 lstrcatA(inf_one
, "\\inf\\");
225 lstrcatA(inf_one
, "test.inf");
226 create_inf_file(inf_one
);
228 lstrcpyA(inf_two
, WIN_DIR
);
229 lstrcatA(inf_two
, "\\system32\\");
230 lstrcatA(inf_two
, "test.inf");
231 create_inf_file(inf_two
);
233 HeapFree(GetProcessHeap(), 0, info
);
234 info
= alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH
, &size
);
236 /* test the INFINFO_DEFAULT_SEARCH search flag */
237 ret
= pSetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH
, info
, size
, &size
);
238 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
239 ok(check_info_filename(info
, inf_one
), "Expected returned filename to be equal\n");
241 HeapFree(GetProcessHeap(), 0, info
);
242 info
= alloc_inf_info("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, &size
);
244 /* test the INFINFO_REVERSE_DEFAULT_SEARCH search flag */
245 ret
= pSetupGetInfInformationA("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH
, info
, size
, &size
);
246 ok(ret
== TRUE
, "Expected SetupGetInfInformation to succeed\n");
247 ok(check_info_filename(info
, inf_two
), "Expected returned filename to be equal\n");
249 DeleteFileA(inf_filename
);
250 DeleteFileA(inf_one
);
251 DeleteFileA(inf_two
);
256 init_function_pointers();
259 test_SetupGetInfInformation();