2004-03-09 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / regtests / win32base / driver.c
1 /*
2 * PROJECT: ReactOS kernel
3 * FILE: regtests/win32base/driver.c
4 * PURPOSE: Win32 base services regression testing driver
5 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
6 * UPDATE HISTORY:
7 * 06-07-2003 CSH Created
8 */
9 #define NTOS_MODE_USER
10 #include <ntos.h>
11 #include "regtests.h"
12
13 PVOID
14 AllocateMemory(ULONG Size)
15 {
16 return (PVOID) RtlAllocateHeap(RtlGetProcessHeap(), 0, Size);
17 }
18
19
20 VOID
21 FreeMemory(PVOID Base)
22 {
23 RtlFreeHeap(RtlGetProcessHeap(), 0, Base);
24 }
25
26
27 static DWORD WINAPI
28 DummyThreadMain(LPVOID lpParameter)
29 {
30 return 0;
31 }
32
33
34 VOID
35 RunPrivateTests(LPTSTR FileName)
36 {
37 HMODULE hModule;
38 HANDLE hEvent;
39
40 hEvent = CreateEventA(
41 NULL,
42 FALSE,
43 FALSE,
44 "WinRegTests");
45 if (hEvent == NULL)
46 {
47 return;
48 }
49
50 hModule = GetModuleHandle(FileName);
51 if (hModule != NULL)
52 {
53 HANDLE hThread;
54
55 /*
56 * The module is a core OS component that is already
57 * mapped into the current process.
58 * NOTE: This will cause all core OS components that are already mapped
59 * into the process to run their regression tests.
60 */
61 hThread = CreateThread(NULL, 0, DummyThreadMain, NULL, 0, NULL);
62 if (hThread != NULL)
63 {
64 DWORD ErrorCode;
65 ErrorCode = WaitForSingleObject(hEvent, 5000); /* Wait up to 5 seconds */
66 CloseHandle(hThread);
67 }
68 }
69 else
70 {
71 hModule = LoadLibrary(FileName);
72 if (hModule != NULL)
73 {
74 CloseHandle(hEvent);
75 FreeLibrary(hModule);
76 }
77 }
78
79 CloseHandle(hEvent);
80 }
81
82
83 VOID STDCALL
84 RegTestMain(TestOutputRoutine OutputRoutine, LPSTR TestName)
85 {
86 /*
87 * Private module regression tests in components already mapped
88 * (ntdll.dll, kernel32.dll, msvcrt.dll)
89 */
90 /* FIXME: Need to pass TestName to the driver */
91 RunPrivateTests(_T("ntdll.dll"));
92
93 /* Other private module regression tests */
94
95 /* Cross-module regression tests */
96 InitializeTests();
97 RegisterTests();
98 PerformTests(OutputRoutine, TestName);
99 }