Skip to content

Commit

Permalink
Address gcc warnings-as-errors in compression code, test improvements (
Browse files Browse the repository at this point in the history
…#973)

Thanks for your contribution!
  • Loading branch information
epistor authored and BillyONeal committed Nov 30, 2018
1 parent 204a526 commit 7368961
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 51 deletions.
19 changes: 17 additions & 2 deletions Release/src/http/common/http_compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ class zlib_compressor_base : public compress_provider
throw std::runtime_error("Prior unrecoverable compression stream error " + std::to_string(m_state));
}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
#endif // __clang__
if (input_size > std::numeric_limits<uInt>::max() || output_size > std::numeric_limits<uInt>::max())
#if defined(__clang__)
#pragma clang diagnostic pop
#endif // __clang__
{
throw std::runtime_error("Compression input or output size out of range");
}
Expand Down Expand Up @@ -183,7 +190,14 @@ class zlib_decompressor_base : public decompress_provider
throw std::runtime_error("Prior unrecoverable decompression stream error " + std::to_string(m_state));
}

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
#endif // __clang__
if (input_size > std::numeric_limits<uInt>::max() || output_size > std::numeric_limits<uInt>::max())
#if defined(__clang__)
#pragma clang diagnostic pop
#endif // __clang__
{
throw std::runtime_error("Compression input or output size out of range");
}
Expand Down Expand Up @@ -297,13 +311,13 @@ class brotli_compressor : public compress_provider
uint32_t block = 0,
uint32_t nomodel = 0,
uint32_t hint = 0)
: m_algorithm(BROTLI)
, m_window(window)
: m_window(window)
, m_quality(quality)
, m_mode(mode)
, m_block(block)
, m_nomodel(nomodel)
, m_hint(hint)
, m_algorithm(BROTLI)
{
(void)reset();
}
Expand Down Expand Up @@ -518,6 +532,7 @@ class brotli_decompressor : public decompress_provider
// have to first allocate a guaranteed-large-enough buffer and then copy out of it, or we'd have to call
// reset() if it failed due to insufficient output buffer space (and we'd need to use
// BrotliDecoderGetErrorCode() to tell if that's why it failed)
(void)hint;
m_state = BrotliDecoderDecompressStream(m_stream, &avail_in, &next_in, &avail_out, &next_out, &total_out);
if (m_state == BROTLI_DECODER_RESULT_ERROR)
{
Expand Down
85 changes: 36 additions & 49 deletions Release/tests/functional/http/client/compression_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,12 @@ SUITE(compression_tests)
bool compressible)
{
std::vector<uint8_t> input_buffer;
std::vector<uint8_t> cmp_buffer;
std::vector<uint8_t> dcmp_buffer;
operation_result r;
std::vector<size_t> chunk_sizes;
size_t csize;
size_t dsize;
size_t i;
size_t nn;

VERIFY_ARE_EQUAL(compressor->algorithm(), decompressor->algorithm());

input_buffer.reserve(buffer_size);
for (size_t i = 0; i < buffer_size; ++i)
for (i = 0; i < buffer_size; ++i)
{
uint8_t element;
if (compressible)
Expand All @@ -209,59 +202,52 @@ SUITE(compression_tests)
}

// compress in chunks
csize = 0;
cmp_buffer.resize(buffer_size); // pessimistic (or not, for non-compressible data)
for (i = 0; i < buffer_size; i += chunk_size)
std::vector<size_t> chunk_sizes;
std::vector<uint8_t> cmp_buffer(buffer_size);
size_t cmpsize = buffer_size;
size_t csize = 0;
operation_result r = {0};
operation_hint hint = operation_hint::has_more;
for (i = 0; i < buffer_size || csize == cmpsize || !r.done; i += r.input_bytes_processed)
{
if (i == buffer_size)
{
// the entire input buffer has been consumed by the compressor
hint = operation_hint::is_last;
}
if (csize == cmpsize)
{
// extend the output buffer if there may be more compressed bytes to retrieve
cmpsize += std::min(chunk_size, (size_t)200);
cmp_buffer.resize(cmpsize);
}
r = compressor
->compress(input_buffer.data() + i,
std::min(chunk_size, buffer_size - i),
cmp_buffer.data() + csize,
std::min(chunk_size, buffer_size - csize),
operation_hint::has_more)
std::min(chunk_size, cmpsize - csize),
hint)
.get();
VERIFY_ARE_EQUAL(r.input_bytes_processed, std::min(chunk_size, buffer_size - i));
VERIFY_ARE_EQUAL(r.done, false);
VERIFY_IS_TRUE(r.input_bytes_processed == std::min(chunk_size, buffer_size - i) ||
r.output_bytes_produced == std::min(chunk_size, cmpsize - csize));
VERIFY_IS_TRUE(hint == operation_hint::is_last || !r.done);
chunk_sizes.push_back(r.output_bytes_produced);
csize += r.output_bytes_produced;
}
if (i >= buffer_size)
{
size_t cmpsize = buffer_size;
do
{
if (csize == cmpsize)
{
// extend the output buffer if there may be more compressed bytes to retrieve
cmpsize += std::min(chunk_size, (size_t)200);
cmp_buffer.resize(cmpsize);
}
r = compressor
->compress(NULL,
0,
cmp_buffer.data() + csize,
std::min(chunk_size, cmpsize - csize),
operation_hint::is_last)
.get();
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
chunk_sizes.push_back(r.output_bytes_produced);
csize += r.output_bytes_produced;
} while (csize == cmpsize);
VERIFY_ARE_EQUAL(r.done, true);

// once more with no input, to assure no error and done
r = compressor->compress(NULL, 0, NULL, 0, operation_hint::is_last).get();
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
VERIFY_ARE_EQUAL(r.done, true);
}
VERIFY_ARE_EQUAL(r.done, true);

// once more with no input or output, to assure no error and done
r = compressor->compress(NULL, 0, NULL, 0, operation_hint::is_last).get();
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
VERIFY_ARE_EQUAL(r.done, true);

cmp_buffer.resize(csize); // actual

// decompress in as-compressed chunks
nn = 0;
dsize = 0;
dcmp_buffer.resize(buffer_size);
std::vector<uint8_t> dcmp_buffer(buffer_size);
size_t dsize = 0;
size_t nn = 0;
for (std::vector<size_t>::iterator it = chunk_sizes.begin(); it != chunk_sizes.end(); ++it)
{
if (*it)
Expand Down Expand Up @@ -358,7 +344,8 @@ SUITE(compression_tests)

void compress_test(std::shared_ptr<compress_factory> cfactory, std::shared_ptr<decompress_factory> dfactory)
{
size_t tuples[][2] = {{7999, 8192},
size_t tuples[][2] = {{3, 1024},
{7999, 8192},
{8192, 8192},
{16001, 8192},
{16384, 8192},
Expand Down

0 comments on commit 7368961

Please sign in to comment.