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#untested:\t\t%d\n", untest
);
163 printf ("\t#unresolved:\t\t%d\n", unresolve
);
173 const char *outstate_list
[] = {
174 "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: ", "XFAILED: ", "XPASSED: "
177 const char ** outstate
= outstate_list
;
179 enum teststate
{ FAILED
, PASSED
, UNTESTED
, UNRESOLVED
, XFAILED
, XPASSED
} laststate
;
196 ~TestState (void) { totals(); }
198 void testrun (bool b
, std::string s
)
206 void pass (std::string s
)
211 std::cout
<< "\t" << outstate
[PASSED
] << s
<< std::endl
;
214 void xpass (std::string s
)
219 std::cout
<< "\t" << outstate
[XPASSED
] << s
<< std::endl
;
222 void fail (std::string s
)
227 std::cout
<< "\t" << outstate
[FAILED
] << s
<< std::endl
;
230 void xfail (std::string s
)
235 std::cout
<< "\t" << outstate
[XFAILED
] << s
<< std::endl
;
238 void untested (std::string s
)
241 laststate
= UNTESTED
;
243 std::cout
<< "\t" << outstate
[UNTESTED
] << s
<< std::endl
;
246 void unresolved (std::string s
)
249 laststate
= UNRESOLVED
;
251 std::cout
<< "\t" << outstate
[UNRESOLVED
] << s
<< std::endl
;
256 std::cout
<< "\t#passed:\t\t" << passed
<< std::endl
;
257 std::cout
<< "\t#real failed:\t\t" << failed
<< std::endl
;
259 std::cout
<< "\t#expected failures:\t\t" << xfailed
<< std::endl
;
261 std::cout
<< "\t#unexpected passes:\t\t" << xpassed
<< std::endl
;
263 std::cout
<< "\t#untested:\t\t" << untest
<< std::endl
;
265 std::cout
<< "\t#unresolved:\t\t" << unresolve
<< std::endl
;
268 // This is so this class can be printed in an ostream.
269 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
271 return os
<< "\t" << outstate
[t
.laststate
] << t
.lastmsg
;
274 int GetState (void) { return laststate
; }
275 std::string
GetMsg (void) { return lastmsg
; }
278 #endif /* __cplusplus */
279 #endif /* _DEJAGNU_H_ */