1 /* DejaGnu unit testing header.
2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
4 This file is part of DejaGnu.
6 DejaGnu is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 DejaGnu is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DejaGnu; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
27 /* If you have problems with DejaGnu dropping failed, untested, or
28 * unresolved messages generated by a unit testcase, then: */
30 /* #define _DEJAGNU_WAIT_ */
34 #include <sys/types.h>
45 static char buffer
[512];
58 select (0, &rfds
, NULL
, NULL
, &tv
);
63 pass (const char* fmt
, ...)
69 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
71 printf ("\tPASSED: %s\n", buffer
);
76 xpass (const char* fmt
, ...)
82 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
84 printf ("\tXPASSED: %s\n", buffer
);
89 fail (const char* fmt
, ...)
95 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
97 printf ("\tFAILED: %s\n", buffer
);
102 xfail (const char* fmt
, ...)
108 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
110 printf ("\tXFAILED: %s\n", buffer
);
115 untested (const char* fmt
, ...)
121 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
123 printf ("\tUNTESTED: %s\n", buffer
);
128 unresolved (const char* fmt
, ...)
134 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
136 printf ("\tUNRESOLVED: %s\n", buffer
);
141 note (const char* fmt
, ...)
146 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
148 printf ("\tNOTE: %s\n", buffer
);
155 printf ("\nTotals:\n");
156 printf ("\t#passed:\t\t%d\n", passed
);
157 printf ("\t#real failed:\t\t%d\n", failed
);
159 printf ("\t#expected failures:\t\t%d\n", xfailed
);
161 printf ("\t#unexpected passes:\t\t%d\n", xpassed
);
163 printf ("\t#untested:\t\t%d\n", untest
);
165 printf ("\t#unresolved:\t\t%d\n", unresolve
);
166 printf ("\tEND: done\n");
176 const char *outstate_list
[] = {
177 "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: ", "XFAILED: ", "XPASSED: "
180 const char ** outstate
= outstate_list
;
182 enum teststate
{ FAILED
, PASSED
, UNTESTED
, UNRESOLVED
, XFAILED
, XPASSED
} laststate
;
199 ~TestState (void) { totals(); }
201 void testrun (bool b
, std::string s
)
209 void pass (std::string s
)
214 std::cout
<< "\t" << outstate
[PASSED
] << s
<< std::endl
;
217 void xpass (std::string s
)
222 std::cout
<< "\t" << outstate
[XPASSED
] << s
<< std::endl
;
225 void fail (std::string s
)
230 std::cout
<< "\t" << outstate
[FAILED
] << s
<< std::endl
;
233 void xfail (std::string s
)
238 std::cout
<< "\t" << outstate
[XFAILED
] << s
<< std::endl
;
241 void untested (std::string s
)
244 laststate
= UNTESTED
;
246 std::cout
<< "\t" << outstate
[UNTESTED
] << s
<< std::endl
;
249 void unresolved (std::string s
)
252 laststate
= UNRESOLVED
;
254 std::cout
<< "\t" << outstate
[UNRESOLVED
] << s
<< std::endl
;
259 std::cout
<< "\t#passed:\t\t" << passed
<< std::endl
;
260 std::cout
<< "\t#real failed:\t\t" << failed
<< std::endl
;
262 std::cout
<< "\t#expected failures:\t\t" << xfailed
<< std::endl
;
264 std::cout
<< "\t#unexpected passes:\t\t" << xpassed
<< std::endl
;
266 std::cout
<< "\t#untested:\t\t" << untest
<< std::endl
;
268 std::cout
<< "\t#unresolved:\t\t" << unresolve
<< std::endl
;
269 std::cout
<< "\tEND: done" << std::endl
;
272 // This is so this class can be printed in an ostream.
273 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
275 return os
<< "\t" << outstate
[t
.laststate
] << t
.lastmsg
;
278 int GetState (void) { return laststate
; }
279 std::string
GetMsg (void) { return lastmsg
; }
282 #endif /* __cplusplus */
283 #endif /* _DEJAGNU_H_ */