Files
boost_beast/extras/beast/unit_test/results.hpp
T

242 lines
4.8 KiB
C++
Raw Normal View History

2017-07-20 08:01:46 -07:00
//
2017-02-06 20:07:03 -05:00
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2017-07-20 08:01:46 -07:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
2016-05-06 19:14:17 -04:00
#ifndef BEAST_UNIT_TEST_RESULTS_HPP
#define BEAST_UNIT_TEST_RESULTS_HPP
2017-07-20 08:01:46 -07:00
2016-05-07 14:57:15 -04:00
#include <beast/unit_test/detail/const_container.hpp>
2017-07-20 08:01:46 -07:00
#include <string>
#include <vector>
namespace beast {
namespace unit_test {
/** Holds a set of test condition outcomes in a testcase. */
class case_results
{
public:
/** Holds the result of evaluating one test condition. */
struct test
{
2016-08-29 10:43:56 -04:00
explicit test(bool pass_)
: pass(pass_)
2017-07-20 08:01:46 -07:00
{
}
2016-08-29 10:43:56 -04:00
test(bool pass_, std::string const& reason_)
: pass(pass_)
, reason(reason_)
2017-07-20 08:01:46 -07:00
{
}
bool pass;
std::string reason;
};
private:
class tests_t
2016-05-07 14:57:15 -04:00
: public detail::const_container <std::vector <test>>
2017-07-20 08:01:46 -07:00
{
private:
std::size_t failed_;
public:
2016-08-26 08:01:44 -04:00
tests_t()
2016-08-29 10:43:56 -04:00
: failed_(0)
2017-07-20 08:01:46 -07:00
{
}
/** Returns the total number of test conditions. */
std::size_t
total() const
{
return cont().size();
}
/** Returns the number of failed test conditions. */
std::size_t
failed() const
{
return failed_;
}
/** Register a successful test condition. */
void
pass()
{
2016-08-29 10:43:56 -04:00
cont().emplace_back(true);
2017-07-20 08:01:46 -07:00
}
/** Register a failed test condition. */
void
2016-08-29 10:43:56 -04:00
fail(std::string const& reason = "")
2017-07-20 08:01:46 -07:00
{
++failed_;
2016-08-29 10:43:56 -04:00
cont().emplace_back(false, reason);
2017-07-20 08:01:46 -07:00
}
};
class log_t
2016-05-07 14:57:15 -04:00
: public detail::const_container <std::vector <std::string>>
2017-07-20 08:01:46 -07:00
{
public:
/** Insert a string into the log. */
void
2016-08-29 10:43:56 -04:00
insert(std::string const& s)
2017-07-20 08:01:46 -07:00
{
2016-08-29 10:43:56 -04:00
cont().push_back(s);
2017-07-20 08:01:46 -07:00
}
};
std::string name_;
public:
2016-08-29 10:43:56 -04:00
explicit case_results(std::string const& name = "")
: name_(name)
2017-07-20 08:01:46 -07:00
{
}
/** Returns the name of this testcase. */
std::string const&
name() const
{
return name_;
}
/** Memberspace for a container of test condition outcomes. */
tests_t tests;
/** Memberspace for a container of testcase log messages. */
log_t log;
};
//--------------------------------------------------------------------------
/** Holds the set of testcase results in a suite. */
class suite_results
2016-05-07 14:57:15 -04:00
: public detail::const_container <std::vector <case_results>>
2017-07-20 08:01:46 -07:00
{
private:
std::string name_;
std::size_t total_ = 0;
std::size_t failed_ = 0;
public:
2016-08-29 10:43:56 -04:00
explicit suite_results(std::string const& name = "")
: name_(name)
2017-07-20 08:01:46 -07:00
{
}
/** Returns the name of this suite. */
std::string const&
name() const
{
return name_;
}
/** Returns the total number of test conditions. */
std::size_t
total() const
{
return total_;
}
/** Returns the number of failures. */
std::size_t
failed() const
{
return failed_;
}
/** Insert a set of testcase results. */
/** @{ */
void
2016-08-29 10:43:56 -04:00
insert(case_results&& r)
2017-07-20 08:01:46 -07:00
{
2016-08-29 10:43:56 -04:00
cont().emplace_back(std::move(r));
2017-07-20 08:01:46 -07:00
total_ += r.tests.total();
failed_ += r.tests.failed();
}
void
2016-08-29 10:43:56 -04:00
insert(case_results const& r)
2017-07-20 08:01:46 -07:00
{
2016-08-29 10:43:56 -04:00
cont().push_back(r);
2017-07-20 08:01:46 -07:00
total_ += r.tests.total();
failed_ += r.tests.failed();
}
/** @} */
};
//------------------------------------------------------------------------------
// VFALCO TODO Make this a template class using scoped allocators
/** Holds the results of running a set of testsuites. */
class results
2016-05-07 14:57:15 -04:00
: public detail::const_container <std::vector <suite_results>>
2017-07-20 08:01:46 -07:00
{
private:
std::size_t m_cases;
std::size_t total_;
std::size_t failed_;
public:
results()
2016-08-29 10:43:56 -04:00
: m_cases(0)
, total_(0)
, failed_(0)
2017-07-20 08:01:46 -07:00
{
}
/** Returns the total number of test cases. */
std::size_t
cases() const
{
return m_cases;
}
/** Returns the total number of test conditions. */
std::size_t
total() const
{
return total_;
}
/** Returns the number of failures. */
std::size_t
failed() const
{
return failed_;
}
/** Insert a set of suite results. */
/** @{ */
void
2016-08-29 10:43:56 -04:00
insert(suite_results&& r)
2017-07-20 08:01:46 -07:00
{
m_cases += r.size();
total_ += r.total();
failed_ += r.failed();
2016-08-29 10:43:56 -04:00
cont().emplace_back(std::move(r));
2017-07-20 08:01:46 -07:00
}
void
2016-08-29 10:43:56 -04:00
insert(suite_results const& r)
2017-07-20 08:01:46 -07:00
{
m_cases += r.size();
total_ += r.total();
failed_ += r.failed();
2016-08-29 10:43:56 -04:00
cont().push_back(r);
2017-07-20 08:01:46 -07:00
}
/** @} */
};
} // unit_test
} // beast
#endif