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 LIST_ENTRY AllTests
;
152 extern VOID
InitializeTests();
153 extern VOID
RegisterTests();
154 extern VOID
PerformTests(TestOutputRoutine OutputRoutine
, LPSTR TestName
);
157 typedef struct _API_DESCRIPTION
161 PCHAR ForwardedFunctionName
;
162 PVOID FunctionAddress
;
163 PVOID MockFunctionAddress
;
164 } API_DESCRIPTION
, *PAPI_DESCRIPTION
;
166 extern API_DESCRIPTION ExternalDependencies
[];
167 extern ULONG MaxExternalDependency
;
170 _GetModuleHandleA(LPCSTR lpModuleName
);
173 _GetProcAddress(HANDLE hModule
,
177 _LoadLibraryA(LPCSTR lpLibFileName
);
180 _ExitProcess(UINT uExitCode
);
183 _CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes
, DWORD dwStackSize
,
184 LPTHREAD_START_ROUTINE lpStartAddress
, LPVOID lpParameter
,
185 DWORD dwCreationFlags
, LPDWORD lpThreadId
);
188 _TerminateThread(HANDLE hThread
, DWORD dwExitCode
);
191 _WaitForSingleObject(HANDLE hHandle
, DWORD dwMilliseconds
);
195 FrameworkGetExportedFunctionNameInternal(PAPI_DESCRIPTION ApiDescription
)
197 if (ApiDescription
->ForwardedFunctionName
!= NULL
)
199 return ApiDescription
->ForwardedFunctionName
;
203 return ApiDescription
->FunctionName
;
208 FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription
)
212 PCHAR exportedFunctionName
;
214 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(ApiDescription
);
216 hModule
= _GetModuleHandleA(ApiDescription
->FileName
);
219 function
= _GetProcAddress(hModule
, exportedFunctionName
);
223 hModule
= _LoadLibraryA(ApiDescription
->FileName
);
226 function
= _GetProcAddress(hModule
, exportedFunctionName
);
227 //FreeLibrary(hModule);
234 FrameworkGetHookInternal(ULONG index
)
237 PCHAR exportedFunctionName
;
239 if (index
> MaxExternalDependency
)
242 if (ExternalDependencies
[index
].MockFunctionAddress
!= NULL
)
243 return ExternalDependencies
[index
].MockFunctionAddress
;
245 if (ExternalDependencies
[index
].FunctionAddress
!= NULL
)
246 return ExternalDependencies
[index
].FunctionAddress
;
248 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(&ExternalDependencies
[index
]);
250 printf("Calling function '%s' in DLL '%s'.\n",
251 exportedFunctionName
,
252 ExternalDependencies
[index
].FileName
);
254 address
= FrameworkGetFunction(&ExternalDependencies
[index
]);
258 printf("Function '%s' not found in DLL '%s'.\n",
259 exportedFunctionName
,
260 ExternalDependencies
[index
].FileName
);
262 ExternalDependencies
[index
].FunctionAddress
= address
;
272 PAPI_DESCRIPTION api
;
275 for (index
= 0; index
<= MaxExternalDependency
; index
++)
277 api
= &ExternalDependencies
[index
];
278 if (strcmp(api
->FunctionName
, name
) == 0)
280 api
->MockFunctionAddress
= address
;
289 PVOID FunctionAddress
;
293 _SetHooks(PHOOK hookTable
)
297 hook
= &hookTable
[0];
298 while (hook
->FunctionName
!= NULL
)
300 _SetHook(hook
->FunctionName
,
301 hook
->FunctionAddress
);
307 _UnsetHooks(PHOOK hookTable
)
311 hook
= &hookTable
[0];
312 while (hook
->FunctionName
!= NULL
)
314 _SetHook(hook
->FunctionName
,
323 PAPI_DESCRIPTION api
;
326 for (index
= 0; index
<= MaxExternalDependency
; index
++)
328 api
= &ExternalDependencies
[index
];
329 api
->MockFunctionAddress
= NULL
;