GCC Code Coverage Report


Directory: ./
File: libs/capy/src/cond.cpp
Date: 2026-01-18 18:26:31
Exec Total Coverage
Lines: 18 24 75.0%
Functions: 4 4 100.0%
Branches: 9 13 69.2%

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/3
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 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 default:
46 return "unknown";
47 }
48 }
49
50 bool
51 8 cond_cat_type::
52 equivalent(
53 system::error_code const& ec,
54 int condition) const noexcept
55 {
56
2/3
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 switch(static_cast<cond>(condition))
57 {
58 4 case cond::eof:
59 4 return ec == capy::error::eof;
60
61 4 case cond::canceled:
62 // Check capy::error::canceled
63
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if(ec == capy::error::canceled)
64 return true;
65 // Check boost::system::errc
66
2/2
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
4 if(ec == boost::system::errc::operation_canceled)
67 2 return true;
68 // Check std::errc
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if(ec == std::errc::operation_canceled)
70 return true;
71 2 return false;
72
73 default:
74 return false;
75 }
76 }
77
78 //-----------------------------------------------
79
80 // msvc 14.0 has a bug that warns about inability
81 // to use constexpr construction here, even though
82 // there's no constexpr construction
83 #if defined(_MSC_VER) && _MSC_VER <= 1900
84 # pragma warning( push )
85 # pragma warning( disable : 4592 )
86 #endif
87
88 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
89 constinit cond_cat_type cond_cat;
90 #else
91 cond_cat_type cond_cat;
92 #endif
93
94 #if defined(_MSC_VER) && _MSC_VER <= 1900
95 # pragma warning( pop )
96 #endif
97
98 } // detail
99
100 } // capy
101 } // boost
102