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

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: Rebased 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
« no previous file with comments | « 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 af5fea01800560f483226fd903dd40fba54085e7..36181cb3e6ca1552fb73617549999387892ff7e9 100644
--- a/tests/standalone/src/FileInputStreamTest.dart
+++ b/tests/standalone/src/FileInputStreamTest.dart
@@ -8,9 +8,9 @@
String getFilename(String path) =>
new File(path).existsSync() ? path : '../' + path;
-void testStringInputStream() {
+void testStringInputStreamSync() {
String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
- // File contains "Hello Dart\nwassup!"
+ // File contains "Hello Dart\nwassup!\n"
File file = new File(fileName);
file.openSync();
StringInputStream x = new StringInputStream(file.openInputStream());
@@ -21,6 +21,60 @@ void testStringInputStream() {
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);
+ };
+}
+
+
void testChunkedInputStream() {
String fileName = getFilename("tests/standalone/src/readuntil_test.dat");
// File contains 19 bytes ("Hello Dart\nwassup!")
@@ -40,7 +94,11 @@ void testChunkedInputStream() {
Expect.equals(null, chunk);
}
+
main() {
- testStringInputStream();
+ testStringInputStreamSync();
+ testInputStreamAsync();
+ testStringInputStreamAsync1();
+ testStringInputStreamAsync2();
testChunkedInputStream();
}
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698