From c76ef3bf313cfa4c83c327e05539bdafd041d200 Mon Sep 17 00:00:00 2001 From: Damian Jarek Date: Mon, 16 Sep 2019 16:28:22 +0200 Subject: [PATCH] Test flush after emitting a dist code Signed-off-by: Damian Jarek --- test/beast/zlib/deflate_stream.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/beast/zlib/deflate_stream.cpp b/test/beast/zlib/deflate_stream.cpp index 1a209778..faf6ffc2 100644 --- a/test/beast/zlib/deflate_stream.cpp +++ b/test/beast/zlib/deflate_stream.cpp @@ -464,6 +464,34 @@ public: BEAST_EXPECT(!ec); } + void + testFlushAfterDistMatch() + { + for (auto out_size : {144, 129}) + { + z_params zp; + deflate_stream ds; + std::array in{}; + // 125 will mostly fill the lit buffer, so emitting a distance code + // results in a flush. + auto constexpr n = 125; + std::iota(in.begin(), in.begin() + n, 0); + std::iota(in.begin() + n, in.end(), 0); + + ds.reset(8, 15, 1, Strategy::normal); + std::string out; + out.resize(out_size); + zp.next_in = in.data(); + zp.avail_in = in.size(); + zp.next_out = &out.front(); + zp.avail_out = out.size(); + + error_code ec; + ds.write(zp, Flush::sync, ec); + BEAST_EXPECT(!ec); + } + } + void run() override { @@ -477,6 +505,7 @@ public: testFlushPartial(); testFlushAtLiteralBufferFull(); testRLEMatchLengthExceedLookahead(); + testFlushAfterDistMatch(); } };