Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdlib.h> | |
| 6 | |
| 7 #include "remoting/base/compressor_zlib.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 static void GenerateTestData(uint8* data, int size, int seed) { | |
| 11 srand(seed); | |
| 12 for (int i = 0; i < size; ++i) | |
| 13 data[i] = rand() % 256; | |
| 14 } | |
| 15 | |
| 16 // Keep compressing |input_data| into |output_data| until the last | |
| 17 // bytes is consumed. | |
|
dmac
2010/07/01 00:12:54
s/bytes/byte/
| |
| 18 static void Compress(remoting::Compressor* compressor, | |
| 19 const uint8* input_data, int input_size, | |
| 20 uint8* output_data, int output_size) { | |
| 21 | |
| 22 // Feed data into the compress until the end. | |
| 23 // This loop will rewrite |output_data| continuously. | |
| 24 while (input_size) { | |
| 25 int consumed, written; | |
| 26 compressor->Write(input_data, input_size, | |
| 27 output_data, output_size, | |
| 28 &consumed, &written); | |
| 29 input_data += consumed; | |
| 30 input_size -= consumed; | |
| 31 } | |
| 32 | |
| 33 // And then flush the remaining data from the compressor. | |
| 34 int written; | |
| 35 while (compressor->Flush(output_data, output_size, &written)) { | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 TEST(CompressorZlibTest, SimpleCompress) { | |
| 40 static const int kRawDataSize = 1024 * 128; | |
| 41 static const int kCompressedDataSize = 256; | |
| 42 uint8 raw_data[kRawDataSize]; | |
| 43 uint8 compressed_data[kCompressedDataSize]; | |
| 44 | |
| 45 // Generate the test data.g | |
| 46 GenerateTestData(raw_data, kRawDataSize, 99); | |
| 47 | |
| 48 // Then use the compressor to compress. | |
| 49 remoting::CompressorZlib compressor; | |
| 50 Compress(&compressor, raw_data, kRawDataSize, | |
|
dmac
2010/07/01 00:12:54
there's actually no test here other than it doesn'
Alpha Left Google
2010/07/01 00:14:57
The test will become invalid if zlib is updated an
| |
| 51 compressed_data, kCompressedDataSize); | |
| 52 } | |
| OLD | NEW |