* Made it possible to include both d3d9types.h and ddrawgdi.h at the same time
[reactos.git] / rostests / apitests / apitest.c
1 #include "apitest.h"
2
3 const char szFileHeader[] = "<html><head><style>\ntd.red {color:red}\ntd.green{color:green}\n</style>\n</head>\n<body>\n<head>\n";
4 const char szTableHeader[] = "<table width = '800'><tr><th align='left'>Function</th><th align='left'>Status</th><th align='left'>Tests (all/passed/failed)</th><th align='left'>Regressions</th></tr>";
5 const char szFileFooter[] = "</table></body></html>";
6
7 void
8 OutputUsage(LPWSTR pszName)
9 {
10 printf("\nUsage:\n\n");
11 printf("%ls.exe <TestName> - perform individual test\n", pszName);
12 printf("%ls.exe all - perform all tests\n", pszName);
13 printf("%ls.exe status - create api status file\n", pszName);
14 printf("%ls.exe -r ... - perform regression testing\n", pszName);
15 printf("\n");
16 }
17
18 BOOL
19 WriteFileHeader(UINT hFile, LPWSTR pszModule)
20 {
21 char szHeader[100];
22
23 _write(hFile, szFileHeader, strlen(szFileHeader));
24 sprintf(szHeader, "<H1>Test results for %ls</H1>", pszModule);
25 _write(hFile, szHeader, strlen(szHeader));
26 _write(hFile, szTableHeader, strlen(szTableHeader));
27 return TRUE;
28 }
29
30 BOOL
31 WriteRow(UINT hFile, LPWSTR pszFunction, PTESTINFO pti)
32 {
33 char szLine[500];
34
35 sprintf(szLine, "<tr><td>%ls</td>", pszFunction);
36
37 switch(pti->nApiStatus)
38 {
39 case APISTATUS_NOT_FOUND:
40 strcat(szLine, "<td class='red'>not found</td>");
41 break;
42 case APISTATUS_UNIMPLEMENTED:
43 strcat(szLine, "<td class='red'>unimplemented</td>");
44 break;
45 case APISTATUS_ASSERTION_FAILED:
46 strcat(szLine, "<td class='red'>assertion failed</td>");
47 break;
48 case APISTATUS_REGRESSION:
49 strcat(szLine, "<td class='red'>Regression!</td>");
50 break;
51 case APISTATUS_NORMAL:
52 strcat(szLine, "<td class='green'>Implemented</td>");
53 break;
54 }
55
56 sprintf(szLine + strlen(szLine), "<td>%d / %d / %d</td><td>%d</td></tr>\n",
57 pti->passed+pti->failed, pti->passed, pti->failed, pti->rfailed);
58
59 _write(hFile, szLine, strlen(szLine));
60 return TRUE;
61 }
62
63 int
64 TestMain(LPWSTR pszName, LPWSTR pszModule)
65 {
66 INT argc, i, j;
67 LPWSTR *argv;
68 TESTINFO ti;
69 INT opassed, ofailed, orfailed;
70 BOOL bAll, bStatus;
71 UINT hFile = 0;
72
73 ti.bRegress = FALSE;
74 bAll = FALSE;
75 bStatus = FALSE;
76 opassed = ofailed = orfailed = 0;
77
78 argv = CommandLineToArgvW(GetCommandLineW(), &argc);
79
80 if (argc < 2)
81 {
82 OutputUsage(pszName);
83 return 0;
84 }
85
86 /* Get options */
87 for (i = 1; i < argc; i++)
88 {
89 if (_wcsicmp(argv[i], L"-r") == 0)
90 {
91 ti.bRegress = TRUE;
92 }
93 else if (_wcsicmp(argv[i], L"all") == 0)
94 {
95 bAll = TRUE;
96 }
97 else if (_wcsicmp(argv[i], L"status") == 0)
98 {
99 bAll = TRUE;
100 bStatus = TRUE;
101 }
102 }
103
104 if (bStatus)
105 {
106 ti.bRegress = TRUE;
107 char szOutputFile[MAX_PATH];
108 wsprintf(szOutputFile, "%ls.html", pszName);
109 hFile = _open(szOutputFile, O_CREAT | O_TRUNC | O_RDWR, 00700);
110 if (hFile == -1)
111 {
112 printf("Could not create output file.\n");
113 return 0;
114 }
115 WriteFileHeader(hFile, pszModule);
116 }
117
118 for (i = 0; i < NumTests(); i++)
119 {
120 for (j = 1; j < argc; j++)
121 {
122 if (bAll || _wcsicmp(argv[j], TestList[i].Test) == 0)
123 {
124 ti.passed = 0;
125 ti.failed = 0;
126 ti.rfailed = 0;
127 if (!IsFunctionPresent(TestList[i].Test))
128 {
129 printf("Function %ls was not found!\n", TestList[i].Test);
130 ti.nApiStatus = APISTATUS_NOT_FOUND;
131 }
132 else
133 {
134 printf("Executing test: %ls\n", TestList[i].Test);
135 ti.nApiStatus = TestList[i].Proc(&ti);
136 opassed += ti.passed;
137 ofailed += ti.failed;
138 orfailed += ti.rfailed;
139 printf(" tests: %d, passed: %d, failed: %d\n\n", ti.passed+ti.failed, ti.passed, ti.failed);
140 }
141 if (bStatus)
142 {
143 if (ti.rfailed > 0)
144 ti.nApiStatus = APISTATUS_REGRESSION;
145 WriteRow(hFile, TestList[i].Test, &ti);
146 }
147 break;
148 }
149 }
150 }
151
152 printf("Overall:\n");
153 printf(" tests: %d, passed: %d, failed: %d\n\n", opassed+ofailed, opassed, ofailed);
154 if (ti.bRegress)
155 {
156 printf(" regressions: %d\n", orfailed);
157 }
158
159 if (bStatus)
160 {
161 _write(hFile, szFileFooter, strlen(szFileFooter));
162 _close(hFile);
163 }
164
165 if (ti.bRegress)
166 return ti.rfailed;
167
168 return ti.failed;
169 }