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

Side by Side Diff: tests/standalone/src/FileInputStreamTest.dart

Issue 9474004: Make FileInputStream and FileOutputStream actually asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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 | « runtime/bin/timer_impl.dart ('k') | tests/standalone/src/FileInvalidArgumentsTest.dart » ('j') | 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) 2012, 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 // Testing file input stream, VM-only, standalone test. 4 // Testing file input stream, VM-only, standalone test.
5 5
6 #import("dart:io"); 6 #import("dart:io");
7 7
8 // Helper method to be able to run the test from the runtime 8 // Helper method to be able to run the test from the runtime
9 // directory, or the top directory. 9 // directory, or the top directory.
10 String getFilename(String path) => 10 String getFilename(String path) =>
(...skipping 14 matching lines...) Expand all
25 }; 25 };
26 } 26 }
27 27
28 void testInputStreamAsync() { 28 void testInputStreamAsync() {
29 String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); 29 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
30 // File contains "Hello Dart\nwassup!\n" 30 // File contains "Hello Dart\nwassup!\n"
31 var expected = "Hello Dart\nwassup!\n".charCodes(); 31 var expected = "Hello Dart\nwassup!\n".charCodes();
32 InputStream x = (new File(fileName)).openInputStreamSync(); 32 InputStream x = (new File(fileName)).openInputStreamSync();
33 var byteCount = 0; 33 var byteCount = 0;
34 x.dataHandler = () { 34 x.dataHandler = () {
35 Expect.equals(expected[byteCount], x.read(1)[0]); 35 Expect.equals(expected[byteCount], x.read(1)[0]);
36 byteCount++; 36 byteCount++;
37 }; 37 };
38 x.closeHandler = () { 38 x.closeHandler = () {
39 Expect.equals(expected.length, byteCount); 39 Expect.equals(expected.length, byteCount);
40 }; 40 };
41 } 41 }
42 42
43 43
44 void testStringInputStreamAsync(String name, int length) { 44 void testStringInputStreamAsync(String name, int length) {
45 String fileName = getFilename("tests/standalone/src/$name"); 45 String fileName = getFilename("tests/standalone/src/$name");
(...skipping 10 matching lines...) Expand all
56 Expect.equals("Line $lineCount", line); 56 Expect.equals("Line $lineCount", line);
57 } 57 }
58 }; 58 };
59 x.closeHandler = () { 59 x.closeHandler = () {
60 Expect.equals(10, lineCount); 60 Expect.equals(10, lineCount);
61 }; 61 };
62 } 62 }
63 63
64 64
65 void testChunkedInputStream() { 65 void testChunkedInputStream() {
66 // Force the test to timeout if it does not finish.
67 ReceivePort done = new ReceivePort.singleShot();
68 done.receive((message, replyTo) {});
69
66 String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); 70 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
67 // File contains 19 bytes ("Hello Dart\nwassup!") 71 // File contains 19 bytes ("Hello Dart\nwassup!")
68 File file = new File(fileName); 72 File file = new File(fileName);
69 ChunkedInputStream x = new ChunkedInputStream(file.openInputStreamSync()); 73 ChunkedInputStream x = new ChunkedInputStream(file.openInputStreamSync());
70 x.chunkSize = 9; 74 x.chunkSize = 9;
71 List<int> chunk = x.read(); 75 x.dataHandler = () {
72 Expect.equals(9, chunk.length); 76 List<int> chunk = x.read();
73 x.chunkSize = 5; 77 Expect.equals(9, chunk.length);
74 chunk = x.read(); 78 x.chunkSize = 5;
75 Expect.equals(5, chunk.length); 79 x.dataHandler = () {
76 chunk = x.read(); 80 chunk = x.read();
77 Expect.equals(5, chunk.length); 81 Expect.equals(5, chunk.length);
78 chunk = x.read(); 82 x.dataHandler = () {
79 Expect.equals(null, chunk); 83 chunk = x.read();
84 Expect.equals(5, chunk.length);
85 chunk = x.read();
86 Expect.equals(null, chunk);
87 done.toSendPort().send(null);
88 };
89 };
90 };
80 } 91 }
81 92
82 93
83 void testOpenInputStreamAsync() { 94 void testOpenInputStreamAsync() {
84 // Create a port for waiting on the final result of this test. 95 // Create a port for waiting on the final result of this test.
85 ReceivePort done = new ReceivePort(); 96 ReceivePort done = new ReceivePort.singleShot();
86 done.receive((message, replyTo) { 97 done.receive((message, replyTo) {});
87 done.close();
88 });
89 98
90 // Test using the asynchronous way of opening an input stream. 99 // Test using the asynchronous way of opening an input stream.
91 String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); 100 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
92 File file = new File(fileName); 101 File file = new File(fileName);
93 file.exists(); 102 file.exists();
94 file.existsHandler = (exists) { 103 file.existsHandler = (exists) {
95 if (exists) { 104 if (exists) {
96 file.openInputStream(); 105 file.openInputStream();
97 } else { 106 } else {
98 Expect.fail("Test file not found"); 107 Expect.fail("Test file not found");
(...skipping 12 matching lines...) Expand all
111 testStringInputStreamSync(); 120 testStringInputStreamSync();
112 testInputStreamAsync(); 121 testInputStreamAsync();
113 // Check the length of these files as both are text files where one 122 // Check the length of these files as both are text files where one
114 // is without a terminating line separator which can easily be added 123 // is without a terminating line separator which can easily be added
115 // back if accidentally opened in a text editor. 124 // back if accidentally opened in a text editor.
116 testStringInputStreamAsync("readline_test1.dat", 111); 125 testStringInputStreamAsync("readline_test1.dat", 111);
117 testStringInputStreamAsync("readline_test2.dat", 114); 126 testStringInputStreamAsync("readline_test2.dat", 114);
118 testChunkedInputStream(); 127 testChunkedInputStream();
119 testOpenInputStreamAsync(); 128 testOpenInputStreamAsync();
120 } 129 }
OLDNEW
« no previous file with comments | « runtime/bin/timer_impl.dart ('k') | tests/standalone/src/FileInvalidArgumentsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698