2 * PROJECT: ReactOS kernel
3 * FILE: regtests/shared/regtests.h
4 * PURPOSE: Regression testing
5 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * 06-07-2003 CSH Created
14 typedef DWORD (STDCALL _LPTHREAD_START_ROUTINE
)(LPVOID lpParameter
);
16 typedef struct __FILETIME
20 } _FILETIME
, *_PFILETIME
, *_LPFILETIME
;
22 extern void SetupOnce();
24 #define _SetupOnce() \
27 /* Valid values for Command parameter of TestRoutine */
28 #define TESTCMD_RUN 0 /* Buffer contains information about what failed */
29 #define TESTCMD_TESTTYPE 1 /* Buffer contains type of test */
30 #define TESTCMD_TESTNAME 2 /* Buffer contains description of test */
31 #define TESTCMD_TIMEOUT 3 /* Buffer contains timeout for test (DWORD, default is 5000 ms) */
36 /* Valid values for return values of TestRoutine */
37 #define TS_TIMEDOUT ((DWORD)-2)
38 #define TS_EXCEPTION ((DWORD)-1)
45 /* Macros to simplify tests */
46 #define _DispatcherTypeTimeout(FunctionName, TestName, TestType, TimeOut) \
48 FunctionName(int Command) \
55 case TESTCMD_TESTTYPE: \
56 *(PDWORD)_Buffer = (DWORD)TestType; \
58 case TESTCMD_TESTNAME: \
59 strcpy(_Buffer, TestName); \
61 case TESTCMD_TIMEOUT: \
62 *(PDWORD)_Buffer = (DWORD)TimeOut; \
65 _Result = TS_FAILED; \
70 #define _DispatcherTimeout(FunctionName, TestName, TimeOut) \
71 _DispatcherTypeTimeout(FunctionName, TestName, TT_NORMAL, TimeOut)
73 #define _DispatcherType(FunctionName, TestName, TestType) \
74 _DispatcherTypeTimeout(FunctionName, TestName, TestType, 5000)
76 #define _Dispatcher(FunctionName, TestName) \
77 _DispatcherTimeout(FunctionName, TestName, 5000)
80 AppendAssertion(char *message
)
82 if (strlen(_Buffer
) != 0)
83 strcat(_Buffer
, "\n");
84 strcat(_Buffer
, message
);
88 #define _AssertTrue(_Condition) \
93 sprintf(_message, "Condition was not true at %s:%d", \
94 __FILE__, __LINE__); \
95 AppendAssertion(_message); \
99 #define _AssertFalse(_Condition) \
103 char _message[100]; \
104 sprintf(_message, "Condition was not false at %s:%d", \
105 __FILE__, __LINE__); \
106 AppendAssertion(_message); \
110 #define _AssertEqualValue(_Expected, _Actual) \
112 ULONG __Expected = (ULONG) (_Expected); \
113 ULONG __Actual = (ULONG) (_Actual); \
114 if ((__Expected) != (__Actual)) \
116 char _message[100]; \
117 sprintf(_message, "Expected %ld/0x%.08lx was %ld/0x%.08lx at %s:%d", \
118 (__Expected), (__Expected), (__Actual), (__Actual), __FILE__, __LINE__); \
119 AppendAssertion(_message); \
123 #define _AssertEqualWideString(_Expected, _Actual) \
125 LPWSTR __Expected = (LPWSTR) (_Expected); \
126 LPWSTR __Actual = (LPWSTR) (_Actual); \
127 if (wcscmp((__Expected), (__Actual)) != 0) \
129 char _message[100]; \
130 sprintf(_message, "Expected %S was %S at %s:%d", \
131 (__Expected), (__Actual), __FILE__, __LINE__); \
132 AppendAssertion(_message); \
136 #define _AssertNotEqualValue(_Expected, _Actual) \
138 ULONG __Expected = (ULONG) (_Expected); \
139 ULONG __Actual = (ULONG) (_Actual); \
140 if ((__Expected) == (__Actual)) \
142 char _message[100]; \
143 sprintf(_message, "Actual value expected to be different from %ld/0x%.08lx at %s:%d", \
144 (__Expected), (__Expected), __FILE__, __LINE__); \
145 AppendAssertion(_message); \
151 * Test routine prototype
152 * Command - The command to process
154 typedef void (*TestRoutine
)(int Command
);
157 * Test output routine prototype
158 * Buffer - Address of buffer with text to output
160 typedef void (*TestOutputRoutine
)(char *Buffer
);
163 * Test driver entry routine.
164 * OutputRoutine - Output routine.
165 * TestName - If NULL all tests are run. If non-NULL specifies the test to be run
167 typedef void STDCALL (*TestDriverMain
)(TestOutputRoutine OutputRoutine
, char *TestName
);
169 typedef struct __TEST
171 LIST_ENTRY ListEntry
;
175 extern VOID
InitializeTests();
176 extern VOID
RegisterTests();
177 extern VOID
PerformTests(TestOutputRoutine OutputRoutine
, LPSTR TestName
);
180 typedef struct __API_DESCRIPTION
184 PCHAR ForwardedFunctionName
;
185 PVOID FunctionAddress
;
186 PVOID MockFunctionAddress
;
187 } _API_DESCRIPTION
, *_PAPI_DESCRIPTION
;
189 extern _API_DESCRIPTION ExternalDependencies
[];
190 extern ULONG MaxExternalDependency
;
193 _GetModuleHandleA(LPCSTR lpModuleName
);
196 _GetProcAddress(HANDLE hModule
,
200 _LoadLibraryA(LPCSTR lpLibFileName
);
203 _ExitProcess(UINT uExitCode
);
206 _CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes
, DWORD dwStackSize
,
207 _LPTHREAD_START_ROUTINE lpStartAddress
, LPVOID lpParameter
,
208 DWORD dwCreationFlags
, LPDWORD lpThreadId
);
211 _TerminateThread(HANDLE hThread
, DWORD dwExitCode
);
214 _WaitForSingleObject(HANDLE hHandle
, DWORD dwMilliseconds
);
220 _CloseHandle(HANDLE handle
);
223 _GetThreadTimes(HANDLE hThread
,
224 _LPFILETIME lpCreationTime
,
225 _LPFILETIME lpExitTime
,
226 _LPFILETIME lpKernelTime
,
227 _LPFILETIME lpUserTime
);
230 _SetPriorityClass(HANDLE hProcess
, DWORD dwPriorityClass
);
233 _SetThreadPriority(HANDLE hThread
, int nPriority
);
236 _GetCurrentProcess();
242 _Sleep(DWORD dwMilliseconds
);
245 static __inline PCHAR
246 FrameworkGetExportedFunctionNameInternal(_PAPI_DESCRIPTION ApiDescription
)
248 if (ApiDescription
->ForwardedFunctionName
!= NULL
)
250 return ApiDescription
->ForwardedFunctionName
;
254 return ApiDescription
->FunctionName
;
258 static __inline PVOID
259 FrameworkGetFunction(_PAPI_DESCRIPTION ApiDescription
)
262 PVOID function
= NULL
;
263 PCHAR exportedFunctionName
;
265 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(ApiDescription
);
267 hModule
= _GetModuleHandleA(ApiDescription
->FileName
);
270 function
= _GetProcAddress(hModule
, exportedFunctionName
);
274 hModule
= _LoadLibraryA(ApiDescription
->FileName
);
277 function
= _GetProcAddress(hModule
, exportedFunctionName
);
278 //FreeLibrary(hModule);
284 static __inline PVOID
285 FrameworkGetHookInternal(ULONG index
)
288 PCHAR exportedFunctionName
;
290 if (index
> MaxExternalDependency
)
293 if (ExternalDependencies
[index
].MockFunctionAddress
!= NULL
)
294 return ExternalDependencies
[index
].MockFunctionAddress
;
296 if (ExternalDependencies
[index
].FunctionAddress
!= NULL
)
297 return ExternalDependencies
[index
].FunctionAddress
;
299 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(&ExternalDependencies
[index
]);
301 printf("Calling function '%s' in DLL '%s'.\n",
302 exportedFunctionName
,
303 ExternalDependencies
[index
].FileName
);
305 address
= FrameworkGetFunction(&ExternalDependencies
[index
]);
309 printf("Function '%s' not found in DLL '%s'.\n",
310 exportedFunctionName
,
311 ExternalDependencies
[index
].FileName
);
313 ExternalDependencies
[index
].FunctionAddress
= address
;
323 _PAPI_DESCRIPTION api
;
326 for (index
= 0; index
<= MaxExternalDependency
; index
++)
328 api
= &ExternalDependencies
[index
];
329 if (strcmp(api
->FunctionName
, name
) == 0)
331 api
->MockFunctionAddress
= address
;
337 typedef struct __HOOK
340 PVOID FunctionAddress
;
344 _SetHooks(_PHOOK hookTable
)
348 hook
= &hookTable
[0];
349 while (hook
->FunctionName
!= NULL
)
351 _SetHook(hook
->FunctionName
,
352 hook
->FunctionAddress
);
358 _UnsetHooks(_PHOOK hookTable
)
362 hook
= &hookTable
[0];
363 while (hook
->FunctionName
!= NULL
)
365 _SetHook(hook
->FunctionName
,
374 _PAPI_DESCRIPTION api
;
377 for (index
= 0; index
<= MaxExternalDependency
; index
++)
379 api
= &ExternalDependencies
[index
];
380 api
->MockFunctionAddress
= NULL
;
384 #endif /* __REGTESTS_H */