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

Side by Side Diff: tests/standalone/io/file_test.dart

Issue 10542102: Add buffering to _FileInputStream implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase to current bleeding-edge Created 8 years, 6 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
« no previous file with comments | « tests/standalone/io/file_input_stream_test.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) 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 // 4 //
5 // Dart test program for testing file I/O. 5 // Dart test program for testing file I/O.
6 6
7 #import("dart:io"); 7 #import("dart:io");
8 #import("dart:isolate"); 8 #import("dart:isolate");
9 9
10 class MyListOfOneElement implements List { 10 class MyListOfOneElement implements List {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 static void testReadWriteStream() { 71 static void testReadWriteStream() {
72 asyncTestStarted(); 72 asyncTestStarted();
73 73
74 // Read a file. 74 // Read a file.
75 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 75 String inFilename = getFilename("tests/vm/data/fixed_length_file");
76 File file; 76 File file;
77 InputStream input; 77 InputStream input;
78 int bytesRead; 78 int bytesRead;
79 79
80 // Test reading all using readInto. 80 // Test reading all using readInto.
81 file = new File(inFilename); 81 var file1 = new File(inFilename);
82 input = file.openInputStream(); 82 var input1 = file1.openInputStream();
83 input.onData = () { 83 List<int> buffer1;
84 List<int> buffer1 = new List<int>(42); 84 input1.onData = () {
85 bytesRead = input.readInto(buffer1, 0, 42); 85 buffer1 = new List<int>(42);
86 bytesRead = input1.readInto(buffer1, 0, 42);
86 Expect.equals(42, bytesRead); 87 Expect.equals(42, bytesRead);
87 Expect.isTrue(input.closed); 88 };
89 input1.onError = (e) { throw e; };
90 input1.onClosed = () {
91 Expect.isTrue(input1.closed);
88 92
89 // Test reading all using readInto and read. 93 // Test reading all using readInto and read.
90 file = new File(inFilename); 94 var file2 = new File(inFilename);
91 input = file.openInputStream(); 95 var input2 = file2.openInputStream();
92 input.onData = () { 96 input2.onData = () {
93 bytesRead = input.readInto(buffer1, 0, 21); 97 bytesRead = input2.readInto(buffer1, 0, 21);
94 Expect.equals(21, bytesRead); 98 Expect.equals(21, bytesRead);
95 buffer1 = input.read(); 99 buffer1 = input2.read();
96 Expect.equals(21, buffer1.length); 100 Expect.equals(21, buffer1.length);
97 Expect.isTrue(input.closed); 101 };
102 input2.onError = (e) { throw e; };
103 input2.onClosed = () {
104 Expect.isTrue(input2.closed);
98 105
99 // Test reading all using read and readInto. 106 // Test reading all using read and readInto.
100 file = new File(inFilename); 107 var file3 = new File(inFilename);
101 input = file.openInputStream(); 108 var input3 = file3.openInputStream();
102 input.onData = () { 109 input3.onData = () {
103 buffer1 = input.read(21); 110 buffer1 = input3.read(21);
104 Expect.equals(21, buffer1.length); 111 Expect.equals(21, buffer1.length);
105 bytesRead = input.readInto(buffer1, 0, 21); 112 bytesRead = input3.readInto(buffer1, 0, 21);
106 Expect.equals(21, bytesRead); 113 Expect.equals(21, bytesRead);
107 Expect.isTrue(input.closed); 114 };
115 input3.onError = (e) { throw e; };
116 input3.onClosed = () {
117 Expect.isTrue(input3.closed);
108 118
109 // Test reading all using read. 119 // Test reading all using read.
110 file = new File(inFilename); 120 var file4 = new File(inFilename);
111 input = file.openInputStream(); 121 var input4 = file4.openInputStream();
112 input.onData = () { 122 input4.onData = () {
113 buffer1 = input.read(); 123 buffer1 = input4.read();
114 Expect.equals(42, buffer1.length); 124 Expect.equals(42, buffer1.length);
115 Expect.isTrue(input.closed); 125 };
126 input4.onError = (e) { throw e; };
127 input4.onClosed = () {
128 Expect.isTrue(input4.closed);
116 129
117 // Write the contents of the file just read into another file. 130 // Write the contents of the file just read into another file.
118 String outFilename = 131 String outFilename =
119 tempDirectory.path.concat("/out_read_write_stream"); 132 tempDirectory.path.concat("/out_read_write_stream");
120 file = new File(outFilename); 133 file = new File(outFilename);
121 OutputStream output = file.openOutputStream(); 134 OutputStream output = file.openOutputStream();
122 bool writeDone = output.writeFrom(buffer1, 0, 42); 135 bool writeDone = output.writeFrom(buffer1, 0, 42);
123 Expect.equals(false, writeDone); 136 Expect.equals(false, writeDone);
124 output.onNoPendingWrites = () { 137 output.onNoPendingWrites = () {
125 output.close(); 138 output.close();
126 output.onClosed = () { 139 output.onClosed = () {
127 // Now read the contents of the file just written. 140 // Now read the contents of the file just written.
128 List<int> buffer2 = new List<int>(42); 141 List<int> buffer2 = new List<int>(42);
129 file = new File(outFilename); 142 var file6 = new File(outFilename);
130 input = file.openInputStream(); 143 var input6 = file6.openInputStream();
131 input.onData = () { 144 input6.onData = () {
132 bytesRead = input.readInto(buffer2, 0, 42); 145 bytesRead = input6.readInto(buffer2, 0, 42);
133 Expect.equals(42, bytesRead); 146 Expect.equals(42, bytesRead);
134 // Now compare the two buffers to check if they are identical. 147 // Now compare the two buffers to check if they are identical.
135 for (int i = 0; i < buffer1.length; i++) { 148 for (int i = 0; i < buffer1.length; i++) {
136 Expect.equals(buffer1[i], buffer2[i]); 149 Expect.equals(buffer1[i], buffer2[i]);
137 } 150 }
138 }; 151 };
139 input.onClosed = () { 152 input6.onError = (e) { throw e; };
153 input6.onClosed = () {
140 // Delete the output file. 154 // Delete the output file.
141 file.deleteSync(); 155 file6.deleteSync();
142 Expect.isFalse(file.existsSync()); 156 Expect.isFalse(file6.existsSync());
143 asyncTestDone("testReadWriteStream"); 157 asyncTestDone("testReadWriteStream");
144 }; 158 };
145 }; 159 };
146 }; 160 };
147 }; 161 };
148 }; 162 };
149 }; 163 };
150 }; 164 };
151 } 165 }
152 166
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 testWriteVariousLists(); 1095 testWriteVariousLists();
1082 testDirectory(); 1096 testDirectory();
1083 testDirectorySync(); 1097 testDirectorySync();
1084 }); 1098 });
1085 } 1099 }
1086 } 1100 }
1087 1101
1088 main() { 1102 main() {
1089 FileTest.testMain(); 1103 FileTest.testMain();
1090 } 1104 }
OLDNEW
« no previous file with comments | « tests/standalone/io/file_input_stream_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698