Files
beast/test/http/basic_fields.cpp
T

97 lines
2.2 KiB
C++
Raw Normal View History

2016-03-11 06:40:37 -05:00
//
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Test that header file is self-contained.
#include <beast/http/basic_fields.hpp>
2016-03-11 06:40:37 -05:00
2016-05-06 19:14:17 -04:00
#include <beast/unit_test/suite.hpp>
#include <boost/lexical_cast.hpp>
2016-03-11 06:40:37 -05:00
namespace beast {
namespace http {
class basic_fields_test : public beast::unit_test::suite
2016-03-11 06:40:37 -05:00
{
public:
template<class Allocator>
using bha = basic_fields<Allocator>;
2016-03-11 06:40:37 -05:00
using bh = basic_fields<std::allocator<char>>;
2016-03-11 06:40:37 -05:00
template<class Allocator>
static
void
fill(std::size_t n, basic_fields<Allocator>& h)
2016-03-11 06:40:37 -05:00
{
for(std::size_t i = 1; i<= n; ++i)
h.insert(boost::lexical_cast<std::string>(i), i);
2016-03-11 06:40:37 -05:00
}
2016-04-30 10:29:39 -04:00
template<class U, class V>
static
void
self_assign(U& u, V&& v)
{
u = std::forward<V>(v);
}
2016-03-11 06:40:37 -05:00
void testHeaders()
{
bh h1;
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h1.empty());
2016-03-11 06:40:37 -05:00
fill(1, h1);
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h1.size() == 1);
2016-03-11 06:40:37 -05:00
bh h2;
h2 = h1;
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h2.size() == 1);
2016-03-11 06:40:37 -05:00
h2.insert("2", "2");
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(std::distance(h2.begin(), h2.end()) == 2);
2016-03-11 06:40:37 -05:00
h1 = std::move(h2);
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h1.size() == 2);
BEAST_EXPECT(h2.size() == 0);
2016-03-11 06:40:37 -05:00
bh h3(std::move(h1));
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h3.size() == 2);
BEAST_EXPECT(h1.size() == 0);
2016-04-30 10:29:39 -04:00
self_assign(h3, std::move(h3));
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h3.size() == 2);
BEAST_EXPECT(h2.erase("Not-Present") == 0);
2016-04-30 10:29:39 -04:00
}
void testRFC2616()
{
bh h;
2016-07-04 13:57:59 -04:00
h.insert("a", "w");
2016-04-30 10:29:39 -04:00
h.insert("a", "x");
2016-07-04 13:57:59 -04:00
h.insert("aa", "y");
h.insert("b", "z");
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h.count("a") == 2);
2016-07-04 13:57:59 -04:00
}
void testErase()
{
bh h;
h.insert("a", "w");
h.insert("a", "x");
h.insert("aa", "y");
h.insert("b", "z");
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h.size() == 4);
2016-07-04 13:57:59 -04:00
h.erase("a");
2016-08-03 15:34:23 -04:00
BEAST_EXPECT(h.size() == 2);
2016-03-11 06:40:37 -05:00
}
void run() override
{
testHeaders();
2016-04-30 10:29:39 -04:00
testRFC2616();
2016-03-11 06:40:37 -05:00
}
};
BEAST_DEFINE_TESTSUITE(basic_fields,http,beast);
2016-03-11 06:40:37 -05:00
2016-05-07 17:06:46 -04:00
} // http
2016-03-11 06:40:37 -05:00
} // beast