2 * SetupAPI device class-related functions tests
4 * Copyright 2015 Víctor Martínez (victor.martinez@reactos.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence as
8 * published by the Free Software Foundation; either version 2 of
9 * 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 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this library; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 static const char inffile
[] = "test.inf";
30 static char CURR_DIR
[MAX_PATH
];
34 static void create_inf_file(LPCSTR filename
, const char *data
)
38 HANDLE handle
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
,
39 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
40 assert(handle
!= INVALID_HANDLE_VALUE
);
41 ret
= WriteFile(handle
, data
, strlen(data
), &res
, NULL
);
46 /* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
48 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
50 return nCode
== HCBT_CREATEWND
? 1: CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
53 static void test_SetupInstallServicesFromInfSectionExA(void)
59 SC_HANDLE scm_handle
, svc_handle
;
61 /* Bail out if we are on win98 */
62 SetLastError(0xdeadbeef);
63 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
65 if (!scm_handle
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
67 win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
70 CloseServiceHandle(scm_handle
);
72 /* Basic inf file to satisfy SetupOpenInfFileA */
73 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
74 create_inf_file(inffile
, inf
);
75 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
76 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
78 /* Nothing but the Version section */
79 SetLastError(0xdeadbeef);
80 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "trolololo", 0, NULL
, NULL
, NULL
,NULL
);
81 ok(!ret
, "Expected failure\n");
82 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
83 "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
84 SetupCloseInfFile(infhandle
);
89 strcat(inf
, "[Winetest.Services]\n");
90 create_inf_file(inffile
, inf
);
91 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
92 SetLastError(0xdeadbeef);
93 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
94 ok(!ret
, "Expected failure\n");
95 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
96 "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
97 SetupCloseInfFile(infhandle
);
100 /* Add a reference */
101 strcat(inf
, "AddService=Winetest,,Winetest.Service\n");
102 create_inf_file(inffile
, inf
);
103 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
104 SetLastError(0xdeadbeef);
105 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
106 ok(!ret
, "Expected failure\n");
107 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
108 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
109 SetupCloseInfFile(infhandle
);
110 DeleteFileA(inffile
);
112 /* Add the section */
113 strcat(inf
, "[Winetest.Service]\n");
114 create_inf_file(inffile
, inf
);
115 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
116 SetLastError(0xdeadbeef);
117 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
118 ok(!ret
, "Expected failure\n");
119 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
120 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
121 SetupCloseInfFile(infhandle
);
122 DeleteFileA(inffile
);
124 /* Just the ServiceBinary */
125 strcat(inf
, "ServiceBinary=%12%\\winetest.sys\n");
126 create_inf_file(inffile
, inf
);
127 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
128 SetLastError(0xdeadbeef);
129 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
130 ok(!ret
, "Expected failure\n");
131 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
132 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
133 SetupCloseInfFile(infhandle
);
134 DeleteFileA(inffile
);
136 /* Add the ServiceType */
137 strcat(inf
, "ServiceType=1\n");
138 create_inf_file(inffile
, inf
);
139 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
140 SetLastError(0xdeadbeef);
141 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
142 ok(!ret
, "Expected failure\n");
143 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
144 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
145 SetupCloseInfFile(infhandle
);
146 DeleteFileA(inffile
);
148 /* Add the StartType */
149 strcat(inf
, "StartType=4\n");
150 create_inf_file(inffile
, inf
);
151 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
152 SetLastError(0xdeadbeef);
153 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
154 ok(!ret
, "Expected failure\n");
155 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
156 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
157 SetupCloseInfFile(infhandle
);
158 DeleteFileA(inffile
);
160 /* This should be it, the minimal entries to install a service */
161 strcat(inf
, "ErrorControl=1");
162 create_inf_file(inffile
, inf
);
163 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
164 SetLastError(0xdeadbeef);
165 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
166 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
168 skip("Not enough rights to install the service\n");
169 SetupCloseInfFile(infhandle
);
170 DeleteFileA(inffile
);
173 ok(ret
, "Expected success\n");
174 ok(GetLastError() == ERROR_SUCCESS
,
175 "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
176 SetupCloseInfFile(infhandle
);
177 DeleteFileA(inffile
);
179 scm_handle
= OpenSCManagerA(NULL
, NULL
, GENERIC_ALL
);
181 /* Open the service to see if it's really there */
182 svc_handle
= OpenServiceA(scm_handle
, "Winetest", DELETE
);
183 ok(svc_handle
!= NULL
, "Service was not created\n");
185 SetLastError(0xdeadbeef);
186 ret
= DeleteService(svc_handle
);
187 ok(ret
, "Service could not be deleted : %d\n", (int)GetLastError());
189 CloseServiceHandle(svc_handle
);
190 CloseServiceHandle(scm_handle
);
192 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
193 strcat(inf
, "[XSP.InstallPerVer]\n");
194 strcat(inf
, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
195 create_inf_file(inffile
, inf
);
196 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
197 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
199 SetLastError(0xdeadbeef);
200 ret
= SetupInstallServicesFromInfSectionExA(infhandle
, "XSP.InstallPerVer", 0, NULL
, NULL
, NULL
,NULL
);
201 ok(ret
, "Expected success\n");
202 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
203 SetupCloseInfFile(infhandle
);
204 DeleteFileA(inffile
);
206 /* TODO: Test the Flags */
208 static void test_SetupInstallServicesFromInfSectionExW(void)
214 SC_HANDLE scm_handle
, svc_handle
;
216 /* Bail out if we are on win98 */
217 SetLastError(0xdeadbeef);
218 scm_handle
= OpenSCManagerW(NULL
, NULL
, GENERIC_ALL
);
220 if (!scm_handle
&& (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
))
222 win_skip("OpenSCManagerW is not implemented, we are most likely on win9x\n");
225 CloseServiceHandle(scm_handle
);
227 /* Basic inf file to satisfy SetupOpenInfFileA */
228 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
229 create_inf_file(inffile
, inf
);
230 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
231 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
233 /* Nothing but the Version section */
234 SetLastError(0xdeadbeef);
235 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"trolololo", 0, NULL
, NULL
, NULL
,NULL
);
236 ok(!ret
, "Expected failure\n");
237 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
238 "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
239 SetupCloseInfFile(infhandle
);
240 DeleteFileA(inffile
);
243 /* Add the section */
244 strcat(inf
, "[Winetest.Services]\n");
245 create_inf_file(inffile
, inf
);
246 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
247 SetLastError(0xdeadbeef);
248 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
249 ok(!ret
, "Expected failure\n");
250 ok(GetLastError() == ERROR_SECTION_NOT_FOUND
,
251 "Expected ERROR_SECTION_NOT_FOUND, got %08d\n", (int)GetLastError());
252 SetupCloseInfFile(infhandle
);
253 DeleteFileA(inffile
);
255 /* Add a reference */
256 strcat(inf
, "AddService=Winetest,,Winetest.Service\n");
257 create_inf_file(inffile
, inf
);
258 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
259 SetLastError(0xdeadbeef);
260 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
261 ok(!ret
, "Expected failure\n");
262 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
263 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
264 SetupCloseInfFile(infhandle
);
265 DeleteFileA(inffile
);
267 /* Add the section */
268 strcat(inf
, "[Winetest.Service]\n");
269 create_inf_file(inffile
, inf
);
270 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
271 SetLastError(0xdeadbeef);
272 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
273 ok(!ret
, "Expected failure\n");
274 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
275 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
276 SetupCloseInfFile(infhandle
);
277 DeleteFileA(inffile
);
279 /* Just the ServiceBinary */
280 strcat(inf
, "ServiceBinary=%12%\\winetest.sys\n");
281 create_inf_file(inffile
, inf
);
282 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
283 SetLastError(0xdeadbeef);
284 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
285 ok(!ret
, "Expected failure\n");
286 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
287 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
288 SetupCloseInfFile(infhandle
);
289 DeleteFileA(inffile
);
291 /* Add the ServiceType */
292 strcat(inf
, "ServiceType=1\n");
293 create_inf_file(inffile
, inf
);
294 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
295 SetLastError(0xdeadbeef);
296 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
297 ok(!ret
, "Expected failure\n");
298 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
299 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
300 SetupCloseInfFile(infhandle
);
301 DeleteFileA(inffile
);
303 /* Add the StartType */
304 strcat(inf
, "StartType=4\n");
305 create_inf_file(inffile
, inf
);
306 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
307 SetLastError(0xdeadbeef);
308 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
309 ok(!ret
, "Expected failure\n");
310 ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT
,
311 "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08d\n", (int)GetLastError());
312 SetupCloseInfFile(infhandle
);
313 DeleteFileA(inffile
);
315 /* This should be it, the minimal entries to install a service */
316 strcat(inf
, "ErrorControl=1");
317 create_inf_file(inffile
, inf
);
318 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
319 SetLastError(0xdeadbeef);
320 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"Winetest.Services", 0, NULL
, NULL
, NULL
, NULL
);
321 if (!ret
&& GetLastError() == ERROR_ACCESS_DENIED
)
323 skip("Not enough rights to install the service\n");
324 SetupCloseInfFile(infhandle
);
325 DeleteFileA(inffile
);
328 ok(ret
, "Expected success\n");
329 ok(GetLastError() == ERROR_SUCCESS
,
330 "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
331 SetupCloseInfFile(infhandle
);
332 DeleteFileA(inffile
);
334 scm_handle
= OpenSCManagerW(NULL
, NULL
, GENERIC_ALL
);
336 /* Open the service to see if it's really there */
337 svc_handle
= OpenServiceW(scm_handle
, L
"Winetest", DELETE
);
338 ok(svc_handle
!= NULL
, "Service was not created\n");
340 SetLastError(0xdeadbeef);
341 ret
= DeleteService(svc_handle
);
342 ok(ret
, "Service could not be deleted : %d\n", (int)GetLastError());
344 CloseServiceHandle(svc_handle
);
345 CloseServiceHandle(scm_handle
);
347 strcpy(inf
, "[Version]\nSignature=\"$Chicago$\"\n");
348 strcat(inf
, "[XSP.InstallPerVer]\n");
349 strcat(inf
, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
350 create_inf_file(inffile
, inf
);
351 sprintf(path
, "%s\\%s", CURR_DIR
, inffile
);
352 infhandle
= SetupOpenInfFileA(path
, NULL
, INF_STYLE_WIN4
, NULL
);
354 SetLastError(0xdeadbeef);
355 ret
= SetupInstallServicesFromInfSectionExW(infhandle
, L
"XSP.InstallPerVer", 0, NULL
, NULL
, NULL
, NULL
);
356 ok(ret
, "Expected success\n");
357 ok(GetLastError() == ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %08d\n", (int)GetLastError());
358 SetupCloseInfFile(infhandle
);
359 DeleteFileA(inffile
);
361 /* TODO: Test the Flags */
365 START_TEST(SetupInstallServicesFromInfSectionEx
)
367 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
369 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
370 GetTempPathA(MAX_PATH
, temp_path
);
371 SetCurrentDirectoryA(temp_path
);
373 strcpy(CURR_DIR
, temp_path
);
375 /* Set CBT hook to disallow MessageBox creation in current thread */
376 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
379 test_SetupInstallServicesFromInfSectionExA();
380 test_SetupInstallServicesFromInfSectionExW();
382 UnhookWindowsHookEx(hhook
);
383 SetCurrentDirectoryA(prev_path
);