]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/http/rfc7230.cpp
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 // Test that header file is self-contained.
11 #include <boost/beast/http/rfc7230.hpp>
13 #include <boost/beast/http/detail/rfc7230.hpp>
14 #include <boost/beast/unit_test/suite.hpp>
18 #include <boost/beast/core/detail/empty_base_optimization.hpp>
24 class rfc7230_test
: public beast::unit_test::suite
29 fmt(std::string
const& s
)
31 return '\'' + s
+ '\'';
38 return std::string(s
.data(), s
.size());
43 str(param_list
const& c
)
46 for(auto const& p
: c
)
49 s
.append(str(p
.first
));
50 if(! p
.second
.empty())
53 s
.append(str(p
.second
));
63 [&](std::string
const& s
)
65 auto const got
= str(param_list
{s
});
66 BEAST_EXPECTS(got
== s
, fmt(got
));
69 [&](std::string
const& s
, std::string
const& answer
)
72 auto const got
= str(param_list
{s
});
74 BEAST_EXPECTS(got
== answer
, fmt(got
));
77 [&](std::string
const& s
, std::string
const& answer
)
79 auto const got
= str(param_list
{s
});
80 BEAST_EXPECTS(got
== answer
, fmt(got
));
89 cs(" ;\t i =\t 1 \t", ";i=1");
90 cq("\t; \t xyz=1 ; ijk=\"q\\\"t\"", ";xyz=1;ijk=q\"t");
100 cq(";xy=\"\\\x01\"", "");
105 str(ext_list
const& ex
)
108 for(auto const& e
: ex
)
112 s
.append(str(e
.first
));
122 [&](std::string
const& s
)
124 auto const got
= str(ext_list
{s
});
125 BEAST_EXPECTS(got
== s
, fmt(got
));
128 [&](std::string
const& s
, std::string
const& good
)
131 auto const got
= str(ext_list
{s
});
133 BEAST_EXPECTS(got
== good
, fmt(got
));
136 [&](std::string
const& s
, std::string
const& good
)
138 auto const got
= str(ext_list
{s
});
139 BEAST_EXPECTS(got
== good
, fmt(got
));
142 ext-basic_parsed_list = *( "," OWS ) ext *( OWS "," [ OWS ext ] )
143 ext = token param-basic_parsed_list
144 param-basic_parsed_list = *( OWS ";" OWS param )
145 param = token OWS "=" OWS ( token / quoted-string )
156 cs(" , \t,, \t,", "");
157 cs( "permessage-deflate; client_no_context_takeover; client_max_window_bits",
158 "permessage-deflate;client_no_context_takeover;client_max_window_bits");
164 cs("\t a, b\t , c\t", "a,b,c");
168 cs("a; \t i\t=\t \t1\t ", "a;i=1");
170 ce("a;i=1;j=2;k=3,b;i=4;j=5;k=6");
172 cq("ab;x=\" \"", "ab;x= ");
173 cq("ab;x=\"\\\"\"", "ab;x=\"");
175 BEAST_EXPECT(ext_list
{"a,b;i=1,c;j=2;k=3"}.exists("A"));
176 BEAST_EXPECT(ext_list
{"a,b;i=1,c;j=2;k=3"}.exists("b"));
177 BEAST_EXPECT(! ext_list
{"a,b;i=1,c;j=2;k=3"}.exists("d"));
186 str(token_list
const& c
)
190 for(auto const& p
: c
)
204 [&](std::string
const& s
)
206 auto const got
= str(token_list
{s
});
207 BEAST_EXPECTS(got
== s
, fmt(got
));
210 [&](std::string
const& s
, std::string
const& good
)
213 auto const got
= str(token_list
{s
});
215 BEAST_EXPECTS(got
== good
, fmt(got
));
231 cs(" \t x \t ", "x");
233 cs("x ,\ty ", "x,y");
234 cs("x, y, z", "x,y,z");
236 BEAST_EXPECT(token_list
{"a,b,c"}.exists("A"));
237 BEAST_EXPECT(token_list
{"a,b,c"}.exists("b"));
238 BEAST_EXPECT(! token_list
{"a,b,c"}.exists("d"));
244 template<class Policy
>
246 std::vector
<std::string
>
247 to_vector(string_view in
)
249 std::vector
<std::string
> v
;
250 detail::basic_parsed_list
<Policy
> list
{in
};
252 detail::basic_parsed_list
<Policy
>{in
})
253 v
.emplace_back(s
.data(), s
.size());
257 template<class Policy
>
259 validate(string_view in
,
260 std::vector
<std::string
> const& v
)
262 BEAST_EXPECT(to_vector
<Policy
>(in
) == v
);
265 template<class Policy
>
269 BEAST_EXPECT(validate_list(
270 detail::basic_parsed_list
<Policy
>{in
}));
273 template<class Policy
>
276 std::vector
<std::string
> const& v
)
278 BEAST_EXPECT(validate_list(
279 detail::basic_parsed_list
<Policy
>{in
}));
280 validate
<Policy
>(in
, v
);
283 template<class Policy
>
287 BEAST_EXPECT(! validate_list(
288 detail::basic_parsed_list
<Policy
>{in
}));
295 #token = [ ( "," / token ) *( OWS "," [ OWS token ] ) ]
297 using type
= detail::opt_token_list_policy
;
301 good
<type
>("\t", {});
302 good
<type
>(" \t", {});
304 good
<type
>(",,", {});
305 good
<type
>(", ,", {});
306 good
<type
>(",\t,", {});
307 good
<type
>(", \t,", {});
308 good
<type
>(", \t, ", {});
309 good
<type
>(", \t,\t", {});
310 good
<type
>(", \t, \t", {});
312 good
<type
>("x", {"x"});
313 good
<type
>(" x", {"x"});
314 good
<type
>("x,,", {"x"});
315 good
<type
>("x, ,", {"x"});
316 good
<type
>("x,, ", {"x"});
317 good
<type
>("x,,,", {"x"});
319 good
<type
>("x,y", {"x","y"});
320 good
<type
>("x ,y", {"x","y"});
321 good
<type
>("x\t,y", {"x","y"});
322 good
<type
>("x \t,y", {"x","y"});
323 good
<type
>(" x,y", {"x","y"});
324 good
<type
>(" x,y ", {"x","y"});
325 good
<type
>(",x,y", {"x","y"});
326 good
<type
>("x,y,", {"x","y"});
327 good
<type
>(",,x,y", {"x","y"});
328 good
<type
>(",x,,y", {"x","y"});
329 good
<type
>(",x,y,", {"x","y"});
330 good
<type
>("x ,, y", {"x","y"});
331 good
<type
>("x , ,y", {"x","y"});
333 good
<type
>("x,y,z", {"x","y","z"});
357 BEAST_DEFINE_TESTSUITE(beast
,http
,rfc7230
);