Regenerated html docs. Tweaked how Makefile.am builds tarballs.
[dejagnu.git] / dejagnu.h
blob4dd6f6cbd9e4b49822bbc9478c4e610d75da2c19
1 /*
2 * Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __DEJAGNU_H__
20 #define __DEJAGNU_H__
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <string.h>
26 /* If you have problems with dejagnu dropping failed, untested, or
27 * unresolved messages generated by a unit testcase,
30 /* #define _DEJAGNU_WAIT_
33 #ifdef _DEJAGNU_WAIT_
34 # include <sys/time.h>
35 # include <sys/types.h>
36 # include <unistd.h>
37 #endif
39 #define _BUFFER_SIZE_ 512
41 static int passed;
42 static int failed;
43 static int untest;
44 static int unresolve;
46 static char buffer[ _BUFFER_SIZE_ ];
48 #ifdef _DEJAGNU_WAIT_
49 void
50 wait(void) {
51 fd_set rfds;
52 struct timeval tv;
54 FD_ZERO(&rfds);
55 tv.tv_sec = 0;
56 tv.tv_usec = 1;
58 select(0, &rfds, NULL, NULL, &tv);
60 #endif
62 inline void
63 pass (const char* fmt, ... ) {
64 va_list ap;
66 passed++;
67 va_start( ap, fmt );
68 vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
69 va_end( ap );
70 printf ("\tPASSED: %s\n", buffer );
71 #ifdef _DEJAGNU_WAIT_
72 wait();
73 #endif
76 inline void
77 fail (const char* fmt, ... ) {
78 va_list ap;
80 failed++;
81 va_start( ap, fmt );
82 vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
83 va_end( ap );
84 printf ("\tFAILED: %s\n", buffer );
85 #ifdef _DEJAGNU_WAIT_
86 wait();
87 #endif
90 inline void
91 untested (const char* fmt, ... ) {
92 va_list ap;
94 untest++;
95 va_start( ap, fmt );
96 vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
97 va_end( ap );
98 printf ("\tUNTESTED: %s\n", buffer );
99 #ifdef _DEJAGNU_WAIT_
100 wait();
101 #endif
104 inline void
105 unresolved (const char* fmt, ... ) {
106 va_list ap;
108 unresolve++;
109 va_start( ap, fmt );
110 vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
111 va_end( ap );
112 printf ("\tUNRESOLVED: %s\n", buffer );
113 #ifdef _DEJAGNU_WAIT_
114 wait();
115 #endif
118 inline void
119 note (const char* fmt, ... ) {
120 va_list ap;
122 va_start( ap, fmt );
123 vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
124 va_end( ap );
125 printf ("\tNOTE: %s\n", buffer );
126 #ifdef _DEJAGNU_WAIT_
127 wait();
128 #endif
131 inline void
132 totals (void) {
133 printf ("\nTotals:\n");
134 printf ("\t#passed:\t\t%d\n", passed);
135 printf ("\t#failed:\t\t%d\n", failed);
136 if (untest)
137 printf ("\t#untested:\t\t%d\n", untest);
138 if (unresolve)
139 printf ("\t#unresolved:\t\t%d\n", unresolved);
142 #ifdef __cplusplus
145 #include <iostream>
146 #include <iomanip>
147 #include <fstream>
148 #include <string>
149 #if 0
150 #ifdef __STDC___
151 #include <sstream>
152 #else
153 #include <strstream>
154 #endif
155 #endif
157 const char *outstate_list[] = {
158 "FAILED: ",
159 "PASSED: ",
160 "UNTESTED: ",
161 "UNRESOLVED: "
164 const char ** outstate = outstate_list;
166 #if 0
167 extern ios& __iomanip_testout (ios&, int);
168 inline smanip<int> testout (int n) {
169 return smanip<int> (__iomanip_testout, n);
171 ios & __iomanip_testout (ios& i, int x) {
172 return i;
175 template<class T>
176 class OMANIP {
177 private:
178 T i;
179 ostream &(*f)(ostream&, T);
180 public:
181 OMANIP(ostream& (*ff)(ostream&, T), T ii) : f(ff), i(ii) {
183 friend ostream operator<<(ostream& us, OMANIP& m) {
184 return m.f(os,m.i);
188 ostream&
189 freakout(ostream& os, int x) {
190 return os << "FREAKOUT" ;
191 // return x << "TESTOUT " << x ;
194 OMANIP<int> testout(int i) {
195 return OMANIP<int>(&freakout,i);
197 #endif
199 enum teststate {FAILED, PASSED,UNTESTED,UNRESOLVED} laststate;
201 class TestState {
202 private:
203 teststate laststate;
204 std::string lastmsg;
205 public:
206 TestState(void) {
207 passed = 0;
208 failed = 0;
209 untest = 0;
210 unresolve = 0;
212 ~TestState(void) {
213 totals();
216 void testrun (bool b, std::string s) {
217 if (b)
218 pass (s);
219 else
220 fail (s);
223 void pass (std::string s) {
224 passed++;
225 laststate = PASSED;
226 lastmsg = s;
227 std::cout << "\t" << outstate[PASSED] << s << std::endl;
229 void pass (const char *c) {
230 std::string s = c;
231 pass (s);
234 void fail (std::string s) {
235 failed++;
236 laststate = FAILED;
237 lastmsg = s;
238 std::cout << "\t" << outstate[FAILED] << s << std::endl;
240 void fail (const char *c) {
241 std::string s = c;
242 fail (s);
245 void untested (std::string s) {
246 untest++;
247 laststate = UNTESTED;
248 lastmsg = s;
249 std::cout << "\t" << outstate[UNTESTED] << s << std::endl;
251 void untested (const char *c) {
252 std::string s = c;
253 untested (s);
256 void unresolved (std::string s) {
257 unresolve++;
258 laststate = UNRESOLVED;
259 lastmsg = s;
260 std::cout << "\t" << outstate[UNRESOLVED] << s << std::endl;
262 void unresolved (const char *c) {
263 std::string s = c;
264 unresolved (s);
267 void totals (void) {
268 std::cout << "\t#passed:\t\t" << passed << std::endl;
269 std::cout << "\t#failed:\t\t" << failed << std::endl;
270 if (untest)
271 std::cout << "\t#untested:\t\t" << untest << std::endl;
272 if (unresolve)
273 std::cout << "\t#unresolved:\t\t" << unresolve << std::endl;
276 // This is so this class can be printed in an ostream.
277 friend std::ostream & operator << (std::ostream &os, TestState& t) {
278 return os << "\t" << outstate[t.laststate] << t.lastmsg ;
281 int GetState(void) {
282 return laststate;
284 std::string GetMsg(void) {
285 return lastmsg;
289 #endif // __cplusplus
290 #endif // _DEJAGNU_H_