1 /* DejaGnu unit testing header.
2 Copyright (C) 2000, 2001, 2002, 2004, 2006, 207, 2008, 2009,
3 2010, 2011, 2012 Free Software Foundation, Inc.
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
;
198 ~TestState (void) { totals(); }
200 void testrun (bool b
, std::string s
)
208 void pass (std::string s
)
213 std::cout
<< "\t" << outstate
[PASSED
] << s
<< std::endl
;
216 void pass (const char *c
)
222 void xpass (std::string s
)
227 std::cout
<< "\t" << outstate
[XPASSED
] << s
<< std::endl
;
230 void xpass (const char *c
)
236 void fail (std::string s
)
241 std::cout
<< "\t" << outstate
[FAILED
] << s
<< std::endl
;
244 void fail (const char *c
)
250 void xfail (std::string s
)
255 std::cout
<< "\t" << outstate
[XFAILED
] << s
<< std::endl
;
258 void xfail (const char *c
)
264 void untested (std::string s
)
267 laststate
= UNTESTED
;
269 std::cout
<< "\t" << outstate
[UNTESTED
] << s
<< std::endl
;
272 void untested (const char *c
)
278 void unresolved (std::string s
)
281 laststate
= UNRESOLVED
;
283 std::cout
<< "\t" << outstate
[UNRESOLVED
] << s
<< std::endl
;
286 void unresolved (const char *c
)
294 std::cout
<< "\t#passed:\t\t" << passed
<< std::endl
;
295 std::cout
<< "\t#real failed:\t\t" << failed
<< std::endl
;
297 std::cout
<< "\t#expected failures:\t\t" << xfailed
<< std::endl
;
299 std::cout
<< "\t#unexpected passes:\t\t" << xpassed
<< std::endl
;
301 std::cout
<< "\t#untested:\t\t" << untest
<< std::endl
;
303 std::cout
<< "\t#unresolved:\t\t" << unresolve
<< std::endl
;
306 // This is so this class can be printed in an ostream.
307 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
309 return os
<< "\t" << outstate
[t
.laststate
] << t
.lastmsg
;
312 int GetState (void) { return laststate
; }
313 std::string
GetMsg (void) { return lastmsg
; }
316 #endif /* __cplusplus */
317 #endif /* _DEJAGNU_H_ */