-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHttp_test.cc
118 lines (87 loc) · 4.45 KB
/
Http_test.cc
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "gtest/gtest.h"
#include "HttpMessage.h"
#include "Response.h"
#include "Request.h"
TEST(Response, BasicBody) {
EXPECT_TRUE(true);
}
TEST(Request, BasicRequest) {
EXPECT_TRUE(true);
}
// TEST(Response, BasicBody) {
// //test basic response with a body
// std::string body = "basicbody";
// Response response("OK","OK",body);
// EXPECT_STREQ(response.ToString(),"HTTP/1.0 200 OK\r\n\r\nbasicbody") << response.ToString();
// }
// TEST(Request, BasicRequest) {
// //test blank request
// std::unique_ptr<Request>
// EXPECT_STREQ(request.ToString(),"GET / HTTP/1.0\r\n\r\n") << request.ToString();
// }
// TEST(Request, IncludingHeader) {
// //test initialization with header fields
// std::map<std::string,std::string> _headers = { {"Content-length","20"}, {"Date","1/2/3"}, {"Host","cnn.com"}};
// Request request("/","GET",_headers);
// EXPECT_STREQ(request.ToString(),"GET / HTTP/1.0\r\nContent-length: 20\r\nDate: 1/2/3\r\nHost: cnn.com\r\n\r\n") << request.ToString();
// }
// TEST(Request, TestHttpMessageMethods) {
// Request request("/","GET");
// //test set and get Version
// request.setVersion("HTTP/1.1");
// EXPECT_STREQ(request.getVersion().c_str(),"HTTP/1.1");
// EXPECT_STREQ(request.ToString(),"GET / HTTP/1.1\r\n\r\n") << request.ToString();
// //test set and get HeaderFields
// request.setHeaderField(HttpMessage::HttpHeaderFields::CONNECTION,"Keep-alive");
// EXPECT_STREQ(request.getHeaderField(HttpMessage::HttpHeaderFields::CONNECTION).c_str(),"Keep-alive");
// EXPECT_STREQ(request.ToString(),"GET / HTTP/1.1\r\nConnection: Keep-alive\r\n\r\n") << request.ToString();
// //test set Connection
// request.setConnection(HttpMessage::HttpConnectionField::KEEP_ALIVE);
// EXPECT_STREQ(request.getHeaderField(HttpMessage::HttpHeaderFields::CONNECTION).c_str(),"keep-alive");
// EXPECT_STREQ(request.ToString(),"GET / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n") << request.ToString();
// }
// TEST(Request, testRequestMethods) {
// Request request("/","GET");
// //test set and get URL
// request.setUrl("/index.html");
// EXPECT_STREQ(request.getUrl().c_str(),"/index.html");
// EXPECT_STREQ(request.ToString(),"GET /index.html HTTP/1.0\r\n\r\n") << request.ToString();
// //test set and get Method
// request.setMethod("POST");
// EXPECT_STREQ(request.getMethod().c_str(),"POST");
// EXPECT_STREQ(request.ToString(),"POST /index.html HTTP/1.0\r\n\r\n") << request.ToString();
// }
// TEST(Request, parseFromWire) {
// //test sample request from raw string
// std::string requestStr = "GET / Http/1.1\r\nHost: 127.0.0.1:4000\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-Encoding: gzip, deflate, sdch, br\r\nAccept-Language: en-GB,en-US;q=0.8,en;q=0.6\r\n\r\n";
// std::vector<unsigned char> wire;
// for (auto it = requestStr.begin(); it != requestStr.end(); ++it) {
// wire.push_back(*it);
// }
// Request request(wire);
// EXPECT_STREQ(request.getMethod().c_str(),"GET");
// EXPECT_STREQ(request.getUrl().c_str(),"/");
// EXPECT_STREQ(request.getVersion().c_str(),"Http/1.1");
// //the reason this is six is because of what we currently analyze, could change
// EXPECT_EQ(request.getHeaderFields().size(),6) << "Didn't recognize 6 fields";
// }
// TEST(Response,testResponseMethods) {
// std::unique_ptr<char> freeablebody(new char[1]());
// freeablebody.get()[0]='\0';
// Response response("OK","OK",std::move(freeablebody),0);
// //test setStatusCode, getStatusCode
// response.setStatusCode("300");
// EXPECT_STREQ(response.getStatusCode().c_str(),"300");
// EXPECT_STREQ(response.ToString(),"HTTP/1.0 300 200\r\n\r\n");
// //test getReasoning, setReasoning
// response.setReasoning("OK");
// EXPECT_STREQ(response.getReasoning().c_str(),"OK");
// EXPECT_STREQ(response.ToString(),"HTTP/1.0 300 OK\r\n\r\n");
// //test getBody, setBody, getBodyLength
// std::unique_ptr<char> newBody(new char[20]());
// std::string bodyString = "bodyString";
// strcpy(newBody.get(),bodyString.c_str());
// response.setBody(std::move(newBody),bodyString.size());
// EXPECT_STREQ(response.getBody(),bodyString.c_str());
// EXPECT_STREQ(response.ToString(),"HTTP/1.0 300 OK\r\n\r\nbodyString");
// }