Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
extension_permessage_compress.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, Peter Thorson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27//#define BOOST_TEST_DYN_LINK
28#define BOOST_TEST_MODULE extension_permessage_deflate
29#include <boost/test/unit_test.hpp>
30
31#include <iostream>
32#include <string>
34
37
38struct config {
40};
43
44using namespace websocketpp;
45
46BOOST_AUTO_TEST_CASE( deflate_init ) {
47 /*compressor_type compressor;
48 websocketpp::http::parser::attribute_list attributes;
49 std::pair<lib::error_code,std::string> neg_ret;
50
51 neg_ret = compressor.negotiate(attributes);
52
53 BOOST_CHECK_EQUAL( neg_ret.first,
54 extensions::permessage_deflate::error::invalid_parameters );*/
55
120 /* processor::extensions::deflate_method d(true);
121 http::parser::attribute_list attributes;
122 lib::error_code ec;
123
124 attributes.push_back(http::parser::attribute("foo","bar"));
125 ec = d.init(attributes);
126 BOOST_CHECK(ec == processor::extensions::error::unknown_method_parameter);
127
128 attributes.clear();
129 attributes.push_back(http::parser::attribute("s2c_max_window_bits","bar"));
130 ec = d.init(attributes);
131 BOOST_CHECK(ec == processor::extensions::error::invalid_algorithm_settings);
132
133 attributes.clear();
134 attributes.push_back(http::parser::attribute("s2c_max_window_bits","7"));
135 ec = d.init(attributes);
136 BOOST_CHECK(ec == processor::extensions::error::invalid_algorithm_settings);
137
138 attributes.clear();
139 attributes.push_back(http::parser::attribute("s2c_max_window_bits","16"));
140 ec = d.init(attributes);
141 BOOST_CHECK(ec == processor::extensions::error::invalid_algorithm_settings);
142
143 attributes.clear();
144 attributes.push_back(http::parser::attribute("s2c_max_window_bits","9"));
145 ec = d.init(attributes);
146 BOOST_CHECK( !ec);
147
148 attributes.clear();
149 ec = d.init(attributes);
150 BOOST_CHECK( !ec);
151
152 processor::extensions::deflate_engine de;
153
154 unsigned char test_in[] = "HelloHelloHelloHello";
155 unsigned char test_out[30];
156
157 uLongf test_out_size = 30;
158
159 int ret;
160
161 ret = compress(test_out, &test_out_size, test_in, 20);
162
163 std::cout << ret << std::endl
164 << websocketpp::utility::to_hex(test_in,20) << std::endl
165 << websocketpp::utility::to_hex(test_out,test_out_size) << std::endl;
166
167 std::string input = "Hello";
168 std::string output;
169 ec = de.compress(input,output);
170
171 BOOST_CHECK( ec == processor::extensions::error::uninitialized );
172
173 //std::cout << ec.message() << websocketpp::utility::to_hex(output) << std::endl;
174
175 ec = de.init(15,15,Z_DEFAULT_COMPRESSION,8,Z_FIXED);
176 //ec = de.init();
177 BOOST_CHECK( !ec );
178
179 ec = de.compress(input,output);
180 std::cout << ec.message() << std::endl
181 << websocketpp::utility::to_hex(input) << std::endl
182 << websocketpp::utility::to_hex(output) << std::endl;
183
184 output.clear();
185
186 ec = de.compress(input,output);
187 std::cout << ec.message() << std::endl
188 << websocketpp::utility::to_hex(input) << std::endl
189 << websocketpp::utility::to_hex(output) << std::endl;
190
191 input = output;
192 output.clear();
193 ec = de.decompress(input,output);
194 std::cout << ec.message() << std::endl
195 << websocketpp::utility::to_hex(input) << std::endl
196 << websocketpp::utility::to_hex(output) << std::endl;
197 */
198}
websocketpp::http::parser::request request_type
Stores, parses, and manipulates HTTP requests.
Definition request.hpp:50
BOOST_AUTO_TEST_CASE(deflate_init)
websocketpp::extensions::permessage_deflate::enabled< config > compressor_type
Namespace for the WebSocket++ project.
Definition base64.hpp:41