GCC Code Coverage Report


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