Add message swap members and free functions

This commit is contained in:
Vinnie Falco
2016-05-28 07:56:38 -04:00
parent 7e8f5401b2
commit 8afdcb9e9f
7 changed files with 125 additions and 4 deletions

View File

@@ -9,6 +9,7 @@
#include <beast/http/message.hpp>
#include <beast/http/headers.hpp>
#include <beast/http/string_body.hpp>
#include <beast/unit_test/suite.hpp>
#include <type_traits>
@@ -126,9 +127,30 @@ public:
}
}
void testSwap()
{
message<true, string_body, headers> m1;
message<true, string_body, headers> m2;
m1.url = "u";
m1.body = "1";
m1.headers.insert("h", "v");
m2.method = "G";
m2.body = "2";
swap(m1, m2);
expect(m1.method == "G");
expect(m2.method.empty());
expect(m1.url.empty());
expect(m2.url == "u");
expect(m1.body == "2");
expect(m2.body == "1");
expect(! m1.headers.exists("h"));
expect(m2.headers.exists("h"));
}
void run() override
{
testConstruction();
testSwap();
}
};

View File

@@ -8,6 +8,8 @@
// Test that header file is self-contained.
#include <beast/http/message_v1.hpp>
#include <beast/http/headers.hpp>
#include <beast/http/string_body.hpp>
#include <beast/unit_test/suite.hpp>
#include <beast/http/empty_body.hpp>
@@ -78,10 +80,36 @@ public:
expect(! is_keep_alive(m));
}
void testSwap()
{
message_v1<false, string_body, headers> m1;
message_v1<false, string_body, headers> m2;
m1.status = 200;
m1.version = 10;
m1.body = "1";
m1.headers.insert("h", "v");
m2.status = 404;
m2.reason = "OK";
m2.body = "2";
m2.version = 11;
swap(m1, m2);
expect(m1.status == 404);
expect(m2.status == 200);
expect(m1.reason == "OK");
expect(m2.reason.empty());
expect(m1.version == 11);
expect(m2.version == 10);
expect(m1.body == "2");
expect(m2.body == "1");
expect(! m1.headers.exists("h"));
expect(m2.headers.exists("h"));
}
void run() override
{
testFreeFunctions();
testPrepare();
testSwap();
}
};