Chromium Code Reviews

Side by Side Diff: remoting/base/decompressor_zlib_unittest.cc

Issue 2868062: EncoderZlib/DecoderZlib for chromoting (Closed)
Patch Set: from .cc to .c Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « remoting/base/decoder_zlib_unittest.cc ('k') | remoting/base/encoder_verbatim.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "remoting/base/compressor_zlib.h" 7 #include "remoting/base/compressor_zlib.h"
8 #include "remoting/base/decompressor_zlib.h" 8 #include "remoting/base/decompressor_zlib.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace remoting {
12
11 static void GenerateTestData(uint8* data, int size, int seed) { 13 static void GenerateTestData(uint8* data, int size, int seed) {
12 srand(seed); 14 srand(seed);
13 for (int i = 0; i < size; ++i) 15 for (int i = 0; i < size; ++i)
14 data[i] = rand() % 256; 16 data[i] = rand() % 256;
15 } 17 }
16 18
17 // Keep compressing |input_data| into |output_data| until the last 19 // Keep compressing |input_data| into |output_data| until the last
18 // bytes is consumed. 20 // bytes is consumed.
19 // 21 //
20 // The compressed size is written to |compressed_size|. 22 // The compressed size is written to |compressed_size|.
21 static void Compress(remoting::Compressor* compressor, 23 static void Compress(remoting::Compressor* compressor,
22 const uint8* input_data, int input_size, 24 const uint8* input_data, int input_size,
23 uint8* output_data, int output_size, 25 uint8* output_data, int output_size,
24 int* compressed_size) { 26 int* compressed_size) {
25 *compressed_size = 0; 27 *compressed_size = 0;
26 while (true) { 28 while (true) {
27 int consumed, written; 29 int consumed, written;
28 bool ret = compressor->Process(input_data, input_size, 30 bool ret = compressor->Process(
29 output_data, output_size, 31 input_data, input_size, output_data, output_size,
30 &consumed, &written); 32 input_size == 0 ?
33 Compressor::CompressorFinish : Compressor::CompressorNoFlush,
34 &consumed, &written);
31 input_data += consumed; 35 input_data += consumed;
32 input_size -= consumed; 36 input_size -= consumed;
33 output_data += written; 37 output_data += written;
34 output_size -= written; 38 output_size -= written;
35 *compressed_size += written; 39 *compressed_size += written;
36 40
37 if (!ret) 41 if (!ret)
38 break; 42 break;
39 } 43 }
40 } 44 }
(...skipping 86 matching lines...)
127 131
128 // Expect that there's only one byte written. 132 // Expect that there's only one byte written.
129 EXPECT_EQ(1, written); 133 EXPECT_EQ(1, written);
130 decompressed_size += written; 134 decompressed_size += written;
131 135
132 if (!ret) 136 if (!ret)
133 break; 137 break;
134 } 138 }
135 EXPECT_EQ(kRawDataSize, decompressed_size); 139 EXPECT_EQ(kRawDataSize, decompressed_size);
136 } 140 }
141
142 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/decoder_zlib_unittest.cc ('k') | remoting/base/encoder_verbatim.cc » ('j') | no next file with comments »

Powered by Google App Engine