2017-07-20 08:01:46 -07:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
|
// 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.
|
2016-11-10 05:34:49 -05:00
|
|
|
#include <beast/http/fields.hpp>
|
2017-04-27 17:38:50 -07:00
|
|
|
|
|
|
|
|
#include <beast/unit_test/suite.hpp>
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
2017-06-05 09:58:55 -07:00
|
|
|
class fields_test : public beast::unit_test::suite
|
2017-04-27 17:38:50 -07:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
template<class Allocator>
|
2017-05-02 12:03:34 -07:00
|
|
|
using fa_t = basic_fields<Allocator>;
|
2017-04-27 17:38:50 -07:00
|
|
|
|
2017-05-02 12:03:34 -07:00
|
|
|
using f_t = fa_t<std::allocator<char>>;
|
2017-04-27 17:38:50 -07:00
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
static
|
|
|
|
|
void
|
2017-05-02 12:03:34 -07:00
|
|
|
fill(std::size_t n, basic_fields<Allocator>& f)
|
2017-04-27 17:38:50 -07:00
|
|
|
{
|
|
|
|
|
for(std::size_t i = 1; i<= n; ++i)
|
2017-05-02 12:03:34 -07:00
|
|
|
f.insert(boost::lexical_cast<std::string>(i), i);
|
2017-04-27 17:38:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class U, class V>
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
self_assign(U& u, V&& v)
|
|
|
|
|
{
|
|
|
|
|
u = std::forward<V>(v);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 06:58:40 -07:00
|
|
|
template<class Alloc>
|
|
|
|
|
static
|
|
|
|
|
bool
|
|
|
|
|
empty(basic_fields<Alloc> const& f)
|
|
|
|
|
{
|
|
|
|
|
return f.begin() == f.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Alloc>
|
|
|
|
|
static
|
|
|
|
|
std::size_t
|
|
|
|
|
size(basic_fields<Alloc> const& f)
|
|
|
|
|
{
|
|
|
|
|
return std::distance(f.begin(), f.end());
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:38:50 -07:00
|
|
|
void testHeaders()
|
|
|
|
|
{
|
2017-05-02 12:03:34 -07:00
|
|
|
f_t f1;
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(empty(f1));
|
2017-05-02 12:03:34 -07:00
|
|
|
fill(1, f1);
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(size(f1) == 1);
|
2017-05-02 12:03:34 -07:00
|
|
|
f_t f2;
|
|
|
|
|
f2 = f1;
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(size(f2) == 1);
|
2017-05-02 12:03:34 -07:00
|
|
|
f2.insert("2", "2");
|
|
|
|
|
BEAST_EXPECT(std::distance(f2.begin(), f2.end()) == 2);
|
|
|
|
|
f1 = std::move(f2);
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(size(f1) == 2);
|
|
|
|
|
BEAST_EXPECT(size(f2) == 0);
|
2017-05-02 12:03:34 -07:00
|
|
|
f_t f3(std::move(f1));
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(size(f3) == 2);
|
|
|
|
|
BEAST_EXPECT(size(f1) == 0);
|
2017-05-02 12:03:34 -07:00
|
|
|
self_assign(f3, std::move(f3));
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(size(f3) == 2);
|
2017-05-02 12:03:34 -07:00
|
|
|
BEAST_EXPECT(f2.erase("Not-Present") == 0);
|
2017-04-27 17:38:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void testRFC2616()
|
|
|
|
|
{
|
2017-05-02 12:03:34 -07:00
|
|
|
f_t f;
|
|
|
|
|
f.insert("a", "w");
|
|
|
|
|
f.insert("a", "x");
|
|
|
|
|
f.insert("aa", "y");
|
|
|
|
|
f.insert("b", "z");
|
|
|
|
|
BEAST_EXPECT(f.count("a") == 2);
|
2017-04-27 17:38:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void testErase()
|
|
|
|
|
{
|
2017-05-02 12:03:34 -07:00
|
|
|
f_t f;
|
|
|
|
|
f.insert("a", "w");
|
|
|
|
|
f.insert("a", "x");
|
|
|
|
|
f.insert("aa", "y");
|
|
|
|
|
f.insert("b", "z");
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(size(f) == 4);
|
2017-05-02 12:03:34 -07:00
|
|
|
f.erase("a");
|
2017-05-30 06:58:40 -07:00
|
|
|
BEAST_EXPECT(size(f) == 2);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:38:50 -07:00
|
|
|
void run() override
|
|
|
|
|
{
|
|
|
|
|
testHeaders();
|
|
|
|
|
testRFC2616();
|
2017-05-30 06:58:40 -07:00
|
|
|
testErase();
|
2017-04-27 17:38:50 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-05 09:58:55 -07:00
|
|
|
BEAST_DEFINE_TESTSUITE(fields,http,beast);
|
2017-04-27 17:38:50 -07:00
|
|
|
|
|
|
|
|
} // http
|
|
|
|
|
} // beast
|