| OLD | NEW |
| 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 // | 4 // |
| 5 // Dart test program for testing file I/O. | 5 // Dart test program for testing file I/O. |
| 6 | 6 |
| 7 | 7 |
| 8 class FileTest { | 8 class FileTest { |
| 9 // Test for file read functionality. | 9 // Test for file read functionality. |
| 10 static int testReadStream() { | 10 static int testReadStream() { |
| 11 // Read a file and check part of it's contents. | 11 // Read a file and check part of it's contents. |
| 12 String filename = getFilename("bin/file_test.cc"); | 12 String filename = getFilename("bin/file_test.cc"); |
| 13 File file = new File(filename, false); | 13 File file = new File(filename); |
| 14 InputStream input = file.inputStream; | 14 FileInputStream input = file.openInputStream(); |
| 15 List<int> buffer = new List<int>(42); | 15 List<int> buffer = new List<int>(42); |
| 16 int bytesRead = input.readInto(buffer, 0, 12); | 16 int bytesRead = input.readInto(buffer, 0, 12); |
| 17 Expect.equals(12, bytesRead); | 17 Expect.equals(12, bytesRead); |
| 18 bytesRead = input.readInto(buffer, 12, 30); | 18 bytesRead = input.readInto(buffer, 12, 30); |
| 19 input.close(); |
| 19 Expect.equals(30, bytesRead); | 20 Expect.equals(30, bytesRead); |
| 20 Expect.equals(47, buffer[0]); // represents '/' in the file. | 21 Expect.equals(47, buffer[0]); // represents '/' in the file. |
| 21 Expect.equals(47, buffer[1]); // represents '/' in the file. | 22 Expect.equals(47, buffer[1]); // represents '/' in the file. |
| 22 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 23 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
| 23 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 24 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
| 24 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 25 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
| 25 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 26 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
| 26 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 27 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
| 27 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 28 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
| 28 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 29 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
| 29 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 30 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
| 30 Expect.equals(104, buffer[10]); // represents 'h' in the file. | 31 Expect.equals(104, buffer[10]); // represents 'h' in the file. |
| 31 Expect.equals(116, buffer[11]); // represents 't' in the file. | 32 Expect.equals(116, buffer[11]); // represents 't' in the file. |
| 32 return 1; | 33 return 1; |
| 33 } | 34 } |
| 35 |
| 34 // Test for file read and write functionality. | 36 // Test for file read and write functionality. |
| 35 static int testReadWriteStream() { | 37 static int testReadWriteStream() { |
| 36 // Read a file. | 38 // Read a file. |
| 37 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 39 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
| 38 File file = new File(inFilename, false); | 40 File file = new File(inFilename); |
| 39 InputStream input = file.inputStream; | 41 FileInputStream input = file.openInputStream(); |
| 40 List<int> buffer1 = new List<int>(42); | 42 List<int> buffer1 = new List<int>(42); |
| 41 int bytesRead = input.readInto(buffer1, 0, 42); | 43 int bytesRead = input.readInto(buffer1, 0, 42); |
| 42 Expect.equals(42, bytesRead); | 44 Expect.equals(42, bytesRead); |
| 43 file.close(); | 45 input.close(); |
| 44 // Write the contents of the file just read into another file. | 46 // Write the contents of the file just read into another file. |
| 45 String outFilename = getFilename("tests/vm/data/fixed_length_file_out"); | 47 String outFilename = getFilename("tests/vm/data/fixed_length_file_out"); |
| 46 file = new File(outFilename, true); | 48 file = new File(outFilename); |
| 47 OutputStream output = file.outputStream; | 49 OutputStream output = file.openOutputStream(); |
| 48 bool writeDone = output.write(buffer1, 0, 42, null); | 50 bool writeDone = output.write(buffer1, 0, 42, null); |
| 49 Expect.equals(true, writeDone); | 51 Expect.equals(true, writeDone); |
| 50 file.close(); | 52 output.close(); |
| 51 // Now read the contents of the file just written. | 53 // Now read the contents of the file just written. |
| 52 List<int> buffer2 = new List<int>(42); | 54 List<int> buffer2 = new List<int>(42); |
| 53 file = new File(outFilename, false); | 55 file = new File(outFilename); |
| 54 input = file.inputStream; | 56 input = file.openInputStream(); |
| 55 bytesRead = input.readInto(buffer2, 0, 42); | 57 bytesRead = input.readInto(buffer2, 0, 42); |
| 58 input.close(); |
| 56 Expect.equals(42, bytesRead); | 59 Expect.equals(42, bytesRead); |
| 57 file.close(); | |
| 58 // Now compare the two buffers to check if they are identical. | 60 // Now compare the two buffers to check if they are identical. |
| 59 for (int i = 0; i < buffer1.length; i++) { | 61 for (int i = 0; i < buffer1.length; i++) { |
| 60 Expect.equals(buffer1[i], buffer2[i]); | 62 Expect.equals(buffer1[i], buffer2[i]); |
| 61 } | 63 } |
| 62 return 1; | 64 return 1; |
| 63 } | 65 } |
| 66 |
| 64 static int testRead() { | 67 static int testRead() { |
| 65 // Read a file and check part of it's contents. | 68 // Read a file and check part of it's contents. |
| 66 String filename = getFilename("bin/file_test.cc"); | 69 String filename = getFilename("bin/file_test.cc"); |
| 67 File file = new File(filename, false); | 70 File file = new File(filename); |
| 68 assert(file != null); | 71 file.openSync(); |
| 69 List<int> buffer = new List<int>(42); | 72 List<int> buffer = new List<int>(42); |
| 70 int bytes_read = 0; | 73 int bytes_read = 0; |
| 71 bytes_read = file.readList(buffer, 0, 12); | 74 bytes_read = file.readListSync(buffer, 0, 12); |
| 72 Expect.equals(12, bytes_read); | 75 Expect.equals(12, bytes_read); |
| 73 bytes_read = file.readList(buffer, 12, 30); | 76 bytes_read = file.readListSync(buffer, 12, 30); |
| 74 Expect.equals(30, bytes_read); | 77 Expect.equals(30, bytes_read); |
| 75 Expect.equals(47, buffer[0]); // represents '/' in the file. | 78 Expect.equals(47, buffer[0]); // represents '/' in the file. |
| 76 Expect.equals(47, buffer[1]); // represents '/' in the file. | 79 Expect.equals(47, buffer[1]); // represents '/' in the file. |
| 77 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 80 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
| 78 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 81 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
| 79 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 82 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
| 80 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 83 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
| 81 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 84 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
| 82 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 85 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
| 83 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 86 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
| 84 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 87 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
| 85 Expect.equals(104, buffer[10]); // represents 'h' in the file. | 88 Expect.equals(104, buffer[10]); // represents 'h' in the file. |
| 86 Expect.equals(116, buffer[11]); // represents 't' in the file. | 89 Expect.equals(116, buffer[11]); // represents 't' in the file. |
| 87 return 1; | 90 return 1; |
| 88 } | 91 } |
| 92 |
| 89 // Test for file read and write functionality. | 93 // Test for file read and write functionality. |
| 90 static int testReadWrite() { | 94 static int testReadWrite() { |
| 91 // Read a file. | 95 // Read a file. |
| 92 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 96 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
| 93 File file = new File(inFilename, false); | 97 File file = new File(inFilename); |
| 98 file.openSync(); |
| 94 List<int> buffer1 = new List<int>(42); | 99 List<int> buffer1 = new List<int>(42); |
| 95 int bytes_read = 0; | 100 int bytes_read = 0; |
| 96 int bytes_written = 0; | 101 int bytes_written = 0; |
| 97 bytes_read = file.readList(buffer1, 0, 42); | 102 bytes_read = file.readListSync(buffer1, 0, 42); |
| 98 Expect.equals(42, bytes_read); | 103 Expect.equals(42, bytes_read); |
| 99 file.close(); | 104 file.closeSync(); |
| 100 // Write the contents of the file just read into another file. | 105 // Write the contents of the file just read into another file. |
| 101 String outFilenameBase = "tests/vm/data/fixed_length_file_out"; | 106 String outFilenameBase = getFilename("tests/vm/data/fixed_length_file_out"); |
| 102 file = createFile(outFilenameBase); | 107 file = new File(outFilenameBase); |
| 103 Expect.isNotNull(file); | 108 file.openSync(true); |
| 104 file.writeList(buffer1, 0, bytes_read); | 109 file.writeListSync(buffer1, 0, bytes_read); |
| 105 file.close(); | 110 file.closeSync(); |
| 106 // Now read the contents of the file just written. | 111 // Now read the contents of the file just written. |
| 107 List<int> buffer2 = new List<int>(bytes_read); | 112 List<int> buffer2 = new List<int>(bytes_read); |
| 108 file = new File(getFilename(outFilenameBase), false); | 113 file = new File(getFilename(outFilenameBase)); |
| 109 assert(file != null); | 114 file.openSync(); |
| 110 bytes_read = file.readList(buffer2, 0, 42); | 115 bytes_read = file.readListSync(buffer2, 0, 42); |
| 111 Expect.equals(42, bytes_read); | 116 Expect.equals(42, bytes_read); |
| 112 file.close(); | 117 file.closeSync(); |
| 113 // Now compare the two buffers to check if they are identical. | 118 // Now compare the two buffers to check if they are identical. |
| 114 Expect.equals(buffer1.length, buffer2.length); | 119 Expect.equals(buffer1.length, buffer2.length); |
| 115 for (int i = 0; i < buffer1.length; i++) { | 120 for (int i = 0; i < buffer1.length; i++) { |
| 116 Expect.equals(buffer1[i], buffer2[i]); | 121 Expect.equals(buffer1[i], buffer2[i]); |
| 117 } | 122 } |
| 118 return 1; | 123 return 1; |
| 119 } | 124 } |
| 120 | 125 |
| 121 // Test for file length functionality. | 126 // Test for file length functionality. |
| 122 static int testLength() { | 127 static int testLength() { |
| 123 String filename = getFilename("tests/vm/data/fixed_length_file"); | 128 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 124 File input = new File(filename, false); | 129 File input = new File(filename); |
| 125 assert(input != null); | 130 input.openSync(); |
| 126 Expect.equals(42, input.length); | 131 Expect.equals(42, input.lengthSync()); |
| 132 input.closeSync(); |
| 127 return 1; | 133 return 1; |
| 128 } | 134 } |
| 135 |
| 129 // Test for file position functionality. | 136 // Test for file position functionality. |
| 130 static int testPosition() { | 137 static int testPosition() { |
| 131 String filename = getFilename("tests/vm/data/fixed_length_file"); | 138 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 132 File input = new File(filename, false); | 139 File input = new File(filename); |
| 133 assert(input != null); | 140 input.openSync(); |
| 134 Expect.equals(0, input.position); | 141 Expect.equals(0, input.positionSync()); |
| 135 List<int> buffer = new List<int>(100); | 142 List<int> buffer = new List<int>(100); |
| 136 input.readList(buffer, 0, 12); | 143 input.readListSync(buffer, 0, 12); |
| 137 Expect.equals(12, input.position); | 144 Expect.equals(12, input.positionSync()); |
| 138 input.readList(buffer, 12, 6); | 145 input.readListSync(buffer, 12, 6); |
| 139 Expect.equals(18, input.position); | 146 Expect.equals(18, input.positionSync()); |
| 147 input.closeSync(); |
| 140 return 1; | 148 return 1; |
| 141 } | 149 } |
| 150 |
| 142 // Tests exception handling after file was closed. | 151 // Tests exception handling after file was closed. |
| 143 static int testCloseException() { | 152 static int testCloseException() { |
| 144 bool exceptionCaught = false; | 153 bool exceptionCaught = false; |
| 145 bool wrongExceptionCaught = false; | 154 bool wrongExceptionCaught = false; |
| 146 String filename = getFilename("tests/vm/data/fixed_length_file_out"); | 155 String filename = getFilename("tests/vm/data/fixed_length_file_out"); |
| 147 File input = new File(filename, true); | 156 File input = new File(filename); |
| 148 Expect.isNotNull(input); | 157 input.openSync(true); |
| 149 assert(input != null); | 158 input.closeSync(); |
| 150 input.close(); | |
| 151 try { | 159 try { |
| 152 input.readByte(); | 160 input.readByteSync(); |
| 153 } catch (FileIOException ex) { | 161 } catch (FileIOException ex) { |
| 154 exceptionCaught = true; | 162 exceptionCaught = true; |
| 155 } catch (Exception ex) { | 163 } catch (Exception ex) { |
| 156 wrongExceptionCaught = true; | 164 wrongExceptionCaught = true; |
| 157 } | 165 } |
| 158 Expect.equals(true, exceptionCaught); | 166 Expect.equals(true, exceptionCaught); |
| 159 Expect.equals(true, !wrongExceptionCaught); | 167 Expect.equals(true, !wrongExceptionCaught); |
| 160 exceptionCaught = false; | 168 exceptionCaught = false; |
| 161 try { | 169 try { |
| 162 input.writeByte(1); | 170 input.writeByteSync(1); |
| 163 } catch (FileIOException ex) { | 171 } catch (FileIOException ex) { |
| 164 exceptionCaught = true; | 172 exceptionCaught = true; |
| 165 } catch (Exception ex) { | 173 } catch (Exception ex) { |
| 166 wrongExceptionCaught = true; | 174 wrongExceptionCaught = true; |
| 167 } | 175 } |
| 168 Expect.equals(true, exceptionCaught); | 176 Expect.equals(true, exceptionCaught); |
| 169 Expect.equals(true, !wrongExceptionCaught); | 177 Expect.equals(true, !wrongExceptionCaught); |
| 170 exceptionCaught = false; | 178 exceptionCaught = false; |
| 171 try { | 179 try { |
| 172 input.writeString("Test"); | 180 input.writeStringSync("Test"); |
| 173 } catch (FileIOException ex) { | 181 } catch (FileIOException ex) { |
| 174 exceptionCaught = true; | 182 exceptionCaught = true; |
| 175 } catch (Exception ex) { | 183 } catch (Exception ex) { |
| 176 wrongExceptionCaught = true; | 184 wrongExceptionCaught = true; |
| 177 } | 185 } |
| 178 Expect.equals(true, exceptionCaught); | 186 Expect.equals(true, exceptionCaught); |
| 179 Expect.equals(true, !wrongExceptionCaught); | 187 Expect.equals(true, !wrongExceptionCaught); |
| 180 exceptionCaught = false; | 188 exceptionCaught = false; |
| 181 try { | 189 try { |
| 182 List<int> buffer = new List<int>(100); | 190 List<int> buffer = new List<int>(100); |
| 183 input.readList(buffer, 0, 10); | 191 input.readListSync(buffer, 0, 10); |
| 184 } catch (FileIOException ex) { | 192 } catch (FileIOException ex) { |
| 185 exceptionCaught = true; | 193 exceptionCaught = true; |
| 186 } catch (Exception ex) { | 194 } catch (Exception ex) { |
| 187 wrongExceptionCaught = true; | 195 wrongExceptionCaught = true; |
| 188 } | 196 } |
| 189 Expect.equals(true, exceptionCaught); | 197 Expect.equals(true, exceptionCaught); |
| 190 Expect.equals(true, !wrongExceptionCaught); | 198 Expect.equals(true, !wrongExceptionCaught); |
| 191 exceptionCaught = false; | 199 exceptionCaught = false; |
| 192 try { | 200 try { |
| 193 List<int> buffer = new List<int>(100); | 201 List<int> buffer = new List<int>(100); |
| 194 input.writeList(buffer, 0, 10); | 202 input.writeListSync(buffer, 0, 10); |
| 195 } catch (FileIOException ex) { | 203 } catch (FileIOException ex) { |
| 196 exceptionCaught = true; | 204 exceptionCaught = true; |
| 197 } catch (Exception ex) { | 205 } catch (Exception ex) { |
| 198 wrongExceptionCaught = true; | 206 wrongExceptionCaught = true; |
| 199 } | 207 } |
| 200 Expect.equals(true, exceptionCaught); | 208 Expect.equals(true, exceptionCaught); |
| 201 Expect.equals(true, !wrongExceptionCaught); | 209 Expect.equals(true, !wrongExceptionCaught); |
| 202 exceptionCaught = false; | 210 exceptionCaught = false; |
| 203 try { | 211 try { |
| 204 input.position; | 212 input.positionSync(); |
| 205 } catch (FileIOException ex) { | 213 } catch (FileIOException ex) { |
| 206 exceptionCaught = true; | 214 exceptionCaught = true; |
| 207 } catch (Exception ex) { | 215 } catch (Exception ex) { |
| 208 wrongExceptionCaught = true; | 216 wrongExceptionCaught = true; |
| 209 } | 217 } |
| 210 Expect.equals(true, exceptionCaught); | 218 Expect.equals(true, exceptionCaught); |
| 211 Expect.equals(true, !wrongExceptionCaught); | 219 Expect.equals(true, !wrongExceptionCaught); |
| 212 exceptionCaught = false; | 220 exceptionCaught = false; |
| 213 try { | 221 try { |
| 214 input.length; | 222 input.lengthSync(); |
| 215 } catch (FileIOException ex) { | 223 } catch (FileIOException ex) { |
| 216 exceptionCaught = true; | 224 exceptionCaught = true; |
| 217 } catch (Exception ex) { | 225 } catch (Exception ex) { |
| 218 wrongExceptionCaught = true; | 226 wrongExceptionCaught = true; |
| 219 } | 227 } |
| 220 Expect.equals(true, exceptionCaught); | 228 Expect.equals(true, exceptionCaught); |
| 221 Expect.equals(true, !wrongExceptionCaught); | 229 Expect.equals(true, !wrongExceptionCaught); |
| 222 exceptionCaught = false; | 230 exceptionCaught = false; |
| 223 try { | 231 try { |
| 224 input.flush(); | 232 input.flushSync(); |
| 225 } catch (FileIOException ex) { | 233 } catch (FileIOException ex) { |
| 226 exceptionCaught = true; | 234 exceptionCaught = true; |
| 227 } catch (Exception ex) { | 235 } catch (Exception ex) { |
| 228 wrongExceptionCaught = true; | 236 wrongExceptionCaught = true; |
| 229 } | 237 } |
| 230 Expect.equals(true, exceptionCaught); | 238 Expect.equals(true, exceptionCaught); |
| 231 Expect.equals(true, !wrongExceptionCaught); | 239 Expect.equals(true, !wrongExceptionCaught); |
| 232 return 1; | 240 return 1; |
| 233 } | 241 } |
| 242 |
| 234 // Tests stream exception handling after file was closed. | 243 // Tests stream exception handling after file was closed. |
| 235 static int testCloseExceptionStream() { | 244 static int testCloseExceptionStream() { |
| 236 bool exceptionCaught = false; | 245 bool exceptionCaught = false; |
| 237 bool wrongExceptionCaught = false; | 246 bool wrongExceptionCaught = false; |
| 238 String filename = getFilename("tests/vm/data/fixed_length_file_out"); | 247 String filename = getFilename("tests/vm/data/fixed_length_file_out"); |
| 239 File file = new File(filename, true); | 248 File file = new File(filename); |
| 240 assert(file != null); | 249 FileInputStream input = file.openInputStream(); |
| 241 file.close(); | 250 input.close(); |
| 242 InputStream input = file.inputStream; | |
| 243 try { | 251 try { |
| 244 List<int> buffer = new List<int>(42); | 252 List<int> buffer = new List<int>(42); |
| 245 input.readInto(buffer, 0, 12); | 253 input.readInto(buffer, 0, 12); |
| 246 } catch (FileIOException ex) { | 254 } catch (FileIOException ex) { |
| 247 exceptionCaught = true; | 255 exceptionCaught = true; |
| 248 } catch (Exception ex) { | 256 } catch (Exception ex) { |
| 249 wrongExceptionCaught = true; | 257 wrongExceptionCaught = true; |
| 250 } | 258 } |
| 251 Expect.equals(true, exceptionCaught); | 259 Expect.equals(true, exceptionCaught); |
| 252 Expect.equals(true, !wrongExceptionCaught); | 260 Expect.equals(true, !wrongExceptionCaught); |
| 253 exceptionCaught = false; | 261 exceptionCaught = false; |
| 254 OutputStream output = file.outputStream; | 262 FileOutputStream output = file.openOutputStream(); |
| 263 output.close(); |
| 255 try { | 264 try { |
| 256 List<int> buffer = new List<int>(42); | 265 List<int> buffer = new List<int>(42); |
| 257 bool readDone = output.write(buffer, 0, 12, null); | 266 bool readDone = output.write(buffer, 0, 12, null); |
| 258 } catch (FileIOException ex) { | 267 } catch (FileIOException ex) { |
| 259 exceptionCaught = true; | 268 exceptionCaught = true; |
| 260 } catch (Exception ex) { | 269 } catch (Exception ex) { |
| 261 wrongExceptionCaught = true; | 270 wrongExceptionCaught = true; |
| 262 } | 271 } |
| 263 Expect.equals(true, exceptionCaught); | 272 Expect.equals(true, exceptionCaught); |
| 264 Expect.equals(true, !wrongExceptionCaught); | 273 Expect.equals(true, !wrongExceptionCaught); |
| 265 return 1; | 274 return 1; |
| 266 } | 275 } |
| 276 |
| 267 // Tests buffer out of bounds exception. | 277 // Tests buffer out of bounds exception. |
| 268 static int testBufferOutOfBoundsException() { | 278 static int testBufferOutOfBoundsException() { |
| 269 bool exceptionCaught = false; | 279 bool exceptionCaught = false; |
| 270 bool wrongExceptionCaught = false; | 280 bool wrongExceptionCaught = false; |
| 271 String filename = getFilename("tests/vm/data/fixed_length_file_out"); | 281 String filename = getFilename("tests/vm/data/fixed_length_file_out"); |
| 272 File file = new File(filename, true); | 282 File file = new File(filename); |
| 273 assert(file != null); | 283 file.openSync(true); |
| 274 try { | 284 try { |
| 275 List<int> buffer = new List<int>(10); | 285 List<int> buffer = new List<int>(10); |
| 276 bool readDone = file.readList(buffer, 0, 12); | 286 bool readDone = file.readListSync(buffer, 0, 12); |
| 277 } catch (IndexOutOfRangeException ex) { | 287 } catch (IndexOutOfRangeException ex) { |
| 278 exceptionCaught = true; | 288 exceptionCaught = true; |
| 279 } catch (Exception ex) { | 289 } catch (Exception ex) { |
| 280 wrongExceptionCaught = true; | 290 wrongExceptionCaught = true; |
| 281 } | 291 } |
| 282 Expect.equals(true, exceptionCaught); | 292 Expect.equals(true, exceptionCaught); |
| 283 Expect.equals(true, !wrongExceptionCaught); | 293 Expect.equals(true, !wrongExceptionCaught); |
| 284 exceptionCaught = false; | 294 exceptionCaught = false; |
| 285 try { | 295 try { |
| 286 List<int> buffer = new List<int>(10); | 296 List<int> buffer = new List<int>(10); |
| 287 bool readDone = file.readList(buffer, 6, 6); | 297 bool readDone = file.readListSync(buffer, 6, 6); |
| 288 } catch (IndexOutOfRangeException ex) { | 298 } catch (IndexOutOfRangeException ex) { |
| 289 exceptionCaught = true; | 299 exceptionCaught = true; |
| 290 } catch (Exception ex) { | 300 } catch (Exception ex) { |
| 291 wrongExceptionCaught = true; | 301 wrongExceptionCaught = true; |
| 292 } | 302 } |
| 293 Expect.equals(true, exceptionCaught); | 303 Expect.equals(true, exceptionCaught); |
| 294 Expect.equals(true, !wrongExceptionCaught); | 304 Expect.equals(true, !wrongExceptionCaught); |
| 295 exceptionCaught = false; | 305 exceptionCaught = false; |
| 296 try { | 306 try { |
| 297 List<int> buffer = new List<int>(10); | 307 List<int> buffer = new List<int>(10); |
| 298 bool readDone = file.readList(buffer, -1, 1); | 308 bool readDone = file.readListSync(buffer, -1, 1); |
| 299 } catch (IndexOutOfRangeException ex) { | 309 } catch (IndexOutOfRangeException ex) { |
| 300 exceptionCaught = true; | 310 exceptionCaught = true; |
| 301 } catch (Exception ex) { | 311 } catch (Exception ex) { |
| 302 wrongExceptionCaught = true; | 312 wrongExceptionCaught = true; |
| 303 } | 313 } |
| 304 Expect.equals(true, exceptionCaught); | 314 Expect.equals(true, exceptionCaught); |
| 305 Expect.equals(true, !wrongExceptionCaught); | 315 Expect.equals(true, !wrongExceptionCaught); |
| 306 exceptionCaught = false; | 316 exceptionCaught = false; |
| 307 try { | 317 try { |
| 308 List<int> buffer = new List<int>(10); | 318 List<int> buffer = new List<int>(10); |
| 309 bool readDone = file.readList(buffer, 0, -1); | 319 bool readDone = file.readListSync(buffer, 0, -1); |
| 310 } catch (IndexOutOfRangeException ex) { | 320 } catch (IndexOutOfRangeException ex) { |
| 311 exceptionCaught = true; | 321 exceptionCaught = true; |
| 312 } catch (Exception ex) { | 322 } catch (Exception ex) { |
| 313 wrongExceptionCaught = true; | 323 wrongExceptionCaught = true; |
| 314 } | 324 } |
| 315 Expect.equals(true, exceptionCaught); | 325 Expect.equals(true, exceptionCaught); |
| 316 Expect.equals(true, !wrongExceptionCaught); | 326 Expect.equals(true, !wrongExceptionCaught); |
| 317 exceptionCaught = false; | 327 exceptionCaught = false; |
| 318 try { | 328 try { |
| 319 List<int> buffer = new List<int>(10); | 329 List<int> buffer = new List<int>(10); |
| 320 bool readDone = file.writeList(buffer, 0, 12); | 330 bool readDone = file.writeListSync(buffer, 0, 12); |
| 321 } catch (IndexOutOfRangeException ex) { | 331 } catch (IndexOutOfRangeException ex) { |
| 322 exceptionCaught = true; | 332 exceptionCaught = true; |
| 323 } catch (Exception ex) { | 333 } catch (Exception ex) { |
| 324 wrongExceptionCaught = true; | 334 wrongExceptionCaught = true; |
| 325 } | 335 } |
| 326 Expect.equals(true, exceptionCaught); | 336 Expect.equals(true, exceptionCaught); |
| 327 Expect.equals(true, !wrongExceptionCaught); | 337 Expect.equals(true, !wrongExceptionCaught); |
| 328 exceptionCaught = false; | 338 exceptionCaught = false; |
| 329 try { | 339 try { |
| 330 List<int> buffer = new List<int>(10); | 340 List<int> buffer = new List<int>(10); |
| 331 bool readDone = file.writeList(buffer, 6, 6); | 341 bool readDone = file.writeListSync(buffer, 6, 6); |
| 332 } catch (IndexOutOfRangeException ex) { | 342 } catch (IndexOutOfRangeException ex) { |
| 333 exceptionCaught = true; | 343 exceptionCaught = true; |
| 334 } catch (Exception ex) { | 344 } catch (Exception ex) { |
| 335 wrongExceptionCaught = true; | 345 wrongExceptionCaught = true; |
| 336 } | 346 } |
| 337 Expect.equals(true, exceptionCaught); | 347 Expect.equals(true, exceptionCaught); |
| 338 Expect.equals(true, !wrongExceptionCaught); | 348 Expect.equals(true, !wrongExceptionCaught); |
| 339 exceptionCaught = false; | 349 exceptionCaught = false; |
| 340 try { | 350 try { |
| 341 List<int> buffer = new List<int>(10); | 351 List<int> buffer = new List<int>(10); |
| 342 bool readDone = file.writeList(buffer, -1, 1); | 352 bool readDone = file.writeListSync(buffer, -1, 1); |
| 343 } catch (IndexOutOfRangeException ex) { | 353 } catch (IndexOutOfRangeException ex) { |
| 344 exceptionCaught = true; | 354 exceptionCaught = true; |
| 345 } catch (Exception ex) { | 355 } catch (Exception ex) { |
| 346 wrongExceptionCaught = true; | 356 wrongExceptionCaught = true; |
| 347 } | 357 } |
| 348 Expect.equals(true, exceptionCaught); | 358 Expect.equals(true, exceptionCaught); |
| 349 Expect.equals(true, !wrongExceptionCaught); | 359 Expect.equals(true, !wrongExceptionCaught); |
| 350 exceptionCaught = false; | 360 exceptionCaught = false; |
| 351 try { | 361 try { |
| 352 List<int> buffer = new List<int>(10); | 362 List<int> buffer = new List<int>(10); |
| 353 bool readDone = file.writeList(buffer, 0, -1); | 363 bool readDone = file.writeListSync(buffer, 0, -1); |
| 354 } catch (IndexOutOfRangeException ex) { | 364 } catch (IndexOutOfRangeException ex) { |
| 355 exceptionCaught = true; | 365 exceptionCaught = true; |
| 356 } catch (Exception ex) { | 366 } catch (Exception ex) { |
| 357 wrongExceptionCaught = true; | 367 wrongExceptionCaught = true; |
| 358 } | 368 } |
| 359 Expect.equals(true, exceptionCaught); | 369 Expect.equals(true, exceptionCaught); |
| 360 Expect.equals(true, !wrongExceptionCaught); | 370 Expect.equals(true, !wrongExceptionCaught); |
| 361 | 371 file.closeSync(); |
| 362 return 1; | 372 return 1; |
| 363 } | 373 } |
| 364 | 374 |
| 365 // Helper method to be able to run the test from the runtime | 375 // Helper method to be able to run the test from the runtime |
| 366 // directory, or the top directory. | 376 // directory, or the top directory. |
| 367 static String getFilename(String path) => | 377 static String getFilename(String path) => |
| 368 FileUtil.fileExists(path) ? path : 'runtime/' + path; | 378 new File(path).existsSync() ? path : 'runtime/' + path; |
| 369 | |
| 370 static File createFile(String path) { | |
| 371 File file = new File(path, true); | |
| 372 if (file === null) { | |
| 373 file = new File('runtime/' + path, true); | |
| 374 } | |
| 375 return file; | |
| 376 } | |
| 377 | 379 |
| 378 // Main test entrypoint. | 380 // Main test entrypoint. |
| 379 static testMain() { | 381 static testMain() { |
| 380 Expect.equals(1, testRead()); | 382 Expect.equals(1, testRead()); |
| 381 Expect.equals(1, testReadWrite()); | 383 Expect.equals(1, testReadWrite()); |
| 382 Expect.equals(1, testReadStream()); | 384 Expect.equals(1, testReadStream()); |
| 383 Expect.equals(1, testReadWriteStream()); | 385 Expect.equals(1, testReadWriteStream()); |
| 384 Expect.equals(1, testLength()); | 386 Expect.equals(1, testLength()); |
| 385 Expect.equals(1, testPosition()); | 387 Expect.equals(1, testPosition()); |
| 386 Expect.equals(1, testCloseException()); | 388 Expect.equals(1, testCloseException()); |
| 387 Expect.equals(1, testCloseExceptionStream()); | 389 Expect.equals(1, testCloseExceptionStream()); |
| 388 Expect.equals(1, testBufferOutOfBoundsException()); | 390 Expect.equals(1, testBufferOutOfBoundsException()); |
| 389 } | 391 } |
| 390 } | 392 } |
| 391 | 393 |
| 392 main() { | 394 main() { |
| 393 FileTest.testMain(); | 395 FileTest.testMain(); |
| 394 } | 396 } |
| OLD | NEW |