Prevent basic_fields operator[] assignment

fix #258
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:16 -07:00
parent f7a0885d17
commit 1a1a1d508b
5 changed files with 41 additions and 40 deletions
+36 -36
View File
@@ -18,17 +18,17 @@ class basic_fields_test : public beast::unit_test::suite
{
public:
template<class Allocator>
using bha = basic_fields<Allocator>;
using fa_t = basic_fields<Allocator>;
using bh = basic_fields<std::allocator<char>>;
using f_t = fa_t<std::allocator<char>>;
template<class Allocator>
static
void
fill(std::size_t n, basic_fields<Allocator>& h)
fill(std::size_t n, basic_fields<Allocator>& f)
{
for(std::size_t i = 1; i<= n; ++i)
h.insert(boost::lexical_cast<std::string>(i), i);
f.insert(boost::lexical_cast<std::string>(i), i);
}
template<class U, class V>
@@ -41,46 +41,46 @@ public:
void testHeaders()
{
bh h1;
BEAST_EXPECT(h1.empty());
fill(1, h1);
BEAST_EXPECT(h1.size() == 1);
bh h2;
h2 = h1;
BEAST_EXPECT(h2.size() == 1);
h2.insert("2", "2");
BEAST_EXPECT(std::distance(h2.begin(), h2.end()) == 2);
h1 = std::move(h2);
BEAST_EXPECT(h1.size() == 2);
BEAST_EXPECT(h2.size() == 0);
bh h3(std::move(h1));
BEAST_EXPECT(h3.size() == 2);
BEAST_EXPECT(h1.size() == 0);
self_assign(h3, std::move(h3));
BEAST_EXPECT(h3.size() == 2);
BEAST_EXPECT(h2.erase("Not-Present") == 0);
f_t f1;
BEAST_EXPECT(f1.empty());
fill(1, f1);
BEAST_EXPECT(f1.size() == 1);
f_t f2;
f2 = f1;
BEAST_EXPECT(f2.size() == 1);
f2.insert("2", "2");
BEAST_EXPECT(std::distance(f2.begin(), f2.end()) == 2);
f1 = std::move(f2);
BEAST_EXPECT(f1.size() == 2);
BEAST_EXPECT(f2.size() == 0);
f_t f3(std::move(f1));
BEAST_EXPECT(f3.size() == 2);
BEAST_EXPECT(f1.size() == 0);
self_assign(f3, std::move(f3));
BEAST_EXPECT(f3.size() == 2);
BEAST_EXPECT(f2.erase("Not-Present") == 0);
}
void testRFC2616()
{
bh h;
h.insert("a", "w");
h.insert("a", "x");
h.insert("aa", "y");
h.insert("b", "z");
BEAST_EXPECT(h.count("a") == 2);
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);
}
void testErase()
{
bh h;
h.insert("a", "w");
h.insert("a", "x");
h.insert("aa", "y");
h.insert("b", "z");
BEAST_EXPECT(h.size() == 4);
h.erase("a");
BEAST_EXPECT(h.size() == 2);
f_t f;
f.insert("a", "w");
f.insert("a", "x");
f.insert("aa", "y");
f.insert("b", "z");
BEAST_EXPECT(f.size() == 4);
f.erase("a");
BEAST_EXPECT(f.size() == 2);
}
void run() override