don't free ans more than necessary
[gnash.git] / testsuite / check.h
blob81698db30f460120eeb34b475d5362d0c0750b84
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010,
3 * 2011, 2012 Free Software Foundation, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #ifndef _CHECK_H_
20 #define _CHECK_H_
22 #ifdef HAVE_CONFIG_H
23 #include "gnashconfig.h"
24 #endif
26 #include <sstream>
27 #include <iostream>
28 #include <string>
30 #define HAVE_DEJAGNU_H 1 // we ship our own now...
31 #ifdef HAVE_DEJAGNU_H
32 #include "dejagnu.h"
34 #define info(x) note x
36 #else
37 //#warning "You should install DejaGnu! Using stubs for pass/fail/xpass/xfail..."
38 class TestState
40 public:
41 void pass(std::string s) { std::cout << "PASSED: " << s << std::endl; };
42 void xpass(std::string s) { std::cout << "XPASSED: " << s << std::endl; };
43 void fail(std::string s) { std::cout << "FAILED: " << s << std::endl; };
44 void xfail(std::string s) { std::cout << "XFAILED: " << s << std::endl; };
45 void unresolved(std::string s) { std::cout << "UNRESOLVED: " << s << std::endl; };
48 #define info(x) { printf("NOTE: "); printf x; putchar('\n'); }
50 #endif
52 TestState _runtest;
54 #define check_equals_label(label, expr, expected) \
55 { \
56 std::stringstream ss; \
57 if ( ! label.empty() ) ss << label << ": "; \
58 if ( expr == expected ) \
59 { \
60 ss << #expr << " == " << expected; \
61 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
62 _runtest.pass(ss.str().c_str()); \
63 } \
64 else \
65 { \
66 ss << #expr << " == '" << expr << "' (expected: " \
67 << expected << ")"; \
68 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
69 _runtest.fail(ss.str().c_str()); \
70 } \
73 #define xcheck_equals_label(label, expr, expected) \
74 { \
75 std::stringstream ss; \
76 if ( label != "" ) ss << label << ": "; \
77 if ( expr == expected ) \
78 { \
79 ss << #expr << " == " << expected; \
80 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
81 _runtest.xpass(ss.str().c_str()); \
82 } \
83 else \
84 { \
85 ss << #expr << " == '" << expr << "' (expected: " \
86 << expected << ")"; \
87 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
88 _runtest.xfail(ss.str().c_str()); \
89 } \
92 #define check_equals(expr, expected) check_equals_label(std::string(), expr, expected)
94 #define xcheck_equals(expr, expected) xcheck_equals_label(std::string(), expr, expected)
96 #define check(expr) \
97 { \
98 std::stringstream ss; \
99 ss << #expr; \
100 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
101 if ( expr ) { \
102 _runtest.pass(ss.str().c_str()); \
103 } else { \
104 _runtest.fail(ss.str().c_str()); \
108 #define xcheck(expr) \
110 std::stringstream ss; \
111 ss << #expr; \
112 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
113 if ( expr ) { \
114 _runtest.xpass(ss.str().c_str()); \
115 } else { \
116 _runtest.xfail(ss.str().c_str()); \
120 #endif // _CHECK_H_