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

Unified Diff: tests/standalone/src/FileTest.dart

Issue 9067004: Refactor the file input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 12 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 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/FileTest.dart
diff --git a/tests/standalone/src/FileTest.dart b/tests/standalone/src/FileTest.dart
index db9fdd43a2bd199ba7414a6bf32c0e4661c18b09..3e7fb3fb833906f5559d7592ac61fc832f9c1e77 100644
--- a/tests/standalone/src/FileTest.dart
+++ b/tests/standalone/src/FileTest.dart
@@ -56,14 +56,44 @@ class FileTest {
// Test for file read and write functionality.
static int testReadWriteStream() {
- // Read a file.
String inFilename = getFilename("tests/vm/data/fixed_length_file");
- File file = new File(inFilename);
- InputStream input = file.openInputStream();
+ File file;
+ InputStream input;
+ int bytesRead;
+
+ // Test reading all using readInto.
+ file = new File(inFilename);
+ input = file.openInputStream();
List<int> buffer1 = new List<int>(42);
- int bytesRead = input.readInto(buffer1, 0, 42);
+ bytesRead = input.readInto(buffer1, 0, 42);
Expect.equals(42, bytesRead);
Expect.isTrue(input.closed);
+
+ // Test reading all using readInto and read.
+ file = new File(inFilename);
+ input = file.openInputStream();
+ bytesRead = input.readInto(buffer1, 0, 21);
+ Expect.equals(21, bytesRead);
+ buffer1 = input.read();
+ Expect.equals(21, buffer1.length);
+ Expect.isTrue(input.closed);
+
+ // Test reading all using read and readInto.
+ file = new File(inFilename);
+ input = file.openInputStream();
+ buffer1 = input.read(21);
+ Expect.equals(21, buffer1.length);
+ bytesRead = input.readInto(buffer1, 0, 21);
+ Expect.equals(21, bytesRead);
+ Expect.isTrue(input.closed);
+
+ // Test reading all using read.
+ file = new File(inFilename);
+ input = file.openInputStream();
+ buffer1 = input.read();
+ Expect.equals(42, buffer1.length);
+ Expect.isTrue(input.closed);
+
// Write the contents of the file just read into another file.
String outFilename = tempDirectory.path + "/out_read_write_stream";
file = new File(outFilename);
@@ -71,6 +101,7 @@ class FileTest {
bool writeDone = output.writeFrom(buffer1, 0, 42);
Expect.equals(true, writeDone);
output.close();
+
// Now read the contents of the file just written.
List<int> buffer2 = new List<int>(42);
file = new File(outFilename);
@@ -490,8 +521,7 @@ class FileTest {
file.createSync();
InputStream input = file.openInputStream();
Expect.isTrue(input.closed);
- Expect.throws(( ) => input.readInto(buffer, 0, 12),
- (e) => e is FileIOException);
+ Expect.isNull(input.readInto(buffer, 0, 12));
OutputStream output = file.openOutputStream();
output.close();
Expect.throws(( ) => output.writeFrom(buffer, 0, 12),
« 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