| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:io"); | 5 #import("dart:io"); |
| 6 | 6 |
| 7 void testEmptyListInputStream() { | 7 void testEmptyListInputStream() { |
| 8 InputStream stream = new ListInputStream([]); | 8 InputStream stream = new ListInputStream(); |
| 9 stream.write([]); |
| 10 stream.markEndOfStream(); |
| 9 ReceivePort donePort = new ReceivePort(); | 11 ReceivePort donePort = new ReceivePort(); |
| 10 | 12 |
| 11 void onData() { | 13 void onData() { |
| 12 throw "No data expected"; | 14 throw "No data expected"; |
| 13 } | 15 } |
| 14 | 16 |
| 15 void onClose() { | 17 void onClose() { |
| 16 donePort.toSendPort().send(null); | 18 donePort.toSendPort().send(null); |
| 17 } | 19 } |
| 18 | 20 |
| 19 stream.dataHandler = onData; | 21 stream.dataHandler = onData; |
| 20 stream.closeHandler = onClose; | 22 stream.closeHandler = onClose; |
| 21 | 23 |
| 22 donePort.receive((x,y) => donePort.close()); | 24 donePort.receive((x,y) => donePort.close()); |
| 23 } | 25 } |
| 24 | 26 |
| 25 void testEmptyDynamicListInputStream() { | 27 void testEmptyDynamicListInputStream() { |
| 26 InputStream stream = new DynamicListInputStream(); | 28 InputStream stream = new ListInputStream(); |
| 27 ReceivePort donePort = new ReceivePort(); | 29 ReceivePort donePort = new ReceivePort(); |
| 28 | 30 |
| 29 void onData() { | 31 void onData() { |
| 30 throw "No data expected"; | 32 throw "No data expected"; |
| 31 } | 33 } |
| 32 | 34 |
| 33 void onClose() { | 35 void onClose() { |
| 34 donePort.toSendPort().send(null); | 36 donePort.toSendPort().send(null); |
| 35 } | 37 } |
| 36 | 38 |
| 37 stream.dataHandler = onData; | 39 stream.dataHandler = onData; |
| 38 stream.closeHandler = onClose; | 40 stream.closeHandler = onClose; |
| 39 stream.markEndOfStream(); | 41 stream.markEndOfStream(); |
| 40 | 42 |
| 41 donePort.receive((x,y) => donePort.close()); | 43 donePort.receive((x,y) => donePort.close()); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void testListInputStream1() { | 46 void testListInputStream1() { |
| 45 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; | 47 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; |
| 46 InputStream stream = new ListInputStream(data); | 48 InputStream stream = new ListInputStream(); |
| 49 stream.write(data); |
| 50 stream.markEndOfStream(); |
| 47 int count = 0; | 51 int count = 0; |
| 48 ReceivePort donePort = new ReceivePort(); | 52 ReceivePort donePort = new ReceivePort(); |
| 49 | 53 |
| 50 void onData() { | 54 void onData() { |
| 51 List<int> x = stream.read(1); | 55 List<int> x = stream.read(1); |
| 52 Expect.equals(1, x.length); | 56 Expect.equals(1, x.length); |
| 53 Expect.equals(data[count++], x[0]); | 57 Expect.equals(data[count++], x[0]); |
| 54 } | 58 } |
| 55 | 59 |
| 56 void onClose() { | 60 void onClose() { |
| 57 Expect.equals(data.length, count); | 61 Expect.equals(data.length, count); |
| 58 donePort.toSendPort().send(count); | 62 donePort.toSendPort().send(count); |
| 59 } | 63 } |
| 60 | 64 |
| 61 stream.dataHandler = onData; | 65 stream.dataHandler = onData; |
| 62 stream.closeHandler = onClose; | 66 stream.closeHandler = onClose; |
| 63 | 67 |
| 64 donePort.receive((x,y) => donePort.close()); | 68 donePort.receive((x,y) => donePort.close()); |
| 65 } | 69 } |
| 66 | 70 |
| 67 void testListInputStream2() { | 71 void testListInputStream2() { |
| 68 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; | 72 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; |
| 69 InputStream stream = new ListInputStream(data); | 73 InputStream stream = new ListInputStream(); |
| 74 stream.write(data); |
| 75 stream.markEndOfStream(); |
| 70 int count = 0; | 76 int count = 0; |
| 71 ReceivePort donePort = new ReceivePort(); | 77 ReceivePort donePort = new ReceivePort(); |
| 72 | 78 |
| 73 void onData() { | 79 void onData() { |
| 74 List<int> x = new List<int>(2); | 80 List<int> x = new List<int>(2); |
| 75 var bytesRead = stream.readInto(x); | 81 var bytesRead = stream.readInto(x); |
| 76 Expect.equals(2, bytesRead); | 82 Expect.equals(2, bytesRead); |
| 77 Expect.equals(data[count++], x[0]); | 83 Expect.equals(data[count++], x[0]); |
| 78 Expect.equals(data[count++], x[1]); | 84 Expect.equals(data[count++], x[1]); |
| 79 } | 85 } |
| 80 | 86 |
| 81 void onClose() { | 87 void onClose() { |
| 82 Expect.equals(data.length, count); | 88 Expect.equals(data.length, count); |
| 83 donePort.toSendPort().send(count); | 89 donePort.toSendPort().send(count); |
| 84 } | 90 } |
| 85 | 91 |
| 86 stream.dataHandler = onData; | 92 stream.dataHandler = onData; |
| 87 stream.closeHandler = onClose; | 93 stream.closeHandler = onClose; |
| 88 | 94 |
| 89 donePort.receive((x,y) => donePort.close()); | 95 donePort.receive((x,y) => donePort.close()); |
| 90 } | 96 } |
| 91 | 97 |
| 92 void testListInputStreamPipe1() { | 98 void testListInputStreamPipe1() { |
| 93 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; | 99 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; |
| 94 InputStream input = new ListInputStream(data); | 100 InputStream input = new ListInputStream(); |
| 101 input.write(data); |
| 102 input.markEndOfStream(); |
| 95 OutputStream output = new ListOutputStream(); | 103 OutputStream output = new ListOutputStream(); |
| 96 ReceivePort donePort = new ReceivePort(); | 104 ReceivePort donePort = new ReceivePort(); |
| 97 | 105 |
| 98 void onClose() { | 106 void onClose() { |
| 99 var contents = output.contents(); | 107 var contents = output.contents(); |
| 100 Expect.equals(data.length, contents.length); | 108 Expect.equals(data.length, contents.length); |
| 101 donePort.toSendPort().send(null); | 109 donePort.toSendPort().send(null); |
| 102 } | 110 } |
| 103 | 111 |
| 104 input.closeHandler = onClose; | 112 input.closeHandler = onClose; |
| 105 input.pipe(output); | 113 input.pipe(output); |
| 106 | 114 |
| 107 donePort.receive((x,y) => donePort.close()); | 115 donePort.receive((x,y) => donePort.close()); |
| 108 } | 116 } |
| 109 | 117 |
| 110 void testListInputStreamPipe2() { | 118 void testListInputStreamPipe2() { |
| 111 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; | 119 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; |
| 112 OutputStream output = new ListOutputStream(); | 120 OutputStream output = new ListOutputStream(); |
| 113 ReceivePort donePort = new ReceivePort(); | 121 ReceivePort donePort = new ReceivePort(); |
| 114 int count = 0; | 122 int count = 0; |
| 115 | 123 |
| 116 void onClose() { | 124 void onClose() { |
| 117 if (count < 10) { | 125 if (count < 10) { |
| 118 InputStream input = new ListInputStream(data); | 126 InputStream input = new ListInputStream(); |
| 127 input.write(data); |
| 128 input.markEndOfStream(); |
| 119 input.closeHandler = onClose; | 129 input.closeHandler = onClose; |
| 120 if (count < 9) { | 130 if (count < 9) { |
| 121 input.pipe(output, close: false); | 131 input.pipe(output, close: false); |
| 122 } else { | 132 } else { |
| 123 input.pipe(output); | 133 input.pipe(output); |
| 124 } | 134 } |
| 125 count++; | 135 count++; |
| 126 } else { | 136 } else { |
| 127 var contents = output.contents(); | 137 var contents = output.contents(); |
| 128 Expect.equals(data.length * 10, contents.length); | 138 Expect.equals(data.length * 10, contents.length); |
| 129 donePort.toSendPort().send(null); | 139 donePort.toSendPort().send(null); |
| 130 } | 140 } |
| 131 } | 141 } |
| 132 | 142 |
| 133 InputStream input = new ListInputStream(data); | 143 InputStream input = new ListInputStream(); |
| 144 input.write(data); |
| 145 input.markEndOfStream(); |
| 134 input.closeHandler = onClose; | 146 input.closeHandler = onClose; |
| 135 input.pipe(output, close: false); | 147 input.pipe(output, close: false); |
| 136 count++; | 148 count++; |
| 137 | 149 |
| 138 donePort.receive((x,y) => donePort.close()); | 150 donePort.receive((x,y) => donePort.close()); |
| 139 } | 151 } |
| 140 | 152 |
| 141 void testListInputClose1() { | 153 void testListInputClose1() { |
| 142 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 154 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 143 InputStream stream = new ListInputStream(data); | 155 InputStream stream = new ListInputStream(); |
| 156 stream.write(data); |
| 157 stream.markEndOfStream(); |
| 144 ReceivePort donePort = new ReceivePort(); | 158 ReceivePort donePort = new ReceivePort(); |
| 145 | 159 |
| 146 void onData() { | 160 void onData() { |
| 147 throw "No data expected"; | 161 throw "No data expected"; |
| 148 } | 162 } |
| 149 | 163 |
| 150 void onClose() { | 164 void onClose() { |
| 151 donePort.toSendPort().send(null); | 165 donePort.toSendPort().send(null); |
| 152 } | 166 } |
| 153 | 167 |
| 154 stream.dataHandler = onData; | 168 stream.dataHandler = onData; |
| 155 stream.closeHandler = onClose; | 169 stream.closeHandler = onClose; |
| 156 stream.close(); | 170 stream.close(); |
| 157 | 171 |
| 158 donePort.receive((x,y) => donePort.close()); | 172 donePort.receive((x,y) => donePort.close()); |
| 159 } | 173 } |
| 160 | 174 |
| 161 void testListInputClose2() { | 175 void testListInputClose2() { |
| 162 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 176 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 163 InputStream stream = new ListInputStream(data); | 177 InputStream stream = new ListInputStream(); |
| 178 stream.write(data); |
| 179 stream.markEndOfStream(); |
| 164 ReceivePort donePort = new ReceivePort(); | 180 ReceivePort donePort = new ReceivePort(); |
| 165 int count = 0; | 181 int count = 0; |
| 166 | 182 |
| 167 void onData() { | 183 void onData() { |
| 168 count += stream.read(2).length; | 184 count += stream.read(2).length; |
| 169 stream.close(); | 185 stream.close(); |
| 170 } | 186 } |
| 171 | 187 |
| 172 void onClose() { | 188 void onClose() { |
| 173 Expect.equals(2, count); | 189 Expect.equals(2, count); |
| 174 donePort.toSendPort().send(count); | 190 donePort.toSendPort().send(count); |
| 175 } | 191 } |
| 176 | 192 |
| 177 stream.dataHandler = onData; | 193 stream.dataHandler = onData; |
| 178 stream.closeHandler = onClose; | 194 stream.closeHandler = onClose; |
| 179 | 195 |
| 180 donePort.receive((x,y) => donePort.close()); | 196 donePort.receive((x,y) => donePort.close()); |
| 181 } | 197 } |
| 182 | 198 |
| 183 void testDynamicListInputStream() { | 199 void testDynamicListInputStream() { |
| 184 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; | 200 List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; |
| 185 InputStream stream = new DynamicListInputStream(); | 201 InputStream stream = new ListInputStream(); |
| 186 int count = 0; | 202 int count = 0; |
| 187 ReceivePort donePort = new ReceivePort(); | 203 ReceivePort donePort = new ReceivePort(); |
| 188 | 204 |
| 189 void onData() { | 205 void onData() { |
| 190 List<int> x = stream.read(1); | 206 List<int> x = stream.read(1); |
| 191 Expect.equals(1, x.length); | 207 Expect.equals(1, x.length); |
| 192 x = stream.read(); | 208 x = stream.read(); |
| 193 Expect.equals(9, x.length); | 209 Expect.equals(9, x.length); |
| 194 count++; | 210 count++; |
| 195 if (count < 10) { | 211 if (count < 10) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 206 | 222 |
| 207 stream.write(data); | 223 stream.write(data); |
| 208 stream.dataHandler = onData; | 224 stream.dataHandler = onData; |
| 209 stream.closeHandler = onClose; | 225 stream.closeHandler = onClose; |
| 210 | 226 |
| 211 donePort.receive((x,y) => donePort.close()); | 227 donePort.receive((x,y) => donePort.close()); |
| 212 } | 228 } |
| 213 | 229 |
| 214 void testDynamicListInputClose1() { | 230 void testDynamicListInputClose1() { |
| 215 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 231 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 216 InputStream stream = new DynamicListInputStream(); | 232 InputStream stream = new ListInputStream(); |
| 217 ReceivePort donePort = new ReceivePort(); | 233 ReceivePort donePort = new ReceivePort(); |
| 218 | 234 |
| 219 void onData() { | 235 void onData() { |
| 220 throw "No data expected"; | 236 throw "No data expected"; |
| 221 } | 237 } |
| 222 | 238 |
| 223 void onClose() { | 239 void onClose() { |
| 224 donePort.toSendPort().send(null); | 240 donePort.toSendPort().send(null); |
| 225 } | 241 } |
| 226 | 242 |
| 227 stream.write(data); | 243 stream.write(data); |
| 228 stream.dataHandler = onData; | 244 stream.dataHandler = onData; |
| 229 stream.closeHandler = onClose; | 245 stream.closeHandler = onClose; |
| 230 stream.close(); | 246 stream.close(); |
| 231 Expect.throws(() => stream.write(data), (e) => e is StreamException); | 247 Expect.throws(() => stream.write(data), (e) => e is StreamException); |
| 232 | 248 |
| 233 donePort.receive((x,y) => donePort.close()); | 249 donePort.receive((x,y) => donePort.close()); |
| 234 } | 250 } |
| 235 | 251 |
| 236 void testDynamicListInputClose2() { | 252 void testDynamicListInputClose2() { |
| 237 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 253 List<int> data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 238 InputStream stream = new DynamicListInputStream(); | 254 InputStream stream = new ListInputStream(); |
| 239 ReceivePort donePort = new ReceivePort(); | 255 ReceivePort donePort = new ReceivePort(); |
| 240 int count = 0; | 256 int count = 0; |
| 241 | 257 |
| 242 void onData() { | 258 void onData() { |
| 243 count += stream.read(15).length; | 259 count += stream.read(15).length; |
| 244 stream.close(); | 260 stream.close(); |
| 245 Expect.throws(() => stream.write(data), (e) => e is StreamException); | 261 Expect.throws(() => stream.write(data), (e) => e is StreamException); |
| 246 } | 262 } |
| 247 | 263 |
| 248 void onClose() { | 264 void onClose() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 265 testListInputStream1(); | 281 testListInputStream1(); |
| 266 testListInputStream2(); | 282 testListInputStream2(); |
| 267 testListInputStreamPipe1(); | 283 testListInputStreamPipe1(); |
| 268 testListInputStreamPipe2(); | 284 testListInputStreamPipe2(); |
| 269 testListInputClose1(); | 285 testListInputClose1(); |
| 270 testListInputClose2(); | 286 testListInputClose2(); |
| 271 testDynamicListInputStream(); | 287 testDynamicListInputStream(); |
| 272 testDynamicListInputClose1(); | 288 testDynamicListInputClose1(); |
| 273 testDynamicListInputClose2(); | 289 testDynamicListInputClose2(); |
| 274 } | 290 } |
| OLD | NEW |