ReactOS 0.4.16-dev-125-g798ea90
svchlp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define register_service_ex   register_service_exA
 
#define register_service   register_serviceA
 

Functions

void send_msg (const char *type, const char *msg)
 
void service_trace (const char *msg,...)
 
void service_ok (int cnd, const char *msg,...)
 
void service_process (BOOL(*start_service)(PCSTR, PCWSTR), int argc, char **argv)
 
SC_HANDLE register_service_exA (SC_HANDLE scm_handle, PCSTR test_name, PCSTR service_name, PCSTR extra_args OPTIONAL, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCSTR lpLoadOrderGroup OPTIONAL, LPDWORD lpdwTagId OPTIONAL, LPCSTR lpDependencies OPTIONAL, LPCSTR lpServiceStartName OPTIONAL, LPCSTR lpPassword OPTIONAL)
 
SC_HANDLE register_service_exW (SC_HANDLE scm_handle, PCWSTR test_name, PCWSTR service_name, PCWSTR extra_args OPTIONAL, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpLoadOrderGroup OPTIONAL, LPDWORD lpdwTagId OPTIONAL, LPCWSTR lpDependencies OPTIONAL, LPCWSTR lpServiceStartName OPTIONAL, LPCWSTR lpPassword OPTIONAL)
 
SC_HANDLE register_serviceA (SC_HANDLE scm_handle, PCSTR test_name, PCSTR service_name, PCSTR extra_args OPTIONAL)
 
SC_HANDLE register_serviceW (SC_HANDLE scm_handle, PCWSTR test_name, PCWSTR service_name, PCWSTR extra_args OPTIONAL)
 
void test_runner (void(*run_test)(PCSTR, PCWSTR, void *), void *param)
 

Macro Definition Documentation

◆ register_service

#define register_service   register_serviceA

Definition at line 69 of file svchlp.h.

◆ register_service_ex

#define register_service_ex   register_service_exA

Definition at line 68 of file svchlp.h.

Function Documentation

◆ register_service_exA()

SC_HANDLE register_service_exA ( SC_HANDLE  scm_handle,
PCSTR  test_name,
PCSTR  service_name,
PCSTR extra_args  OPTIONAL,
DWORD  dwDesiredAccess,
DWORD  dwServiceType,
DWORD  dwStartType,
DWORD  dwErrorControl,
LPCSTR lpLoadOrderGroup  OPTIONAL,
LPDWORD lpdwTagId  OPTIONAL,
LPCSTR lpDependencies  OPTIONAL,
LPCSTR lpServiceStartName  OPTIONAL,
LPCSTR lpPassword  OPTIONAL 
)

Definition at line 86 of file svchlp.c.

100{
101 SC_HANDLE service;
102 CHAR service_cmd[MAX_PATH+150];
103
104 /* Retrieve our full path */
105 if (!GetModuleFileNameA(NULL, service_cmd, MAX_PATH))
106 {
107 skip("GetModuleFileNameW failed with error %lu!\n", GetLastError());
108 return NULL;
109 }
110
111 /*
112 * Build up our custom command line. The first parameter is the test name,
113 * the second parameter is the flag used to decide whether we should start
114 * as a service.
115 */
116 StringCbCatA(service_cmd, sizeof(service_cmd), " ");
117 StringCbCatA(service_cmd, sizeof(service_cmd), test_name);
118 StringCbCatA(service_cmd, sizeof(service_cmd), " ");
119 StringCbCatA(service_cmd, sizeof(service_cmd), service_name);
120 if (extra_args)
121 {
122 StringCbCatA(service_cmd, sizeof(service_cmd), " ");
123 StringCbCatA(service_cmd, sizeof(service_cmd), extra_args);
124 }
125
126 trace("service_cmd \"%s\"\n", service_cmd);
127
129 dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl,
130 service_cmd, lpLoadOrderGroup, lpdwTagId, lpDependencies,
131 lpServiceStartName, lpPassword);
132 if (!service && GetLastError() == ERROR_ACCESS_DENIED)
133 {
134 skip("Not enough access right to create service.\n");
135 return NULL;
136 }
137
138 ok(service != NULL, "CreateService failed: %lu\n", GetLastError());
139 return service;
140}
static char service_name[100]
static SC_HANDLE scm_handle
Definition: ServiceArgs.c:20
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
static const char * test_name
Definition: run.c:177
SC_HANDLE WINAPI CreateServiceA(SC_HANDLE hSCManager, LPCSTR lpServiceName, LPCSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCSTR lpBinaryPathName, LPCSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCSTR lpDependencies, LPCSTR lpServiceStartName, LPCSTR lpPassword)
Definition: scm.c:680
STRSAFEAPI StringCbCatA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:337
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
char CHAR
Definition: xmlstorage.h:175

