2004-03-09 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / regtests / shared / regtests.c
1 /*
2 * PROJECT: ReactOS kernel
3 * FILE: regtests/shared/regtests.c
4 * PURPOSE: Regression testing framework
5 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
6 * UPDATE HISTORY:
7 * 06-07-2003 CSH Created
8 */
9 #include <roscfg.h>
10 #include <stdio.h>
11 #define NTOS_MODE_USER
12 #include <ntos.h>
13 #include "regtests.h"
14 #include <string.h>
15
16 #define NDEBUG
17 #include <debug.h>
18
19 LIST_ENTRY AllTests;
20
21 int
22 DriverTest()
23 {
24 /* Dummy */
25 return 0;
26 }
27
28
29 int
30 _regtestsTest()
31 {
32 /* Dummy */
33 return 0;
34 }
35
36
37 VOID
38 InitializeTests()
39 {
40 InitializeListHead(&AllTests);
41 }
42
43 VOID
44 PerformTest(TestOutputRoutine OutputRoutine, PROS_TEST Test, LPSTR TestName)
45 {
46 char OutputBuffer[200];
47 char Buffer[200];
48 char Name[200];
49 int Result;
50
51 memset(Name, 0, sizeof(Name));
52 memset(Buffer, 0, sizeof(Buffer));
53
54 if (!((Test->Routine)(TESTCMD_TESTNAME, Name) == 0))
55 {
56 if (TestName != NULL)
57 {
58 return;
59 }
60 strcpy(Name, "Unnamed");
61 }
62
63 if (TestName != NULL)
64 {
65 if (_stricmp(Name, TestName) != 0)
66 {
67 return;
68 }
69 }
70
71 #ifdef SEH
72 __try {
73 #endif
74 Result = (Test->Routine)(TESTCMD_RUN, Buffer);
75 #ifdef SEH
76 } __except(EXCEPTION_EXECUTE_HANDLER) {
77 Result = TS_FAILED;
78 strcpy(Buffer, "Failed due to exception");
79 }
80 #endif
81
82 if (Result != TS_OK)
83 {
84 sprintf(OutputBuffer, "ROSREGTEST: (%s) Status: Failed (%s)\n", Name, Buffer);
85 }
86 else
87 {
88 sprintf(OutputBuffer, "ROSREGTEST: (%s) Status: Success\n", Name);
89 }
90 if (OutputRoutine != NULL)
91 {
92 (*OutputRoutine)(OutputBuffer);
93 }
94 else
95 {
96 DbgPrint(OutputBuffer);
97 }
98 }
99
100 VOID
101 PerformTests(TestOutputRoutine OutputRoutine, LPSTR TestName)
102 {
103 PLIST_ENTRY CurrentEntry;
104 PLIST_ENTRY NextEntry;
105 PROS_TEST Current;
106
107 CurrentEntry = AllTests.Flink;
108 while (CurrentEntry != &AllTests)
109 {
110 NextEntry = CurrentEntry->Flink;
111 Current = CONTAINING_RECORD(CurrentEntry, ROS_TEST, ListEntry);
112 PerformTest(OutputRoutine, Current, TestName);
113 CurrentEntry = NextEntry;
114 }
115 }
116
117 VOID
118 AddTest(TestRoutine Routine)
119 {
120 PROS_TEST Test;
121
122 Test = (PROS_TEST) AllocateMemory(sizeof(ROS_TEST));
123 if (Test == NULL)
124 {
125 DbgPrint("Out of memory");
126 return;
127 }
128
129 Test->Routine = Routine;
130
131 InsertTailList(&AllTests, &Test->ListEntry);
132 }