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_TESTTYPE 1 /* Buffer contains type of test */
20 #define TESTCMD_TESTNAME 2 /* Buffer contains description of test */
21 #define TESTCMD_TIMEOUT 3 /* Buffer contains timeout for test (DWORD, default is 5000 ms) */
25 #define TT_PERFORMANCE 1
27 /* Valid values for return values of TestRoutine */
28 #define TS_TIMEDOUT ((DWORD)-2)
29 #define TS_EXCEPTION ((DWORD)-1)
36 /* Macros to simplify tests */
37 #define _DispatcherTypeTimeout(FunctionName, TestName, TestType, TimeOut) \
39 FunctionName(int Command) \
46 case TESTCMD_TESTTYPE: \
47 *(PDWORD)_Buffer = (DWORD)TestType; \
49 case TESTCMD_TESTNAME: \
50 strcpy(_Buffer, TestName); \
52 case TESTCMD_TIMEOUT: \
53 *(PDWORD)_Buffer = (DWORD)TimeOut; \
56 _Result = TS_FAILED; \
61 #define _DispatcherTimeout(FunctionName, TestName, TimeOut) \
62 _DispatcherTypeTimeout(FunctionName, TestName, TT_NORMAL, TimeOut)
64 #define _DispatcherType(FunctionName, TestName, TestType) \
65 _DispatcherTypeTimeout(FunctionName, TestName, TestType, 5000)
67 #define _Dispatcher(FunctionName, TestName) \
68 _DispatcherTimeout(FunctionName, TestName, 5000)
71 AppendAssertion(char *message
)
73 if (strlen(_Buffer
) != 0)
74 strcat(_Buffer
, "\n");
75 strcat(_Buffer
, message
);
79 #define _AssertTrue(_Condition) \
84 sprintf(_message, "Condition was not true at %s:%d", \
85 __FILE__, __LINE__); \
86 AppendAssertion(_message); \
90 #define _AssertFalse(_Condition) \
95 sprintf(_message, "Condition was not false at %s:%d", \
96 __FILE__, __LINE__); \
97 AppendAssertion(_message); \
101 #define _AssertEqualValue(_Expected, _Actual) \
103 ULONG __Expected = (ULONG) (_Expected); \
104 ULONG __Actual = (ULONG) (_Actual); \
105 if ((__Expected) != (__Actual)) \
107 char _message[100]; \
108 sprintf(_message, "Expected %ld/0x%.08lx was %ld/0x%.08lx at %s:%d", \
109 (__Expected), (__Expected), (__Actual), (__Actual), __FILE__, __LINE__); \
110 AppendAssertion(_message); \
114 #define _AssertEqualWideString(_Expected, _Actual) \
116 LPWSTR __Expected = (LPWSTR) (_Expected); \
117 LPWSTR __Actual = (LPWSTR) (_Actual); \
118 if (wcscmp((__Expected), (__Actual)) != 0) \
120 char _message[100]; \
121 sprintf(_message, "Expected %S was %S at %s:%d", \
122 (__Expected), (__Actual), __FILE__, __LINE__); \
123 AppendAssertion(_message); \
127 #define _AssertNotEqualValue(_Expected, _Actual) \
129 ULONG __Expected = (ULONG) (_Expected); \
130 ULONG __Actual = (ULONG) (_Actual); \
131 if ((__Expected) == (__Actual)) \
133 char _message[100]; \
134 sprintf(_message, "Actual value expected to be different from %ld/0x%.08lx at %s:%d", \
135 (__Expected), (__Expected), __FILE__, __LINE__); \
136 AppendAssertion(_message); \
142 * Test routine prototype
143 * Command - The command to process
145 typedef void (*TestRoutine
)(int Command
);
148 * Test output routine prototype
149 * Buffer - Address of buffer with text to output
151 typedef void (*TestOutputRoutine
)(char *Buffer
);
154 * Test driver entry routine.
155 * OutputRoutine - Output routine.
156 * TestName - If NULL all tests are run. If non-NULL specifies the test to be run
158 typedef void STDCALL (*TestDriverMain
)(TestOutputRoutine OutputRoutine
, char *TestName
);
160 typedef struct __TEST
162 LIST_ENTRY ListEntry
;
166 extern VOID
InitializeTests();
167 extern VOID
RegisterTests();
168 extern VOID
PerformTests(TestOutputRoutine OutputRoutine
, LPSTR TestName
);
171 typedef struct __API_DESCRIPTION
175 PCHAR ForwardedFunctionName
;
176 PVOID FunctionAddress
;
177 PVOID MockFunctionAddress
;
178 } _API_DESCRIPTION
, *_PAPI_DESCRIPTION
;
180 extern _API_DESCRIPTION ExternalDependencies
[];
181 extern ULONG MaxExternalDependency
;
184 _GetModuleHandleA(LPCSTR lpModuleName
);
187 _GetProcAddress(HANDLE hModule
,
191 _LoadLibraryA(LPCSTR lpLibFileName
);
194 _ExitProcess(UINT uExitCode
);
197 _CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes
, DWORD dwStackSize
,
198 LPTHREAD_START_ROUTINE lpStartAddress
, LPVOID lpParameter
,
199 DWORD dwCreationFlags
, LPDWORD lpThreadId
);
202 _TerminateThread(HANDLE hThread
, DWORD dwExitCode
);
205 _WaitForSingleObject(HANDLE hHandle
, DWORD dwMilliseconds
);
211 _CloseHandle(HANDLE handle
);
214 _GetThreadTimes(HANDLE hThread
, LPFILETIME lpCreationTime
,
215 LPFILETIME lpExitTime
, LPFILETIME lpKernelTime
,
216 LPFILETIME lpUserTime
);
219 _SetPriorityClass(HANDLE hProcess
, DWORD dwPriorityClass
);
222 _SetThreadPriority(HANDLE hThread
, int nPriority
);
225 _GetCurrentProcess();
231 _GetThreadContext(HANDLE hThread
, LPCONTEXT lpContext
);
234 _SuspendThread(HANDLE hThread
);
237 _ResumeThread(HANDLE hThread
);
240 _Sleep(DWORD dwMilliseconds
);
244 FrameworkGetExportedFunctionNameInternal(_PAPI_DESCRIPTION ApiDescription
)
246 if (ApiDescription
->ForwardedFunctionName
!= NULL
)
248 return ApiDescription
->ForwardedFunctionName
;
252 return ApiDescription
->FunctionName
;
257 FrameworkGetFunction(_PAPI_DESCRIPTION ApiDescription
)
260 PVOID function
= NULL
;
261 PCHAR exportedFunctionName
;
263 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(ApiDescription
);
265 hModule
= _GetModuleHandleA(ApiDescription
->FileName
);
268 function
= _GetProcAddress(hModule
, exportedFunctionName
);
272 hModule
= _LoadLibraryA(ApiDescription
->FileName
);
275 function
= _GetProcAddress(hModule
, exportedFunctionName
);
276 //FreeLibrary(hModule);
283 FrameworkGetHookInternal(ULONG index
)
286 PCHAR exportedFunctionName
;
288 if (index
> MaxExternalDependency
)
291 if (ExternalDependencies
[index
].MockFunctionAddress
!= NULL
)
292 return ExternalDependencies
[index
].MockFunctionAddress
;
294 if (ExternalDependencies
[index
].FunctionAddress
!= NULL
)
295 return ExternalDependencies
[index
].FunctionAddress
;
297 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(&ExternalDependencies
[index
]);
299 printf("Calling function '%s' in DLL '%s'.\n",
300 exportedFunctionName
,
301 ExternalDependencies
[index
].FileName
);
303 address
= FrameworkGetFunction(&ExternalDependencies
[index
]);
307 printf("Function '%s' not found in DLL '%s'.\n",
308 exportedFunctionName
,
309 ExternalDependencies
[index
].FileName
);
311 ExternalDependencies
[index
].FunctionAddress
= address
;
321 _PAPI_DESCRIPTION api
;
324 for (index
= 0; index
<= MaxExternalDependency
; index
++)
326 api
= &ExternalDependencies
[index
];
327 if (strcmp(api
->FunctionName
, name
) == 0)
329 api
->MockFunctionAddress
= address
;
335 typedef struct __HOOK
338 PVOID FunctionAddress
;
342 _SetHooks(_PHOOK hookTable
)
346 hook
= &hookTable
[0];
347 while (hook
->FunctionName
!= NULL
)
349 _SetHook(hook
->FunctionName
,
350 hook
->FunctionAddress
);
356 _UnsetHooks(_PHOOK hookTable
)
360 hook
= &hookTable
[0];
361 while (hook
->FunctionName
!= NULL
)
363 _SetHook(hook
->FunctionName
,
372 _PAPI_DESCRIPTION api
;
375 for (index
= 0; index
<= MaxExternalDependency
; index
++)
377 api
= &ExternalDependencies
[index
];
378 api
->MockFunctionAddress
= NULL
;