1// 2// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 3// 4// Distributed under the Boost Software License, Version 1.0. (See accompanying 5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6// 7// Official repository: https://github.com/boostorg/beast 8// 9 10#ifndef BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP 11#define BOOST_BEAST_TEST_IMPL_FAIL_COUNT_IPP 12 13#include <boost/beast/_experimental/test/fail_count.hpp> 14#include <boost/throw_exception.hpp> 15 16namespace boost { 17namespace beast { 18namespace test { 19 20fail_count:: 21fail_count( 22 std::size_t n, 23 error_code ev) 24 : n_(n) 25 , ec_(ev) 26{ 27} 28 29void 30fail_count:: 31fail() 32{ 33 if(i_ < n_) 34 ++i_; 35 if(i_ == n_) 36 BOOST_THROW_EXCEPTION(system_error{ec_}); 37} 38 39bool 40fail_count:: 41fail(error_code& ec) 42{ 43 if(i_ < n_) 44 ++i_; 45 if(i_ == n_) 46 { 47 ec = ec_; 48 return true; 49 } 50 ec = {}; 51 return false; 52} 53 54} // test 55} // beast 56} // boost 57 58#endif 59