-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathresponse_test.cpp
52 lines (41 loc) · 1.51 KB
/
response_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
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <boost/asio.hpp>
#include "request_handler.h"
#include <string>
TEST(ResponseTest, ResponseOKTest)
{
std::string s= "This is my testing string";
http::server::Response r;
r.SetStatus(http::server::Response::OK);
r.SetBody(s);
r.AddHeader("Content-Type", "text/plain");
r.AddHeader("Content-Length", std::to_string(s.length()));
std::string expected_string = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 25\r\n\r\n";
expected_string += s;
EXPECT_EQ(expected_string, r.ToString());
}
TEST(ResponseTest, ResponseNOTFOUNDTest)
{
std::string s= "This is my testing string";
http::server::Response r;
r.SetStatus(http::server::Response::NOT_FOUND);
r.SetBody(s);
r.AddHeader("Content-Type", "text/plain");
r.AddHeader("Content-Length", std::to_string(s.length()));
std::string expected_string = "HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: 25\r\n\r\n";
expected_string += s;
EXPECT_EQ(expected_string, r.ToString());
}
TEST(ResponseTest, ResponseBADREQUESTTest)
{
std::string s= "This is my testing string";
http::server::Response r;
r.SetStatus(http::server::Response::BAD_REQUEST);
r.SetBody(s);
r.AddHeader("Content-Type", "text/plain");
r.AddHeader("Content-Length", std::to_string(s.length()));
std::string expected_string = "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nContent-Length: 25\r\n\r\n";
expected_string += s;
EXPECT_EQ(expected_string, r.ToString());
}