Commit ac1a0d96 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

advapi32/tests: Tweak the service start/stop tests so they work on NT4.

parent 127b2741
...@@ -2065,12 +2065,11 @@ cleanup: ...@@ -2065,12 +2065,11 @@ cleanup:
CloseServiceHandle(scm_handle); CloseServiceHandle(scm_handle);
} }
static DWORD try_start_stop(SC_HANDLE svc_handle, const char* name, int todo) static DWORD try_start_stop(SC_HANDLE svc_handle, const char* name, int todo, DWORD is_nt4)
{ {
BOOL ret; BOOL ret;
DWORD needed, le1, le2; DWORD le1, le2;
SERVICE_STATUS status; SERVICE_STATUS status;
SERVICE_STATUS_PROCESS statusproc;
ret = StartServiceA(svc_handle, 0, NULL); ret = StartServiceA(svc_handle, 0, NULL);
le1 = GetLastError(); le1 = GetLastError();
...@@ -2078,6 +2077,9 @@ static DWORD try_start_stop(SC_HANDLE svc_handle, const char* name, int todo) ...@@ -2078,6 +2077,9 @@ static DWORD try_start_stop(SC_HANDLE svc_handle, const char* name, int todo)
if (pQueryServiceStatusEx) if (pQueryServiceStatusEx)
{ {
DWORD needed;
SERVICE_STATUS_PROCESS statusproc;
ret = pQueryServiceStatusEx(svc_handle, SC_STATUS_PROCESS_INFO, (BYTE*)&statusproc, sizeof(statusproc), &needed); ret = pQueryServiceStatusEx(svc_handle, SC_STATUS_PROCESS_INFO, (BYTE*)&statusproc, sizeof(statusproc), &needed);
ok(ret, "%s: QueryServiceStatusEx() failed le=%u\n", name, GetLastError()); ok(ret, "%s: QueryServiceStatusEx() failed le=%u\n", name, GetLastError());
todo_wine ok(statusproc.dwCurrentState == SERVICE_STOPPED, "%s: should be stopped state=%x\n", name, statusproc.dwCurrentState); todo_wine ok(statusproc.dwCurrentState == SERVICE_STOPPED, "%s: should be stopped state=%x\n", name, statusproc.dwCurrentState);
...@@ -2092,11 +2094,14 @@ static DWORD try_start_stop(SC_HANDLE svc_handle, const char* name, int todo) ...@@ -2092,11 +2094,14 @@ static DWORD try_start_stop(SC_HANDLE svc_handle, const char* name, int todo)
else else
ok(le2 == le1, "%s: the second try should yield the same error: %u != %u\n", name, le1, le2); ok(le2 == le1, "%s: the second try should yield the same error: %u != %u\n", name, le1, le2);
status.dwCurrentState = 0xdeadbeef;
ret = ControlService(svc_handle, SERVICE_CONTROL_STOP, &status); ret = ControlService(svc_handle, SERVICE_CONTROL_STOP, &status);
le2 = GetLastError(); le2 = GetLastError();
ok(!ret, "%s: ControlService() should have failed\n", name); ok(!ret, "%s: ControlService() should have failed\n", name);
todo_wine ok(le2 == ERROR_SERVICE_NOT_ACTIVE, "%s: %d != ERROR_SERVICE_NOT_ACTIVE\n", name, le2); todo_wine ok(le2 == ERROR_SERVICE_NOT_ACTIVE, "%s: %d != ERROR_SERVICE_NOT_ACTIVE\n", name, le2);
todo_wine ok(status.dwCurrentState == SERVICE_STOPPED, "%s: should be stopped state=%x\n", name, status.dwCurrentState); todo_wine ok(status.dwCurrentState == SERVICE_STOPPED ||
broken(is_nt4), /* NT4 returns a random value */
"%s: should be stopped state=%x\n", name, status.dwCurrentState);
return le1; return le1;
} }
...@@ -2105,7 +2110,7 @@ static void test_start_stop(void) ...@@ -2105,7 +2110,7 @@ static void test_start_stop(void)
{ {
BOOL ret; BOOL ret;
SC_HANDLE scm_handle, svc_handle; SC_HANDLE scm_handle, svc_handle;
DWORD le; DWORD le, is_nt4;
static const char servicename[] = "Winetest"; static const char servicename[] = "Winetest";
char cmd[MAX_PATH+20]; char cmd[MAX_PATH+20];
const char* displayname; const char* displayname;
...@@ -2121,6 +2126,10 @@ static void test_start_stop(void) ...@@ -2121,6 +2126,10 @@ static void test_start_stop(void)
return; return;
} }
/* Detect NT4 */
svc_handle = OpenServiceA(scm_handle, NULL, GENERIC_READ);
is_nt4=(svc_handle == NULL && GetLastError() == ERROR_INVALID_PARAMETER);
/* Do some cleanup in case a previous run crashed */ /* Do some cleanup in case a previous run crashed */
svc_handle = OpenServiceA(scm_handle, servicename, GENERIC_ALL); svc_handle = OpenServiceA(scm_handle, servicename, GENERIC_ALL);
if (svc_handle) if (svc_handle)
...@@ -2144,21 +2153,30 @@ static void test_start_stop(void) ...@@ -2144,21 +2153,30 @@ static void test_start_stop(void)
ok(FALSE, "Could not create the service: %d\n", GetLastError()); ok(FALSE, "Could not create the service: %d\n", GetLastError());
goto cleanup; goto cleanup;
} }
le = try_start_stop(svc_handle, displayname, 1); le = try_start_stop(svc_handle, displayname, 1, is_nt4);
todo_wine ok(le == ERROR_SERVICE_DISABLED, "%d != ERROR_SERVICE_DISABLED\n", le); todo_wine ok(le == ERROR_SERVICE_DISABLED, "%d != ERROR_SERVICE_DISABLED\n", le);
/* Then with a process that exits right away */ /* Then one with a bad path */
displayname = "Winetest Exit Service"; displayname = "Winetest Bad Path";
ret = ChangeServiceConfigA(svc_handle, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, NULL, NULL, displayname); ret = ChangeServiceConfigA(svc_handle, SERVICE_NO_CHANGE, SERVICE_DEMAND_START, SERVICE_NO_CHANGE, "c:\\no_such_file.exe", NULL, NULL, NULL, NULL, NULL, displayname);
ok(ret, "ChangeServiceConfig() failed le=%u\n", GetLastError()); ok(ret, "ChangeServiceConfig() failed le=%u\n", GetLastError());
le = try_start_stop(svc_handle, displayname, 0); try_start_stop(svc_handle, displayname, 0, is_nt4);
todo_wine ok(le == ERROR_SERVICE_REQUEST_TIMEOUT, "%d != ERROR_SERVICE_REQUEST_TIMEOUT\n", le);
/* Again with a bad path */ if (is_nt4)
displayname = "Winetest Bad Path"; {
ret = ChangeServiceConfigA(svc_handle, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, "no_such_file.exe", NULL, NULL, NULL, NULL, NULL, displayname); /* NT4 does not detect when a service fails to start and uses an
* insanely long timeout: 120s. So skip the rest of the tests.
*/
win_skip("Skip some service start/stop tests on NT4\n");
goto cleanup;
}
/* Again with a process that exits right away */
displayname = "Winetest Exit Service";
ret = ChangeServiceConfigA(svc_handle, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, cmd, NULL, NULL, NULL, NULL, NULL, displayname);
ok(ret, "ChangeServiceConfig() failed le=%u\n", GetLastError()); ok(ret, "ChangeServiceConfig() failed le=%u\n", GetLastError());
try_start_stop(svc_handle, displayname, 0); le = try_start_stop(svc_handle, displayname, 0, is_nt4);
todo_wine ok(le == ERROR_SERVICE_REQUEST_TIMEOUT, "%d != ERROR_SERVICE_REQUEST_TIMEOUT\n", le);
/* And finally with a service that plays dead, forcing a timeout. /* And finally with a service that plays dead, forcing a timeout.
* This time we will put no quotes. That should work too, even if there are * This time we will put no quotes. That should work too, even if there are
...@@ -2169,7 +2187,7 @@ static void test_start_stop(void) ...@@ -2169,7 +2187,7 @@ static void test_start_stop(void)
ret = ChangeServiceConfigA(svc_handle, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, cmd, NULL, NULL, NULL, NULL, NULL, displayname); ret = ChangeServiceConfigA(svc_handle, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, cmd, NULL, NULL, NULL, NULL, NULL, displayname);
ok(ret, "ChangeServiceConfig() failed le=%u\n", GetLastError()); ok(ret, "ChangeServiceConfig() failed le=%u\n", GetLastError());
le = try_start_stop(svc_handle, displayname, 0); le = try_start_stop(svc_handle, displayname, 0, is_nt4);
todo_wine ok(le == ERROR_SERVICE_REQUEST_TIMEOUT, "%d != ERROR_SERVICE_REQUEST_TIMEOUT\n", le); todo_wine ok(le == ERROR_SERVICE_REQUEST_TIMEOUT, "%d != ERROR_SERVICE_REQUEST_TIMEOUT\n", le);
cleanup: cleanup:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment