Go to the documentation of this file.00001 #ifndef _CHECK_H_
00002 #define _CHECK_H_
00003
00004 #ifdef HAVE_CONFIG_H
00005 #include "gnashconfig.h"
00006 #endif
00007
00008 #include <sstream>
00009 #include <iostream>
00010 #include <string>
00011
00012 #define HAVE_DEJAGNU_H 1 // we ship our own now...
00013 #ifdef HAVE_DEJAGNU_H
00014 #include "dejagnu.h"
00015
00016 #define info(x) note x
00017
00018 #else
00019
00020 class TestState
00021 {
00022 public:
00023 void pass(std::string s) { std::cout << "PASSED: " << s << std::endl; };
00024 void xpass(std::string s) { std::cout << "XPASSED: " << s << std::endl; };
00025 void fail(std::string s) { std::cout << "FAILED: " << s << std::endl; };
00026 void xfail(std::string s) { std::cout << "XFAILED: " << s << std::endl; };
00027 void unresolved(std::string s) { std::cout << "UNRESOLVED: " << s << std::endl; };
00028 };
00029
00030 #define info(x) { printf("NOTE: "); printf x; putchar('\n'); }
00031
00032 #endif
00033
00034 TestState _runtest;
00035
00036 #define check_equals_label(label, expr, expected) \
00037 { \
00038 std::stringstream ss; \
00039 if ( ! label.empty() ) ss << label << ": "; \
00040 if ( expr == expected ) \
00041 { \
00042 ss << #expr << " == " << expected; \
00043 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
00044 _runtest.pass(ss.str().c_str()); \
00045 } \
00046 else \
00047 { \
00048 ss << #expr << " == '" << expr << "' (expected: " \
00049 << expected << ")"; \
00050 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
00051 _runtest.fail(ss.str().c_str()); \
00052 } \
00053 }
00054
00055 #define xcheck_equals_label(label, expr, expected) \
00056 { \
00057 std::stringstream ss; \
00058 if ( label != "" ) ss << label << ": "; \
00059 if ( expr == expected ) \
00060 { \
00061 ss << #expr << " == " << expected; \
00062 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
00063 _runtest.xpass(ss.str().c_str()); \
00064 } \
00065 else \
00066 { \
00067 ss << #expr << " == '" << expr << "' (expected: " \
00068 << expected << ")"; \
00069 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
00070 _runtest.xfail(ss.str().c_str()); \
00071 } \
00072 }
00073
00074 #define check_equals(expr, expected) check_equals_label(std::string(), expr, expected)
00075
00076 #define xcheck_equals(expr, expected) xcheck_equals_label(std::string(), expr, expected)
00077
00078 #define check(expr) \
00079 { \
00080 std::stringstream ss; \
00081 ss << #expr; \
00082 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
00083 if ( expr ) { \
00084 _runtest.pass(ss.str().c_str()); \
00085 } else { \
00086 _runtest.fail(ss.str().c_str()); \
00087 } \
00088 }
00089
00090 #define xcheck(expr) \
00091 { \
00092 std::stringstream ss; \
00093 ss << #expr; \
00094 ss << " [" << __FILE__ << ":" << __LINE__ << "]"; \
00095 if ( expr ) { \
00096 _runtest.xpass(ss.str().c_str()); \
00097 } else { \
00098 _runtest.xfail(ss.str().c_str()); \
00099 } \
00100 }
00101
00102 #endif // _CHECK_H_