1 /* DejaGnu unit testing header.
2 Copyright (C) 2000-2016, 2022 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 see the section
29 * "Priority of Expect Patterns" in *note (dejagnu)Writing a test case. or
30 * use the DejaGnu built-in unit testing support in your testsuite, which
31 * has been improved to resolve this issue in DejaGnu 1.6.3. */
43 static char buffer
[512];
46 pass (const char* fmt
, ...)
52 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
54 printf ("\tPASSED: %s\n", buffer
);
58 xpass (const char* fmt
, ...)
64 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
66 printf ("\tXPASSED: %s\n", buffer
);
70 fail (const char* fmt
, ...)
76 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
78 printf ("\tFAILED: %s\n", buffer
);
82 xfail (const char* fmt
, ...)
88 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
90 printf ("\tXFAILED: %s\n", buffer
);
94 untested (const char* fmt
, ...)
98 DG__status
.untested
++;
100 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
102 printf ("\tUNTESTED: %s\n", buffer
);
106 unresolved (const char* fmt
, ...)
110 DG__status
.unresolved
++;
112 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
114 printf ("\tUNRESOLVED: %s\n", buffer
);
118 unsupported (const char* fmt
, ...)
122 DG__status
.unsupported
++;
124 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
126 printf ("\tUNSUPPORTED: %s\n", buffer
);
130 note (const char* fmt
, ...)
135 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
137 printf ("\tNOTE: %s\n", buffer
);
143 printf ("\nTotals:\n");
144 printf ("\t#passed:\t\t%d\n", DG__status
.pass
);
145 printf ("\t#real failed:\t\t%d\n", DG__status
.fail
);
146 if (DG__status
.xfail
)
147 printf ("\t#expected failures:\t\t%d\n", DG__status
.xfail
);
148 if (DG__status
.xpass
)
149 printf ("\t#unexpected passes:\t\t%d\n", DG__status
.xpass
);
150 if (DG__status
.untested
)
151 printf ("\t#untested:\t\t%d\n", DG__status
.untested
);
152 if (DG__status
.unresolved
)
153 printf ("\t#unresolved:\t\t%d\n", DG__status
.unresolved
);
154 if (DG__status
.unsupported
)
155 printf ("\t#unsupported:\t\t%d\n", DG__status
.unsupported
);
156 printf ("\tEND: done\n");
166 const char *outstate_list
[] = {
167 "FAILED: ", "PASSED: ",
168 "UNTESTED: ", "UNRESOLVED: ", "UNSUPPORTED: ",
169 "XFAILED: ", "XPASSED: "
172 const char ** outstate
= outstate_list
;
174 enum teststate
{ FAILED
, PASSED
,
175 UNTESTED
, UNRESOLVED
, UNSUPPORTED
,
176 XFAILED
, XPASSED
} laststate
;
187 DG__status
.untested
= 0;
188 DG__status
.xpass
= 0;
189 DG__status
.xfail
= 0;
190 DG__status
.unresolved
= 0;
191 DG__status
.unsupported
= 0;
194 ~TestState (void) { totals(); }
196 void testrun (bool b
, std::string s
)
204 void pass (std::string s
)
209 std::cout
<< "\t" << outstate
[PASSED
] << s
<< std::endl
;
212 void xpass (std::string s
)
217 std::cout
<< "\t" << outstate
[XPASSED
] << s
<< std::endl
;
220 void fail (std::string s
)
225 std::cout
<< "\t" << outstate
[FAILED
] << s
<< std::endl
;
228 void xfail (std::string s
)
233 std::cout
<< "\t" << outstate
[XFAILED
] << s
<< std::endl
;
236 void untested (std::string s
)
238 DG__status
.untested
++;
239 laststate
= UNTESTED
;
241 std::cout
<< "\t" << outstate
[UNTESTED
] << s
<< std::endl
;
244 void unresolved (std::string s
)
246 DG__status
.unresolved
++;
247 laststate
= UNRESOLVED
;
249 std::cout
<< "\t" << outstate
[UNRESOLVED
] << s
<< std::endl
;
252 void unsupported (std::string s
)
254 DG__status
.unsupported
++;
255 laststate
= UNSUPPORTED
;
257 std::cout
<< "\t" << outstate
[UNSUPPORTED
] << s
<< std::endl
;
260 void note (std::string s
)
262 std::cout
<< "\t" << "NOTE: " << s
<< std::endl
;
267 std::cout
<< std::endl
<< "Totals:" << std::endl
;
269 std::cout
<< "\t#passed:\t\t"
270 << DG__status
.pass
<< std::endl
;
271 std::cout
<< "\t#real failed:\t\t"
272 << DG__status
.fail
<< std::endl
;
274 if (DG__status
.xfail
)
275 std::cout
<< "\t#expected failures:\t\t"
276 << DG__status
.xfail
<< std::endl
;
277 if (DG__status
.xpass
)
278 std::cout
<< "\t#unexpected passes:\t\t"
279 << DG__status
.xpass
<< std::endl
;
280 if (DG__status
.untested
)
281 std::cout
<< "\t#untested:\t\t"
282 << DG__status
.untested
<< std::endl
;
283 if (DG__status
.unresolved
)
284 std::cout
<< "\t#unresolved:\t\t"
285 << DG__status
.unresolved
<< std::endl
;
286 if (DG__status
.unsupported
)
287 std::cout
<< "\t#unsupported:\t\t"
288 << DG__status
.unsupported
<< std::endl
;
290 std::cout
<< "\tEND: done" << std::endl
;
293 // This is so this class can be printed in an ostream.
294 friend std::ostream
& operator << (std::ostream
&os
, TestState
& t
)
296 return os
<< "\t" << outstate
[t
.laststate
] << t
.lastmsg
;
299 int GetState (void) { return laststate
; }
300 std::string
GetMsg (void) { return lastmsg
; }
303 #endif /* __cplusplus */
304 #endif /* _DEJAGNU_H_ */