GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/impl/method.ipp
Date: 2023-12-11 14:11:20
Exec Total Coverage
Lines: 178 181 98.3%
Functions: 2 2 100.0%
Branches: 133 140 95.0%

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 #ifndef BOOST_HTTP_PROTO_IMPL_METHOD_IPP
11 #define BOOST_HTTP_PROTO_IMPL_METHOD_IPP
12
13 #include <boost/http_proto/method.hpp>
14 #include <boost/http_proto/detail/sv.hpp>
15 #include <boost/throw_exception.hpp>
16 #include <stdexcept>
17
18 namespace boost {
19 namespace http_proto {
20
21 core::string_view
22 92 to_string(method v)
23 {
24 using namespace detail::string_literals;
25
35/35
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 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 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 34 taken 1 times.
92 switch(v)
26 {
27 3 case method::delete_: return "DELETE"_sv;
28 55 case method::get: return "GET"_sv;
29 1 case method::head: return "HEAD"_sv;
30 1 case method::post: return "POST"_sv;
31 1 case method::put: return "PUT"_sv;
32 2 case method::connect: return "CONNECT"_sv;
33 1 case method::options: return "OPTIONS"_sv;
34 1 case method::trace: return "TRACE"_sv;
35
36 1 case method::copy: return "COPY"_sv;
37 1 case method::lock: return "LOCK"_sv;
38 1 case method::mkcol: return "MKCOL"_sv;
39 1 case method::move: return "MOVE"_sv;
40 1 case method::propfind: return "PROPFIND"_sv;
41 1 case method::proppatch: return "PROPPATCH"_sv;
42 1 case method::search: return "SEARCH"_sv;
43 1 case method::unlock: return "UNLOCK"_sv;
44 1 case method::bind: return "BIND"_sv;
45 1 case method::rebind: return "REBIND"_sv;
46 1 case method::unbind: return "UNBIND"_sv;
47 1 case method::acl: return "ACL"_sv;
48
49 1 case method::report: return "REPORT"_sv;
50 1 case method::mkactivity: return "MKACTIVITY"_sv;
51 1 case method::checkout: return "CHECKOUT"_sv;
52 1 case method::merge: return "MERGE"_sv;
53
54 1 case method::msearch: return "M-SEARCH"_sv;
55 1 case method::notify: return "NOTIFY"_sv;
56 1 case method::subscribe: return "SUBSCRIBE"_sv;
57 1 case method::unsubscribe: return "UNSUBSCRIBE"_sv;
58
59 1 case method::patch: return "PATCH"_sv;
60 1 case method::purge: return "PURGE"_sv;
61
62 1 case method::mkcalendar: return "MKCALENDAR"_sv;
63
64 1 case method::link: return "LINK"_sv;
65 1 case method::unlink: return "UNLINK"_sv;
66
67 1 case method::unknown:
68 1 return "<unknown>"_sv;
69 }
70
71
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 BOOST_THROW_EXCEPTION(
72 std::invalid_argument("unknown method"));
73 }
74
75 method
76 1349 string_to_method(
77 core::string_view v)
78 {
79 /*
80 ACL
81 BIND
82 CHECKOUT
83 CONNECT
84 COPY
85 DELETE
86 GET
87 HEAD
88 LINK
89 LOCK
90 M-SEARCH
91 MERGE
92 MKACTIVITY
93 MKCALENDAR
94 MKCOL
95 MOVE
96 NOTIFY
97 OPTIONS
98 PATCH
99 POST
100 PROPFIND
101 PROPPATCH
102 PURGE
103 PUT
104 REBIND
105 REPORT
106 SEARCH
107 SUBSCRIBE
108 TRACE
109 UNBIND
110 UNLINK
111 UNLOCK
112 UNSUBSCRIBE
113 */
114 using namespace detail::string_literals;
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1349 times.
1349 if(v.size() < 3)
116 return method::unknown;
117 1349 auto c = v[0];
118 1349 v.remove_prefix(1);
119
16/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 1236 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 12 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 55 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 8 times.
✓ Branch 15 taken 1 times.
1349 switch(c)
120 {
121 2 case 'A':
122
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "CL"_sv)
123 1 return method::acl;
124 1 break;
125
126 4 case 'B':
127
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if(v == "IND"_sv)
128 1 return method::bind;
129 3 break;
130
131 7 case 'C':
132 7 c = v[0];
133 7 v.remove_prefix(1);
134
2/3
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
7 switch(c)
135 {
136 2 case 'H':
137
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "ECKOUT"_sv)
138 1 return method::checkout;
139 1 break;
140
141 5 case 'O':
142
2/2
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
5 if(v == "NNECT"_sv)
143 2 return method::connect;
144
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if(v == "PY"_sv)
145 1 return method::copy;
146 BOOST_FALLTHROUGH;
147
148 default:
149 2 break;
150 }
151 3 break;
152
153 4 case 'D':
154
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
4 if(v == "ELETE"_sv)
155 3 return method::delete_;
156 1 break;
157
158 1236 case 'G':
159
2/2
✓ Branch 2 taken 1235 times.
✓ Branch 3 taken 1 times.
1236 if(v == "ET"_sv)
160 1235 return method::get;
161 1 break;
162
163 2 case 'H':
164
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "EAD"_sv)
165 1 return method::head;
166 1 break;
167
168 4 case 'L':
169
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if(v == "INK"_sv)
170 1 return method::link;
171
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if(v == "OCK"_sv)
172 1 return method::lock;
173 2 break;
174
175 12 case 'M':
176 12 c = v[0];
177 12 v.remove_prefix(1);
178
4/5
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
12 switch(c)
179 {
180 2 case '-':
181
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "SEARCH"_sv)
182 1 return method::msearch;
183 1 break;
184
185 2 case 'E':
186
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "RGE"_sv)
187 1 return method::merge;
188 1 break;
189
190 6 case 'K':
191
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if(v == "ACTIVITY"_sv)
192 1 return method::mkactivity;
193
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
5 if(v[0] == 'C')
194 {
195 4 v.remove_prefix(1);
196
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if(v == "ALENDAR"_sv)
197 1 return method::mkcalendar;
198
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if(v == "OL"_sv)
199 1 return method::mkcol;
200 2 break;
201 }
202 1 break;
203
204 2 case 'O':
205
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "VE"_sv)
206 1 return method::move;
207 BOOST_FALLTHROUGH;
208
209 default:
210 1 break;
211 }
212 6 break;
213
214 2 case 'N':
215
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "OTIFY"_sv)
216 1 return method::notify;
217 1 break;
218
219 2 case 'O':
220
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "PTIONS"_sv)
221 1 return method::options;
222 1 break;
223
224 55 case 'P':
225 55 c = v[0];
226 55 v.remove_prefix(1);
227
4/5
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
55 switch(c)
228 {
229 2 case 'A':
230
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "TCH"_sv)
231 1 return method::patch;
232 1 break;
233
234 45 case 'O':
235
2/2
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 1 times.
45 if(v == "ST"_sv)
236 44 return method::post;
237 1 break;
238
239 4 case 'R':
240
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if(v == "OPFIND"_sv)
241 1 return method::propfind;
242
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if(v == "OPPATCH"_sv)
243 1 return method::proppatch;
244 2 break;
245
246 4 case 'U':
247
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if(v == "RGE"_sv)
248 1 return method::purge;
249
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if(v == "T"_sv)
250 1 return method::put;
251 BOOST_FALLTHROUGH;
252
253 default:
254 2 break;
255 }
256 6 break;
257
258 4 case 'R':
259
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if(v[0] != 'E')
260 break;
261 4 v.remove_prefix(1);
262
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if(v == "BIND"_sv)
263 1 return method::rebind;
264
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if(v == "PORT"_sv)
265 1 return method::report;
266 2 break;
267
268 4 case 'S':
269
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if(v == "EARCH"_sv)
270 1 return method::search;
271
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if(v == "UBSCRIBE"_sv)
272 1 return method::subscribe;
273 2 break;
274
275 2 case 'T':
276
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if(v == "RACE"_sv)
277 1 return method::trace;
278 1 break;
279
280 8 case 'U':
281
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if(v[0] != 'N')
282 break;
283 8 v.remove_prefix(1);
284
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7 times.
8 if(v == "BIND"_sv)
285 1 return method::unbind;
286
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 6 times.
7 if(v == "LINK"_sv)
287 1 return method::unlink;
288
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if(v == "LOCK"_sv)
289 1 return method::unlock;
290
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
5 if(v == "SUBSCRIBE"_sv)
291 1 return method::unsubscribe;
292 4 break;
293
294 1 default:
295 1 break;
296 }
297
298 36 return method::unknown;
299 }
300
301 } // http_proto
302 } // boost
303
304 #endif
305