123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- #ifndef BOOST_BEAST_UNIT_TEST_RESULTS_HPP
- #define BOOST_BEAST_UNIT_TEST_RESULTS_HPP
- #include <boost/beast/_experimental/unit_test/detail/const_container.hpp>
- #include <string>
- #include <vector>
- namespace boost {
- namespace beast {
- namespace unit_test {
- class case_results
- {
- public:
-
- struct test
- {
- explicit test(bool pass_)
- : pass(pass_)
- {
- }
- test(bool pass_, std::string const& reason_)
- : pass(pass_)
- , reason(reason_)
- {
- }
- bool pass;
- std::string reason;
- };
- private:
- class tests_t
- : public detail::const_container <std::vector <test>>
- {
- private:
- std::size_t failed_;
- public:
- tests_t()
- : failed_(0)
- {
- }
-
- std::size_t
- total() const
- {
- return cont().size();
- }
-
- std::size_t
- failed() const
- {
- return failed_;
- }
-
- void
- pass()
- {
- cont().emplace_back(true);
- }
-
- void
- fail(std::string const& reason = "")
- {
- ++failed_;
- cont().emplace_back(false, reason);
- }
- };
- class log_t
- : public detail::const_container <std::vector <std::string>>
- {
- public:
-
- void
- insert(std::string const& s)
- {
- cont().push_back(s);
- }
- };
- std::string name_;
- public:
- explicit case_results(std::string const& name = "")
- : name_(name)
- {
- }
-
- std::string const&
- name() const
- {
- return name_;
- }
-
- tests_t tests;
-
- log_t log;
- };
- class suite_results
- : public detail::const_container <std::vector <case_results>>
- {
- private:
- std::string name_;
- std::size_t total_ = 0;
- std::size_t failed_ = 0;
- public:
- explicit suite_results(std::string const& name = "")
- : name_(name)
- {
- }
-
- std::string const&
- name() const
- {
- return name_;
- }
-
- std::size_t
- total() const
- {
- return total_;
- }
-
- std::size_t
- failed() const
- {
- return failed_;
- }
-
-
- void
- insert(case_results&& r)
- {
- cont().emplace_back(std::move(r));
- total_ += r.tests.total();
- failed_ += r.tests.failed();
- }
- void
- insert(case_results const& r)
- {
- cont().push_back(r);
- total_ += r.tests.total();
- failed_ += r.tests.failed();
- }
-
- };
- class results
- : public detail::const_container <std::vector <suite_results>>
- {
- private:
- std::size_t m_cases;
- std::size_t total_;
- std::size_t failed_;
- public:
- results()
- : m_cases(0)
- , total_(0)
- , failed_(0)
- {
- }
-
- std::size_t
- cases() const
- {
- return m_cases;
- }
-
- std::size_t
- total() const
- {
- return total_;
- }
-
- std::size_t
- failed() const
- {
- return failed_;
- }
-
-
- void
- insert(suite_results&& r)
- {
- m_cases += r.size();
- total_ += r.total();
- failed_ += r.failed();
- cont().emplace_back(std::move(r));
- }
- void
- insert(suite_results const& r)
- {
- m_cases += r.size();
- total_ += r.total();
- failed_ += r.failed();
- cont().push_back(r);
- }
-
- };
- }
- }
- }
- #endif
|