1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Data Differential YATL (i.e. libtest) library
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "mem_config.h"
39 #include <libtest/common.h>
48 TestCase(const std::string
& arg
):
54 const std::string
& name() const
59 test_return_t
result() const
64 void result(test_return_t arg
)
69 void result(test_return_t arg
, const libtest::Timer
& timer_
)
75 const libtest::Timer
& timer() const
80 void timer(libtest::Timer
& arg
)
87 test_return_t _result
;
88 libtest::Timer _timer
;
91 Formatter::Formatter(const std::string
& arg
) :
96 Formatter::~Formatter()
98 for (TestCases::iterator iter
= _testcases
.begin(); iter
!= _testcases
.end(); ++iter
)
104 TestCase
* Formatter::current()
106 return _testcases
.back();
109 void Formatter::skipped()
111 current()->result(TEST_SKIPPED
);
112 Out
<< name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";
117 void Formatter::failed()
120 current()->result(TEST_FAILURE
);
122 Out
<< name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]";
127 void Formatter::success(const libtest::Timer
& timer_
)
130 current()->result(TEST_SUCCESS
, timer_
);
135 << current()->timer()
136 << " [ " << test_strerror(current()->result()) << " ]";
141 void Formatter::xml(libtest::Framework
& framework_
, std::ofstream
& output
)
143 output
<< "<testsuites name=\"" << framework_
.name() << "\">" << std::endl
;
144 for (Suites::iterator framework_iter
= framework_
.suites().begin();
145 framework_iter
!= framework_
.suites().end();
148 output
<< "\t<testsuite name=\"" << (*framework_iter
)->name() << "\" classname=\"\" package=\"\">" << std::endl
;
150 for (TestCases::iterator case_iter
= (*framework_iter
)->formatter()->testcases().begin();
151 case_iter
!= (*framework_iter
)->formatter()->testcases().end();
154 output
<< "\t\t<testcase name=\""
155 << (*case_iter
)->name()
157 << (*case_iter
)->timer().elapsed_milliseconds()
161 switch ((*case_iter
)->result())
164 output
<< "\t\t <skipped/>" << std::endl
;
168 output
<< "\t\t <failure message=\"\" type=\"\"/>"<< std::endl
;
174 output
<< "\t\t</testcase>" << std::endl
;
176 output
<< "\t</testsuite>" << std::endl
;
178 output
<< "</testsuites>" << std::endl
;
181 void Formatter::push_testcase(const std::string
& arg
)
183 assert(_suite_name
.empty() == false);
184 TestCase
* _current_testcase
= new TestCase(arg
);
185 _testcases
.push_back(_current_testcase
);
188 void Formatter::reset()
191 } // namespace libtest