1 /* DejaGnu unit testing header.
2 Copyright (C) 2000, 2001, 2002, 2004, 2006 Free Software
5 This file is part of DejaGnu.
7 DejaGnu is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 DejaGnu is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with DejaGnu; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
28 /* If you have problems with DejaGnu dropping failed, untested, or
29 * unresolved messages generated by a unit testcase, then: */
31 /* #define _DEJAGNU_WAIT_ */
35 #include <sys/types.h>
46 static char buffer
[512];
59 select (0, &rfds
, NULL
, NULL
, &tv
);
64 pass (const char* fmt
, ...)
70 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
72 printf ("\tPASSED: %s\n", buffer
);
77 xpass (const char* fmt
, ...)
83 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
85 printf ("\tXPASSED: %s\n", buffer
);
90 fail (const char* fmt
, ...)
96 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
98 printf ("\tFAILED: %s\n", buffer
);
103 xfail (const char* fmt
, ...)
109 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
111 printf ("\tXFAILED: %s\n", buffer
);
116 untested (const char* fmt
, ...)
122 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
124 printf ("\tUNTESTED: %s\n", buffer
);
129 unresolved (const char* fmt
, ...)
135 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
137 printf ("\tUNRESOLVED: %s\n", buffer
);
142 note (const char* fmt
, ...)
147 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
149 printf ("\tNOTE: %s\n", buffer
);
156 printf ("\nTotals:\n");
157 printf ("\t#passed:\t\t%d\n", passed
);
158 printf ("\t#real failed:\t\t%d\n", failed
);
160 printf ("\t#expected failures:\t\t%d\n", xfailed
);
162 printf ("\t#untested:\t\t%d\n", untest
);
164 printf ("\t#unresolved:\t\t%d\n", unresolve
);
174 const char *outstate_list
[] = {
175 "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: ", "XFAILED: ", "XPASSED: "
178 const char ** outstate
= outstate_list
;
180 enum teststate
{ FAILED
, PASSED
, UNTESTED
, UNRESOLVED
, XFAILED
, XPASSED
} laststate
;
197 ~TestState (void) { totals(); }
199 void testrun (bool b
, std::string s
)
207 void pass (std::string s
)
212 std::cout
<< "\t" << outstate
[PASSED
] << s
<< std::endl
;
215 void pass (const char *c
)
221 void xpass (std::string s
)
226 std::cout
<< "\t" << outstate
[XPASSED
] << s
<< std::endl
;
229 void xpass (const char *c
)
235 void fail (std::string s
)
240 std::cout
<< "\t" << outstate
[FAILED
] << s
<< std::endl
;
243 void fail (const char *c
)
249 void xfail (std::string s
)
254 std::cout
<< "\t" << outstate
[XFAILED
] << s
<< std::endl
;
257 void xfail (const char *c
)
263 void untested (std::string s
)
266 laststate
= UNTESTED
;
268 std::cout
<< "\t" << outstate
[UNTESTED
] << s
<< std::endl
;
271 void untested (const char *c
)
277 void unresolved (std::string s
)
280 laststate
= UNRESOLVED
;
282 std::cout
<< "\t" << outstate
[UNRESOLVED
] << s
<< std::endl
;
285 void unresolved (const char *c
)
293 std::cout
<< "\t#passed:\t\t" << passed
<< std::endl
;
294 std::cout
<< "\t#real failed:\t\t" << failed
<< std::endl
;
296 std::cout
<< "\t#expected failures:\t\t" << xfailed
<< std::endl
;
298 std::cout
<< "\t#unexpected passes:\t\t" << xpassed
<< std::endl
;
300 std::cout
<< "\t#untested:\t\t" << untest
<< std::endl
;
302 std::cout
<< "\t#unresolved:\t\t" << unresolve
<< std::endl
;
305 // This is so this class can be printed in an ostream.
306 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
308 return os
<< "\t" << outstate
[t
.laststate
] << t
.lastmsg
;
311 int GetState (void) { return laststate
; }
312 std::string
GetMsg (void) { return lastmsg
; }
315 #endif /* __cplusplus */
316 #endif /* _DEJAGNU_H_ */