18 #include <gtest/gtest.h>
23 #include "gen-cpp/Descriptors_types.h"
34 for (
int i = 0; i < 1024; i++) {
35 for (uint8_t ch =
'a'; ch <=
'z'; ++ch) {
38 for (uint8_t ch =
'Z'; ch >=
'A'; --ch) {
55 void RunTest(THdfsCompression::type format) {
56 scoped_ptr<Codec> compressor;
57 scoped_ptr<Codec> decompressor;
65 if(format == THdfsCompression::LZ4) {
73 if (format != THdfsCompression::BZIP2) {
82 decompressor->Close();
86 scoped_ptr<Codec> compressor;
87 scoped_ptr<Codec> decompressor;
99 decompressor->Close();
103 int64_t input_len, uint8_t* input) {
106 int64_t compressed_length;
108 input, &compressed_length, &compressed).
ok());
111 EXPECT_TRUE(decompressor->
ProcessBlock(
false, compressed_length,
112 compressed, &output_len, &output).
ok());
114 EXPECT_EQ(output_len, input_len);
115 EXPECT_EQ(memcmp(input, output, input_len), 0);
118 int64_t max_compressed_length = compressor->
MaxOutputLen(input_len, input);
121 if (max_compressed_length != -1) {
122 EXPECT_GE(max_compressed_length, 0);
124 compressed_length = max_compressed_length;
127 EXPECT_TRUE(compressor->
ProcessBlock(
true, input_len, input, &compressed_length,
131 output_len = decompressor->
MaxOutputLen(compressed_length, compressed);
132 if (output_len == -1) output_len = input_len;
135 EXPECT_TRUE(decompressor->
ProcessBlock(
true, compressed_length, compressed,
136 &output_len, &output).
ok());
138 EXPECT_EQ(output_len, input_len);
139 EXPECT_EQ(memcmp(input, output, input_len), 0);
143 int64_t input_len, uint8_t* input) {
145 int64_t compressed_length;
147 input, &compressed_length, &compressed).
ok());
150 int64_t total_output_produced = 0;
151 int64_t compressed_bytes_remaining = compressed_length;
154 EXPECT_LE(total_output_produced, input_len);
155 uint8_t* output = NULL;
156 int64_t output_len = 0;
157 int64_t compressed_bytes_read = 0;
159 compressed, &compressed_bytes_read, &output_len, &output, &eos).
ok());
160 EXPECT_EQ(memcmp(input + total_output_produced, output, output_len), 0);
161 total_output_produced += output_len;
162 compressed = compressed + compressed_bytes_read;
163 compressed_bytes_remaining -= compressed_bytes_read;
165 EXPECT_EQ(0, compressed_bytes_remaining);
166 EXPECT_EQ(total_output_produced, input_len);
171 Codec* decompressor, int64_t input_len, uint8_t* input) {
173 int64_t max_compressed_length = compressor->
MaxOutputLen(input_len, input);
175 int64_t compressed_length = max_compressed_length;
177 EXPECT_TRUE(compressor->
ProcessBlock(
true, input_len, input, &compressed_length,
180 int64_t output_len = decompressor->
MaxOutputLen(compressed_length, compressed);
181 if (output_len == -1) output_len = input_len;
184 EXPECT_TRUE(decompressor->
ProcessBlock(
true, compressed_length, compressed,
185 &output_len, &output).
ok());
187 EXPECT_EQ(output_len, input_len);
188 EXPECT_EQ(memcmp(input, output, input_len), 0);
205 RunTest(THdfsCompression::DEFAULT);
209 RunTest(THdfsCompression::SNAPPY);
213 RunTest(THdfsCompression::LZ4);
217 RunTest(THdfsCompression::GZIP);
218 RunTestStreaming(THdfsCompression::GZIP);
222 RunTest(THdfsCompression::DEFLATE);
223 RunTestStreaming(THdfsCompression::GZIP);
227 RunTest(THdfsCompression::BZIP2);
231 RunTest(THdfsCompression::SNAPPY_BLOCKED);
238 scoped_ptr<Codec> compressor;
241 int64_t input_len = 3;
242 const uint8_t input[3] = {1, 2, 3};
243 int64_t output_len = -1;
244 uint8_t* output = NULL;
248 compressor->ProcessBlock(
false, input_len, input, &output_len, &output).ok());
249 EXPECT_GE(output_len, 0);
252 compressor->ProcessBlock(
false, input_len, input, &output_len, &output).ok());
253 EXPECT_GE(output_len, 0);
260 int main(
int argc,
char **argv) {
261 ::testing::InitGoogleTest(&argc, argv);
262 return RUN_ALL_TESTS();
void RunTestStreaming(THdfsCompression::type format)
static Status CreateCompressor(MemPool *mem_pool, bool reuse, THdfsCompression::type format, boost::scoped_ptr< Codec > *compressor)
TEST_F(InstructionCounterTest, Count)
static Status CreateDecompressor(MemPool *mem_pool, bool reuse, THdfsCompression::type format, boost::scoped_ptr< Codec > *decompressor)
virtual Status ProcessBlock(bool output_preallocated, int64_t input_length, const uint8_t *input, int64_t *output_length, uint8_t **output)=0
Process a block of data, either compressing or decompressing it.
uint8_t input_[2 *26 *1024]
virtual Status ProcessBlockStreaming(int64_t input_length, const uint8_t *input, int64_t *input_bytes_read, int64_t *output_length, uint8_t **output, bool *eos)
This class is thread-safe.
void RunTest(THdfsCompression::type format)
void CompressAndDecompress(Codec *compressor, Codec *decompressor, int64_t input_len, uint8_t *input)
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
virtual int64_t MaxOutputLen(int64_t input_len, const uint8_t *input=NULL)=0
int main(int argc, char **argv)
void CompressAndDecompressNoOutputAllocated(Codec *compressor, Codec *decompressor, int64_t input_len, uint8_t *input)
void CompressAndStreamingDecompress(Codec *compressor, Codec *decompressor, int64_t input_len, uint8_t *input)
uint8_t input_streaming_[32 *1024 *1024+1]
uint8_t * Allocate(int size)