Referenced by register_serviceA().

◆ register_service_exW()

SC_HANDLE register_service_exW ( SC_HANDLE  scm_handle,
PCWSTR  test_name,
PCWSTR  service_name,
PCWSTR extra_args  OPTIONAL,
DWORD  dwDesiredAccess,
DWORD  dwServiceType,
DWORD  dwStartType,
DWORD  dwErrorControl,
LPCWSTR lpLoadOrderGroup  OPTIONAL,
LPDWORD lpdwTagId  OPTIONAL,
LPCWSTR lpDependencies  OPTIONAL,
LPCWSTR lpServiceStartName  OPTIONAL,
LPCWSTR lpPassword  OPTIONAL 
)

Definition at line 142 of file svchlp.c.

156{
157 SC_HANDLE service;
158 WCHAR service_cmd[MAX_PATH+150];
159
160 /* Retrieve our full path */
161 if (!GetModuleFileNameW(NULL, service_cmd, MAX_PATH))
162 {
163 skip("GetModuleFileNameW failed with error %lu!\n", GetLastError());
164 return NULL;
165 }
166
167 /*
168 * Build up our custom command line. The first parameter is the test name,
169 * the second parameter is the flag used to decide whether we should start
170 * as a service.
171 */
172 StringCbCatW(service_cmd, sizeof(service_cmd), L" ");
173 StringCbCatW(service_cmd, sizeof(service_cmd), test_name);
174 StringCbCatW(service_cmd, sizeof(service_cmd), L" ");
175 StringCbCatW(service_cmd, sizeof(service_cmd), service_name);
176 if (extra_args)
177 {
178 StringCbCatW(service_cmd, sizeof(service_cmd), L" ");
179 StringCbCatW(service_cmd, sizeof(service_cmd), extra_args);
180 }
181
182 trace("service_cmd \"%ls\"\n", service_cmd);
183
185 dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl,
186 service_cmd, lpLoadOrderGroup, lpdwTagId, lpDependencies,
187 lpServiceStartName, lpPassword);
188 if (!service && GetLastError() == ERROR_ACCESS_DENIED)
189 {
190 skip("Not enough access right to create service.\n");
191 return NULL;
192 }
193
194 ok(service != NULL, "CreateService failed: %lu\n", GetLastError());
195 return service;
196}
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
#define L(x)
Definition: ntvdm.h:50
SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, LPCWSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword)
Definition: scm.c:812
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by my_test_server(), and register_serviceW().

◆ register_serviceA()

SC_HANDLE register_serviceA ( SC_HANDLE  scm_handle,
PCSTR  test_name,
PCSTR  service_name,
PCSTR extra_args  OPTIONAL 
)

Definition at line 198 of file svchlp.c.

203{
209 NULL, NULL, NULL, NULL, NULL);
210}
SC_HANDLE register_service_exA(SC_HANDLE scm_handle, PCSTR test_name, PCSTR service_name, PCSTR extra_args OPTIONAL, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCSTR lpLoadOrderGroup OPTIONAL, LPDWORD lpdwTagId OPTIONAL, LPCSTR lpDependencies OPTIONAL, LPCSTR lpServiceStartName OPTIONAL, LPCSTR lpPassword OPTIONAL)
Definition: svchlp.c:86
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define SERVICE_DEMAND_START
Definition: cmtypes.h:978
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
#define SERVICE_ERROR_IGNORE
Definition: cmtypes.h:981

◆ register_serviceW()

SC_HANDLE register_serviceW ( SC_HANDLE  scm_handle,
PCWSTR  test_name,
PCWSTR  service_name,
PCWSTR extra_args  OPTIONAL 
)

Definition at line 212 of file svchlp.c.

217{
223 NULL, NULL, NULL, NULL, NULL);
224}
SC_HANDLE register_service_exW(SC_HANDLE scm_handle, PCWSTR test_name, PCWSTR service_name, PCWSTR extra_args OPTIONAL, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpLoadOrderGroup OPTIONAL, LPDWORD lpdwTagId OPTIONAL, LPCWSTR lpDependencies OPTIONAL, LPCWSTR lpServiceStartName OPTIONAL, LPCWSTR lpPassword OPTIONAL)
Definition: svchlp.c:142

◆ send_msg()

void send_msg ( const char type,
const char msg 
)

Definition at line 27 of file svchlp.c.

28{
29 DWORD written = 0;
30 char buf[512];
31
32 StringCbPrintfA(buf, sizeof(buf), "%s:%s", type, msg);
33 WriteFile(hClientPipe, buf, lstrlenA(buf)+1, &written, NULL);
34}
#define msg(x)
Definition: auth_time.c:54
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
static HANDLE hClientPipe
Definition: svchlp.c:18

