|
||||
File indexing completed on 2025-01-18 09:29:23
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_TEST_FAIL_COUNT_HPP 0011 #define BOOST_BEAST_TEST_FAIL_COUNT_HPP 0012 0013 #include <boost/beast/core/detail/config.hpp> 0014 #include <boost/beast/_experimental/test/error.hpp> 0015 #include <cstdlib> 0016 0017 namespace boost { 0018 namespace beast { 0019 namespace test { 0020 0021 /** A countdown to simulated failure 0022 0023 On the Nth operation, the class will fail with the specified 0024 error code, or the default error code of @ref error::test_failure. 0025 0026 Instances of this class may be used to build objects which 0027 are specifically designed to aid in writing unit tests, for 0028 interfaces which can throw exceptions or return `error_code` 0029 values representing failure. 0030 */ 0031 class fail_count 0032 { 0033 std::size_t n_; 0034 std::size_t i_ = 0; 0035 error_code ec_; 0036 0037 public: 0038 fail_count(fail_count&&) = default; 0039 0040 /** Construct a counter 0041 0042 @param n The 0-based index of the operation to fail on or after 0043 @param ev An optional error code to use when generating a simulated failure 0044 */ 0045 BOOST_BEAST_DECL 0046 explicit 0047 fail_count( 0048 std::size_t n, 0049 error_code ev = error::test_failure); 0050 0051 /// Throw an exception on the Nth failure 0052 BOOST_BEAST_DECL 0053 void 0054 fail(); 0055 0056 /// Set an error code on the Nth failure 0057 BOOST_BEAST_DECL 0058 bool 0059 fail(error_code& ec); 0060 }; 0061 0062 } // test 0063 } // beast 0064 } // boost 0065 0066 #ifdef BOOST_BEAST_HEADER_ONLY 0067 #include <boost/beast/_experimental/test/impl/fail_count.ipp> 0068 #endif 0069 0070 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |