| 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 #import("dart:isolate"); | 6 #import("dart:isolate"); |
| 7 | 7 |
| 8 void testEmptyListOutputStream1() { | 8 void testEmptyListOutputStream1() { |
| 9 OutputStream stream = new ListOutputStream(); | 9 OutputStream stream = new ListOutputStream(); |
| 10 Expect.equals(null, stream.contents()); | 10 Expect.equals(null, stream.contents()); |
| 11 stream.close(); | 11 stream.close(); |
| 12 Expect.equals(null, stream.contents()); | 12 Expect.equals(null, stream.contents()); |
| 13 Expect.throws(() { stream.write([0]); }); | 13 Expect.throws(() { stream.write([0]); }); |
| 14 } | 14 } |
| 15 | 15 |
| 16 | 16 |
| 17 void testEmptyListOutputStream2() { | 17 void testEmptyListOutputStream2() { |
| 18 OutputStream stream = new ListOutputStream(); | 18 OutputStream stream = new ListOutputStream(); |
| 19 ReceivePort donePort = new ReceivePort(); | 19 ReceivePort donePort = new ReceivePort(); |
| 20 | 20 |
| 21 void onNoPendingWrite() { | 21 void onNoPendingWrite() { |
| 22 stream.close(); | 22 stream.close(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void onClose() { | 25 void onClose() { |
| 26 Expect.equals(null, stream.contents()); | 26 Expect.equals(null, stream.contents()); |
| 27 donePort.toSendPort().send(null); | 27 donePort.toSendPort().send(null); |
| 28 } | 28 } |
| 29 | 29 |
| 30 stream.noPendingWriteHandler = onNoPendingWrite; | 30 stream.onNoPendingWrite = onNoPendingWrite; |
| 31 stream.closeHandler = onClose; | 31 stream.onClose = onClose; |
| 32 | 32 |
| 33 donePort.receive((x,y) => donePort.close()); | 33 donePort.receive((x,y) => donePort.close()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 void testListOutputStream1() { | 37 void testListOutputStream1() { |
| 38 OutputStream stream = new ListOutputStream(); | 38 OutputStream stream = new ListOutputStream(); |
| 39 Expect.equals(null, stream.contents()); | 39 Expect.equals(null, stream.contents()); |
| 40 stream.write([1, 2]); | 40 stream.write([1, 2]); |
| 41 stream.writeFrom([1, 2, 3, 4, 5], 2, 2); | 41 stream.writeFrom([1, 2, 3, 4, 5], 2, 2); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 72 | 72 |
| 73 void onClose() { | 73 void onClose() { |
| 74 Expect.equals(4, stage); | 74 Expect.equals(4, stage); |
| 75 var contents = stream.contents(); | 75 var contents = stream.contents(); |
| 76 Expect.equals(5, contents.length); | 76 Expect.equals(5, contents.length); |
| 77 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]); | 77 for (var i = 0; i < contents.length; i++) Expect.equals(i + 1, contents[i]); |
| 78 Expect.equals(null, stream.contents()); | 78 Expect.equals(null, stream.contents()); |
| 79 donePort.toSendPort().send(null); | 79 donePort.toSendPort().send(null); |
| 80 } | 80 } |
| 81 | 81 |
| 82 stream.noPendingWriteHandler = onNoPendingWrite; | 82 stream.onNoPendingWrite = onNoPendingWrite; |
| 83 stream.closeHandler = onClose; | 83 stream.onClose = onClose; |
| 84 | 84 |
| 85 donePort.receive((x,y) => donePort.close()); | 85 donePort.receive((x,y) => donePort.close()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 main() { | 88 main() { |
| 89 testEmptyListOutputStream1(); | 89 testEmptyListOutputStream1(); |
| 90 testEmptyListOutputStream2(); | 90 testEmptyListOutputStream2(); |
| 91 testListOutputStream1(); | 91 testListOutputStream1(); |
| 92 testListOutputStream2(); | 92 testListOutputStream2(); |
| 93 } | 93 } |
| OLD | NEW |