2
* Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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. */
19
21
#ifndef __DEJAGNU_H__
20
22
#define __DEJAGNU_H__
23
25
#include <stdarg.h>
24
26
#include <string.h>
26
/* If you have problems with dejagnu dropping failed, untested, or
27
* unresolved messages generated by a unit testcase,
28
/* If you have problems with DejaGnu dropping failed, untested, or
29
* unresolved messages generated by a unit testcase, then: */
30
/* #define _DEJAGNU_WAIT_
31
/* #define _DEJAGNU_WAIT_ */
33
33
#ifdef _DEJAGNU_WAIT_
34
# include <sys/time.h>
35
# include <sys/types.h>
35
#include <sys/types.h>
39
#define _BUFFER_SIZE_ 512
44
42
static int unresolve;
46
static char buffer[ _BUFFER_SIZE_ ];
44
static char buffer[512];
58
select(0, &rfds, NULL, NULL, &tv);
57
select (0, &rfds, NULL, NULL, &tv);
63
pass (const char* fmt, ... ) {
62
pass (const char* fmt, ...)
68
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
70
printf ("\tPASSED: %s\n", buffer );
77
fail (const char* fmt, ... ) {
82
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
84
printf ("\tFAILED: %s\n", buffer );
91
untested (const char* fmt, ... ) {
96
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
98
printf ("\tUNTESTED: %s\n", buffer );
105
unresolved (const char* fmt, ... ) {
110
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
112
printf ("\tUNRESOLVED: %s\n", buffer );
113
#ifdef _DEJAGNU_WAIT_
119
note (const char* fmt, ... ) {
123
vsnprintf( buffer, _BUFFER_SIZE_, fmt, ap );
125
printf ("\tNOTE: %s\n", buffer );
126
#ifdef _DEJAGNU_WAIT_
133
printf ("\nTotals:\n");
134
printf ("\t#passed:\t\t%d\n", passed);
135
printf ("\t#failed:\t\t%d\n", failed);
137
printf ("\t#untested:\t\t%d\n", untest);
139
printf ("\t#unresolved:\t\t%d\n", unresolved);
68
vsnprintf (buffer, sizeof (buffer), fmt, ap);
70
printf ("\tPASSED: %s\n", buffer);
75
fail (const char* fmt, ...)
81
vsnprintf (buffer, sizeof (buffer), fmt, ap);
83
printf ("\tFAILED: %s\n", buffer);
88
untested (const char* fmt, ...)
94
vsnprintf (buffer, sizeof (buffer), fmt, ap);
96
printf ("\tUNTESTED: %s\n", buffer);
101
unresolved (const char* fmt, ...)
107
vsnprintf (buffer, sizeof (buffer), fmt, ap);
109
printf ("\tUNRESOLVED: %s\n", buffer);
114
note (const char* fmt, ...)
119
vsnprintf (buffer, sizeof (buffer), fmt, ap);
121
printf ("\tNOTE: %s\n", buffer);
128
printf ("\nTotals:\n");
129
printf ("\t#passed:\t\t%d\n", passed);
130
printf ("\t#failed:\t\t%d\n", failed);
132
printf ("\t#untested:\t\t%d\n", untest);
134
printf ("\t#unresolved:\t\t%d\n", unresolved);
142
137
#ifdef __cplusplus
145
139
#include <iostream>
146
140
#include <iomanip>
147
141
#include <fstream>
148
142
#include <string>
157
144
const char *outstate_list[] = {
145
"FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: "
164
148
const char ** outstate = outstate_list;
167
extern ios& __iomanip_testout (ios&, int);
168
inline smanip<int> testout (int n) {
169
return smanip<int> (__iomanip_testout, n);
171
ios & __iomanip_testout (ios& i, int x) {
179
ostream &(*f)(ostream&, T);
181
OMANIP(ostream& (*ff)(ostream&, T), T ii) : f(ff), i(ii) {
183
friend ostream operator<<(ostream& us, OMANIP& m) {
189
freakout(ostream& os, int x) {
190
return os << "FREAKOUT" ;
191
// return x << "TESTOUT " << x ;
194
OMANIP<int> testout(int i) {
195
return OMANIP<int>(&freakout,i);
199
enum teststate {FAILED, PASSED,UNTESTED,UNRESOLVED} laststate;
150
enum teststate { FAILED, PASSED, UNTESTED, UNRESOLVED} laststate;
201
152
class TestState {
216
void testrun (bool b, std::string s) {
223
void pass (std::string s) {
165
~TestState (void) { totals(); }
167
void testrun (bool b, std::string s)
175
void pass (std::string s)
225
178
laststate = PASSED;
227
180
std::cout << "\t" << outstate[PASSED] << s << std::endl;
229
void pass (const char *c) {
183
void pass (const char *c)
234
void fail (std::string s) {
189
void fail (std::string s)
236
192
laststate = FAILED;
238
194
std::cout << "\t" << outstate[FAILED] << s << std::endl;
240
void fail (const char *c) {
197
void fail (const char *c)
241
199
std::string s = c;
245
void untested (std::string s) {
203
void untested (std::string s)
247
206
laststate = UNTESTED;
249
208
std::cout << "\t" << outstate[UNTESTED] << s << std::endl;
251
void untested (const char *c) {
211
void untested (const char *c)
252
213
std::string s = c;
256
void unresolved (std::string s) {
217
void unresolved (std::string s)
258
220
laststate = UNRESOLVED;
260
222
std::cout << "\t" << outstate[UNRESOLVED] << s << std::endl;
262
void unresolved (const char *c) {
225
void unresolved (const char *c)
263
227
std::string s = c;
268
233
std::cout << "\t#passed:\t\t" << passed << std::endl;
269
234
std::cout << "\t#failed:\t\t" << failed << std::endl;
271
std::cout << "\t#untested:\t\t" << untest << std::endl;
236
std::cout << "\t#untested:\t\t" << untest << std::endl;
273
std::cout << "\t#unresolved:\t\t" << unresolve << std::endl;
238
std::cout << "\t#unresolved:\t\t" << unresolve << std::endl;
276
241
// This is so this class can be printed in an ostream.
277
friend std::ostream & operator << (std::ostream &os, TestState& t) {
278
return os << "\t" << outstate[t.laststate] << t.lastmsg ;
284
std::string GetMsg(void) {
242
friend std::ostream & operator << (std::ostream &os, TestState& t)
244
return os << "\t" << outstate[t.laststate] << t.lastmsg ;
247
int GetState (void) { return laststate; }
248
std::string GetMsg (void) { return lastmsg; }
289
#endif // __cplusplus
290
#endif // _DEJAGNU_H_
251
#endif /* __cplusplus */
252
#endif /* _DEJAGNU_H_ */