1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * Unit tests for setupapi.dll query functions
3*c2c66affSColin Finck *
4*c2c66affSColin Finck * Copyright (C) 2006 James Hawkins
5*c2c66affSColin Finck *
6*c2c66affSColin Finck * This library is free software; you can redistribute it and/or
7*c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
8*c2c66affSColin Finck * License as published by the Free Software Foundation; either
9*c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
10*c2c66affSColin Finck *
11*c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
12*c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14*c2c66affSColin Finck * Lesser General Public License for more details.
15*c2c66affSColin Finck *
16*c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
17*c2c66affSColin Finck * License along with this library; if not, write to the Free Software
18*c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19*c2c66affSColin Finck */
20*c2c66affSColin Finck
21*c2c66affSColin Finck #include <stdio.h>
22*c2c66affSColin Finck #include <windows.h>
23*c2c66affSColin Finck #include <setupapi.h>
24*c2c66affSColin Finck #include "wine/test.h"
25*c2c66affSColin Finck
26*c2c66affSColin Finck static CHAR CURR_DIR[MAX_PATH];
27*c2c66affSColin Finck static CHAR WIN_DIR[MAX_PATH];
28*c2c66affSColin Finck
get_directories(void)29*c2c66affSColin Finck static void get_directories(void)
30*c2c66affSColin Finck {
31*c2c66affSColin Finck int len;
32*c2c66affSColin Finck
33*c2c66affSColin Finck GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
34*c2c66affSColin Finck len = lstrlenA(CURR_DIR);
35*c2c66affSColin Finck
36*c2c66affSColin Finck if(len && (CURR_DIR[len-1] == '\\'))
37*c2c66affSColin Finck CURR_DIR[len-1] = 0;
38*c2c66affSColin Finck
39*c2c66affSColin Finck GetWindowsDirectoryA(WIN_DIR, MAX_PATH);
40*c2c66affSColin Finck len = lstrlenA(WIN_DIR);
41*c2c66affSColin Finck
42*c2c66affSColin Finck if (len && (WIN_DIR[len-1] == '\\'))
43*c2c66affSColin Finck WIN_DIR[len-1] = 0;
44*c2c66affSColin Finck }
45*c2c66affSColin Finck
46*c2c66affSColin Finck static const char inf_data1[] =
47*c2c66affSColin Finck "[Version]\n"
48*c2c66affSColin Finck "Signature=\"$Chicago$\"\n"
49*c2c66affSColin Finck "AdvancedINF=2.5\n"
50*c2c66affSColin Finck "[SourceDisksNames]\n"
51*c2c66affSColin Finck "2 = %SrcDiskName%, LANCOM\\LANtools\\lanconf.cab\n"
52*c2c66affSColin Finck "[SourceDisksFiles]\n"
53*c2c66affSColin Finck "lanconf.exe = 2\n"
54*c2c66affSColin Finck "[DestinationDirs]\n"
55*c2c66affSColin Finck "DefaultDestDir = 24, %DefaultDest%\n"
56*c2c66affSColin Finck "[Strings]\n"
57*c2c66affSColin Finck "LangDir = english\n"
58*c2c66affSColin Finck "DefaultDest = LANCOM\n"
59*c2c66affSColin Finck "SrcDiskName = \"LANCOM Software CD\"\n";
60*c2c66affSColin Finck
61*c2c66affSColin Finck static const char inf_data2[] =
62*c2c66affSColin Finck "[SourceFileInfo]\n"
63*c2c66affSColin Finck "sp1qfe\\bitsinst.exe=250B3702C7CCD7C2F9E4DAA1555C933E,000600060A28062C,27136,SP1QFE\n"
64*c2c66affSColin Finck "sp1qfe\\bitsprx2.dll=4EBEA67F4BB4EB402E725CA7CA2857AE,000600060A280621,7680,SP1QFE\n"
65*c2c66affSColin Finck "sp1qfe\\bitsprx3.dll=C788A1D9330DA011EF25E95D3BC7BDE5,000600060A280621,7168,SP1QFE\n"
66*c2c66affSColin Finck "sp1qfe\\qmgr.dll=696AC82FB290A03F205901442E0E9589,000600060A280621,361984,SP1QFE\n"
67*c2c66affSColin Finck "sp1qfe\\qmgrprxy.dll=8B5848144829E1BC985EA4C3D8CA7E3F,000600060A280621,17408,SP1QFE\n"
68*c2c66affSColin Finck "sp1qfe\\winhttp.dll=3EC6F518114606CA59D4160322077437,000500010A280615,331776,SP1QFE\n"
69*c2c66affSColin Finck "sp1qfe\\xpob2res.dll=DB83156B9F496F20D1EA70E4ABEC0166,000500010A280622,158720,SP1QFE\n";
70*c2c66affSColin Finck
71*c2c66affSColin Finck static const char inf_data3[] =
72*c2c66affSColin Finck "[Version]\n"
73*c2c66affSColin Finck "Signature = \"$Windows NT$\"\n"
74*c2c66affSColin Finck "[DestinationDirs]\n"
75*c2c66affSColin Finck "CopyAlways.Windir.files = 10\n"
76*c2c66affSColin Finck "[CopyAlways.Windir.Files]\n"
77*c2c66affSColin Finck "WindowsCodecs.dll\n";
78*c2c66affSColin Finck
79*c2c66affSColin Finck static const char inf_data4[] =
80*c2c66affSColin Finck "[Version]\n"
81*c2c66affSColin Finck "Signature = \"$Windows NT$\"\n"
82*c2c66affSColin Finck "[CopyAlways.System32.Files]\n"
83*c2c66affSColin Finck "WindowsCodecs.dll\n";
84*c2c66affSColin Finck
85*c2c66affSColin Finck static const char inf_data5[] =
86*c2c66affSColin Finck "[Version]\n"
87*c2c66affSColin Finck "Signature = \"$Windows NT$\"\n"
88*c2c66affSColin Finck "[DestinationDirs]\n"
89*c2c66affSColin Finck "DefaultDestDir = 11\n"
90*c2c66affSColin Finck "CopyAlways.Windir.files = 10\n"
91*c2c66affSColin Finck "[CopyAlways.Windir.Files]\n"
92*c2c66affSColin Finck "WindowsCodecs.dll\n";
93*c2c66affSColin Finck
94*c2c66affSColin Finck static const char inf_data6[] =
95*c2c66affSColin Finck "[Version]\n"
96*c2c66affSColin Finck "Signature = \"$Windows NT$\"\n"
97*c2c66affSColin Finck "[DestinationDirs]\n"
98*c2c66affSColin Finck "DefaultDestDir = 10\n"
99*c2c66affSColin Finck "[CopyAlways.Windir.Files]\n"
100*c2c66affSColin Finck "WindowsCodecs.dll\n";
101*c2c66affSColin Finck
create_inf_file(LPSTR filename,const char * data,DWORD size)102*c2c66affSColin Finck static BOOL create_inf_file(LPSTR filename, const char *data, DWORD size)
103*c2c66affSColin Finck {
104*c2c66affSColin Finck BOOL ret;
105*c2c66affSColin Finck DWORD dwNumberOfBytesWritten;
106*c2c66affSColin Finck HANDLE hf = CreateFileA(filename, GENERIC_WRITE, 0, NULL,
107*c2c66affSColin Finck CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
108*c2c66affSColin Finck if (hf == INVALID_HANDLE_VALUE) return FALSE;
109*c2c66affSColin Finck ret = WriteFile(hf, data, size, &dwNumberOfBytesWritten, NULL);
110*c2c66affSColin Finck CloseHandle(hf);
111*c2c66affSColin Finck return ret;
112*c2c66affSColin Finck }
113*c2c66affSColin Finck
check_info_filename(PSP_INF_INFORMATION info,LPSTR test)114*c2c66affSColin Finck static BOOL check_info_filename(PSP_INF_INFORMATION info, LPSTR test)
115*c2c66affSColin Finck {
116*c2c66affSColin Finck LPSTR filename;
117*c2c66affSColin Finck DWORD size;
118*c2c66affSColin Finck BOOL ret = FALSE;
119*c2c66affSColin Finck
120*c2c66affSColin Finck if (!SetupQueryInfFileInformationA(info, 0, NULL, 0, &size))
121*c2c66affSColin Finck return FALSE;
122*c2c66affSColin Finck
123*c2c66affSColin Finck filename = HeapAlloc(GetProcessHeap(), 0, size);
124*c2c66affSColin Finck if (!filename)
125*c2c66affSColin Finck return FALSE;
126*c2c66affSColin Finck
127*c2c66affSColin Finck SetupQueryInfFileInformationA(info, 0, filename, size, &size);
128*c2c66affSColin Finck
129*c2c66affSColin Finck if (!lstrcmpiA(test, filename))
130*c2c66affSColin Finck ret = TRUE;
131*c2c66affSColin Finck
132*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, filename);
133*c2c66affSColin Finck return ret;
134*c2c66affSColin Finck }
135*c2c66affSColin Finck
alloc_inf_info(LPCSTR filename,DWORD search,PDWORD size)136*c2c66affSColin Finck static PSP_INF_INFORMATION alloc_inf_info(LPCSTR filename, DWORD search, PDWORD size)
137*c2c66affSColin Finck {
138*c2c66affSColin Finck PSP_INF_INFORMATION info;
139*c2c66affSColin Finck BOOL ret;
140*c2c66affSColin Finck
141*c2c66affSColin Finck ret = SetupGetInfInformationA(filename, search, NULL, 0, size);
142*c2c66affSColin Finck if (!ret)
143*c2c66affSColin Finck return NULL;
144*c2c66affSColin Finck
145*c2c66affSColin Finck info = HeapAlloc(GetProcessHeap(), 0, *size);
146*c2c66affSColin Finck return info;
147*c2c66affSColin Finck }
148*c2c66affSColin Finck
test_SetupGetInfInformation(void)149*c2c66affSColin Finck static void test_SetupGetInfInformation(void)
150*c2c66affSColin Finck {
151*c2c66affSColin Finck PSP_INF_INFORMATION info;
152*c2c66affSColin Finck CHAR inf_filename[MAX_PATH];
153*c2c66affSColin Finck CHAR inf_one[MAX_PATH], inf_two[MAX_PATH];
154*c2c66affSColin Finck LPSTR revfile;
155*c2c66affSColin Finck DWORD size;
156*c2c66affSColin Finck HINF hinf;
157*c2c66affSColin Finck BOOL ret;
158*c2c66affSColin Finck
159*c2c66affSColin Finck lstrcpyA(inf_filename, CURR_DIR);
160*c2c66affSColin Finck lstrcatA(inf_filename, "\\");
161*c2c66affSColin Finck lstrcatA(inf_filename, "test.inf");
162*c2c66affSColin Finck
163*c2c66affSColin Finck /* try an invalid inf handle */
164*c2c66affSColin Finck size = 0xdeadbeef;
165*c2c66affSColin Finck SetLastError(0xbeefcafe);
166*c2c66affSColin Finck ret = SetupGetInfInformationA(NULL, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
167*c2c66affSColin Finck ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
168*c2c66affSColin Finck ok(GetLastError() == ERROR_INVALID_HANDLE ||
169*c2c66affSColin Finck broken(GetLastError() == ERROR_BAD_PATHNAME) || /* win95 */
170*c2c66affSColin Finck broken(GetLastError() == ERROR_FILE_NOT_FOUND) || /* win98 */
171*c2c66affSColin Finck broken(GetLastError() == ERROR_PATH_NOT_FOUND) || /* NT4 */
172*c2c66affSColin Finck broken(GetLastError() == ERROR_INVALID_NAME) || /* win2k */
173*c2c66affSColin Finck broken(GetLastError() == ERROR_GENERAL_SYNTAX), /* another win2k / winMe */
174*c2c66affSColin Finck "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
175*c2c66affSColin Finck ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
176*c2c66affSColin Finck
177*c2c66affSColin Finck /* try an invalid inf filename */
178*c2c66affSColin Finck /* do not use NULL as absolute inf filename on win9x/winMe (crash) */
179*c2c66affSColin Finck if ((GetLastError() != ERROR_BAD_PATHNAME) && /* win95 */
180*c2c66affSColin Finck (GetLastError() != ERROR_FILE_NOT_FOUND) && /* win98 */
181*c2c66affSColin Finck (GetLastError() != ERROR_GENERAL_SYNTAX)) /* winMe */
182*c2c66affSColin Finck {
183*c2c66affSColin Finck size = 0xdeadbeef;
184*c2c66affSColin Finck SetLastError(0xbeefcafe);
185*c2c66affSColin Finck ret = SetupGetInfInformationA(NULL, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size);
186*c2c66affSColin Finck ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
187*c2c66affSColin Finck ok(GetLastError() == ERROR_INVALID_PARAMETER,
188*c2c66affSColin Finck "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
189*c2c66affSColin Finck ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
190*c2c66affSColin Finck }
191*c2c66affSColin Finck
192*c2c66affSColin Finck create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1);
193*c2c66affSColin Finck
194*c2c66affSColin Finck /* try an invalid search flag */
195*c2c66affSColin Finck size = 0xdeadbeef;
196*c2c66affSColin Finck SetLastError(0xbeefcafe);
197*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, -1, NULL, 0, &size);
198*c2c66affSColin Finck ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
199*c2c66affSColin Finck ok(GetLastError() == ERROR_INVALID_PARAMETER,
200*c2c66affSColin Finck "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
201*c2c66affSColin Finck ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
202*c2c66affSColin Finck
203*c2c66affSColin Finck /* try a nonexistent inf file */
204*c2c66affSColin Finck size = 0xdeadbeef;
205*c2c66affSColin Finck SetLastError(0xbeefcafe);
206*c2c66affSColin Finck ret = SetupGetInfInformationA("idontexist", INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size);
207*c2c66affSColin Finck ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
208*c2c66affSColin Finck ok(GetLastError() == ERROR_FILE_NOT_FOUND,
209*c2c66affSColin Finck "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
210*c2c66affSColin Finck ok(size == 0xdeadbeef, "Expected size to remain unchanged\n");
211*c2c66affSColin Finck
212*c2c66affSColin Finck /* successfully open the inf file */
213*c2c66affSColin Finck size = 0xdeadbeef;
214*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, &size);
215*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
216*c2c66affSColin Finck ok(size != 0xdeadbeef, "Expected a valid size on return\n");
217*c2c66affSColin Finck
218*c2c66affSColin Finck /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size' */
219*c2c66affSColin Finck SetLastError(0xbeefcafe);
220*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, &size);
221*c2c66affSColin Finck ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
222*c2c66affSColin Finck ok(GetLastError() == ERROR_INVALID_PARAMETER,
223*c2c66affSColin Finck "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
224*c2c66affSColin Finck
225*c2c66affSColin Finck /* set ReturnBuffer to NULL and ReturnBufferSize to non-zero value 'size-1' */
226*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size-1, &size);
227*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
228*c2c66affSColin Finck
229*c2c66affSColin Finck /* some tests for behaviour with a NULL RequiredSize pointer */
230*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, 0, NULL);
231*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
232*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size - 1, NULL);
233*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
234*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, NULL, size, NULL);
235*c2c66affSColin Finck ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
236*c2c66affSColin Finck
237*c2c66affSColin Finck info = HeapAlloc(GetProcessHeap(), 0, size);
238*c2c66affSColin Finck
239*c2c66affSColin Finck /* try valid ReturnBuffer but too small size */
240*c2c66affSColin Finck SetLastError(0xbeefcafe);
241*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, info, size - 1, &size);
242*c2c66affSColin Finck ok(ret == FALSE, "Expected SetupGetInfInformation to fail\n");
243*c2c66affSColin Finck ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
244*c2c66affSColin Finck "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
245*c2c66affSColin Finck
246*c2c66affSColin Finck /* successfully get the inf information */
247*c2c66affSColin Finck ret = SetupGetInfInformationA(inf_filename, INFINFO_INF_NAME_IS_ABSOLUTE, info, size, &size);
248*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
249*c2c66affSColin Finck ok(check_info_filename(info, inf_filename), "Expected returned filename to be equal\n");
250*c2c66affSColin Finck
251*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, info);
252*c2c66affSColin Finck
253*c2c66affSColin Finck /* try the INFINFO_INF_SPEC_IS_HINF search flag */
254*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
255*c2c66affSColin Finck info = alloc_inf_info(hinf, INFINFO_INF_SPEC_IS_HINF, &size);
256*c2c66affSColin Finck ret = SetupGetInfInformationA(hinf, INFINFO_INF_SPEC_IS_HINF, info, size, &size);
257*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
258*c2c66affSColin Finck ok(check_info_filename(info, inf_filename), "Expected returned filename to be equal\n");
259*c2c66affSColin Finck SetupCloseInfFile(hinf);
260*c2c66affSColin Finck
261*c2c66affSColin Finck lstrcpyA(inf_two, WIN_DIR);
262*c2c66affSColin Finck lstrcatA(inf_two, "\\system32\\");
263*c2c66affSColin Finck lstrcatA(inf_two, "test.inf");
264*c2c66affSColin Finck ret = create_inf_file(inf_two, inf_data1, sizeof(inf_data1) - 1);
265*c2c66affSColin Finck if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
266*c2c66affSColin Finck {
267*c2c66affSColin Finck skip("need admin rights\n");
268*c2c66affSColin Finck goto done;
269*c2c66affSColin Finck }
270*c2c66affSColin Finck ok(ret, "can't create inf file %u\n", GetLastError());
271*c2c66affSColin Finck
272*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, info);
273*c2c66affSColin Finck info = alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH, &size);
274*c2c66affSColin Finck
275*c2c66affSColin Finck /* check if system32 is searched for inf */
276*c2c66affSColin Finck ret = SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH, info, size, &size);
277*c2c66affSColin Finck if (!ret && GetLastError() == ERROR_FILE_NOT_FOUND)
278*c2c66affSColin Finck revfile = inf_one; /* Vista */
279*c2c66affSColin Finck else
280*c2c66affSColin Finck revfile = inf_two;
281*c2c66affSColin Finck
282*c2c66affSColin Finck lstrcpyA(inf_one, WIN_DIR);
283*c2c66affSColin Finck lstrcatA(inf_one, "\\inf\\");
284*c2c66affSColin Finck lstrcatA(inf_one, "test.inf");
285*c2c66affSColin Finck create_inf_file(inf_one, inf_data1, sizeof(inf_data1) - 1);
286*c2c66affSColin Finck
287*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, info);
288*c2c66affSColin Finck info = alloc_inf_info("test.inf", INFINFO_DEFAULT_SEARCH, &size);
289*c2c66affSColin Finck
290*c2c66affSColin Finck /* test the INFINFO_DEFAULT_SEARCH search flag */
291*c2c66affSColin Finck ret = SetupGetInfInformationA("test.inf", INFINFO_DEFAULT_SEARCH, info, size, &size);
292*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed: %d\n", GetLastError());
293*c2c66affSColin Finck ok(check_info_filename(info, inf_one), "Expected returned filename to be equal\n");
294*c2c66affSColin Finck
295*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, info);
296*c2c66affSColin Finck info = alloc_inf_info("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH, &size);
297*c2c66affSColin Finck
298*c2c66affSColin Finck /* test the INFINFO_REVERSE_DEFAULT_SEARCH search flag */
299*c2c66affSColin Finck ret = SetupGetInfInformationA("test.inf", INFINFO_REVERSE_DEFAULT_SEARCH, info, size, &size);
300*c2c66affSColin Finck ok(ret == TRUE, "Expected SetupGetInfInformation to succeed\n");
301*c2c66affSColin Finck ok(check_info_filename(info, revfile), "Expected returned filename to be equal\n");
302*c2c66affSColin Finck
303*c2c66affSColin Finck done:
304*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, info);
305*c2c66affSColin Finck DeleteFileA(inf_filename);
306*c2c66affSColin Finck DeleteFileA(inf_one);
307*c2c66affSColin Finck DeleteFileA(inf_two);
308*c2c66affSColin Finck }
309*c2c66affSColin Finck
test_SetupGetSourceFileLocation(void)310*c2c66affSColin Finck static void test_SetupGetSourceFileLocation(void)
311*c2c66affSColin Finck {
312*c2c66affSColin Finck char buffer[MAX_PATH] = "not empty", inf_filename[MAX_PATH];
313*c2c66affSColin Finck UINT source_id;
314*c2c66affSColin Finck DWORD required, error;
315*c2c66affSColin Finck HINF hinf;
316*c2c66affSColin Finck BOOL ret;
317*c2c66affSColin Finck
318*c2c66affSColin Finck lstrcpyA(inf_filename, CURR_DIR);
319*c2c66affSColin Finck lstrcatA(inf_filename, "\\");
320*c2c66affSColin Finck lstrcatA(inf_filename, "test.inf");
321*c2c66affSColin Finck
322*c2c66affSColin Finck create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1);
323*c2c66affSColin Finck
324*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
325*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
326*c2c66affSColin Finck
327*c2c66affSColin Finck required = 0;
328*c2c66affSColin Finck source_id = 0;
329*c2c66affSColin Finck
330*c2c66affSColin Finck ret = SetupGetSourceFileLocationA(hinf, NULL, "lanconf.exe", &source_id, buffer, sizeof(buffer), &required);
331*c2c66affSColin Finck ok(ret, "SetupGetSourceFileLocation failed\n");
332*c2c66affSColin Finck
333*c2c66affSColin Finck ok(required == 1, "unexpected required size: %d\n", required);
334*c2c66affSColin Finck ok(source_id == 2, "unexpected source id: %d\n", source_id);
335*c2c66affSColin Finck ok(!lstrcmpA("", buffer), "unexpected result string: %s\n", buffer);
336*c2c66affSColin Finck
337*c2c66affSColin Finck SetupCloseInfFile(hinf);
338*c2c66affSColin Finck DeleteFileA(inf_filename);
339*c2c66affSColin Finck
340*c2c66affSColin Finck create_inf_file(inf_filename, inf_data2, sizeof(inf_data2) - 1);
341*c2c66affSColin Finck
342*c2c66affSColin Finck SetLastError(0xdeadbeef);
343*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
344*c2c66affSColin Finck error = GetLastError();
345*c2c66affSColin Finck ok(hinf == INVALID_HANDLE_VALUE, "could open inf file\n");
346*c2c66affSColin Finck ok(error == ERROR_WRONG_INF_STYLE, "got wrong error: %d\n", error);
347*c2c66affSColin Finck
348*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_OLDNT, NULL);
349*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
350*c2c66affSColin Finck
351*c2c66affSColin Finck ret = SetupGetSourceFileLocationA(hinf, NULL, "", &source_id, buffer, sizeof(buffer), &required);
352*c2c66affSColin Finck ok(!ret, "SetupGetSourceFileLocation succeeded\n");
353*c2c66affSColin Finck
354*c2c66affSColin Finck SetupCloseInfFile(hinf);
355*c2c66affSColin Finck DeleteFileA(inf_filename);
356*c2c66affSColin Finck }
357*c2c66affSColin Finck
test_SetupGetSourceInfo(void)358*c2c66affSColin Finck static void test_SetupGetSourceInfo(void)
359*c2c66affSColin Finck {
360*c2c66affSColin Finck char buffer[MAX_PATH], inf_filename[MAX_PATH];
361*c2c66affSColin Finck DWORD required;
362*c2c66affSColin Finck HINF hinf;
363*c2c66affSColin Finck BOOL ret;
364*c2c66affSColin Finck
365*c2c66affSColin Finck lstrcpyA(inf_filename, CURR_DIR);
366*c2c66affSColin Finck lstrcatA(inf_filename, "\\");
367*c2c66affSColin Finck lstrcatA(inf_filename, "test.inf");
368*c2c66affSColin Finck
369*c2c66affSColin Finck create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1);
370*c2c66affSColin Finck
371*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
372*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
373*c2c66affSColin Finck
374*c2c66affSColin Finck required = 0;
375*c2c66affSColin Finck
376*c2c66affSColin Finck ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_PATH, buffer, sizeof(buffer), &required);
377*c2c66affSColin Finck ok(ret, "SetupGetSourceInfoA failed\n");
378*c2c66affSColin Finck
379*c2c66affSColin Finck ok(required == 1, "unexpected required size: %d\n", required);
380*c2c66affSColin Finck ok(!lstrcmpA("", buffer), "unexpected result string: %s\n", buffer);
381*c2c66affSColin Finck
382*c2c66affSColin Finck required = 0;
383*c2c66affSColin Finck buffer[0] = 0;
384*c2c66affSColin Finck
385*c2c66affSColin Finck ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_TAGFILE, buffer, sizeof(buffer), &required);
386*c2c66affSColin Finck ok(ret, "SetupGetSourceInfoA failed\n");
387*c2c66affSColin Finck
388*c2c66affSColin Finck ok(required == 28, "unexpected required size: %d\n", required);
389*c2c66affSColin Finck ok(!lstrcmpA("LANCOM\\LANtools\\lanconf.cab", buffer), "unexpected result string: %s\n", buffer);
390*c2c66affSColin Finck
391*c2c66affSColin Finck required = 0;
392*c2c66affSColin Finck buffer[0] = 0;
393*c2c66affSColin Finck
394*c2c66affSColin Finck ret = SetupGetSourceInfoA(hinf, 2, SRCINFO_DESCRIPTION, buffer, sizeof(buffer), &required);
395*c2c66affSColin Finck ok(ret, "SetupGetSourceInfoA failed\n");
396*c2c66affSColin Finck
397*c2c66affSColin Finck ok(required == 19, "unexpected required size: %d\n", required);
398*c2c66affSColin Finck ok(!lstrcmpA("LANCOM Software CD", buffer), "unexpected result string: %s\n", buffer);
399*c2c66affSColin Finck
400*c2c66affSColin Finck SetupCloseInfFile(hinf);
401*c2c66affSColin Finck DeleteFileA(inf_filename);
402*c2c66affSColin Finck }
403*c2c66affSColin Finck
test_SetupGetTargetPath(void)404*c2c66affSColin Finck static void test_SetupGetTargetPath(void)
405*c2c66affSColin Finck {
406*c2c66affSColin Finck char buffer[MAX_PATH], inf_filename[MAX_PATH];
407*c2c66affSColin Finck char destfile[MAX_PATH];
408*c2c66affSColin Finck DWORD required;
409*c2c66affSColin Finck HINF hinf;
410*c2c66affSColin Finck INFCONTEXT ctx;
411*c2c66affSColin Finck BOOL ret;
412*c2c66affSColin Finck
413*c2c66affSColin Finck lstrcpyA(inf_filename, CURR_DIR);
414*c2c66affSColin Finck lstrcatA(inf_filename, "\\");
415*c2c66affSColin Finck lstrcatA(inf_filename, "test.inf");
416*c2c66affSColin Finck
417*c2c66affSColin Finck create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1);
418*c2c66affSColin Finck
419*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
420*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
421*c2c66affSColin Finck
422*c2c66affSColin Finck ctx.Inf = hinf;
423*c2c66affSColin Finck ctx.CurrentInf = hinf;
424*c2c66affSColin Finck ctx.Section = 7;
425*c2c66affSColin Finck ctx.Line = 0;
426*c2c66affSColin Finck
427*c2c66affSColin Finck required = 0;
428*c2c66affSColin Finck
429*c2c66affSColin Finck ret = SetupGetTargetPathA(hinf, &ctx, NULL, buffer, sizeof(buffer), &required);
430*c2c66affSColin Finck ok(ret, "SetupGetTargetPathA failed\n");
431*c2c66affSColin Finck ok(required == 10, "unexpected required size: %d\n", required);
432*c2c66affSColin Finck /* Retrieve the system drive from the windows directory.
433*c2c66affSColin Finck * (%SystemDrive% is not available on Win9x)
434*c2c66affSColin Finck */
435*c2c66affSColin Finck lstrcpyA(destfile, WIN_DIR);
436*c2c66affSColin Finck destfile[3] = '\0';
437*c2c66affSColin Finck lstrcatA(destfile, "LANCOM");
438*c2c66affSColin Finck ok(!lstrcmpiA(destfile, buffer), "unexpected result string: %s\n", buffer);
439*c2c66affSColin Finck
440*c2c66affSColin Finck SetupCloseInfFile(hinf);
441*c2c66affSColin Finck DeleteFileA(inf_filename);
442*c2c66affSColin Finck
443*c2c66affSColin Finck create_inf_file(inf_filename, inf_data3, sizeof(inf_data3) - 1);
444*c2c66affSColin Finck
445*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
446*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
447*c2c66affSColin Finck
448*c2c66affSColin Finck required = 0;
449*c2c66affSColin Finck
450*c2c66affSColin Finck ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
451*c2c66affSColin Finck ok(ret, "SetupGetTargetPathA failed\n");
452*c2c66affSColin Finck
453*c2c66affSColin Finck lstrcpyA(destfile, WIN_DIR);
454*c2c66affSColin Finck
455*c2c66affSColin Finck ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
456*c2c66affSColin Finck ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
457*c2c66affSColin Finck
458*c2c66affSColin Finck SetupCloseInfFile(hinf);
459*c2c66affSColin Finck DeleteFileA(inf_filename);
460*c2c66affSColin Finck
461*c2c66affSColin Finck create_inf_file(inf_filename, inf_data4, sizeof(inf_data4) - 1);
462*c2c66affSColin Finck
463*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
464*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
465*c2c66affSColin Finck
466*c2c66affSColin Finck required = 0;
467*c2c66affSColin Finck
468*c2c66affSColin Finck ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.System32.Files", buffer, sizeof(buffer), &required);
469*c2c66affSColin Finck ok(ret, "SetupGetTargetPathA failed\n");
470*c2c66affSColin Finck
471*c2c66affSColin Finck GetSystemDirectoryA(destfile, MAX_PATH);
472*c2c66affSColin Finck
473*c2c66affSColin Finck ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
474*c2c66affSColin Finck ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
475*c2c66affSColin Finck
476*c2c66affSColin Finck SetupCloseInfFile(hinf);
477*c2c66affSColin Finck DeleteFileA(inf_filename);
478*c2c66affSColin Finck
479*c2c66affSColin Finck create_inf_file(inf_filename, inf_data5, sizeof(inf_data5) - 1);
480*c2c66affSColin Finck
481*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
482*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
483*c2c66affSColin Finck
484*c2c66affSColin Finck required = 0;
485*c2c66affSColin Finck
486*c2c66affSColin Finck ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
487*c2c66affSColin Finck ok(ret, "SetupGetTargetPathA failed\n");
488*c2c66affSColin Finck
489*c2c66affSColin Finck lstrcpyA(destfile, WIN_DIR);
490*c2c66affSColin Finck
491*c2c66affSColin Finck ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
492*c2c66affSColin Finck ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
493*c2c66affSColin Finck
494*c2c66affSColin Finck SetupCloseInfFile(hinf);
495*c2c66affSColin Finck DeleteFileA(inf_filename);
496*c2c66affSColin Finck
497*c2c66affSColin Finck create_inf_file(inf_filename, inf_data6, sizeof(inf_data6) - 1);
498*c2c66affSColin Finck
499*c2c66affSColin Finck hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
500*c2c66affSColin Finck ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
501*c2c66affSColin Finck
502*c2c66affSColin Finck required = 0;
503*c2c66affSColin Finck
504*c2c66affSColin Finck ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
505*c2c66affSColin Finck ok(ret, "SetupGetTargetPathA failed\n");
506*c2c66affSColin Finck
507*c2c66affSColin Finck lstrcpyA(destfile, WIN_DIR);
508*c2c66affSColin Finck
509*c2c66affSColin Finck ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
510*c2c66affSColin Finck ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
511*c2c66affSColin Finck
512*c2c66affSColin Finck SetupCloseInfFile(hinf);
513*c2c66affSColin Finck DeleteFileA(inf_filename);
514*c2c66affSColin Finck }
515*c2c66affSColin Finck
START_TEST(query)516*c2c66affSColin Finck START_TEST(query)
517*c2c66affSColin Finck {
518*c2c66affSColin Finck get_directories();
519*c2c66affSColin Finck
520*c2c66affSColin Finck test_SetupGetInfInformation();
521*c2c66affSColin Finck test_SetupGetSourceFileLocation();
522*c2c66affSColin Finck test_SetupGetSourceInfo();
523*c2c66affSColin Finck test_SetupGetTargetPath();
524*c2c66affSColin Finck }
525