Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:25:01

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_UNIT_TEST_RESULTS_HPP
0011 #define BOOST_BEAST_UNIT_TEST_RESULTS_HPP
0012 
0013 #include <boost/beast/_experimental/unit_test/detail/const_container.hpp>
0014 
0015 #include <string>
0016 #include <vector>
0017 
0018 namespace boost {
0019 namespace beast {
0020 namespace unit_test {
0021 
0022 /** Holds a set of test condition outcomes in a testcase. */
0023 class case_results
0024 {
0025 public:
0026     /** Holds the result of evaluating one test condition. */
0027     struct test
0028     {
0029         explicit test(bool pass_)
0030             : pass(pass_)
0031         {
0032         }
0033 
0034         test(bool pass_, std::string const& reason_)
0035             : pass(pass_)
0036             , reason(reason_)
0037         {
0038         }
0039 
0040         bool pass;
0041         std::string reason;
0042     };
0043 
0044 private:
0045     class tests_t
0046         : public detail::const_container <std::vector <test>>
0047     {
0048     private:
0049         std::size_t failed_;
0050 
0051     public:
0052         tests_t()
0053             : failed_(0)
0054         {
0055         }
0056 
0057         /** Returns the total number of test conditions. */
0058         std::size_t
0059         total() const
0060         {
0061             return cont().size();
0062         }
0063 
0064         /** Returns the number of failed test conditions. */
0065         std::size_t
0066         failed() const
0067         {
0068             return failed_;
0069         }
0070 
0071         /** Register a successful test condition. */
0072         void
0073         pass()
0074         {
0075             cont().emplace_back(true);
0076         }
0077 
0078         /** Register a failed test condition. */
0079         void
0080         fail(std::string const& reason = "")
0081         {
0082             ++failed_;
0083             cont().emplace_back(false, reason);
0084         }
0085     };
0086 
0087     class log_t
0088         : public detail::const_container <std::vector <std::string>>
0089     {
0090     public:
0091         /** Insert a string into the log. */
0092         void
0093         insert(std::string const& s)
0094         {
0095             cont().push_back(s);
0096         }
0097     };
0098 
0099     std::string name_;
0100 
0101 public:
0102     explicit case_results(std::string const& name = "")
0103         : name_(name)
0104     {
0105     }
0106 
0107     /** Returns the name of this testcase. */
0108     std::string const&
0109     name() const
0110     {
0111         return name_;
0112     }
0113 
0114     /** Memberspace for a container of test condition outcomes. */
0115     tests_t tests;
0116 
0117     /** Memberspace for a container of testcase log messages. */
0118     log_t log;
0119 };
0120 
0121 //--------------------------------------------------------------------------
0122 
0123 /** Holds the set of testcase results in a suite. */
0124 class suite_results
0125     : public detail::const_container <std::vector <case_results>>
0126 {
0127 private:
0128     std::string name_;
0129     std::size_t total_ = 0;
0130     std::size_t failed_ = 0;
0131 
0132 public:
0133     explicit suite_results(std::string const& name = "")
0134         : name_(name)
0135     {
0136     }
0137 
0138     /** Returns the name of this suite. */
0139     std::string const&
0140     name() const
0141     {
0142         return name_;
0143     }
0144 
0145     /** Returns the total number of test conditions. */
0146     std::size_t
0147     total() const
0148     {
0149         return total_;
0150     }
0151 
0152     /** Returns the number of failures. */
0153     std::size_t
0154     failed() const
0155     {
0156         return failed_;
0157     }
0158 
0159     /** Insert a set of testcase results. */
0160     /** @{ */
0161     void
0162     insert(case_results&& r)
0163     {
0164         cont().emplace_back(std::move(r));
0165         total_ += r.tests.total();
0166         failed_ += r.tests.failed();
0167     }
0168 
0169     void
0170     insert(case_results const& r)
0171     {
0172         cont().push_back(r);
0173         total_ += r.tests.total();
0174         failed_ += r.tests.failed();
0175     }
0176     /** @} */
0177 };
0178 
0179 //------------------------------------------------------------------------------
0180 
0181 // VFALCO TODO Make this a template class using scoped allocators
0182 /** Holds the results of running a set of testsuites. */
0183 class results
0184     : public detail::const_container <std::vector <suite_results>>
0185 {
0186 private:
0187     std::size_t m_cases;
0188     std::size_t total_;
0189     std::size_t failed_;
0190 
0191 public:
0192     results()
0193         : m_cases(0)
0194         , total_(0)
0195         , failed_(0)
0196     {
0197     }
0198 
0199     /** Returns the total number of test cases. */
0200     std::size_t
0201     cases() const
0202     {
0203         return m_cases;
0204     }
0205 
0206     /** Returns the total number of test conditions. */
0207     std::size_t
0208     total() const
0209     {
0210         return total_;
0211     }
0212 
0213     /** Returns the number of failures. */
0214     std::size_t
0215     failed() const
0216     {
0217         return failed_;
0218     }
0219 
0220     /** Insert a set of suite results. */
0221     /** @{ */
0222     void
0223     insert(suite_results&& r)
0224     {
0225         m_cases += r.size();
0226         total_ += r.total();
0227         failed_ += r.failed();
0228         cont().emplace_back(std::move(r));
0229     }
0230 
0231     void
0232     insert(suite_results const& r)
0233     {
0234         m_cases += r.size();
0235         total_ += r.total();
0236         failed_ += r.failed();
0237         cont().push_back(r);
0238     }
0239     /** @} */
0240 };
0241 
0242 } // unit_test
0243 } // beast
0244 } // boost
0245 
0246 #endif