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

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

Issue 8819021: Simulate data and close callbacks on a synchronous file input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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
« runtime/bin/file_impl.dart ('K') | « runtime/bin/file_impl.dart ('k') | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 FileInputStream, VM-only, standalone test. 4 // Testing FileInputStream, VM-only, standalone test.
5 5
6 // Helper method to be able to run the test from the runtime 6 // Helper method to be able to run the test from the runtime
7 // directory, or the top directory. 7 // directory, or the top directory.
8 String getFilename(String path) => 8 String getFilename(String path) =>
9 new File(path).existsSync() ? path : '../' + path; 9 new File(path).existsSync() ? path : '../' + path;
10 10
11 main() { 11 void testStringInputStreamSync() {
12 String fName = getFilename("tests/standalone/src/readuntil_test.dat"); 12 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
13 // File contains "Hello Dart\nwassup!" 13 // File contains "Hello Dart\nwassup!\n"
14 File file = new File(fName); 14 File file = new File(fileName);
15 file.openSync(); 15 file.openSync();
16 StringInputStream x = new StringInputStream(file.openInputStream()); 16 StringInputStream x = new StringInputStream(file.openInputStream());
17 String line = x.readLine(); 17 String line = x.readLine();
18 Expect.equals("Hello Dart", line); 18 Expect.equals("Hello Dart", line);
19 file.closeSync(); 19 file.closeSync();
20 line = x.readLine(); 20 line = x.readLine();
21 Expect.equals("wassup!", line); 21 Expect.equals("wassup!", line);
22 } 22 }
23
24
25 void testInputStreamAsync() {
26 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
27 // File contains "Hello Dart\nwassup!\n"
28 var expected = "Hello Dart\nwassup!\n".charCodes();
29 File file = new File(fileName);
30 file.openSync();
31 InputStream x = file.openInputStream();
32 var byteCount = 0;
33 x.dataHandler = () {
34 Expect.equals(expected[byteCount], x.read(1)[0]);
35 byteCount++;
36 };
37 x.closeHandler = () {
38 Expect.equals(expected.length, byteCount);
39 };
40 }
41
42
43 void testStringInputStreamAsync1() {
44 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
45 // File contains "Hello Dart\nwassup!\n"
46 File file = new File(fileName);
47 file.openSync();
48 StringInputStream x = new StringInputStream(file.openInputStream());
49 var result = "";
50 x.dataHandler = () {
51 result += x.read();
52 };
53 x.closeHandler = () {
54 Expect.equals("Hello Dart\nwassup!\n", result);
55 };
56 }
57
58
59 void testStringInputStreamAsync2() {
60 String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
61 // File contains "Hello Dart\nwassup!\n"
62 File file = new File(fileName);
63 file.openSync();
64 StringInputStream x = new StringInputStream(file.openInputStream());
65 int lineCount = 0;
66 x.lineHandler = () {
67 var line = x.readLine();
68 Expect.isTrue(lineCount == 0 || lineCount == 1);
69 if (lineCount == 0) Expect.equals("Hello Dart", line);
70 if (lineCount == 1) Expect.equals("wassup!", line);
71 lineCount++;
72 };
73 x.closeHandler = () {
74 Expect.equals(2, lineCount);
75 };
76 }
77
78
79 main() {
80 testStringInputStreamSync();
81 testInputStreamAsync();
82 testStringInputStreamAsync1();
83 testStringInputStreamAsync2();
84 }
OLDNEW
« runtime/bin/file_impl.dart ('K') | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698