* debian/rules: Install all the doc formats.
[dejagnu.git] / dejagnu.h
blob7d6c7f75a871f72d66e496d26304a4f5f3198a72
1 /*
2 * Copyright (C) 2000, 2001 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.
19 #ifndef __DEJAGNU_H__
20 #define __DEJAGNU_H__
22 #include <stdio.h>
24 static int passed;
25 static int failed;
26 static int untest;
27 static int unresolve;
29 inline void
30 pass (const char *s) {
31 passed++;
32 printf ("\tPASSED: %s\n", s);
35 inline void
36 fail (const char *s) {
37 failed++;
38 printf ("\tFAILED: %s\n", s);
41 inline void
42 untested (const char *s) {
43 untest++;
44 printf ("\tUNTESTED: %s\n", s);
47 inline void
48 unresolved (const char *s) {
49 unresolve++;
50 printf ("\tUNRESOLVED: %s\n", s);
53 inline void
54 totals (void) {
55 printf ("\nTotals:\n");
56 printf ("\t#passed:\t\t%d\n", passed);
57 printf ("\t#failed:\t\t%d\n", failed);
58 if (untest)
59 printf ("\t#untested:\t\t%d\n", untest);
60 if (unresolve)
61 printf ("\t#unresolved:\t\t%d\n", unresolved);
64 #ifdef __cplusplus
66 #include <iostream>
67 #include <iomanip>
68 #include <fstream>
69 #include <string>
70 #include <strstream>
72 char *outstate[] = {
73 "FAILED: ",
74 "PASSED: ",
75 "UNTESTED: ",
76 "UNRESOLVED: "
79 #if 0
80 extern ios& __iomanip_testout (ios&, int);
81 inline smanip<int> testout (int n) {
82 return smanip<int> (__iomanip_testout, n);
84 ios & __iomanip_testout (ios& i, int x) {
85 return i;
88 template<class T>
89 class OMANIP {
90 private:
91 T i;
92 ostream &(*f)(ostream&, T);
93 public:
94 OMANIP(ostream& (*ff)(ostream&, T), T ii) : f(ff), i(ii) {
96 friend ostream operator<<(ostream& us, OMANIP& m) {
97 return m.f(os,m.i);
101 ostream&
102 freakout(ostream& os, int x) {
103 return os << "FREAKOUT" ;
104 // return x << "TESTOUT " << x ;
107 OMANIP<int> testout(int i) {
108 return OMANIP<int>(&freakout,i);
110 #endif
112 char *testout (int x) {
113 const int len = 128;
114 static char buf[len];
115 static ostrstream oss(buf, len, ios::out);
116 oss.seekp(ios::beg);
117 oss << outstate[x] << ends;
118 return buf;
121 enum teststate {FAILED, PASSED,UNTESTED,UNRESOLVED} laststate;
123 class TestState {
124 private:
125 teststate laststate;
126 string lastmsg;
127 public:
128 TestState(void) {
129 passed = 0;
130 failed = 0;
131 untest = 0;
132 unresolve = 0;
134 ~TestState(void) {
135 totals();
138 void testrun (bool b, string s) {
139 if (b)
140 pass (s);
141 else
142 fail (s);
145 void pass (string s) {
146 passed++;
147 laststate = PASSED;
148 lastmsg = s;
149 cout << "\t" << testout(PASSED) << s << endl;
151 void pass (const char *c) {
152 string s = c;
153 pass (s);
156 void fail (string s) {
157 failed++;
158 laststate = FAILED;
159 lastmsg = s;
160 cout << "\t" << testout(FAILED) << s << endl;
162 void fail (const char *c) {
163 string s = c;
164 fail (s);
167 void untested (string s) {
168 untest++;
169 laststate = UNTESTED;
170 lastmsg = s;
171 cout << "\t" << testout(UNTESTED) << s << endl;
173 void untested (const char *c) {
174 string s = c;
175 untested (s);
178 void unresolved (string s) {
179 unresolve++;
180 laststate = UNRESOLVED;
181 lastmsg = s;
182 cout << "\t" << testout(UNRESOLVED) << s << endl;
184 void unresolved (const char *c) {
185 string s = c;
186 unresolved (s);
189 void totals (void) {
190 cout << "\t#passed:\t\t" << passed << endl;
191 cout << "\t#failed:\t\t" << failed << endl;
192 if (untest)
193 cout << "\t#untested:\t\t" << untest << endl;
194 if (unresolve)
195 cout << "\t#unresolved:\t\t" << unresolve << endl;
198 // This is so thjis class can be printed in an ostream.
199 friend ostream & operator << (ostream &os, TestState& t) {
200 return os << "\t" << outstate[t.laststate] << t.lastmsg ;
203 int GetState(void) {
204 return laststate;
206 string GetMsg(void) {
207 return lastmsg;
211 #endif // __cplusplus
212 #endif // _DEJAGNU_H_