Referenced by service_ok(), and service_trace().

◆ service_ok()

void service_ok ( int  cnd,
const char msg,
  ... 
)

Definition at line 48 of file svchlp.c.

49{
51 char buf[512];
52
54 StringCbVPrintfA(buf, sizeof(buf), msg, valist);
56
57 send_msg(cnd ? "OK" : "FAIL", buf);
58}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static __ms_va_list valist
Definition: printf.c:66
STRSAFEAPI StringCbVPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat, va_list argList)
Definition: strsafe.h:502
void send_msg(const char *type, const char *msg)
Definition: svchlp.c:27

◆ service_process()

void service_process ( BOOL(*)(PCSTR, PCWSTR start_service,
int  argc,
char **  argv 
)

Definition at line 60 of file svchlp.c.

61{
62 BOOL res;
63
66 StringCbPrintfW(named_pipe_name, sizeof(named_pipe_name), L"\\\\.\\pipe\\%ls_pipe", service_nameW);
67
69 if (!res)
70 return;
71
74 return;
75
76 service_trace("Service process starting...\n");
78 service_trace("Service process stopped.\n");
79
81}
#define CloseHandle
Definition: compat.h:739
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define MultiByteToWideChar
Definition: compat.h:110
static HRESULT start_service(const WCHAR *name, VARIANT *retval)
Definition: service.c:169
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint res
Definition: glext.h:9613
#define argv
Definition: mplay32.c:18
BOOL WINAPI WaitNamedPipeW(LPCWSTR lpNamedPipeName, DWORD nTimeOut)
Definition: npipe.c:458
#define GENERIC_WRITE
Definition: nt_native.h:90
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
STRSAFEAPI StringCbCopyA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:161
static CHAR service_nameA[100]
Definition: svchlp.c:21
void service_trace(const char *msg,...)
Definition: svchlp.c:36
static WCHAR service_nameW[100]
Definition: svchlp.c:22
static WCHAR named_pipe_name[100]
Definition: svchlp.c:19
#define NMPWAIT_USE_DEFAULT_WAIT
Definition: winbase.h:134

◆ service_trace()

void service_trace ( const char msg,
  ... 
)

Definition at line 36 of file svchlp.c.

37{
39 char buf[512];
40
42 StringCbVPrintfA(buf, sizeof(buf), msg, valist);
44
45 send_msg("TRACE", buf);
46}

Referenced by service_main(), and service_process().

◆ test_runner()

void test_runner ( void(*)(PCSTR, PCWSTR, void *)  run_test,
void param 
)

Definition at line 280 of file svchlp.c.

281{
282 HANDLE hServerPipe = INVALID_HANDLE_VALUE;
284
285 StringCbPrintfW(service_nameW, sizeof(service_nameW), L"WineTestService%lu", GetTickCount());
287 //trace("service_name: %ls\n", service_nameW);
288 StringCbPrintfW(named_pipe_name, sizeof(named_pipe_name), L"\\\\.\\pipe\\%ls_pipe", service_nameW);
289
291 PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT, 10, 2048, 2048, 10000, NULL);
292 ok(hServerPipe != INVALID_HANDLE_VALUE, "CreateNamedPipe failed: %lu\n", GetLastError());
293 if (hServerPipe == INVALID_HANDLE_VALUE)
294 return;
295
296 hThread = CreateThread(NULL, 0, pipe_thread, (LPVOID)hServerPipe, 0, NULL);
297 ok(hThread != NULL, "CreateThread failed: %lu\n", GetLastError());
298 if (!hThread)
299 goto Quit;
300
302
303 ok(WaitForSingleObject(hThread, 10000) == WAIT_OBJECT_0, "Timeout waiting for thread\n");
304
305Quit:
306 if (hThread)
307 {
308 /* Be sure to kill the thread if it did not already terminate */
311 }
312
313 if (hServerPipe != INVALID_HANDLE_VALUE)
314 CloseHandle(hServerPipe);
315}
#define WideCharToMultiByte
Definition: compat.h:111
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:587
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
GLfloat param
Definition: glext.h:5796
#define run_test(test)
Definition: ms_seh.c:71
HANDLE hThread
Definition: wizard.c:28
HANDLE WINAPI CreateNamedPipeW(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: npipe.c:246
static DWORD WINAPI pipe_thread(void *param)
Definition: svchlp.c:226
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define PIPE_ACCESS_INBOUND
Definition: winbase.h:165
#define PIPE_WAIT
Definition: winbase.h:171
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:168