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

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

Issue 16125005: Make new StreamController be async by default. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 7 years, 6 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 | Annotate | Revision Log
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 "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 void testZLibDeflate() { 10 void testZLibDeflate() {
11 test(int level, List<int> expected) { 11 test(int level, List<int> expected) {
12 var port = new ReceivePort(); 12 var port = new ReceivePort();
13 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 13 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
14 var controller = new StreamController(); 14 var controller = new StreamController(sync: true);
15 controller.stream.transform(new ZLibDeflater(gzip: false, level: level)) 15 controller.stream.transform(new ZLibDeflater(gzip: false, level: level))
16 .fold([], (buffer, data) { 16 .fold([], (buffer, data) {
17 buffer.addAll(data); 17 buffer.addAll(data);
18 return buffer; 18 return buffer;
19 }) 19 })
20 .then((data) { 20 .then((data) {
21 Expect.listEquals(expected, data); 21 Expect.listEquals(expected, data);
22 port.close(); 22 port.close();
23 }); 23 });
24 controller.add(data); 24 controller.add(data);
25 controller.close(); 25 controller.close();
26 } 26 }
27 test(6, [120, 156, 99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 175, 27 test(6, [120, 156, 99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 175,
28 0, 46]); 28 0, 46]);
29 } 29 }
30 30
31 31
32 void testZLibDeflateEmpty() { 32 void testZLibDeflateEmpty() {
33 var port = new ReceivePort(); 33 var port = new ReceivePort();
34 var controller = new StreamController(); 34 var controller = new StreamController(sync: true);
35 controller.stream.transform(new ZLibDeflater(gzip: false, level: 6)) 35 controller.stream.transform(new ZLibDeflater(gzip: false, level: 6))
36 .fold([], (buffer, data) { 36 .fold([], (buffer, data) {
37 buffer.addAll(data); 37 buffer.addAll(data);
38 return buffer; 38 return buffer;
39 }) 39 })
40 .then((data) { 40 .then((data) {
41 Expect.listEquals([120, 156, 3, 0, 0, 0, 0, 1], data); 41 Expect.listEquals([120, 156, 3, 0, 0, 0, 0, 1], data);
42 port.close(); 42 port.close();
43 }); 43 });
44 controller.close(); 44 controller.close();
45 } 45 }
46 46
47 47
48 void testZLibDeflateGZip() { 48 void testZLibDeflateGZip() {
49 var port = new ReceivePort(); 49 var port = new ReceivePort();
50 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 50 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
51 var controller = new StreamController(); 51 var controller = new StreamController(sync: true);
52 controller.stream.transform(new ZLibDeflater()) 52 controller.stream.transform(new ZLibDeflater())
53 .fold([], (buffer, data) { 53 .fold([], (buffer, data) {
54 buffer.addAll(data); 54 buffer.addAll(data);
55 return buffer; 55 return buffer;
56 }) 56 })
57 .then((data) { 57 .then((data) {
58 Expect.equals(30, data.length); 58 Expect.equals(30, data.length);
59 Expect.listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 59 Expect.listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0,
60 70, 215, 108, 69, 10, 0, 0, 0], 60 70, 215, 108, 69, 10, 0, 0, 0],
61 // Skip header, as it can change. 61 // Skip header, as it can change.
(...skipping 23 matching lines...) Expand all
85 test(10); 85 test(10);
86 test(42); 86 test(42);
87 test(null); 87 test(null);
88 test("9"); 88 test("9");
89 } 89 }
90 90
91 void testZLibInflate() { 91 void testZLibInflate() {
92 test2(bool gzip, int level) { 92 test2(bool gzip, int level) {
93 var port = new ReceivePort(); 93 var port = new ReceivePort();
94 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 94 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
95 var controller = new StreamController(); 95 var controller = new StreamController(sync: true);
96 controller.stream 96 controller.stream
97 .transform(new ZLibDeflater(gzip: gzip, level: level)) 97 .transform(new ZLibDeflater(gzip: gzip, level: level))
98 .transform(new ZLibInflater()) 98 .transform(new ZLibInflater())
99 .fold([], (buffer, data) { 99 .fold([], (buffer, data) {
100 buffer.addAll(data); 100 buffer.addAll(data);
101 return buffer; 101 return buffer;
102 }) 102 })
103 .then((inflated) { 103 .then((inflated) {
104 Expect.listEquals(data, inflated); 104 Expect.listEquals(data, inflated);
105 port.close(); 105 port.close();
(...skipping 10 matching lines...) Expand all
116 } 116 }
117 } 117 }
118 118
119 void main() { 119 void main() {
120 testZLibDeflate(); 120 testZLibDeflate();
121 testZLibDeflateEmpty(); 121 testZLibDeflateEmpty();
122 testZLibDeflateGZip(); 122 testZLibDeflateGZip();
123 testZLibDeflateInvalidLevel(); 123 testZLibDeflateInvalidLevel();
124 testZLibInflate(); 124 testZLibInflate();
125 } 125 }
OLDNEW
« no previous file with comments | « tests/standalone/io/web_socket_protocol_processor_test.dart ('k') | tools/dom/src/KeyboardEventStream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698