-
Notifications
You must be signed in to change notification settings - Fork 2
/
http-tests.cpp
69 lines (57 loc) · 2.07 KB
/
http-tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
Copyright 2009-2019 Red Anchor Trading Co. Ltd.
Distributed under the Boost Software License, Version 1.0.
See <http://www.boost.org/LICENSE_1_0.txt>
*/
#include "fost-inet-test.hpp"
#include <fost/http.server.hpp>
using namespace fostlib;
FSL_TEST_SUITE(http_server);
FSL_TEST_FUNCTION(mock_no_handler) {
http::server::request req(
"GET", url::filepath_string("/"),
std::unique_ptr<binary_body>(new binary_body));
empty_mime response;
FSL_CHECK_EXCEPTION(req(response), exceptions::null &);
}
namespace {
void handler(bool &called, const mime &, const ascii_string &) {
called = true;
}
}
FSL_TEST_FUNCTION(mock_with_handler) {
bool called = false;
http::server::request req(
"GET", "/", std::unique_ptr<binary_body>(new binary_body),
[&called](const mime &m, const ascii_string &a) {
handler(called, m, a);
});
empty_mime response;
req(response);
FSL_CHECK(called);
}
FSL_TEST_FUNCTION(request_get) {
http::user_agent::request get("GET", url());
FSL_CHECK(get.data().begin() == get.data().end());
}
FSL_TEST_FUNCTION(request_post) {
http::user_agent::request post1("POST", url());
FSL_CHECK(post1.data().begin() == post1.data().end());
http::user_agent::request post2("POST", url(), string("body data"));
FSL_CHECK(post2.data().begin() != post2.data().end());
FSL_CHECK_EQ(
fostlib::string("body data"),
std::string(
reinterpret_cast<const char *>(
(*post2.data().begin()).first),
reinterpret_cast<const char *>(
(*post2.data().begin()).second)));
// Ensure the first pass didn't consume the data
FSL_CHECK_EQ(
fostlib::string("body data"),
std::string(
reinterpret_cast<const char *>(
(*post2.data().begin()).first),
reinterpret_cast<const char *>(
(*post2.data().begin()).second)));
}