Renamed variables.
[cppu.git] / cppu.h
blob76c5ed04231d4ecc3018ef1a90923edea0051708
1 #ifndef _CPPU_H_
2 #define _CPPU_H_
4 #include <string>
5 #include <vector>
6 /**
7 * TODO: Copyright, license...
8 * TODO: Udelat to tak, aby se vse vypisovalo za behu a nemuselo se cekat
9 * na dobehnuti celeho testu
11 * TODO: TestSuite a to i takova, ktera muze obsahovat TestSuity
13 * TODO: Dopsat vsechny aserce
16 /**
17 * Struct describing error message.
19 struct error_message_t{
20 std::string file;
21 int line;
22 std::string message;
25 /**
26 * Struct describing state after run test.
28 struct test_state_t{
29 std::string test_name;
30 int assertations;
31 int fails;
32 int successes;
33 std::vector<error_message_t> error_messages;
35 inline void clean(void){assertations=0;fails=0;successes=0;error_messages.clear();}
40 /**
41 * Main class
43 class TestCase{
44 protected:
45 int tests;
46 int fails;
47 int successes;
49 /**
50 * Name of current test case
52 std::string name;
54 /**
55 * List of states of all ran tests.
57 std::vector<test_state_t> tests_states;
59 /**
60 * State of currently running test.
61 * This struct must be empty before running next test method.
63 test_state_t current_test;
66 void prepareTest(std::string test_name);
67 void finishTest(void);
69 void recordSuccessAssertation(void);
70 void recordFailAssertation(std::string file, int line,
71 std::string error_message);
73 public:
74 explicit TestCase(std::string n) : fails(0), successes(0), name(n){}
76 virtual void setUp(void){}
77 virtual void tearDown(void){}
79 /**
80 * Method describing tests.
81 * This must be redeclared in extended class.
83 virtual void run_tests() = 0;
85 /**
86 * This run the test case.
87 * Returns number of failed tests or 255 (lesser number)
89 int run(void);
92 int numTests(){return tests;}
93 int numFails(void){return fails;}
94 int numSuccesses(void){return successes;}
95 void summary(void);
99 /***** TestCase MACROS *****/
100 #define assertEquals(a,b) \
101 if ((a) == (b)){ \
102 recordSuccessAssertation(); \
103 }else{ \
104 recordFailAssertation(__FILE__, __LINE__, #a " not equals " #b); \
106 #define assertEqualsM(a,b,message) \
107 if ((a) == (b)){ \
108 recordSuccessAssertation(); \
109 }else{ \
110 recordFailAssertation(__FILE__, __LINE__, message); \
113 #define assertNotEquals(a,b) \
114 if ((a) != (b)){ \
115 recordSuccessAssertation(); \
116 }else{ \
117 recordFailAssertation(__FILE__, __LINE__, #a " equals " #b); \
119 #define assertNotEqualsM(a,b,message) \
120 if ((a) != (b)){ \
121 recordSuccessAssertation(); \
122 }else{ \
123 recordFailAssertation(__FILE__, __LINE__, message); \
127 #endif
128 /* vim: set sw=4 ts=4 et ft=cpp tw=75 cindent: */