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
13 /* Valid values for Command parameter of TestRoutine */
14 #define TESTCMD_RUN 0 /* Buffer contains information about what failed */
15 #define TESTCMD_TESTNAME 1 /* Buffer contains description of test */
17 /* Valid values for return values of TestRoutine */
18 #define TS_EXCEPTION -1
22 /* Macros to simplify tests */
23 #define DISPATCHER(FunctionName, TestName) \
25 FunctionName(int Command, \
31 return RunTest(Buffer); \
32 case TESTCMD_TESTNAME: \
33 strcpy(Buffer, TestName); \
41 #define FAIL(ErrorMessage) \
42 sprintf(Buffer, "%s\n", ErrorMessage); \
45 #define FAIL_IF_NULL(GivenValue, ErrorMessage) if (GivenValue == NULL) { FAIL(ErrorMessage); }
46 #define FAIL_IF_TRUE(GivenValue, ErrorMessage) if (GivenValue == TRUE) { FAIL(ErrorMessage); }
47 #define FAIL_IF_FALSE(GivenValue, ErrorMessage) if (GivenValue == FALSE) { FAIL(ErrorMessage); }
48 #define FAIL_IF_EQUAL(GivenValue, FailValue, ErrorMessage) if (GivenValue == FailValue) { FAIL(ErrorMessage); }
49 #define FAIL_IF_NOT_EQUAL(GivenValue, FailValue, ErrorMessage) if (GivenValue != FailValue) { FAIL(ErrorMessage); }
50 #define FAIL_IF_LESS_EQUAL(GivenValue, FailValue, ErrorMessage) if (GivenValue <= FailValue) { FAIL(ErrorMessage); }
51 #define FAIL_IF_GREATER_EQUAL(GivenValue, FailValue, ErrorMessage) if (GivenValue >= FailValue) { FAIL(ErrorMessage); }
54 * Test routine prototype
55 * Command - The command to process
56 * Buffer - Pointer to buffer in which to return context information
58 typedef int (*TestRoutine
)(int Command
, char *Buffer
);
61 * Test output routine prototype
62 * Buffer - Address of buffer with text to output
64 typedef void (*TestOutputRoutine
)(char *Buffer
);
67 * Test driver entry routine.
68 * OutputRoutine - Output routine.
69 * TestName - If NULL all tests are run. If non-NULL specifies the test to be run
71 typedef void STDCALL (*TestDriverMain
)(TestOutputRoutine OutputRoutine
, char *TestName
);
73 typedef struct _ROS_TEST
77 } ROS_TEST
, *PROS_TEST
;
79 extern LIST_ENTRY AllTests
;
81 extern VOID
InitializeTests();
82 extern VOID
RegisterTests();
83 extern VOID
PerformTests(TestOutputRoutine OutputRoutine
, LPSTR TestName
);
85 /* Routines provided by the driver */
86 extern PVOID
AllocateMemory(ULONG Size
);
87 extern VOID
FreeMemory(PVOID Base
);
90 typedef struct _API_DESCRIPTION
94 PVOID FunctionAddress
;
95 PVOID MockFunctionAddress
;
96 } API_DESCRIPTION
, *PAPI_DESCRIPTION
;
98 extern API_DESCRIPTION ExternalDependencies
[];
99 extern ULONG MaxExternalDependency
;
102 FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription
)
107 hModule
= GetModuleHandleA(ApiDescription
->FileName
);
110 Function
= GetProcAddress(hModule
, ApiDescription
->FunctionName
);
114 hModule
= LoadLibraryA(ApiDescription
->FileName
);
117 Function
= GetProcAddress(hModule
, ApiDescription
->FunctionName
);
118 //FreeLibrary(hModule);
124 static inline PVOID STDCALL
125 FrameworkGetHookInternal(ULONG index
)
129 if (index
> MaxExternalDependency
)
132 if (ExternalDependencies
[index
].MockFunctionAddress
!= NULL
)
133 return ExternalDependencies
[index
].MockFunctionAddress
;
135 if (ExternalDependencies
[index
].FunctionAddress
!= NULL
)
136 return ExternalDependencies
[index
].FunctionAddress
;
138 address
= FrameworkGetFunction(&ExternalDependencies
[index
]);
139 ExternalDependencies
[index
].FunctionAddress
= address
;
149 PAPI_DESCRIPTION api
;
152 for (index
= 0; index
<= MaxExternalDependency
; index
++)
154 api
= &ExternalDependencies
[index
];
155 if (strcmp(api
->FunctionName
, name
) == 0)
157 api
->FunctionAddress
= address
;
166 PVOID FunctionAddress
;
170 _SetHooks(PHOOK hookTable
)
174 hook
= &hookTable
[0];
175 _SetHook(hook
->FunctionName
,
176 hook
->FunctionAddress
);
180 _UnsetHooks(PHOOK hookTable
)
184 hook
= &hookTable
[0];
185 _SetHook(hook
->FunctionName
,