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

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

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 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
« no previous file with comments | « tests/standalone/io/windows_file_system_async_links_test.dart ('k') | no next file » | 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) 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";
6 import 'dart:async'; 5 import 'dart:async';
7 import 'dart:io'; 6 import 'dart:io';
8 import 'dart:isolate'; 7
8 import "package:async_helper/async_helper.dart";
9 import "package:expect/expect.dart";
9 10
10 void testZLibDeflate() { 11 void testZLibDeflate() {
11 test(int level, List<int> expected) { 12 test(int level, List<int> expected) {
12 var port = new ReceivePort(); 13 asyncStart();
13 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 14 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
14 var controller = new StreamController(sync: true); 15 var controller = new StreamController(sync: true);
15 controller.stream.transform(new ZLibEncoder(gzip: false, level: level)) 16 controller.stream.transform(new ZLibEncoder(gzip: false, level: level))
16 .fold([], (buffer, data) { 17 .fold([], (buffer, data) {
17 buffer.addAll(data); 18 buffer.addAll(data);
18 return buffer; 19 return buffer;
19 }) 20 })
20 .then((data) { 21 .then((data) {
21 Expect.listEquals(expected, data); 22 Expect.listEquals(expected, data);
22 port.close(); 23 asyncEnd();
23 }); 24 });
24 controller.add(data); 25 controller.add(data);
25 controller.close(); 26 controller.close();
26 } 27 }
27 test(6, [120, 156, 99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 175, 28 test(6, [120, 156, 99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 175,
28 0, 46]); 29 0, 46]);
29 } 30 }
30 31
31 32
32 void testZLibDeflateEmpty() { 33 void testZLibDeflateEmpty() {
33 var port = new ReceivePort(); 34 asyncStart();
34 var controller = new StreamController(sync: true); 35 var controller = new StreamController(sync: true);
35 controller.stream.transform(new ZLibEncoder(gzip: false, level: 6)) 36 controller.stream.transform(new ZLibEncoder(gzip: false, level: 6))
36 .fold([], (buffer, data) { 37 .fold([], (buffer, data) {
37 buffer.addAll(data); 38 buffer.addAll(data);
38 return buffer; 39 return buffer;
39 }) 40 })
40 .then((data) { 41 .then((data) {
41 Expect.listEquals([120, 156, 3, 0, 0, 0, 0, 1], data); 42 Expect.listEquals([120, 156, 3, 0, 0, 0, 0, 1], data);
42 port.close(); 43 asyncEnd();
43 }); 44 });
44 controller.close(); 45 controller.close();
45 } 46 }
46 47
47 48
48 void testZLibDeflateGZip() { 49 void testZLibDeflateGZip() {
49 var port = new ReceivePort(); 50 asyncStart();
50 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 51 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
51 var controller = new StreamController(sync: true); 52 var controller = new StreamController(sync: true);
52 controller.stream.transform(new ZLibEncoder(gzip: true)) 53 controller.stream.transform(new ZLibEncoder(gzip: true))
53 .fold([], (buffer, data) { 54 .fold([], (buffer, data) {
54 buffer.addAll(data); 55 buffer.addAll(data);
55 return buffer; 56 return buffer;
56 }) 57 })
57 .then((data) { 58 .then((data) {
58 Expect.equals(30, data.length); 59 Expect.equals(30, data.length);
59 Expect.listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 60 Expect.listEquals([99, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0,
60 70, 215, 108, 69, 10, 0, 0, 0], 61 70, 215, 108, 69, 10, 0, 0, 0],
61 // Skip header, as it can change. 62 // Skip header, as it can change.
62 data.sublist(10)); 63 data.sublist(10));
63 port.close(); 64 asyncEnd();
64 }); 65 });
65 controller.add(data); 66 controller.add(data);
66 controller.close(); 67 controller.close();
67 } 68 }
68 69
69 void testZLibDeflateInvalidLevel() { 70 void testZLibDeflateInvalidLevel() {
70 test2(gzip, level) { 71 test2(gzip, level) {
71 var port = new ReceivePort();
72 try { 72 try {
73 new ZLibEncoder(gzip: gzip, level: level).startChunkedConversion(null); 73 new ZLibEncoder(gzip: gzip, level: level).startChunkedConversion(null);
74 Expect.fail("No exception thrown");
74 } catch (e) { 75 } catch (e) {
75 port.close();
76 } 76 }
77 } 77 }
78 test(level) { 78 test(level) {
79 test2(false, level); 79 test2(false, level);
80 test2(true, level); 80 test2(true, level);
81 test2(9, level); 81 test2(9, level);
82 } 82 }
83 test(-2); 83 test(-2);
84 test(-20); 84 test(-20);
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 asyncStart();
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(sync: true); 95 var controller = new StreamController(sync: true);
96 controller.stream 96 controller.stream
97 .transform(new ZLibEncoder(gzip: gzip, level: level)) 97 .transform(new ZLibEncoder(gzip: gzip, level: level))
98 .transform(new ZLibDecoder()) 98 .transform(new ZLibDecoder())
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 asyncEnd();
106 }); 106 });
107 controller.add(data); 107 controller.add(data);
108 controller.close(); 108 controller.close();
109 } 109 }
110 void test(int level) { 110 void test(int level) {
111 test2(false, level); 111 test2(false, level);
112 test2(true, level); 112 test2(true, level);
113 } 113 }
114 for (int i = -1; i < 10; i++) { 114 for (int i = -1; i < 10; i++) {
115 test(i); 115 test(i);
(...skipping 10 matching lines...) Expand all
126 void test(int level) { 126 void test(int level) {
127 test2(false, level); 127 test2(false, level);
128 test2(true, level); 128 test2(true, level);
129 } 129 }
130 for (int i = -1; i < 10; i++) { 130 for (int i = -1; i < 10; i++) {
131 test(i); 131 test(i);
132 } 132 }
133 } 133 }
134 134
135 void main() { 135 void main() {
136 asyncStart();
136 testZLibDeflate(); 137 testZLibDeflate();
137 testZLibDeflateEmpty(); 138 testZLibDeflateEmpty();
138 testZLibDeflateGZip(); 139 testZLibDeflateGZip();
139 testZLibDeflateInvalidLevel(); 140 testZLibDeflateInvalidLevel();
140 testZLibInflate(); 141 testZLibInflate();
141 testZLibInflateSync(); 142 testZLibInflateSync();
143 asyncEnd();
142 } 144 }
OLDNEW
« no previous file with comments | « tests/standalone/io/windows_file_system_async_links_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698