initial load of upstream version 1.06.32
[xmlrpc-c] / src / cpp / test / tools.hpp
1 #ifndef TEST_HPP_INCLUDED
2 #define TEST_HPP_INCLUDED
3
4 #include <string>
5
6 #include "xmlrpc-c/girerr.hpp"
7 using girerr::error;
8
9 class testSuite {
10 /*----------------------------------------------------------------------------
11    This is a base class for a test suite.  Give the suite a name
12    (to be used in messages about it) and some test code via
13    virtual methods suiteName() and runtests(), respectively.
14
15    runtests() should throw either an 'error' object or an 'XmlRpcFault'
16    object if the test fails.  It should throw something else if the
17    test can't run.  It should throw nothing if the tests pass.
18
19    You don't normally keep an object of this class around.  You don't
20    even give it a name.  You simply refer to a literal object, like so:
21
22      myTestSuite().run(0)
23 -----------------------------------------------------------------------------*/
24 public:
25     virtual ~testSuite();
26
27     void run(unsigned int const indentation);
28
29     virtual void runtests(unsigned int const) {
30         throw(error("test suite does not have a runtests() method"));
31     };
32     virtual std::string suiteName() {
33         return "unnamed test suite";
34     }
35 };
36
37
38
39 void 
40 logFailedTest(const char * const fileName, 
41               unsigned int const lineNum, 
42               const char * const statement);
43
44 error
45 fileLineError(std::string  const filename,
46               unsigned int const lineNumber,
47               std::string  const description);
48
49 #define TEST(statement) \
50     do { \
51         if (!(statement)) \
52             logFailedTest(__FILE__, __LINE__, #statement); \
53     } while (0)
54
55
56 #define TEST_PASSED() \
57     do { } while (0)
58
59 #define TEST_FAILED(reason) \
60     do { \
61         logFailedTest(__FILE__, __LINE__, (reason)); \
62     } while (0)
63
64 #define EXPECT_ERROR(statement) \
65     do { try { statement } catch (error) {break;} \
66       throw(fileLineError(__FILE__, __LINE__, "Didn't get expected error")); \
67     } while (0)
68
69 #define trickToStraightenOutEmacsIndentation \
70 ;
71
72 #endif