]>
Commit | Line | Data |
---|---|---|
1 | // | |
2 | // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot 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 | ||
8 | // Test that header file is self-contained. | |
9 | #include <beast/http/basic_fields.hpp> | |
10 | ||
11 | #include <beast/unit_test/suite.hpp> | |
12 | #include <boost/lexical_cast.hpp> | |
13 | ||
14 | namespace beast { | |
15 | namespace http { | |
16 | ||
17 | class basic_fields_test : public beast::unit_test::suite | |
18 | { | |
19 | public: | |
20 | template<class Allocator> | |
21 | using bha = basic_fields<Allocator>; | |
22 | ||
23 | using bh = basic_fields<std::allocator<char>>; | |
24 | ||
25 | template<class Allocator> | |
26 | static | |
27 | void | |
28 | fill(std::size_t n, basic_fields<Allocator>& h) | |
29 | { | |
30 | for(std::size_t i = 1; i<= n; ++i) | |
31 | h.insert(boost::lexical_cast<std::string>(i), i); | |
32 | } | |
33 | ||
34 | template<class U, class V> | |
35 | static | |
36 | void | |
37 | self_assign(U& u, V&& v) | |
38 | { | |
39 | u = std::forward<V>(v); | |
40 | } | |
41 | ||
42 | void testHeaders() | |
43 | { | |
44 | bh h1; | |
45 | BEAST_EXPECT(h1.empty()); | |
46 | fill(1, h1); | |
47 | BEAST_EXPECT(h1.size() == 1); | |
48 | bh h2; | |
49 | h2 = h1; | |
50 | BEAST_EXPECT(h2.size() == 1); | |
51 | h2.insert("2", "2"); | |
52 | BEAST_EXPECT(std::distance(h2.begin(), h2.end()) == 2); | |
53 | h1 = std::move(h2); | |
54 | BEAST_EXPECT(h1.size() == 2); | |
55 | BEAST_EXPECT(h2.size() == 0); | |
56 | bh h3(std::move(h1)); | |
57 | BEAST_EXPECT(h3.size() == 2); | |
58 | BEAST_EXPECT(h1.size() == 0); | |
59 | self_assign(h3, std::move(h3)); | |
60 | BEAST_EXPECT(h3.size() == 2); | |
61 | BEAST_EXPECT(h2.erase("Not-Present") == 0); | |
62 | } | |
63 | ||
64 | void testRFC2616() | |
65 | { | |
66 | bh h; | |
67 | h.insert("a", "w"); | |
68 | h.insert("a", "x"); | |
69 | h.insert("aa", "y"); | |
70 | h.insert("b", "z"); | |
71 | BEAST_EXPECT(h.count("a") == 2); | |
72 | } | |
73 | ||
74 | void testErase() | |
75 | { | |
76 | bh h; | |
77 | h.insert("a", "w"); | |
78 | h.insert("a", "x"); | |
79 | h.insert("aa", "y"); | |
80 | h.insert("b", "z"); | |
81 | BEAST_EXPECT(h.size() == 4); | |
82 | h.erase("a"); | |
83 | BEAST_EXPECT(h.size() == 2); | |
84 | } | |
85 | ||
86 | void run() override | |
87 | { | |
88 | testHeaders(); | |
89 | testRFC2616(); | |
90 | } | |
91 | }; | |
92 | ||
93 | BEAST_DEFINE_TESTSUITE(basic_fields,http,beast); | |
94 | ||
95 | } // http | |
96 | } // beast |