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
12 extern void SetupOnce();
14 #define _SetupOnce() \
17 /* Valid values for Command parameter of TestRoutine */
18 #define TESTCMD_RUN 0 /* Buffer contains information about what failed */
19 #define TESTCMD_TESTNAME 1 /* Buffer contains description of test */
20 #define TESTCMD_TIMEOUT 2 /* Buffer contains timeout for test (DWORD, default is 5000 ms) */
22 /* Valid values for return values of TestRoutine */
23 #define TS_EXCEPTION -1
30 /* Macros to simplify tests */
31 #define _DispatcherTimeout(FunctionName, TestName, TimeOut) \
33 FunctionName(int Command) \
40 case TESTCMD_TESTNAME: \
41 strcpy(_Buffer, TestName); \
43 case TESTCMD_TIMEOUT: \
44 *(PDWORD)_Buffer = (DWORD)TimeOut; \
47 _Result = TS_FAILED; \
52 #define _Dispatcher(FunctionName, TestName) _DispatcherTimeout(FunctionName, TestName, 5000)
55 AppendAssertion(char *message
)
57 if (strlen(_Buffer
) != 0)
58 strcat(_Buffer
, "\n");
59 strcat(_Buffer
, message
);
63 #define _AssertTrue(_Condition) \
68 sprintf(_message, "Condition was not true at %s:%d", \
69 __FILE__, __LINE__); \
70 AppendAssertion(_message); \
74 #define _AssertFalse(_Condition) \
79 sprintf(_message, "Condition was not false at %s:%d", \
80 __FILE__, __LINE__); \
81 AppendAssertion(_message); \
85 #define _AssertEqualValue(_Expected, _Actual) \
87 ULONG __Expected = (ULONG) (_Expected); \
88 ULONG __Actual = (ULONG) (_Actual); \
89 if ((__Expected) != (__Actual)) \
92 sprintf(_message, "Expected %ld/0x%.08lx was %ld/0x%.08lx at %s:%d", \
93 (__Expected), (__Expected), (__Actual), (__Actual), __FILE__, __LINE__); \
94 AppendAssertion(_message); \
98 #define _AssertEqualWideString(_Expected, _Actual) \
100 LPWSTR __Expected = (LPWSTR) (_Expected); \
101 LPWSTR __Actual = (LPWSTR) (_Actual); \
102 if (wcscmp((__Expected), (__Actual)) != 0) \
104 char _message[100]; \
105 sprintf(_message, "Expected %S was %S at %s:%d", \
106 (__Expected), (__Actual), __FILE__, __LINE__); \
107 AppendAssertion(_message); \
111 #define _AssertNotEqualValue(_Expected, _Actual) \
113 ULONG __Expected = (ULONG) (_Expected); \
114 ULONG __Actual = (ULONG) (_Actual); \
115 if ((__Expected) == (__Actual)) \
117 char _message[100]; \
118 sprintf(_message, "Actual value expected to be different from %ld/0x%.08lx at %s:%d", \
119 (__Expected), (__Expected), __FILE__, __LINE__); \
120 AppendAssertion(_message); \
126 * Test routine prototype
127 * Command - The command to process
129 typedef void (*TestRoutine
)(int Command
);
132 * Test output routine prototype
133 * Buffer - Address of buffer with text to output
135 typedef void (*TestOutputRoutine
)(char *Buffer
);
138 * Test driver entry routine.
139 * OutputRoutine - Output routine.
140 * TestName - If NULL all tests are run. If non-NULL specifies the test to be run
142 typedef void STDCALL (*TestDriverMain
)(TestOutputRoutine OutputRoutine
, char *TestName
);
144 typedef struct _ROS_TEST
146 LIST_ENTRY ListEntry
;
148 } ROS_TEST
, *PROS_TEST
;
150 extern VOID
InitializeTests();
151 extern VOID
RegisterTests();
152 extern VOID
PerformTests(TestOutputRoutine OutputRoutine
, LPSTR TestName
);
155 typedef struct _API_DESCRIPTION
159 PCHAR ForwardedFunctionName
;
160 PVOID FunctionAddress
;
161 PVOID MockFunctionAddress
;
162 } API_DESCRIPTION
, *PAPI_DESCRIPTION
;
164 extern API_DESCRIPTION ExternalDependencies
[];
165 extern ULONG MaxExternalDependency
;
168 _GetModuleHandleA(LPCSTR lpModuleName
);
171 _GetProcAddress(HANDLE hModule
,
175 _LoadLibraryA(LPCSTR lpLibFileName
);
178 _ExitProcess(UINT uExitCode
);
181 _CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes
, DWORD dwStackSize
,
182 LPTHREAD_START_ROUTINE lpStartAddress
, LPVOID lpParameter
,
183 DWORD dwCreationFlags
, LPDWORD lpThreadId
);
186 _TerminateThread(HANDLE hThread
, DWORD dwExitCode
);
189 _WaitForSingleObject(HANDLE hHandle
, DWORD dwMilliseconds
);
195 _CloseHandle(HANDLE handle
);
198 _GetThreadTimes(HANDLE hThread
, LPFILETIME lpCreationTime
,
199 LPFILETIME lpExitTime
, LPFILETIME lpKernelTime
,
200 LPFILETIME lpUserTime
);
203 _SetPriorityClass(HANDLE hProcess
, DWORD dwPriorityClass
);
206 _SetThreadPriority(HANDLE hThread
, int nPriority
);
210 FrameworkGetExportedFunctionNameInternal(PAPI_DESCRIPTION ApiDescription
)
212 if (ApiDescription
->ForwardedFunctionName
!= NULL
)
214 return ApiDescription
->ForwardedFunctionName
;
218 return ApiDescription
->FunctionName
;
223 FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription
)
226 PVOID function
= NULL
;
227 PCHAR exportedFunctionName
;
229 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(ApiDescription
);
231 hModule
= _GetModuleHandleA(ApiDescription
->FileName
);
234 function
= _GetProcAddress(hModule
, exportedFunctionName
);
238 hModule
= _LoadLibraryA(ApiDescription
->FileName
);
241 function
= _GetProcAddress(hModule
, exportedFunctionName
);
242 //FreeLibrary(hModule);
249 FrameworkGetHookInternal(ULONG index
)
252 PCHAR exportedFunctionName
;
254 if (index
> MaxExternalDependency
)
257 if (ExternalDependencies
[index
].MockFunctionAddress
!= NULL
)
258 return ExternalDependencies
[index
].MockFunctionAddress
;
260 if (ExternalDependencies
[index
].FunctionAddress
!= NULL
)
261 return ExternalDependencies
[index
].FunctionAddress
;
263 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(&ExternalDependencies
[index
]);
265 printf("Calling function '%s' in DLL '%s'.\n",
266 exportedFunctionName
,
267 ExternalDependencies
[index
].FileName
);
269 address
= FrameworkGetFunction(&ExternalDependencies
[index
]);
273 printf("Function '%s' not found in DLL '%s'.\n",
274 exportedFunctionName
,
275 ExternalDependencies
[index
].FileName
);
277 ExternalDependencies
[index
].FunctionAddress
= address
;
287 PAPI_DESCRIPTION api
;
290 for (index
= 0; index
<= MaxExternalDependency
; index
++)
292 api
= &ExternalDependencies
[index
];
293 if (strcmp(api
->FunctionName
, name
) == 0)
295 api
->MockFunctionAddress
= address
;
304 PVOID FunctionAddress
;
308 _SetHooks(PHOOK hookTable
)
312 hook
= &hookTable
[0];
313 while (hook
->FunctionName
!= NULL
)
315 _SetHook(hook
->FunctionName
,
316 hook
->FunctionAddress
);
322 _UnsetHooks(PHOOK hookTable
)
326 hook
= &hookTable
[0];
327 while (hook
->FunctionName
!= NULL
)
329 _SetHook(hook
->FunctionName
,
338 PAPI_DESCRIPTION api
;
341 for (index
= 0; index
<= MaxExternalDependency
; index
++)
343 api
= &ExternalDependencies
[index
];
344 api
->MockFunctionAddress
= NULL
;