Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: tests/standalone/io/zlib_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import "package:async_helper/async_helper.dart"; 9 import "package:async_helper/async_helper.dart";
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
11 11
12 void testZLibDeflateEmpty() { 12 void testZLibDeflateEmpty() {
13 asyncStart(); 13 asyncStart();
14 var controller = new StreamController(sync: true); 14 var controller = new StreamController(sync: true);
15 controller.stream.transform(new ZLibEncoder(gzip: false, level: 6)) 15 controller.stream.transform(new ZLibEncoder(gzip: false, level: 6)).fold([],
16 .fold([], (buffer, data) { 16 (buffer, data) {
17 buffer.addAll(data); 17 buffer.addAll(data);
18 return buffer; 18 return buffer;
19 }) 19 }).then((data) {
20 .then((data) { 20 Expect.listEquals([120, 156, 3, 0, 0, 0, 0, 1], data);
21 Expect.listEquals([120, 156, 3, 0, 0, 0, 0, 1], data); 21 asyncEnd();
22 asyncEnd(); 22 });
23 });
24 controller.close(); 23 controller.close();
25 } 24 }
26 25
27 void testZLibDeflateEmptyGzip() { 26 void testZLibDeflateEmptyGzip() {
28 asyncStart(); 27 asyncStart();
29 var controller = new StreamController(sync: true); 28 var controller = new StreamController(sync: true);
30 controller.stream.transform(new ZLibEncoder(gzip: true, level: 6)) 29 controller.stream.transform(new ZLibEncoder(gzip: true, level: 6)).fold([],
31 .fold([], (buffer, data) { 30 (buffer, data) {
32 buffer.addAll(data); 31 buffer.addAll(data);
33 return buffer; 32 return buffer;
34 }) 33 }).then((data) {
35 .then((data) { 34 Expect.isTrue(data.length > 0);
36 Expect.isTrue(data.length > 0); 35 Expect.listEquals([], new ZLibDecoder().convert(data));
37 Expect.listEquals([], new ZLibDecoder().convert(data)); 36 asyncEnd();
38 asyncEnd(); 37 });
39 });
40 controller.close(); 38 controller.close();
41 } 39 }
42 40
43 void testZLibDeflate(List<int> data) { 41 void testZLibDeflate(List<int> data) {
44 asyncStart(); 42 asyncStart();
45 var controller = new StreamController(sync: true); 43 var controller = new StreamController(sync: true);
46 controller.stream.transform(new ZLibEncoder(gzip: false, level: 6)) 44 controller.stream.transform(new ZLibEncoder(gzip: false, level: 6)).fold([],
47 .fold([], (buffer, data) { 45 (buffer, data) {
48 buffer.addAll(data); 46 buffer.addAll(data);
49 return buffer; 47 return buffer;
50 }) 48 }).then((data) {
51 .then((data) { 49 Expect.listEquals([
52 Expect.listEquals( 50 120,
53 [120, 156, 99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 51 156,
54 175, 0, 46], 52 99,
55 data); 53 96,
56 asyncEnd(); 54 100,
57 }); 55 98,
56 102,
57 97,
58 101,
59 99,
60 231,
61 224,
62 4,
63 0,
64 0,
65 175,
66 0,
67 46
68 ], data);
69 asyncEnd();
70 });
58 controller.add(data); 71 controller.add(data);
59 controller.close(); 72 controller.close();
60 } 73 }
61 74
62 void testZLibDeflateGZip(List<int> data) { 75 void testZLibDeflateGZip(List<int> data) {
63 asyncStart(); 76 asyncStart();
64 var controller = new StreamController(sync: true); 77 var controller = new StreamController(sync: true);
65 controller.stream.transform(new ZLibEncoder(gzip: true)) 78 controller.stream.transform(new ZLibEncoder(gzip: true)).fold([],
66 .fold([], (buffer, data) { 79 (buffer, data) {
67 buffer.addAll(data); 80 buffer.addAll(data);
68 return buffer; 81 return buffer;
69 }) 82 }).then((data) {
70 .then((data) { 83 Expect.equals(30, data.length);
71 Expect.equals(30, data.length); 84 Expect.listEquals(
72 Expect.listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 85 [
73 70, 215, 108, 69, 10, 0, 0, 0], 86 99,
74 // Skip header, as it can change. 87 96,
75 data.sublist(10)); 88 100,
76 asyncEnd(); 89 98,
77 }); 90 102,
91 97,
92 101,
93 99,
94 231,
95 224,
96 4,
97 0,
98 70,
99 215,
100 108,
101 69,
102 10,
103 0,
104 0,
105 0
106 ],
107 // Skip header, as it can change.
108 data.sublist(10));
109 asyncEnd();
110 });
78 controller.add(data); 111 controller.add(data);
79 controller.close(); 112 controller.close();
80 } 113 }
81 114
82 void testZLibDeflateRaw(List<int> data) { 115 void testZLibDeflateRaw(List<int> data) {
83 asyncStart(); 116 asyncStart();
84 var controller = new StreamController(sync: true); 117 var controller = new StreamController(sync: true);
85 controller.stream.transform(new ZLibEncoder(raw: true, level: 6)) 118 controller.stream.transform(new ZLibEncoder(raw: true, level: 6)).fold([],
86 .fold([], (buffer, data) { 119 (buffer, data) {
87 buffer.addAll(data); 120 buffer.addAll(data);
88 return buffer; 121 return buffer;
89 }) 122 }).then((data) {
90 .then((data) { 123 Expect
91 Expect.listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0], 124 .listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0], data);
92 data); 125 asyncEnd();
93 asyncEnd(); 126 });
94 });
95 controller.add(data); 127 controller.add(data);
96 controller.close(); 128 controller.close();
97 } 129 }
98 130
99 void testZLibDeflateInvalidLevel() { 131 void testZLibDeflateInvalidLevel() {
100 test2(gzip, level) { 132 test2(gzip, level) {
101 [true, false].forEach((gzip) { 133 [true, false].forEach((gzip) {
102 [-2, -20, 10, 42, null, "9"].forEach((level) { 134 [-2, -20, 10, 42, null, "9"].forEach((level) {
103 Expect.throws( 135 Expect.throws(() => new ZLibEncoder(gzip: gzip, level: level),
104 () => new ZLibEncoder(gzip: gzip, level: level), 136 (e) => e is ArgumentError, "'level' must be in range -1..9");
105 (e) => e is ArgumentError,
106 "'level' must be in range -1..9"
107 );
108 }); 137 });
109 }); 138 });
110 }; 139 }
140
141 ;
111 } 142 }
112 143
113 void testZLibInflate(List<int> data) { 144 void testZLibInflate(List<int> data) {
114 [true, false].forEach((gzip) { 145 [true, false].forEach((gzip) {
115 [ZLibOption.STRATEGY_FILTERED, ZLibOption.STRATEGY_HUFFMAN_ONLY, 146 [
116 ZLibOption.STRATEGY_RLE, ZLibOption.STRATEGY_FIXED, 147 ZLibOption.STRATEGY_FILTERED,
117 ZLibOption.STRATEGY_DEFAULT].forEach((strategy) { 148 ZLibOption.STRATEGY_HUFFMAN_ONLY,
149 ZLibOption.STRATEGY_RLE,
150 ZLibOption.STRATEGY_FIXED,
151 ZLibOption.STRATEGY_DEFAULT
152 ].forEach((strategy) {
118 [3, 6, 9].forEach((level) { 153 [3, 6, 9].forEach((level) {
119 asyncStart(); 154 asyncStart();
120 var controller = new StreamController(sync: true); 155 var controller = new StreamController(sync: true);
121 controller.stream 156 controller.stream
122 .transform(new ZLibEncoder(gzip: gzip, level: level, 157 .transform(
123 strategy: strategy)) 158 new ZLibEncoder(gzip: gzip, level: level, strategy: strategy))
124 .transform(new ZLibDecoder()) 159 .transform(new ZLibDecoder())
125 .fold([], (buffer, data) { 160 .fold([], (buffer, data) {
126 buffer.addAll(data); 161 buffer.addAll(data);
127 return buffer; 162 return buffer;
128 }) 163 }).then((inflated) {
129 .then((inflated) { 164 Expect.listEquals(data, inflated);
130 Expect.listEquals(data, inflated); 165 asyncEnd();
131 asyncEnd(); 166 });
132 });
133 controller.add(data); 167 controller.add(data);
134 controller.close(); 168 controller.close();
135 }); 169 });
136 }); 170 });
137 }); 171 });
138 } 172 }
139 173
140 void testZLibInflateRaw(List<int> data) { 174 void testZLibInflateRaw(List<int> data) {
141 [3, 6, 9].forEach((level) { 175 [3, 6, 9].forEach((level) {
142 asyncStart(); 176 asyncStart();
143 var controller = new StreamController(sync: true); 177 var controller = new StreamController(sync: true);
144 controller.stream 178 controller.stream
145 .transform(new ZLibEncoder(raw: true, level: level)) 179 .transform(new ZLibEncoder(raw: true, level: level))
146 .transform(new ZLibDecoder(raw: true)) 180 .transform(new ZLibDecoder(raw: true))
147 .fold([], (buffer, data) { 181 .fold([], (buffer, data) {
148 buffer.addAll(data); 182 buffer.addAll(data);
149 return buffer; 183 return buffer;
150 }) 184 }).then((inflated) {
151 .then((inflated) { 185 Expect.listEquals(data, inflated);
152 Expect.listEquals(data, inflated); 186 asyncEnd();
153 asyncEnd(); 187 });
154 });
155 controller.add(data); 188 controller.add(data);
156 controller.close(); 189 controller.close();
157 }); 190 });
158 } 191 }
159 192
160 void testZLibInflateSync(List<int> data) { 193 void testZLibInflateSync(List<int> data) {
161 [true, false].forEach((gzip) { 194 [true, false].forEach((gzip) {
162 [3, 6, 9].forEach((level) { 195 [3, 6, 9].forEach((level) {
163 var encoded = new ZLibEncoder(gzip: gzip, level: level).convert(data); 196 var encoded = new ZLibEncoder(gzip: gzip, level: level).convert(data);
164 var decoded = new ZLibDecoder().convert(encoded); 197 var decoded = new ZLibDecoder().convert(encoded);
(...skipping 14 matching lines...) Expand all
179 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 212 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
180 213
181 [true, false].forEach((gzip) { 214 [true, false].forEach((gzip) {
182 [3, 6, 9].forEach((level) { 215 [3, 6, 9].forEach((level) {
183 asyncStart(); 216 asyncStart();
184 var controller = new StreamController(sync: true); 217 var controller = new StreamController(sync: true);
185 controller.stream 218 controller.stream
186 .transform(new ZLibEncoder(gzip: gzip, level: level, windowBits: 8)) 219 .transform(new ZLibEncoder(gzip: gzip, level: level, windowBits: 8))
187 .transform(new ZLibDecoder(windowBits: 10)) 220 .transform(new ZLibDecoder(windowBits: 10))
188 .fold([], (buffer, data) { 221 .fold([], (buffer, data) {
189 buffer.addAll(data); 222 buffer.addAll(data);
190 return buffer; 223 return buffer;
191 }) 224 }).then((inflated) {
192 .then((inflated) { 225 Expect.listEquals(data, inflated);
193 Expect.listEquals(data, inflated); 226 asyncEnd();
194 asyncEnd(); 227 });
195 });
196 controller.add(data); 228 controller.add(data);
197 controller.close(); 229 controller.close();
198 }); 230 });
199 }); 231 });
200 } 232 }
201 233
202 void testZlibWithDictionary() { 234 void testZlibWithDictionary() {
203 var dict = [102, 111, 111, 98, 97, 114]; 235 var dict = [102, 111, 111, 98, 97, 114];
204 var data = [98, 97, 114, 102, 111, 111]; 236 var data = [98, 97, 114, 102, 111, 111];
205 237
206 [3, 6, 9].forEach((level) { 238 [3, 6, 9].forEach((level) {
207 var encoded = new ZLibEncoder(level: level, dictionary: dict) 239 var encoded = new ZLibEncoder(level: level, dictionary: dict).convert(data);
208 .convert(data);
209 var decoded = new ZLibDecoder(dictionary: dict).convert(encoded); 240 var decoded = new ZLibDecoder(dictionary: dict).convert(encoded);
210 Expect.listEquals(data, decoded); 241 Expect.listEquals(data, decoded);
211 }); 242 });
212 } 243 }
213 244
214 var generateListTypes = [ 245 var generateListTypes = [
215 (list) => list, 246 (list) => list,
216 (list) => new Uint8List.fromList(list), 247 (list) => new Uint8List.fromList(list),
217 (list) => new Int8List.fromList(list), 248 (list) => new Int8List.fromList(list),
218 (list) => new Uint16List.fromList(list), 249 (list) => new Uint16List.fromList(list),
219 (list) => new Int16List.fromList(list), 250 (list) => new Int16List.fromList(list),
220 (list) => new Uint32List.fromList(list), 251 (list) => new Uint32List.fromList(list),
221 (list) => new Int32List.fromList(list), 252 (list) => new Int32List.fromList(list),
222 ]; 253 ];
223 254
224 var generateViewTypes = [ 255 var generateViewTypes = [
225 (list) => new Uint8List.view((new Uint8List.fromList(list)).buffer, 1, 8), 256 (list) => new Uint8List.view((new Uint8List.fromList(list)).buffer, 1, 8),
226 (list) => new Int8List.view((new Int8List.fromList(list)).buffer, 1, 8), 257 (list) => new Int8List.view((new Int8List.fromList(list)).buffer, 1, 8),
227 (list) => new Uint16List.view((new Uint16List.fromList(list)).buffer, 2, 6), 258 (list) => new Uint16List.view((new Uint16List.fromList(list)).buffer, 2, 6),
228 (list) => new Int16List.view((new Int16List.fromList(list)).buffer, 2, 6), 259 (list) => new Int16List.view((new Int16List.fromList(list)).buffer, 2, 6),
229 (list) => new Uint32List.view((new Uint32List.fromList(list)).buffer, 4, 4), 260 (list) => new Uint32List.view((new Uint32List.fromList(list)).buffer, 4, 4),
230 (list) => new Int32List.view((new Int32List.fromList(list)).buffer, 4, 4), 261 (list) => new Int32List.view((new Int32List.fromList(list)).buffer, 4, 4),
231 ]; 262 ];
232 263
233
234 void main() { 264 void main() {
235 asyncStart(); 265 asyncStart();
236 testZLibDeflateEmpty(); 266 testZLibDeflateEmpty();
237 testZLibDeflateEmptyGzip(); 267 testZLibDeflateEmptyGzip();
238 testZLibDeflateInvalidLevel(); 268 testZLibDeflateInvalidLevel();
239 generateListTypes.forEach((f) { 269 generateListTypes.forEach((f) {
240 var data = f([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); 270 var data = f([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
241 testZLibDeflate(data); 271 testZLibDeflate(data);
242 testZLibDeflateGZip(data); 272 testZLibDeflateGZip(data);
243 testZLibDeflateRaw(data); 273 testZLibDeflateRaw(data);
244 testZLibInflate(data); 274 testZLibInflate(data);
245 testZLibInflateSync(data); 275 testZLibInflateSync(data);
246 testZLibInflateRaw(data); 276 testZLibInflateRaw(data);
247 }); 277 });
248 generateViewTypes.forEach((f) { 278 generateViewTypes.forEach((f) {
249 var data = f([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); 279 var data = f([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
250 testZLibInflate(data); 280 testZLibInflate(data);
251 testZLibInflateSync(data); 281 testZLibInflateSync(data);
252 testZLibInflateRaw(data); 282 testZLibInflateRaw(data);
253 }); 283 });
254 testZlibInflateThrowsWithSmallerWindow(); 284 testZlibInflateThrowsWithSmallerWindow();
255 testZlibInflateWithLargerWindow(); 285 testZlibInflateWithLargerWindow();
256 testZlibWithDictionary(); 286 testZlibWithDictionary();
257 asyncEnd(); 287 asyncEnd();
258 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698