-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver_test.cpp
More file actions
80 lines (67 loc) · 1.8 KB
/
server_test.cpp
File metadata and controls
80 lines (67 loc) · 1.8 KB
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
70
71
72
73
74
75
76
77
78
79
#include "gtest/gtest.h"
#include "server.hpp"
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/array.hpp>
TEST(ServerTesting, ConstructorCheck) {
try
{
http::server::server server_("config");
}
catch(boost::system::error_code &e)
{
EXPECT_EQ(e.message(), "Numerical argument out of domain");
}
}
TEST(ServerTesting, AddressCheck) {
try
{
http::server::server server_("config");
}
catch(boost::system::error_code &e)
{
EXPECT_EQ(e.message(), "Bad address");
}
}
TEST(ConnectionTesting, InitializationAndConnectionTest) {
try
{
http::server::server server_("config");
}
catch(boost::system::error_code &e)
{
std::cout << e.message() << std::endl;
}
}
class Handler{
public:
boost::array<char, 1> data_;
void handlerWrite(
const boost::system::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes written.
){}
void handlerRead(const boost::system::error_code& error, std::size_t bytes_transferred)
{}
};
TEST(ConnectionTesting, ConnectionConstructor) {
try
{
Handler* handler = new Handler();
boost::asio::io_service io;
boost::asio::ip::tcp::socket sock(io);
std::string buffer = "GET /index.html HTTP/1.1\r\n\r\n";
std::make_shared<http::server::connection>(std::move(sock))->start();
sock.async_write_some(boost::asio::buffer(buffer),
boost::bind(&Handler::handlerWrite, handler,
boost::asio::placeholders::error, boost::asio::placeholders::iterator));
sock.async_read_some(boost::asio::buffer(handler->data_),
boost::bind(&Handler::handlerRead, handler,
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
delete(handler);
}
catch(boost::system::error_code &e)
{
//std::cout << e.message();
EXPECT_EQ(e.message(), "Success");
}
}