advapi32/service: Test for duplicate displayname.
[wine/gsoc_dplay.git] / dlls / advapi32 / tests / service.c
blob4013988488a93a9c97c6d69e7dcdc841acca1015
1 /*
2 * Unit tests for service functions
4 * Copyright (c) 2007 Paul Vriens
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winsvc.h"
27 #include "lmcons.h"
29 #include "wine/test.h"
31 static void test_open_scm(void)
33 SC_HANDLE scm_handle;
35 /* No access rights */
36 SetLastError(0xdeadbeef);
37 scm_handle = OpenSCManagerA(NULL, NULL, 0);
38 ok(scm_handle != NULL, "Expected success\n");
39 ok(GetLastError() == ERROR_SUCCESS /* W2K3, Vista */ ||
40 GetLastError() == 0xdeadbeef /* NT4, XP */ ||
41 GetLastError() == ERROR_IO_PENDING /* W2K */,
42 "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
43 CloseServiceHandle(scm_handle);
45 /* Unknown database name */
46 SetLastError(0xdeadbeef);
47 scm_handle = OpenSCManagerA(NULL, "DoesNotExist", SC_MANAGER_CONNECT);
48 ok(!scm_handle, "Expected failure\n");
49 ok(GetLastError() == ERROR_INVALID_NAME, "Expected ERROR_INVALID_NAME, got %d\n", GetLastError());
50 CloseServiceHandle(scm_handle); /* Just in case */
52 /* MSDN says only ServiceActive is allowed, or NULL */
53 SetLastError(0xdeadbeef);
54 scm_handle = OpenSCManagerA(NULL, SERVICES_FAILED_DATABASEA, SC_MANAGER_CONNECT);
55 ok(!scm_handle, "Expected failure\n");
56 ok(GetLastError() == ERROR_DATABASE_DOES_NOT_EXIST, "Expected ERROR_DATABASE_DOES_NOT_EXIST, got %d\n", GetLastError());
57 CloseServiceHandle(scm_handle); /* Just in case */
59 /* Remote unknown host */
60 SetLastError(0xdeadbeef);
61 scm_handle = OpenSCManagerA("DOESNOTEXIST", SERVICES_ACTIVE_DATABASEA, SC_MANAGER_CONNECT);
62 ok(!scm_handle, "Expected failure\n");
63 todo_wine
64 ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE, "Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
65 CloseServiceHandle(scm_handle); /* Just in case */
67 /* Proper call with an empty hostname */
68 SetLastError(0xdeadbeef);
69 scm_handle = OpenSCManagerA("", SERVICES_ACTIVE_DATABASEA, SC_MANAGER_CONNECT);
70 ok(scm_handle != NULL, "Expected success\n");
71 ok(GetLastError() == ERROR_SUCCESS /* W2K3, Vista */ ||
72 GetLastError() == ERROR_ENVVAR_NOT_FOUND /* NT4 */ ||
73 GetLastError() == 0xdeadbeef /* XP */ ||
74 GetLastError() == ERROR_IO_PENDING /* W2K */,
75 "Expected ERROR_SUCCESS, ERROR_IO_PENDING, ERROR_ENVVAR_NOT_FOUND or 0xdeadbeef, got %d\n", GetLastError());
76 CloseServiceHandle(scm_handle);
78 /* Again a correct one */
79 SetLastError(0xdeadbeef);
80 scm_handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
81 ok(scm_handle != NULL, "Expected success\n");
82 ok(GetLastError() == ERROR_SUCCESS /* W2K3, Vista */ ||
83 GetLastError() == 0xdeadbeef /* NT4, XP */ ||
84 GetLastError() == ERROR_IO_PENDING /* W2K */,
85 "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
86 CloseServiceHandle(scm_handle);
89 static void test_open_svc(void)
91 SC_HANDLE scm_handle, svc_handle;
93 /* All NULL (invalid access rights) */
94 SetLastError(0xdeadbeef);
95 svc_handle = OpenServiceA(NULL, NULL, 0);
96 ok(!svc_handle, "Expected failure\n");
97 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
99 /* TODO: Add some tests with invalid handles. These produce errors on Windows but crash on Wine */
101 /* NULL service */
102 scm_handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
103 SetLastError(0xdeadbeef);
104 svc_handle = OpenServiceA(scm_handle, NULL, GENERIC_READ);
105 ok(!svc_handle, "Expected failure\n");
106 ok(GetLastError() == ERROR_INVALID_ADDRESS /* W2K, XP, W2K3, Vista */ ||
107 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
108 "Expected ERROR_INVALID_ADDRESS or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
110 /* Non-existent service */
111 scm_handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
112 SetLastError(0xdeadbeef);
113 svc_handle = OpenServiceA(scm_handle, "deadbeef", GENERIC_READ);
114 ok(!svc_handle, "Expected failure\n");
115 ok(GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST, "Expected ERROR_SERVICE_DOES_NOT_EXIST, got %d\n", GetLastError());
116 CloseServiceHandle(scm_handle);
118 /* Proper SCM handle but different access rights */
119 scm_handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
120 SetLastError(0xdeadbeef);
121 svc_handle = OpenServiceA(scm_handle, "Spooler", GENERIC_WRITE);
122 if (!svc_handle && (GetLastError() == ERROR_ACCESS_DENIED))
123 skip("Not enough rights to get a handle to the service\n");
124 else
126 ok(svc_handle != NULL, "Expected success\n");
127 ok(GetLastError() == ERROR_SUCCESS /* W2K3, Vista */ ||
128 GetLastError() == ERROR_IO_PENDING /* W2K */ ||
129 GetLastError() == 0xdeadbeef /* XP, NT4 */,
130 "Expected ERROR_SUCCESS or 0xdeadbeef, got %d\n", GetLastError());
131 CloseServiceHandle(svc_handle);
133 CloseServiceHandle(scm_handle);
136 static void test_create_delete_svc(void)
138 SC_HANDLE scm_handle, svc_handle1;
139 CHAR username[UNLEN + 1];
140 DWORD user_size = UNLEN + 1;
141 CHAR account[UNLEN + 3];
142 static const CHAR servicename [] = "Winetest";
143 static const CHAR pathname [] = "we_dont_care.exe";
144 static const CHAR empty [] = "";
145 static const CHAR spooler [] = "Spooler"; /* Should be available on all platforms */
146 static const CHAR password [] = "secret";
147 BOOL spooler_exists = FALSE;
148 BOOL ret;
149 CHAR display[4096];
150 DWORD display_size = sizeof(display);
152 /* Get the username and turn it into an account to be used in some tests */
153 GetUserNameA(username, &user_size);
154 lstrcpy(account, ".\\");
155 lstrcat(account, username);
157 /* All NULL */
158 SetLastError(0xdeadbeef);
159 svc_handle1 = CreateServiceA(NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
160 ok(!svc_handle1, "Expected failure\n");
161 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
163 scm_handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
165 /* Only a valid handle to the Service Control Manager */
166 SetLastError(0xdeadbeef);
167 svc_handle1 = CreateServiceA(scm_handle, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
168 ok(!svc_handle1, "Expected failure\n");
169 ok(GetLastError() == ERROR_INVALID_ADDRESS /* W2K, W2K3, XP, Vista */ ||
170 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
171 "Expected ERROR_INVALID_ADDRESS or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
173 /* Now with a servicename */
174 SetLastError(0xdeadbeef);
175 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
176 ok(!svc_handle1, "Expected failure\n");
177 ok(GetLastError() == ERROR_INVALID_ADDRESS /* W2K, W2K3, XP, Vista */ ||
178 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
179 "Expected ERROR_INVALID_ADDRESS or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
181 /* Or just a binary name */
182 SetLastError(0xdeadbeef);
183 svc_handle1 = CreateServiceA(scm_handle, NULL, NULL, 0, 0, 0, 0, pathname, NULL, NULL, NULL, NULL, NULL);
184 ok(!svc_handle1, "Expected failure\n");
185 ok(GetLastError() == ERROR_INVALID_ADDRESS /* W2K, W2K3, XP, Vista */ ||
186 GetLastError() == ERROR_INVALID_PARAMETER /* NT4 */,
187 "Expected ERROR_INVALID_ADDRESS or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
189 /* Both servicename and binary name (We only have connect rights) */
190 SetLastError(0xdeadbeef);
191 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, 0, 0, 0, pathname, NULL, NULL, NULL, NULL, NULL);
192 ok(!svc_handle1, "Expected failure\n");
193 ok(GetLastError() == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
195 /* They can even be empty at this stage of parameter checking */
196 SetLastError(0xdeadbeef);
197 svc_handle1 = CreateServiceA(scm_handle, empty, NULL, 0, 0, 0, 0, pathname, NULL, NULL, NULL, NULL, NULL);
198 ok(!svc_handle1, "Expected failure\n");
199 ok(GetLastError() == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
201 SetLastError(0xdeadbeef);
202 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, 0, 0, 0, empty, NULL, NULL, NULL, NULL, NULL);
203 ok(!svc_handle1, "Expected failure\n");
204 ok(GetLastError() == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
206 /* Open the Service Control Manager with minimal rights for creation (verified with 'SC_MANAGER_ALL_ACCESS &~ SC_MANAGER_CREATE_SERVICE') */
207 CloseServiceHandle(scm_handle);
208 SetLastError(0xdeadbeef);
209 scm_handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
210 if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
212 skip("Not enough rights to get a handle to the manager\n");
213 return;
216 /* TODO: It looks like account (ServiceStartName) and (maybe) password are checked at this place */
218 /* Empty strings for servicename and binary name are checked */
219 SetLastError(0xdeadbeef);
220 svc_handle1 = CreateServiceA(scm_handle, empty, NULL, 0, 0, 0, 0, pathname, NULL, NULL, NULL, NULL, NULL);
221 ok(!svc_handle1, "Expected failure\n");
222 ok(GetLastError() == ERROR_INVALID_NAME, "Expected ERROR_INVALID_NAME, got %d\n", GetLastError());
224 SetLastError(0xdeadbeef);
225 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, 0, 0, 0, empty, NULL, NULL, NULL, NULL, NULL);
226 ok(!svc_handle1, "Expected failure\n");
227 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
229 SetLastError(0xdeadbeef);
230 svc_handle1 = CreateServiceA(scm_handle, empty, NULL, 0, 0, 0, 0, empty, NULL, NULL, NULL, NULL, NULL);
231 ok(!svc_handle1, "Expected failure\n");
232 ok(GetLastError() == ERROR_INVALID_NAME, "Expected ERROR_INVALID_NAME, got %d\n", GetLastError());
234 /* Valid call (as we will see later) except for the empty binary name (to proof it's indeed an ERROR_INVALID_PARAMETER */
235 SetLastError(0xdeadbeef);
236 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, SERVICE_WIN32_OWN_PROCESS, SERVICE_DISABLED, 0, empty, NULL, NULL, NULL, NULL, NULL);
237 ok(!svc_handle1, "Expected failure\n");
238 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
240 /* Windows checks if the 'service type', 'access type' and the combination of them are valid, so let's test that */
242 /* Illegal (service-type, which is used as a mask can't have a mix. Except the one with SERVICE_INTERACTIVE_PROCESS which is tested below) */
243 SetLastError(0xdeadbeef);
244 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, GENERIC_ALL, SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS,
245 SERVICE_DISABLED, 0, pathname, NULL, NULL, NULL, NULL, NULL);
246 ok(!svc_handle1, "Expected failure\n");
247 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
249 /* Illegal (SERVICE_INTERACTIVE_PROCESS is only allowed with SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS) */
250 SetLastError(0xdeadbeef);
251 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, GENERIC_ALL, SERVICE_FILE_SYSTEM_DRIVER | SERVICE_INTERACTIVE_PROCESS,
252 SERVICE_DISABLED, 0, pathname, NULL, NULL, NULL, NULL, NULL);
253 ok(!svc_handle1, "Expected failure\n");
254 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
256 /* Illegal (this combination is only allowed when the LocalSystem account (ServiceStartName) is used)
257 * Not having a correct account would have resulted in an ERROR_INVALID_SERVICE_ACCOUNT.
259 SetLastError(0xdeadbeef);
260 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, GENERIC_ALL, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
261 SERVICE_DISABLED, 0, pathname, NULL, NULL, NULL, account, password);
262 ok(!svc_handle1, "Expected failure\n");
263 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
265 /* Illegal (start-type is not a mask and should only be one of the possibilities)
266 * Remark : 'OR'-ing them could result in a valid possibility (but doesn't make sense as it's most likely not the wanted start-type)
268 SetLastError(0xdeadbeef);
269 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, GENERIC_ALL, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START | SERVICE_DISABLED,
270 0, pathname, NULL, NULL, NULL, NULL, NULL);
271 ok(!svc_handle1, "Expected failure\n");
272 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
274 /* Illegal (SERVICE_BOOT_START and SERVICE_SYSTEM_START or only allowed for driver services) */
275 SetLastError(0xdeadbeef);
276 svc_handle1 = CreateServiceA(scm_handle, servicename, NULL, 0, SERVICE_WIN32_OWN_PROCESS, SERVICE_BOOT_START, 0, pathname, NULL, NULL, NULL, NULL, NULL);
277 ok(!svc_handle1, "Expected failure\n");
278 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
280 /* The service already exists (check first, just in case) */
281 svc_handle1 = OpenServiceA(scm_handle, spooler, GENERIC_READ);
282 if (svc_handle1)
284 spooler_exists = TRUE;
285 CloseServiceHandle(svc_handle1);
286 SetLastError(0xdeadbeef);
287 svc_handle1 = CreateServiceA(scm_handle, spooler, NULL, 0, SERVICE_WIN32_OWN_PROCESS, SERVICE_DISABLED, 0, pathname, NULL, NULL, NULL, NULL, NULL);
288 ok(!svc_handle1, "Expected failure\n");
289 ok(GetLastError() == ERROR_SERVICE_EXISTS, "Expected ERROR_SERVICE_EXISTS, got %d\n", GetLastError());
291 else
292 skip("Spooler service doesn't exist\n");
294 /* To find an existing displayname we check the 'Spooler' service. Although the registry doesn't show DisplayName on NT4, this call
295 * will return a displayname which is equal to the servicename and can't be used as well for a new displayname.
297 if (spooler_exists)
299 ret = GetServiceDisplayNameA(scm_handle, spooler, display, &display_size);
301 if (!ret)
302 skip("Could not retrieve a displayname for the Spooler service\n");
303 else
305 svc_handle1 = CreateServiceA(scm_handle, servicename, display, 0, SERVICE_WIN32_OWN_PROCESS, SERVICE_DISABLED, 0,
306 pathname, NULL, NULL, NULL, NULL, NULL);
307 todo_wine
309 ok(!svc_handle1, "Expected failure\n");
310 ok(GetLastError() == ERROR_DUPLICATE_SERVICE_NAME, "Expected ERROR_DUPLICATE_SERVICE_NAME, got %d\n", GetLastError());
314 else
315 skip("Could not retrieve a displayname (Spooler service doesn't exist)\n");
317 /* FIXME: Remove this when Wine is fixed */
318 if (svc_handle1)
320 DeleteService(svc_handle1);
321 CloseServiceHandle(svc_handle1);
324 CloseServiceHandle(scm_handle);
328 static void test_close(void)
330 SC_HANDLE handle;
331 BOOL ret;
333 /* NULL handle */
334 SetLastError(0xdeadbeef);
335 ret = CloseServiceHandle(NULL);
336 todo_wine
338 ok(!ret, "Expected failure\n");
339 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
342 /* TODO: Add some tests with invalid handles. These produce errors on Windows but crash on Wine */
344 /* Proper call */
345 handle = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
346 SetLastError(0xdeadbeef);
347 ret = CloseServiceHandle(handle);
348 ok(ret, "Expected success\n");
349 ok(GetLastError() == ERROR_IO_PENDING /* W2K */ ||
350 GetLastError() == ERROR_SUCCESS /* W2K3 */ ||
351 GetLastError() == 0xdeadbeef /* NT4, XP, Vista */,
352 "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
355 static void test_sequence(void)
357 SC_HANDLE scm_handle, svc_handle;
358 BOOL ret;
359 QUERY_SERVICE_CONFIGA *config;
360 DWORD given, needed;
361 static const CHAR servicename [] = "Winetest";
362 static const CHAR displayname [] = "Winetest dummy service";
363 static const CHAR pathname [] = "we_dont_care.exe";
364 static const CHAR dependencies[] = "Master1\0Master2\0+MasterGroup1\0\0";
365 static const CHAR password [] = "";
366 static const CHAR empty [] = "";
367 static const CHAR localsystem [] = "LocalSystem";
369 SetLastError(0xdeadbeef);
370 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
372 if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
374 skip("Not enough rights to get a handle to the manager\n");
375 return;
377 else
378 ok(scm_handle != NULL, "Could not get a handle to the manager: %d\n", GetLastError());
380 if (!scm_handle) return;
382 /* Create a dummy service */
383 SetLastError(0xdeadbeef);
384 svc_handle = CreateServiceA(scm_handle, servicename, displayname, GENERIC_ALL,
385 SERVICE_INTERACTIVE_PROCESS | SERVICE_WIN32_OWN_PROCESS, SERVICE_DISABLED, SERVICE_ERROR_IGNORE,
386 pathname, NULL, NULL, dependencies, NULL, password);
388 if (!svc_handle && (GetLastError() == ERROR_SERVICE_EXISTS))
390 /* We try and open the service and do the rest of the tests. Some could
391 * fail if the tests were changed between these runs.
393 trace("Deletion probably didn't work last time\n");
394 SetLastError(0xdeadbeef);
395 svc_handle = OpenServiceA(scm_handle, servicename, GENERIC_ALL);
396 if (!svc_handle && (GetLastError() == ERROR_ACCESS_DENIED))
398 skip("Not enough rights to open the service\n");
399 CloseServiceHandle(scm_handle);
400 return;
402 ok(svc_handle != NULL, "Could not open the service : %d\n", GetLastError());
404 else if (!svc_handle && (GetLastError() == ERROR_ACCESS_DENIED))
406 skip("Not enough rights to create the service\n");
407 CloseServiceHandle(scm_handle);
408 return;
410 else
411 ok(svc_handle != NULL, "Could not create the service : %d\n", GetLastError());
413 if (!svc_handle) return;
415 /* TODO:
416 * Before we do a QueryServiceConfig we should check the registry. This will make sure
417 * that the correct keys are used.
420 /* Request the size for the buffer */
421 SetLastError(0xdeadbeef);
422 ret = QueryServiceConfigA(svc_handle, NULL, 0, &needed);
423 ok(!ret, "Expected failure\n");
424 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
426 config = HeapAlloc(GetProcessHeap(), 0, needed);
427 given = needed;
428 SetLastError(0xdeadbeef);
429 ret = QueryServiceConfigA(svc_handle, config, given, &needed);
430 ok(ret, "Expected success\n");
431 todo_wine
433 ok(GetLastError() == ERROR_SUCCESS /* W2K3 */||
434 GetLastError() == 0xdeadbeef /* NT4, XP, Vista */ ||
435 GetLastError() == ERROR_IO_PENDING /* W2K */,
436 "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
437 ok(given == needed, "Expected the given (%d) and needed (%d) buffersizes to be equal\n", given, needed);
439 ok(config->lpBinaryPathName && config->lpLoadOrderGroup && config->lpDependencies && config->lpServiceStartName &&
440 config->lpDisplayName, "Expected all string struct members to be non-NULL\n");
441 ok(config->dwServiceType == (SERVICE_INTERACTIVE_PROCESS | SERVICE_WIN32_OWN_PROCESS),
442 "Expected SERVICE_INTERACTIVE_PROCESS | SERVICE_WIN32_OWN_PROCESS, got %d\n", config->dwServiceType);
443 ok(config->dwStartType == SERVICE_DISABLED, "Expected SERVICE_DISABLED, got %d\n", config->dwStartType);
444 ok(config->dwErrorControl == SERVICE_ERROR_IGNORE, "Expected SERVICE_ERROR_IGNORE, got %d\n", config->dwErrorControl);
445 ok(!strcmp(config->lpBinaryPathName, pathname), "Expected '%s', got '%s'\n", pathname, config->lpBinaryPathName);
446 ok(!strcmp(config->lpLoadOrderGroup, empty), "Expected an empty string, got '%s'\n", config->lpLoadOrderGroup);
447 ok(config->dwTagId == 0, "Expected 0, got %d\n", config->dwTagId);
448 /* TODO: Show the double 0 terminated string */
449 todo_wine
451 ok(!memcmp(config->lpDependencies, dependencies, sizeof(dependencies)), "Wrong string\n");
452 ok(!strcmp(config->lpServiceStartName, localsystem), "Expected 'LocalSystem', got '%s'\n", config->lpServiceStartName);
454 ok(!strcmp(config->lpDisplayName, displayname), "Expected '%s', got '%s'\n", displayname, config->lpDisplayName);
456 SetLastError(0xdeadbeef);
457 ret = DeleteService(svc_handle);
458 ok(ret, "Expected success\n");
459 ok(GetLastError() == ERROR_SUCCESS /* W2K3 */||
460 GetLastError() == 0xdeadbeef /* NT4, XP, Vista */ ||
461 GetLastError() == ERROR_IO_PENDING /* W2K */,
462 "Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
464 CloseServiceHandle(svc_handle);
465 CloseServiceHandle(scm_handle);
468 START_TEST(service)
470 SC_HANDLE scm_handle;
472 /* Bail out if we are on win98 */
473 SetLastError(0xdeadbeef);
474 scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
476 if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
478 skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
479 return;
481 CloseServiceHandle(scm_handle);
483 /* First some parameter checking */
484 test_open_scm();
485 test_open_svc();
486 test_create_delete_svc();
487 test_close();
488 /* Test the creation, querying and deletion of a service */
489 test_sequence();