Code

Mnemonics in "Export bitmap", and "Rows and Columns" dialogs (Bug 170765)
[inkscape.git] / cxxtest / cxxtest / TestSuite.cpp
1 #ifndef __cxxtest__TestSuite_cpp__
2 #define __cxxtest__TestSuite_cpp__
4 #include <cxxtest/TestSuite.h>
6 namespace CxxTest
7 {
8     //
9     // TestSuite members
10     //
11     TestSuite::~TestSuite() {}
12     void TestSuite::setUp() {}
13     void TestSuite::tearDown() {}
15     //
16     // Test-aborting stuff
17     //
18     static bool currentAbortTestOnFail = false;
20     bool abortTestOnFail()
21     {
22         return currentAbortTestOnFail;
23     }
25     void setAbortTestOnFail( bool value )
26     {
27         currentAbortTestOnFail = value;
28     }
29     
30     void doAbortTest()
31     {
32 #   if defined(_CXXTEST_HAVE_EH)
33         if ( currentAbortTestOnFail )
34             throw AbortTest();
35 #   endif // _CXXTEST_HAVE_EH
36     }
38     //
39     // Max dump size
40     //
41     static unsigned currentMaxDumpSize = CXXTEST_MAX_DUMP_SIZE;
43     unsigned maxDumpSize()
44     {
45         return currentMaxDumpSize;
46     }
47     
48     void setMaxDumpSize( unsigned value )
49     {
50         currentMaxDumpSize = value;
51     }
53     //
54     // Some non-template functions
55     //
56     void doTrace( const char *file, unsigned line, const char *message )
57     {
58         tracker().trace( file, line, message );
59     }
61     void doWarn( const char *file, unsigned line, const char *message )
62     {
63         tracker().warning( file, line, message );
64     }
66     void doFailTest( const char *file, unsigned line, const char *message )
67     {
68         tracker().failedTest( file, line, message );
69         TS_ABORT();
70     }
72     void doFailAssert( const char *file, unsigned line,
73                        const char *expression, const char *message )
74     {
75         if ( message )
76             tracker().failedTest( file, line, message );
77         tracker().failedAssert( file, line, expression );
78         TS_ABORT();
79     }
81     bool sameData( const void *x, const void *y, unsigned size )
82     {
83         if ( size == 0 )
84             return true;
85         
86         if ( x == y )
87             return true;
89         if ( !x || !y )
90             return false;
92         const char *cx = (const char *)x;
93         const char *cy = (const char *)y;
94         while ( size -- )
95             if ( *cx++ != *cy++ )
96                 return false;
98         return true;
99     }
101     void doAssertSameData( const char *file, unsigned line,
102                            const char *xExpr, const void *x,
103                            const char *yExpr, const void *y,
104                            const char *sizeExpr, unsigned size,
105                            const char *message )
106     {
107         if ( !sameData( x, y, size ) ) {
108             if ( message )
109                 tracker().failedTest( file, line, message );
110             tracker().failedAssertSameData( file, line, xExpr, yExpr, sizeExpr, x, y, size );
111             TS_ABORT();
112         }
113     }
115     void doFailAssertThrows( const char *file, unsigned line,
116                              const char *expr, const char *type,
117                              bool otherThrown,
118                              const char *message )
119     {
120         if ( message )
121             tracker().failedTest( file, line, message );
122         
123         tracker().failedAssertThrows( file, line, expr, type, otherThrown );
124         TS_ABORT();
125     }
127     void doFailAssertThrowsNot( const char *file, unsigned line,
128                                 const char *expression, const char *message )
129     {
130         if ( message )
131             tracker().failedTest( file, line, message );
132         
133         tracker().failedAssertThrowsNot( file, line, expression );
134         TS_ABORT();
135     }
136 };
138 #endif // __cxxtest__TestSuite_cpp__