MCPcopy Create free account
hub / github.com/apache/impala / CompressAndDecompress

Method CompressAndDecompress

be/src/util/decompress-test.cc:127–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125 }
126
127 void CompressAndDecompress(Codec* compressor, Codec* decompressor,
128 int64_t input_len, uint8_t* input) {
129 // Non-preallocated output buffers
130 uint8_t* compressed;
131 int64_t compressed_length;
132 EXPECT_OK(compressor->ProcessBlock(false, input_len,
133 input, &compressed_length, &compressed));
134 uint8_t* output;
135 int64_t output_len;
136 EXPECT_OK(decompressor->ProcessBlock(false, compressed_length,
137 compressed, &output_len, &output));
138
139 EXPECT_EQ(output_len, input_len);
140 EXPECT_EQ(Ubsan::MemCmp(input, output, input_len), 0);
141
142 // Preallocated output buffers
143 int64_t max_compressed_length = compressor->MaxOutputLen(input_len, input);
144
145 // Don't redo compression if compressor doesn't support MaxOutputLen()
146 if (max_compressed_length != -1) {
147 EXPECT_GE(max_compressed_length, 0);
148 uint8_t* compressed = mem_pool_.Allocate(max_compressed_length);
149 compressed_length = max_compressed_length;
150 EXPECT_OK(compressor->ProcessBlock(true, input_len, input, &compressed_length,
151 &compressed));
152 }
153
154 output_len = decompressor->MaxOutputLen(compressed_length, compressed);
155 if (output_len == -1) output_len = input_len;
156 output = mem_pool_.Allocate(output_len);
157
158 EXPECT_OK(decompressor->ProcessBlock(true, compressed_length, compressed,
159 &output_len, &output));
160
161 EXPECT_EQ(output_len, input_len);
162 EXPECT_EQ(Ubsan::MemCmp(input, output, input_len), 0);
163 }
164
165 // Test the behavior when the decompressor is given too little / too much space.
166 // Verify that the decompressor returns an error when the space is not enough, gives

Callers

nothing calls this directly

Calls 3

ProcessBlockMethod · 0.45
MaxOutputLenMethod · 0.45
AllocateMethod · 0.45

Tested by

no test coverage detected