GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 66.7% 18 / 0 / 27
Functions: 100.0% 4 / 0 / 4
Branches: 60.0% 9 / 0 / 15

libs/capy/src/cond.cpp
Line Branch Exec Source
1 //
2 // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.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/cppalliance/capy
8 //
9
10 #include <boost/capy/cond.hpp>
11 #include <boost/capy/error.hpp>
12 #include <boost/system/errc.hpp>
13 #include <system_error>
14
15 namespace boost {
16 namespace capy {
17
18 namespace detail {
19
20 const char*
21 1 cond_cat_type::
22 name() const noexcept
23 {
24 1 return "boost.capy";
25 }
26
27 std::string
28 2 cond_cat_type::
29 message(int code) const
30 {
31
1/1
✓ Branch 2 taken 2 times.
4 return message(code, nullptr, 0);
32 }
33
34 char const*
35 2 cond_cat_type::
36 message(
37 int code,
38 char*,
39 std::size_t) const noexcept
40 {
41
2/4
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 switch(static_cast<cond>(code))
42 {
43 1 case cond::eof: return "end of file";
44 1 case cond::canceled: return "operation canceled";
45 case cond::stream_truncated: return "stream truncated";
46 default:
47 return "unknown";
48 }
49 }
50
51 bool
52 9 cond_cat_type::
53 equivalent(
54 system::error_code const& ec,
55 int condition) const noexcept
56 {
57
2/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 switch(static_cast<cond>(condition))
58 {
59 5 case cond::eof:
60 5 return ec == capy::error::eof;
61
62 4 case cond::canceled:
63 // Check capy::error::canceled
64
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if(ec == capy::error::canceled)
65 return true;
66 // Check boost::system::errc
67
2/2
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
4 if(ec == boost::system::errc::operation_canceled)
68 2 return true;
69 // Check std::errc
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if(ec == std::errc::operation_canceled)
71 return true;
72 2 return false;
73
74 case cond::stream_truncated:
75 return ec == capy::error::stream_truncated;
76
77 default:
78 return false;
79 }
80 }
81
82 //-----------------------------------------------
83
84 // msvc 14.0 has a bug that warns about inability
85 // to use constexpr construction here, even though
86 // there's no constexpr construction
87 #if defined(_MSC_VER) && _MSC_VER <= 1900
88 # pragma warning( push )
89 # pragma warning( disable : 4592 )
90 #endif
91
92 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
93 constinit cond_cat_type cond_cat;
94 #else
95 cond_cat_type cond_cat;
96 #endif
97
98 #if defined(_MSC_VER) && _MSC_VER <= 1900
99 # pragma warning( pop )
100 #endif
101
102 } // detail
103
104 } // capy
105 } // boost
106