Files
beast/test/http/basic_headers.cpp

96 lines
2.1 KiB
C++
Raw Normal View History

2017-07-20 08:01:46 -07: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_headers.hpp>
#include <beast/unit_test/suite.hpp>
2017-07-20 08:01:46 -07:00
namespace beast {
namespace http {
class basic_headers_test : public beast::unit_test::suite
2017-07-20 08:01:46 -07:00
{
public:
template<class Allocator>
using bha = basic_headers<Allocator>;
using bh = basic_headers<std::allocator<char>>;
template<class Allocator>
static
void
fill(std::size_t n, basic_headers<Allocator>& h)
{
for(std::size_t i = 1; i<= n; ++i)
h.insert(std::to_string(i), i);
}
template<class U, class V>
static
void
self_assign(U& u, V&& v)
{
u = std::forward<V>(v);
}
2017-07-20 08:01:46 -07:00
void testHeaders()
{
bh h1;
expect(h1.empty());
fill(1, h1);
expect(h1.size() == 1);
bh h2;
h2 = h1;
expect(h2.size() == 1);
h2.insert("2", "2");
expect(std::distance(h2.begin(), h2.end()) == 2);
h1 = std::move(h2);
expect(h1.size() == 2);
expect(h2.size() == 0);
bh h3(std::move(h1));
expect(h3.size() == 2);
expect(h1.size() == 0);
self_assign(h3, std::move(h3));
expect(h3.size() == 2);
expect(h2.erase("Not-Present") == 0);
}
void testRFC2616()
{
bh h;
h.insert("a", "w");
h.insert("a", "x");
h.insert("aa", "y");
h.insert("b", "z");
expect(h.count("a") == 2);
}
void testErase()
{
bh h;
h.insert("a", "w");
h.insert("a", "x");
h.insert("aa", "y");
h.insert("b", "z");
expect(h.size() == 4);
h.erase("a");
expect(h.size() == 2);
2017-07-20 08:01:46 -07:00
}
void run() override
{
testHeaders();
testRFC2616();
2017-07-20 08:01:46 -07:00
}
};
BEAST_DEFINE_TESTSUITE(basic_headers,http,beast);
} // http
2017-07-20 08:01:46 -07:00
} // beast