-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCompressionHandler_test.cc
75 lines (67 loc) · 2.31 KB
/
CompressionHandler_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
#include <string>
#include <fstream>
#include <boost/log/trivial.hpp>
#include "gtest/gtest.h"
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <sstream>
#include "CompressionHandler.h"
TEST(CompressionHandlerTest, BasicGzipTest) {
std::string basic_string = "basic_string";
Team15::server::CompressionHandler ch;
ch.Init("",NginxConfig());
Request r;
Response response;
response.SetBody(basic_string);
ch.HandleRequest(r,&response);
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbuf;
inbuf.push(boost::iostreams::gzip_decompressor());
std::stringstream compressed;
compressed << response.body();
inbuf.push(compressed);
std::stringstream out;
boost::iostreams::copy(inbuf,out);
EXPECT_STREQ(out.str().c_str(),basic_string.c_str());
}
TEST(CompressionHandlerTest, LongStringGzip) {
std::string basic_string = "asdfjklqewryio12347890zxcvnm,adfsjkl;oiu143\r\nasdfklasdf010238474327878cxcjxlzcjxzKLCJkxzLCJZXKppqowueriwqeorunmmdfsfsdkfsdi23782318!#$@%^&*^%$#@!%^&GFDKLVCJXKLVCZXVZVXCM<NVCZXM<NVZCX";
Team15::server::CompressionHandler ch;
ch.Init("",NginxConfig());
Request r;
Response response;
response.SetBody(basic_string);
ch.HandleRequest(r,&response);
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbuf;
inbuf.push(boost::iostreams::gzip_decompressor());
std::stringstream compressed;
compressed << response.body();
inbuf.push(compressed);
std::stringstream out;
boost::iostreams::copy(inbuf,out);
EXPECT_STREQ(out.str().c_str(),basic_string.c_str());
}
TEST(CompressionHandlerTest, BinaryGzipTest) {
std::ifstream is("libgtest.a",std::ios::in | std::ios::binary);
ASSERT_EQ(!!is,true); // check that is is valid
std::string basic_string;
char c;
while (is.get(c)) {
basic_string +=c;
}
is.close();
Team15::server::CompressionHandler ch;
ch.Init("",NginxConfig());
Request r;
Response response;
response.SetBody(basic_string);
ch.HandleRequest(r,&response);
boost::iostreams::filtering_streambuf<boost::iostreams::input> inbuf;
inbuf.push(boost::iostreams::gzip_decompressor());
std::stringstream compressed;
compressed << response.body();
inbuf.push(compressed);
std::stringstream out;
boost::iostreams::copy(inbuf,out);
EXPECT_STREQ(out.str().c_str(),basic_string.c_str());
}