OLD | NEW |
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:isolate'; | 7 import 'dart:isolate'; |
8 | 8 |
9 void testZLibDeflate() { | 9 void testZLibDeflate() { |
10 test(int level, List<int> expected) { | 10 test(int level, List<int> expected) { |
11 var port = new ReceivePort(); | 11 var port = new ReceivePort(); |
12 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 12 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
13 var controller = new StreamController(); | 13 var controller = new StreamController(); |
14 controller.stream.transform(new ZLibDeflater(gzip: false, level: level)) | 14 controller.stream.transform(new ZLibDeflater(gzip: false, level: level)) |
15 .reduce([], (buffer, data) { | 15 .fold([], (buffer, data) { |
16 buffer.addAll(data); | 16 buffer.addAll(data); |
17 return buffer; | 17 return buffer; |
18 }) | 18 }) |
19 .then((data) { | 19 .then((data) { |
20 Expect.listEquals(expected, data); | 20 Expect.listEquals(expected, data); |
21 port.close(); | 21 port.close(); |
22 }); | 22 }); |
23 controller.add(data); | 23 controller.add(data); |
24 controller.close(); | 24 controller.close(); |
25 } | 25 } |
(...skipping 19 matching lines...) Expand all Loading... |
45 255, 255]); | 45 255, 255]); |
46 test(9, [120, 218, 98, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 0, | 46 test(9, [120, 218, 98, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, 0, |
47 255, 255]); | 47 255, 255]); |
48 } | 48 } |
49 | 49 |
50 | 50 |
51 void testZLibDeflateEmpty() { | 51 void testZLibDeflateEmpty() { |
52 var port = new ReceivePort(); | 52 var port = new ReceivePort(); |
53 var controller = new StreamController(); | 53 var controller = new StreamController(); |
54 controller.stream.transform(new ZLibDeflater(gzip: false, level: 6)) | 54 controller.stream.transform(new ZLibDeflater(gzip: false, level: 6)) |
55 .reduce([], (buffer, data) { | 55 .fold([], (buffer, data) { |
56 buffer.addAll(data); | 56 buffer.addAll(data); |
57 return buffer; | 57 return buffer; |
58 }) | 58 }) |
59 .then((data) { | 59 .then((data) { |
60 print(data); | 60 print(data); |
61 Expect.listEquals([120, 156, 2, 0, 0, 0, 255, 255], data); | 61 Expect.listEquals([120, 156, 2, 0, 0, 0, 255, 255], data); |
62 port.close(); | 62 port.close(); |
63 }); | 63 }); |
64 controller.close(); | 64 controller.close(); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 void testZLibDeflateGZip() { | 68 void testZLibDeflateGZip() { |
69 var port = new ReceivePort(); | 69 var port = new ReceivePort(); |
70 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 70 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
71 var controller = new StreamController(); | 71 var controller = new StreamController(); |
72 controller.stream.transform(new ZLibDeflater()) | 72 controller.stream.transform(new ZLibDeflater()) |
73 .reduce([], (buffer, data) { | 73 .fold([], (buffer, data) { |
74 buffer.addAll(data); | 74 buffer.addAll(data); |
75 return buffer; | 75 return buffer; |
76 }) | 76 }) |
77 .then((data) { | 77 .then((data) { |
78 Expect.equals(26, data.length); | 78 Expect.equals(26, data.length); |
79 Expect.listEquals([98, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, | 79 Expect.listEquals([98, 96, 100, 98, 102, 97, 101, 99, 231, 224, 4, 0, 0, |
80 0, 255, 255], | 80 0, 255, 255], |
81 // Skip header, as it can change. | 81 // Skip header, as it can change. |
82 data.sublist(10)); | 82 data.sublist(10)); |
83 port.close(); | 83 port.close(); |
(...skipping 25 matching lines...) Expand all Loading... |
109 } | 109 } |
110 | 110 |
111 void testZLibInflate() { | 111 void testZLibInflate() { |
112 test2(bool gzip, int level) { | 112 test2(bool gzip, int level) { |
113 var port = new ReceivePort(); | 113 var port = new ReceivePort(); |
114 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 114 var data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
115 var controller = new StreamController(); | 115 var controller = new StreamController(); |
116 controller.stream | 116 controller.stream |
117 .transform(new ZLibDeflater(gzip: gzip, level: level)) | 117 .transform(new ZLibDeflater(gzip: gzip, level: level)) |
118 .transform(new ZLibInflater()) | 118 .transform(new ZLibInflater()) |
119 .reduce([], (buffer, data) { | 119 .fold([], (buffer, data) { |
120 buffer.addAll(data); | 120 buffer.addAll(data); |
121 return buffer; | 121 return buffer; |
122 }) | 122 }) |
123 .then((inflated) { | 123 .then((inflated) { |
124 Expect.listEquals(data, inflated); | 124 Expect.listEquals(data, inflated); |
125 port.close(); | 125 port.close(); |
126 }); | 126 }); |
127 controller.add(data); | 127 controller.add(data); |
128 controller.close(); | 128 controller.close(); |
129 } | 129 } |
130 void test(int level) { | 130 void test(int level) { |
131 test2(false, level); | 131 test2(false, level); |
132 test2(true, level); | 132 test2(true, level); |
133 } | 133 } |
134 for (int i = -1; i < 10; i++) { | 134 for (int i = -1; i < 10; i++) { |
135 test(i); | 135 test(i); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void main() { | 139 void main() { |
140 testZLibDeflate(); | 140 testZLibDeflate(); |
141 testZLibDeflateEmpty(); | 141 testZLibDeflateEmpty(); |
142 testZLibDeflateGZip(); | 142 testZLibDeflateGZip(); |
143 testZLibDeflateInvalidLevel(); | 143 testZLibDeflateInvalidLevel(); |
144 testZLibInflate(); | 144 testZLibInflate(); |
145 } | 145 } |
OLD | NEW |