6 /************** TestBase **************/
7 void TestBase::printSummary(std::ostream
& out
) const
10 out
<< "==================================================" << endl
;
11 out
<< "| | failed | succeed | total |" << endl
;
12 out
<< "|------------------------------------------------|" << endl
;
13 out
<< "| assertations: | ";
15 out
<< left
<< assertationsFailed();
18 out
<< left
<< assertationsSucceed();
21 out
<< left
<< assertations();
25 out
<< left
<< testsFailed();
28 out
<< left
<< testsSucceed();
31 out
<< left
<< tests();
33 out
<< "| tests cases: | ";
35 out
<< left
<< testCasesFailed();
38 out
<< left
<< testCasesSucceed();
41 out
<< left
<< testCases();
43 out
<< "| tests suites: | ";
45 out
<< left
<< testSuitesFailed();
48 out
<< left
<< testSuitesSucceed();
51 out
<< left
<< testSuites();
53 out
<< "==================================================" << endl
;
55 /************** TestBase END **********/
58 /************** TestCase **************/
59 //TODO: 3 almost same functions: how reduce duplicities?
60 int TestCase::assertations() const
64 vector
<test_state_t
>::const_iterator it
= _tests_states
.begin();
65 vector
<test_state_t
>::const_iterator it_end
= _tests_states
.end();
66 for (;it
!= it_end
; it
++){
67 assertations
+= it
->assertations
;
73 int TestCase::assertationsFailed() const
77 vector
<test_state_t
>::const_iterator it
= _tests_states
.begin();
78 vector
<test_state_t
>::const_iterator it_end
= _tests_states
.end();
79 for (;it
!= it_end
; it
++){
80 assertations
+= it
->fails
;
86 int TestCase::assertationsSucceed() const
90 vector
<test_state_t
>::const_iterator it
= _tests_states
.begin();
91 vector
<test_state_t
>::const_iterator it_end
= _tests_states
.end();
92 for (;it
!= it_end
; it
++){
93 assertations
+= it
->successes
;
99 void TestCase::run(bool verbose
)
103 this->_verbose
= true;
110 this->_verbose
= false;
113 void TestCase::errorMessages(ostream
&out
) const
115 vector
<error_message_t
>::const_iterator error_it
;
116 vector
<error_message_t
>::const_iterator error_it_end
;
117 vector
<test_state_t
>::const_iterator it
= _tests_states
.begin();
118 vector
<test_state_t
>::const_iterator it_end
= _tests_states
.end();
119 for (;it
!= it_end
; ++it
){
120 if (it
->error_messages
.size() > 0){
121 error_it
= it
->error_messages
.begin();
122 error_it_end
= it
->error_messages
.end();
123 for (;error_it
!= error_it_end
; ++error_it
){
124 out
<< _getErrorMessage(error_it
->file
, error_it
->line
,
125 it
->test_name
, error_it
->message
) << endl
;
134 string
TestCase::_getErrorMessage(const string file
, const int line
,
135 const string test_method
, const string error_message
) const
137 std::stringstream ss
;
141 return (file
+ ":" + l
+ ": " + _name
+ "::" + test_method
+ " :: " + error_message
);
144 void TestCase::_prepareTest(string name
)
148 _current_test
.clean();
149 _current_test
.test_name
= name
;
152 void TestCase::_finishTest(void)
154 if (_current_test
.fails
> 0){
159 _tests_states
.push_back(_current_test
);
163 void TestCase::_successAssertation(void)
165 _current_test
.assertations
++;
166 _current_test
.successes
++;
169 void TestCase::_failAssertation(string file
, int line
,
170 string error_message
)
174 _current_test
.assertations
++;
175 _current_test
.fails
++;
179 tmp
.message
= error_message
;
180 _current_test
.error_messages
.push_back(tmp
);
183 cout
<< _getErrorMessage(file
, line
, _current_test
.test_name
,
184 error_message
) << endl
;
186 /************** TestCase END **********/
190 /************** TestSuite *************/
191 TestSuite::~TestSuite()
193 vector
<TestBase
*>::iterator it
= tests
.begin();
194 vector
<TestBase
*>::iterator it_end
= tests
.end();
195 for (;it
!= it_end
; it
++){
200 void TestSuite::run(bool verbose
)
202 vector
<TestBase
*>::iterator it
= tests
.begin();
203 vector
<TestBase
*>::iterator it_end
= tests
.end();
204 for (;it
!= it_end
; it
++){
208 /************** TestSuite END *********/