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