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

Unified 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 side-by-side diff with in-line comments
Download patch
« runtime/bin/file_impl.dart ('K') | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/FileInputStreamTest.dart
diff --git a/tests/standalone/src/FileInputStreamTest.dart b/tests/standalone/src/FileInputStreamTest.dart
index a61ac68987c8100e018226d380ab2d394e9e53f6..d74e7dc1ea3164c7549c3efaf9c0cbafc8df2a9b 100644
--- a/tests/standalone/src/FileInputStreamTest.dart
+++ b/tests/standalone/src/FileInputStreamTest.dart
@@ -8,10 +8,10 @@
String getFilename(String path) =>
new File(path).existsSync() ? path : '../' + path;
-main() {
- String fName = getFilename("tests/standalone/src/readuntil_test.dat");
- // File contains "Hello Dart\nwassup!"
- File file = new File(fName);
+void testStringInputStreamSync() {
+ String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
+ // File contains "Hello Dart\nwassup!\n"
+ File file = new File(fileName);
file.openSync();
StringInputStream x = new StringInputStream(file.openInputStream());
String line = x.readLine();
@@ -20,3 +20,65 @@ main() {
line = x.readLine();
Expect.equals("wassup!", line);
}
+
+
+void testInputStreamAsync() {
+ String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
+ // File contains "Hello Dart\nwassup!\n"
+ var expected = "Hello Dart\nwassup!\n".charCodes();
+ File file = new File(fileName);
+ file.openSync();
+ InputStream x = file.openInputStream();
+ var byteCount = 0;
+ x.dataHandler = () {
+ Expect.equals(expected[byteCount], x.read(1)[0]);
+ byteCount++;
+ };
+ x.closeHandler = () {
+ Expect.equals(expected.length, byteCount);
+ };
+}
+
+
+void testStringInputStreamAsync1() {
+ String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
+ // File contains "Hello Dart\nwassup!\n"
+ File file = new File(fileName);
+ file.openSync();
+ StringInputStream x = new StringInputStream(file.openInputStream());
+ var result = "";
+ x.dataHandler = () {
+ result += x.read();
+ };
+ x.closeHandler = () {
+ Expect.equals("Hello Dart\nwassup!\n", result);
+ };
+}
+
+
+void testStringInputStreamAsync2() {
+ String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
+ // File contains "Hello Dart\nwassup!\n"
+ File file = new File(fileName);
+ file.openSync();
+ StringInputStream x = new StringInputStream(file.openInputStream());
+ int lineCount = 0;
+ x.lineHandler = () {
+ var line = x.readLine();
+ Expect.isTrue(lineCount == 0 || lineCount == 1);
+ if (lineCount == 0) Expect.equals("Hello Dart", line);
+ if (lineCount == 1) Expect.equals("wassup!", line);
+ lineCount++;
+ };
+ x.closeHandler = () {
+ Expect.equals(2, lineCount);
+ };
+}
+
+
+main() {
+ testStringInputStreamSync();
+ testInputStreamAsync();
+ testStringInputStreamAsync1();
+ testStringInputStreamAsync2();
+}
« 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