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

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: Remove accidental edit 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
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 15 matching lines...) Expand all
61 }; 61 };
62 } 62 }
63 63
64 64
65 void testChunkedInputStream() { 65 void testChunkedInputStream() {
66 String fileName = getFilename("tests/standalone/src/readuntil_test.dat"); 66 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
67 // File contains 19 bytes ("Hello Dart\nwassup!") 67 // File contains 19 bytes ("Hello Dart\nwassup!")
68 File file = new File(fileName); 68 File file = new File(fileName);
69 ChunkedInputStream x = new ChunkedInputStream(file.openInputStreamSync()); 69 ChunkedInputStream x = new ChunkedInputStream(file.openInputStreamSync());
70 x.chunkSize = 9; 70 x.chunkSize = 9;
71 List<int> chunk = x.read(); 71 x.dataHandler = () {
72 Expect.equals(9, chunk.length); 72 List<int> chunk = x.read();
73 x.chunkSize = 5; 73 Expect.equals(9, chunk.length);
74 chunk = x.read(); 74 x.chunkSize = 5;
Søren Gjesse 2012/02/28 07:40:25 I guess that this test is actually wrong, as the d
Mads Ager (google) 2012/02/28 08:21:00 Thanks. Done.
75 Expect.equals(5, chunk.length); 75 chunk = x.read();
76 chunk = x.read(); 76 Expect.equals(5, chunk.length);
77 Expect.equals(5, chunk.length); 77 chunk = x.read();
78 chunk = x.read(); 78 Expect.equals(5, chunk.length);
79 Expect.equals(null, chunk); 79 chunk = x.read();
80 Expect.equals(null, chunk);
81 };
80 } 82 }
81 83
82 84
83 void testOpenInputStreamAsync() { 85 void testOpenInputStreamAsync() {
84 // Create a port for waiting on the final result of this test. 86 // Create a port for waiting on the final result of this test.
85 ReceivePort done = new ReceivePort(); 87 ReceivePort done = new ReceivePort();
86 done.receive((message, replyTo) { 88 done.receive((message, replyTo) {
87 done.close(); 89 done.close();
88 }); 90 });
89 91
(...skipping 21 matching lines...) Expand all
111 testStringInputStreamSync(); 113 testStringInputStreamSync();
112 testInputStreamAsync(); 114 testInputStreamAsync();
113 // Check the length of these files as both are text files where one 115 // 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 116 // is without a terminating line separator which can easily be added
115 // back if accidentally opened in a text editor. 117 // back if accidentally opened in a text editor.
116 testStringInputStreamAsync("readline_test1.dat", 111); 118 testStringInputStreamAsync("readline_test1.dat", 111);
117 testStringInputStreamAsync("readline_test2.dat", 114); 119 testStringInputStreamAsync("readline_test2.dat", 114);
118 testChunkedInputStream(); 120 testChunkedInputStream();
119 testOpenInputStreamAsync(); 121 testOpenInputStreamAsync();
120 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698