]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/test/zlib/inflate_stream.cpp
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // Test that header file is self-contained.
9 #include <beast/zlib/inflate_stream.hpp>
12 #include <beast/unit_test/suite.hpp>
19 class inflate_stream_test
: public beast::unit_test::suite
22 //--------------------------------------------------------------------------
38 Beast(Split in
, Split check
, Flush flush
= Flush::sync
)
48 std::string
const& in
,
49 std::string
const& check
,
50 unit_test::suite
& suite
) const
53 [&](std::size_t i
, std::size_t j
)
55 std::string
out(check
.size(), 0);
57 zs
.next_in
= in
.data();
58 zs
.next_out
= &out
[0];
63 bool bi
= ! (i
< in
.size());
64 bool bo
= ! (j
< check
.size());
68 is
.write(zs
, flush_
, ec
);
69 if( ec
== error::need_buffers
||
70 ec
== error::end_of_stream
)
72 out
.resize(zs
.total_out
);
73 suite
.expect(out
== check
, __FILE__
, __LINE__
);
78 suite
.fail(ec
.message(), __FILE__
, __LINE__
);
81 if(zs
.avail_in
== 0 && ! bi
)
84 zs
.avail_in
= in
.size() - i
;
86 if(zs
.avail_out
== 0 && ! bo
)
89 zs
.avail_out
= check
.size() - j
;
100 case once
: i0
= in
.size(); i1
= i0
; break;
101 case half
: i0
= in
.size() / 2; i1
= i0
; break;
102 case full
: i0
= 1; i1
= in
.size(); break;
108 case once
: j0
= check
.size(); j1
= j0
; break;
109 case half
: j0
= check
.size() / 2; j1
= j0
; break;
110 case full
: j0
= 1; j1
= check
.size(); break;
113 for(std::size_t i
= i0
; i
<= i1
; ++i
)
114 for(std::size_t j
= j0
; j
<= j1
; ++j
)
126 ZLib(Split in
, Split check
, int flush
= Z_SYNC_FLUSH
)
136 std::string
const& in
,
137 std::string
const& check
,
138 unit_test::suite
& suite
) const
141 [&](std::size_t i
, std::size_t j
)
144 std::string
out(check
.size(), 0);
146 memset(&zs
, 0, sizeof(zs
));
147 result
= inflateInit2(&zs
, -window
);
150 suite
.fail("! Z_OK", __FILE__
, __LINE__
);
153 zs
.next_in
= (Bytef
*)in
.data();
154 zs
.next_out
= (Bytef
*)out
.data();
155 zs
.avail_in
= static_cast<uInt
>(i
);
156 zs
.avail_out
= static_cast<uInt
>(j
);
157 bool bi
= ! (i
< in
.size());
158 bool bo
= ! (j
< check
.size());
161 result
= inflate(&zs
, flush_
);
162 if( result
== Z_BUF_ERROR
||
163 result
== Z_STREAM_END
) // per zlib FAQ
165 out
.resize(zs
.total_out
);
166 suite
.expect(out
== check
, __FILE__
, __LINE__
);
171 suite
.fail("! Z_OK", __FILE__
, __LINE__
);
174 if(zs
.avail_in
== 0 && ! bi
)
177 zs
.avail_in
= static_cast<uInt
>(in
.size() - i
);
179 if(zs
.avail_out
== 0 && ! bo
)
182 zs
.avail_out
= static_cast<uInt
>(check
.size() - j
);
194 case once
: i0
= in
.size(); i1
= i0
; break;
195 case half
: i0
= in
.size() / 2; i1
= i0
; break;
196 case full
: i0
= 1; i1
= in
.size(); break;
202 case once
: j0
= check
.size(); j1
= j0
; break;
203 case half
: j0
= check
.size() / 2; j1
= j0
; break;
204 case full
: j0
= 1; j1
= check
.size(); break;
207 for(std::size_t i
= i0
; i
<= i1
; ++i
)
208 for(std::size_t j
= j0
; j
<= j1
; ++j
)
215 unit_test::suite
& suite_
;
223 Matrix(unit_test::suite
& suite
)
235 level(int from
, int to
)
248 window(int from
, int to
)
261 strategy(int from
, int to
)
270 strategy(what
, what
);
278 std::string
const& check
) const
280 using namespace std::chrono
;
281 using clock_type
= steady_clock
;
282 auto const when
= clock_type::now();
284 for(auto level
= level_
[0];
285 level
<= level_
[1]; ++level
)
287 for(auto window
= window_
[0];
288 window
<= window_
[1]; ++window
)
290 for(auto strategy
= strategy_
[0];
291 strategy
<= strategy_
[1]; ++strategy
)
295 zd
.windowBits(window
);
296 zd
.strategy(strategy
);
297 auto const in
= zd(check
);
298 f(window
, in
, check
, suite_
);
302 auto const elapsed
= clock_type::now() - when
;
306 milliseconds
>(elapsed
).count() << "ms\n";
317 "{\n \"AutobahnPython/0.6.0\": {\n"
319 " \"behavior\": \"OK\",\n"
320 " \"behaviorClose\": \"OK\",\n"
321 " \"duration\": 2,\n"
322 " \"remoteCloseCode\": 1000,\n"
323 " \"reportfile\": \"autobahnpython_0_6_0_case_1_1_1.json\"\n"
325 m("1. beast", Beast
{half
, half
}, check
);
326 m("1. zlib ", ZLib
{half
, half
}, check
);
330 auto const check
= corpus1(50000);
331 m("2. beast", Beast
{half
, half
}, check
);
332 m("2. zlib ", ZLib
{half
, half
}, check
);
336 auto const check
= corpus2(50000);
337 m("3. beast", Beast
{half
, half
}, check
);
338 m("3. zlib ", ZLib
{half
, half
}, check
);
342 auto const check
= corpus1(10000);
345 m
.strategy(Z_DEFAULT_STRATEGY
);
346 m("4. beast", Beast
{once
, full
}, check
);
347 m("4. zlib ", ZLib
{once
, full
}, check
);
351 auto const check
= corpus2(10000);
354 m
.strategy(Z_DEFAULT_STRATEGY
);
355 m("5. beast", Beast
{once
, full
}, check
);
356 m("5. zlib ", ZLib
{once
, full
}, check
);
362 auto const check
= corpus1(200);
363 m("6. beast", Beast
{full
, full
}, check
);
364 m("6. zlib ", ZLib
{full
, full
}, check
);
370 auto const check
= corpus2(500);
371 m("7. beast", Beast
{full
, full
}, check
);
372 m("7. zlib ", ZLib
{full
, full
}, check
);
376 auto const check
= corpus2(10000);
379 m
.strategy(Z_DEFAULT_STRATEGY
);
380 m("8. beast", Beast
{full
, once
, Flush::block
}, check
);
381 m("8. zlib ", ZLib
{full
, once
, Z_BLOCK
}, check
);
384 // VFALCO Fails, but I'm unsure of what the correct
385 // behavior of Z_TREES/Flush::trees is.
389 auto const check
= corpus2(10000);
392 m
.strategy(Z_DEFAULT_STRATEGY
);
393 m("9. beast", Beast
{full
, once
, Flush::trees
}, check
);
394 m("9. zlib ", ZLib
{full
, once
, Z_TREES
}, check
);
403 "sizeof(inflate_stream) == " <<
404 sizeof(inflate_stream
) << std::endl
;
409 BEAST_DEFINE_TESTSUITE(inflate_stream
,core
,beast
);