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 */
21 /* Valid values for return values of TestRoutine */
22 #define TS_EXCEPTION -1
29 /* Macros to simplify tests */
30 #define _Dispatcher(FunctionName, TestName) \
32 FunctionName(int Command) \
39 case TESTCMD_TESTNAME: \
40 strcpy(_Buffer, TestName); \
43 _Result = TS_FAILED; \
49 AppendAssertion(char *message
)
51 if (strlen(_Buffer
) != 0)
52 strcat(_Buffer
, "\n");
53 strcat(_Buffer
, message
);
57 #define _AssertTrue(_Condition) \
62 sprintf(_message, "Condition was not true at %s:%d", \
63 __FILE__, __LINE__); \
64 AppendAssertion(_message); \
68 #define _AssertFalse(_Condition) \
73 sprintf(_message, "Condition was not false at %s:%d", \
74 __FILE__, __LINE__); \
75 AppendAssertion(_message); \
79 #define _AssertEqualValue(_Expected, _Actual) \
81 ULONG __Expected = (ULONG) (_Expected); \
82 ULONG __Actual = (ULONG) (_Actual); \
83 if ((__Expected) != (__Actual)) \
86 sprintf(_message, "Expected %d/0x%.08x was %d/0x%.08x at %s:%d", \
87 (__Expected), (__Expected), (__Actual), (__Actual), __FILE__, __LINE__); \
88 AppendAssertion(_message); \
92 #define _AssertEqualWideString(_Expected, _Actual) \
94 LPWSTR __Expected = (LPWSTR) (_Expected); \
95 LPWSTR __Actual = (LPWSTR) (_Actual); \
96 if (wcscmp((__Expected), (__Actual)) != 0) \
99 sprintf(_message, "Expected %S was %S at %s:%d", \
100 (__Expected), (__Actual), __FILE__, __LINE__); \
101 AppendAssertion(_message); \
105 #define _AssertNotEqualValue(_Expected, _Actual) \
107 ULONG __Expected = (ULONG) (_Expected); \
108 ULONG __Actual = (ULONG) (_Actual); \
109 if ((__Expected) == (__Actual)) \
111 char _message[100]; \
112 sprintf(_message, "Actual value expected to be different from %d/0x%.08x at %s:%d", \
113 (__Expected), (__Expected), __FILE__, __LINE__); \
114 AppendAssertion(_message); \
120 * Test routine prototype
121 * Command - The command to process
123 typedef void (*TestRoutine
)(int Command
);
126 * Test output routine prototype
127 * Buffer - Address of buffer with text to output
129 typedef void (*TestOutputRoutine
)(char *Buffer
);
132 * Test driver entry routine.
133 * OutputRoutine - Output routine.
134 * TestName - If NULL all tests are run. If non-NULL specifies the test to be run
136 typedef void STDCALL (*TestDriverMain
)(TestOutputRoutine OutputRoutine
, char *TestName
);
138 typedef struct _ROS_TEST
140 LIST_ENTRY ListEntry
;
142 } ROS_TEST
, *PROS_TEST
;
144 extern LIST_ENTRY AllTests
;
146 extern VOID
InitializeTests();
147 extern VOID
RegisterTests();
148 extern VOID
PerformTests(TestOutputRoutine OutputRoutine
, LPSTR TestName
);
151 typedef struct _API_DESCRIPTION
155 PCHAR ForwardedFunctionName
;
156 PVOID FunctionAddress
;
157 PVOID MockFunctionAddress
;
158 } API_DESCRIPTION
, *PAPI_DESCRIPTION
;
160 extern API_DESCRIPTION ExternalDependencies
[];
161 extern ULONG MaxExternalDependency
;
164 _GetModuleHandleA(LPCSTR lpModuleName
);
167 _GetProcAddress(HANDLE hModule
,
171 _LoadLibraryA(LPCSTR lpLibFileName
);
174 _ExitProcess(UINT uExitCode
);
177 FrameworkGetExportedFunctionNameInternal(PAPI_DESCRIPTION ApiDescription
)
179 if (ApiDescription
->ForwardedFunctionName
!= NULL
)
181 return ApiDescription
->ForwardedFunctionName
;
185 return ApiDescription
->FunctionName
;
190 FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription
)
194 PCHAR exportedFunctionName
;
196 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(ApiDescription
);
198 hModule
= _GetModuleHandleA(ApiDescription
->FileName
);
201 function
= _GetProcAddress(hModule
, exportedFunctionName
);
205 hModule
= _LoadLibraryA(ApiDescription
->FileName
);
208 function
= _GetProcAddress(hModule
, exportedFunctionName
);
209 //FreeLibrary(hModule);
216 FrameworkGetHookInternal(ULONG index
)
219 PCHAR exportedFunctionName
;
221 if (index
> MaxExternalDependency
)
224 if (ExternalDependencies
[index
].MockFunctionAddress
!= NULL
)
225 return ExternalDependencies
[index
].MockFunctionAddress
;
227 if (ExternalDependencies
[index
].FunctionAddress
!= NULL
)
228 return ExternalDependencies
[index
].FunctionAddress
;
230 exportedFunctionName
= FrameworkGetExportedFunctionNameInternal(&ExternalDependencies
[index
]);
232 printf("Calling function '%s' in DLL '%s'.\n",
233 exportedFunctionName
,
234 ExternalDependencies
[index
].FileName
);
236 address
= FrameworkGetFunction(&ExternalDependencies
[index
]);
240 printf("Function '%s' not found in DLL '%s'.\n",
241 exportedFunctionName
,
242 ExternalDependencies
[index
].FileName
);
244 ExternalDependencies
[index
].FunctionAddress
= address
;
254 PAPI_DESCRIPTION api
;
257 for (index
= 0; index
<= MaxExternalDependency
; index
++)
259 api
= &ExternalDependencies
[index
];
260 if (strcmp(api
->FunctionName
, name
) == 0)
262 api
->MockFunctionAddress
= address
;
271 PVOID FunctionAddress
;
275 _SetHooks(PHOOK hookTable
)
279 hook
= &hookTable
[0];
280 while (hook
->FunctionName
!= NULL
)
282 _SetHook(hook
->FunctionName
,
283 hook
->FunctionAddress
);
289 _UnsetHooks(PHOOK hookTable
)
293 hook
= &hookTable
[0];
294 while (hook
->FunctionName
!= NULL
)
296 _SetHook(hook
->FunctionName
,
305 PAPI_DESCRIPTION api
;
308 for (index
= 0; index
<= MaxExternalDependency
; index
++)
310 api
= &ExternalDependencies
[index
];
311 api
->MockFunctionAddress
= NULL
;