Add parameter type tests on getURL()-based FSCommand.
[gnash.git] / testsuite / dejagnu.h
blob50903c4947ed6e48f1c0445b3ee1c598ce52f0c2
1 /* DejaGnu unit testing header.
2 Copyright (C) 2000, 2001, 2002, 2004, 2006, 207, 2008, 2009,
3 2010, 2011, 2012 Free Software Foundation, Inc.
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. */
21 #ifndef __DEJAGNU_H__
22 #define __DEJAGNU_H__
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include <string.h>
28 /* If you have problems with DejaGnu dropping failed, untested, or
29 * unresolved messages generated by a unit testcase, then: */
31 /* #define _DEJAGNU_WAIT_ */
33 #ifdef _DEJAGNU_WAIT_
34 #include <sys/time.h>
35 #include <sys/types.h>
36 #include <unistd.h>
37 #endif
39 static int passed;
40 static int failed;
41 static int untest;
42 static int unresolve;
43 static int xfailed;
44 static int xpassed;
46 static char buffer[512];
48 void
49 wait (void)
51 #ifdef _DEJAGNU_WAIT_
52 fd_set rfds;
53 struct timeval tv;
55 FD_ZERO (&rfds);
56 tv.tv_sec = 0;
57 tv.tv_usec = 1;
59 select (0, &rfds, NULL, NULL, &tv);
60 #endif
63 inline void
64 pass (const char* fmt, ...)
66 va_list ap;
68 passed++;
69 va_start (ap, fmt);
70 vsnprintf (buffer, sizeof (buffer), fmt, ap);
71 va_end (ap);
72 printf ("\tPASSED: %s\n", buffer);
73 wait ();
76 inline void
77 xpass (const char* fmt, ...)
79 va_list ap;
81 passed++;
82 va_start (ap, fmt);
83 vsnprintf (buffer, sizeof (buffer), fmt, ap);
84 va_end (ap);
85 printf ("\tXPASSED: %s\n", buffer);
86 wait ();
89 inline void
90 fail (const char* fmt, ...)
92 va_list ap;
94 failed++;
95 va_start (ap, fmt);
96 vsnprintf (buffer, sizeof (buffer), fmt, ap);
97 va_end (ap);
98 printf ("\tFAILED: %s\n", buffer);
99 wait ();
102 inline void
103 xfail (const char* fmt, ...)
105 va_list ap;
107 failed++;
108 va_start (ap, fmt);
109 vsnprintf (buffer, sizeof (buffer), fmt, ap);
110 va_end (ap);
111 printf ("\tXFAILED: %s\n", buffer);
112 wait ();
115 inline void
116 untested (const char* fmt, ...)
118 va_list ap;
120 untest++;
121 va_start (ap, fmt);
122 vsnprintf (buffer, sizeof (buffer), fmt, ap);
123 va_end (ap);
124 printf ("\tUNTESTED: %s\n", buffer);
125 wait ();
128 inline void
129 unresolved (const char* fmt, ...)
131 va_list ap;
133 unresolve++;
134 va_start (ap, fmt);
135 vsnprintf (buffer, sizeof (buffer), fmt, ap);
136 va_end (ap);
137 printf ("\tUNRESOLVED: %s\n", buffer);
138 wait ();
141 inline void
142 note (const char* fmt, ...)
144 va_list ap;
146 va_start (ap, fmt);
147 vsnprintf (buffer, sizeof (buffer), fmt, ap);
148 va_end (ap);
149 printf ("\tNOTE: %s\n", buffer);
150 wait ();
153 inline void
154 totals (void)
156 printf ("\nTotals:\n");
157 printf ("\t#passed:\t\t%d\n", passed);
158 printf ("\t#real failed:\t\t%d\n", failed);
159 if (xfailed)
160 printf ("\t#expected failures:\t\t%d\n", xfailed);
161 if (untest)
162 printf ("\t#untested:\t\t%d\n", untest);
163 if (unresolve)
164 printf ("\t#unresolved:\t\t%d\n", unresolve);
167 #ifdef __cplusplus
169 #include <iostream>
170 #include <iomanip>
171 #include <fstream>
172 #include <string>
174 const char *outstate_list[] = {
175 "FAILED: ", "PASSED: ", "UNTESTED: ", "UNRESOLVED: ", "XFAILED: ", "XPASSED: "
178 const char ** outstate = outstate_list;
180 enum teststate { FAILED, PASSED, UNTESTED, UNRESOLVED, XFAILED, XPASSED} laststate;
182 class TestState {
183 private:
184 teststate laststate;
185 std::string lastmsg;
186 public:
187 TestState (void)
189 passed = 0;
190 failed = 0;
191 untest = 0;
192 xpassed = 0;
193 xfailed = 0;
194 unresolve = 0;
195 laststate = FAILED;
198 ~TestState (void) { totals(); }
200 void testrun (bool b, std::string s)
202 if (b)
203 pass (s);
204 else
205 fail (s);
208 void pass (std::string s)
210 passed++;
211 laststate = PASSED;
212 lastmsg = s;
213 std::cout << "\t" << outstate[PASSED] << s << std::endl;
216 void pass (const char *c)
218 std::string s = c;
219 pass (s);
222 void xpass (std::string s)
224 xpassed++;
225 laststate = PASSED;
226 lastmsg = s;
227 std::cout << "\t" << outstate[XPASSED] << s << std::endl;
230 void xpass (const char *c)
232 std::string s = c;
233 xpass (s);
236 void fail (std::string s)
238 failed++;
239 laststate = FAILED;
240 lastmsg = s;
241 std::cout << "\t" << outstate[FAILED] << s << std::endl;
244 void fail (const char *c)
246 std::string s = c;
247 fail (s);
250 void xfail (std::string s)
252 xfailed++;
253 laststate = XFAILED;
254 lastmsg = s;
255 std::cout << "\t" << outstate[XFAILED] << s << std::endl;
258 void xfail (const char *c)
260 std::string s = c;
261 xfail (s);
264 void untested (std::string s)
266 untest++;
267 laststate = UNTESTED;
268 lastmsg = s;
269 std::cout << "\t" << outstate[UNTESTED] << s << std::endl;
272 void untested (const char *c)
274 std::string s = c;
275 untested (s);
278 void unresolved (std::string s)
280 unresolve++;
281 laststate = UNRESOLVED;
282 lastmsg = s;
283 std::cout << "\t" << outstate[UNRESOLVED] << s << std::endl;
286 void unresolved (const char *c)
288 std::string s = c;
289 unresolved (s);
292 void totals (void)
294 std::cout << "\t#passed:\t\t" << passed << std::endl;
295 std::cout << "\t#real failed:\t\t" << failed << std::endl;
296 if (xfailed)
297 std::cout << "\t#expected failures:\t\t" << xfailed << std::endl;
298 if (xpassed)
299 std::cout << "\t#unexpected passes:\t\t" << xpassed << std::endl;
300 if (untest)
301 std::cout << "\t#untested:\t\t" << untest << std::endl;
302 if (unresolve)
303 std::cout << "\t#unresolved:\t\t" << unresolve << std::endl;
306 // This is so this class can be printed in an ostream.
307 friend std::ostream & operator << (std::ostream &os, TestState& t)
309 return os << "\t" << outstate[t.laststate] << t.lastmsg ;
312 int GetState (void) { return laststate; }
313 std::string GetMsg (void) { return lastmsg; }
316 #endif /* __cplusplus */
317 #endif /* _DEJAGNU_H_ */