GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/error.cpp
Date: 2024-04-22 17:18:35
Exec Total Coverage
Lines: 53 57 93.0%
Functions: 7 7 100.0%
Branches: 42 49 85.7%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 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/http_proto
8 //
9
10 #include <boost/http_proto/error.hpp>
11 #include <boost/url/grammar/error.hpp>
12 #include <boost/assert.hpp>
13 #include <cstring>
14
15 namespace boost {
16 namespace http_proto {
17
18 namespace detail {
19
20 const char*
21 32 error_cat_type::
22 name() const noexcept
23 {
24 32 return "boost.http.proto";
25 }
26
27 std::string
28 95 error_cat_type::
29 message(int code) const
30 {
31
1/2
✓ Branch 3 taken 95 times.
✗ Branch 4 not taken.
95 return message(code, nullptr, 0);
32 }
33
34 char const*
35 95 error_cat_type::
36 message(
37 int code,
38 char*,
39 std::size_t) const noexcept
40 {
41
32/33
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 64 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 23 taken 1 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 1 times.
✓ Branch 28 taken 1 times.
✓ Branch 29 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
95 switch(static_cast<error>(code))
42 {
43 1 case error::expect_100_continue: return "expect continue";
44 1 case error::end_of_message: return "end of message";
45 1 case error::end_of_stream: return "end of stream";
46 1 case error::in_place_overflow: return "in place overflow";
47 1 case error::need_data: return "need data";
48
49 1 case error::bad_connection: return "bad Connection";
50 1 case error::bad_content_length: return "bad Content-Length";
51 1 case error::bad_expect: return "bad Expect";
52 64 case error::bad_field_name: return "bad field name";
53 1 case error::bad_field_value: return "bad field value";
54 1 case error::bad_field_smuggle: return "bad field smuggle";
55 1 case error::bad_line_ending: return "bad line ending";
56 1 case error::bad_list: return "bad list";
57 1 case error::bad_method: return "bad method";
58 1 case error::bad_number: return "bad number";
59 1 case error::bad_payload: return "bad payload";
60 1 case error::bad_version: return "bad version";
61 1 case error::bad_reason: return "bad reason-phrase";
62 1 case error::bad_request_target: return "bad request-target";
63 1 case error::bad_status_code: return "bad status-code";
64 1 case error::bad_status_line: return "bad status-line";
65 1 case error::bad_transfer_encoding: return "bad Transfer-Encoding";
66 1 case error::bad_upgrade: return "bad Upgrade";
67
68 1 case error::body_too_large: return "body too large";
69 1 case error::headers_limit: return "headers limit";
70 1 case error::start_line_limit: return "start line limit";
71 1 case error::field_size_limit: return "field size limit";
72 1 case error::fields_limit: return "fields limit";
73 1 case error::incomplete: return "incomplete";
74
75 1 case error::numeric_overflow: return "numeric overflow";
76 1 case error::multiple_content_length: return "multiple Content-Length";
77 1 case error::buffer_overflow: return "buffer overflow";
78 default:
79 return "unknown";
80 }
81 }
82
83 //-----------------------------------------------
84
85 const char*
86 1 condition_cat_type::
87 name() const noexcept
88 {
89 1 return "boost.http.proto";
90 }
91
92 std::string
93 1 condition_cat_type::
94 message(int code) const
95 {
96
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 return message(code, nullptr, 0);
97 }
98
99 char const*
100 1 condition_cat_type::
101 message(
102 int code,
103 char*,
104 std::size_t) const noexcept
105 {
106 switch(static_cast<condition>(code))
107 {
108 default:
109 1 case condition::need_more_input: return "need more input";
110 }
111 }
112
113 bool
114 11332 condition_cat_type::
115 equivalent(
116 system::error_code const& ec,
117 int code) const noexcept
118 {
119
1/2
✓ Branch 0 taken 11332 times.
✗ Branch 1 not taken.
11332 switch(static_cast<condition>(code))
120 {
121 11332 case condition::need_more_input:
122
4/4
✓ Branch 2 taken 3759 times.
✓ Branch 3 taken 7573 times.
✓ Branch 4 taken 273 times.
✓ Branch 5 taken 3486 times.
15091 if( ec == urls::grammar::error::need_more ||
123
2/2
✓ Branch 2 taken 7846 times.
✓ Branch 3 taken 3486 times.
15091 ec == error::need_data)
124 7846 return true;
125 3486 break;
126
127 default:
128 break;
129 }
130 return
131
1/4
✗ Branch 2 not taken.
✓ Branch 3 taken 3486 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3486 *this == ec.category() &&
132 3486 ec.value() == code;
133 }
134
135 //-----------------------------------------------
136
137 // msvc 14.0 has a bug that warns about inability
138 // to use constexpr construction here, even though
139 // there's no constexpr construction
140 #if defined(_MSC_VER) && _MSC_VER <= 1900
141 # pragma warning( push )
142 # pragma warning( disable : 4592 )
143 #endif
144
145 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
146 constinit error_cat_type error_cat;
147 constinit condition_cat_type condition_cat;
148 #else
149 error_cat_type error_cat;
150 condition_cat_type condition_cat;
151 #endif
152
153 #if defined(_MSC_VER) && _MSC_VER <= 1900
154 # pragma warning( pop )
155 #endif
156
157 } // detail
158
159 } // http_proto
160 } // boost
161