-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver_test.cpp
81 lines (67 loc) · 2.03 KB
/
server_test.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
70
71
72
73
74
75
76
77
78
79
80
81
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "server.h"
#include <boost/asio.hpp>
// #include "mock_connection.h"
boost::asio::io_service io_service_;
boost::asio::ip::tcp::socket socket_(io_service_);
class ServerTest: public ::testing::Test {
protected:
int errc_success = 0;
bool fake_connection(boost::system::error_code ec)
{
NginxConfigParser config_parser;
NginxConfig config;
config_parser.Parse("config", &config);
http::server::server s("localhost", config);
return s.create_connection(ec);
}
boost::system::error_code create_error(int error_code)
{
if (error_code == errc_success)
return boost::system::errc::make_error_code(boost::system::errc::success);
else
return boost::system::errc::make_error_code(boost::system::errc::invalid_argument);
}
};
TEST_F(ServerTest, RunTest) {
NginxConfigParser config_parser;
NginxConfig config;
config_parser.Parse("config", &config);
http::server::server("localhost", config);
EXPECT_TRUE(true);
}
TEST_F(ServerTest, ServerRunning) {
NginxConfigParser config_parser;
NginxConfig config;
config_parser.Parse("config", &config);
http::server::server s("localhost", config);
s.create_connection(create_error(0));
EXPECT_TRUE(s.getStatus());
}
// TEST_F(ServerTest, ServerRunning2) {
// NginxConfigParser config_parser;
// NginxConfig config;
// config_parser.Parse("config", &config);
// http::server::server s("localhost", config);
// // s.run();
// EXPECT_TRUE(s.getStatus());
// }
TEST_F(ServerTest, ErrorSuccess) {
EXPECT_TRUE(fake_connection(create_error(0)));
}
TEST_F(ServerTest, ErrorFail) {
EXPECT_FALSE(fake_connection(create_error(1)));
}
TEST_F(ServerTest, CorrectInfoTest) {
NginxConfigParser config_parser;
NginxConfig config;
config_parser.Parse("config", &config);
http::server::server s("localhost", config);
EXPECT_EQ("8001", s.getPortNum());
EXPECT_EQ("localhost", s.getAddress());
}
// TEST_F(ServerTest, MockTest) {
// //MockConnection mock_connection(std::move(socket_));
// EXPECT_TRUE(true);
// }