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

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

Issue 17033003: dart:io | Add File.rename (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes Created 7 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 | « sdk/lib/io/file_impl.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:collection'; 9 import 'dart:collection';
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 openedFile.setPositionSync(2); 1211 openedFile.setPositionSync(2);
1212 openedFile.writeStringSync(string); 1212 openedFile.writeStringSync(string);
1213 Expect.equals(4, openedFile.lengthSync()); 1213 Expect.equals(4, openedFile.lengthSync());
1214 openedFile.closeSync(); 1214 openedFile.closeSync();
1215 var readBack = file.readAsStringSync(); 1215 var readBack = file.readAsStringSync();
1216 Expect.stringEquals(readBack, '$string$string'); 1216 Expect.stringEquals(readBack, '$string$string');
1217 file.deleteSync(); 1217 file.deleteSync();
1218 Expect.isFalse(file.existsSync()); 1218 Expect.isFalse(file.existsSync());
1219 } 1219 }
1220 1220
1221 // Test that opens the same file for writing then for appending to test
1222 // that the file is not truncated when opened for appending.
1223 static void testRename() {
1224 var file = new File('${tempDirectory.path}/rename_name');
1225 file.create().then((file) {
1226 file.rename("${tempDirectory.path}/rename_newname").then((newfile) {
1227 file.exists().then((e) {
1228 Expect.isFalse(e);
1229 newfile.exists().then((e) {
1230 Expect.isTrue(e);
1231 newfile.delete().then((_) {
1232 file.exists().then((e) {
1233 Expect.isFalse(e);
1234 if (Platform.operatingSystem != "windows") {
1235 var brokenLink =
1236 new Link('${tempDirectory.path}/rename_name');
1237 brokenLink.create(
1238 '${tempDirectory.path}/rename_newname').then((_) {
1239 file.rename("xxx").then((_) {
1240 throw "Rename of broken link succeeded";
1241 }).catchError((e) {
1242 Expect.isTrue(e is FileException);
1243 asyncTestDone("testRename");
1244 });
1245 });
1246
1247 } else {
1248 asyncTestDone("testRename");
1249 }
1250 });
1251 });
1252 });
1253 });
1254 });
1255 });
1256 asyncTestStarted();
1257 }
1258
1259 static void testRenameSync() {
1260 var file = new File('${tempDirectory.path}/rename_name_sync');
1261 file.createSync();
1262 var newfile = file.renameSync('${tempDirectory.path}/rename_newname_sync');
1263 Expect.isFalse(file.existsSync());
1264 Expect.isTrue(newfile.existsSync());
1265 newfile.deleteSync();
1266 Expect.isFalse(newfile.existsSync());
1267 if (Platform.operatingSystem != "windows") {
1268 var brokenLink = new Link('${tempDirectory.path}/rename_name_sync');
1269 brokenLink.createSync('${tempDirectory.path}/rename_newname_sync');
1270 Expect.throws(() => file.renameSync('xxx'));
1271 }
1272 }
1273
1221 // Helper method to be able to run the test from the runtime 1274 // Helper method to be able to run the test from the runtime
1222 // directory, or the top directory. 1275 // directory, or the top directory.
1223 static String getFilename(String path) => 1276 static String getFilename(String path) =>
1224 new File(path).existsSync() ? path : 'runtime/$path'; 1277 new File(path).existsSync() ? path : 'runtime/$path';
1225 1278
1226 static String getDataFilename(String path) => 1279 static String getDataFilename(String path) =>
1227 new File(path).existsSync() ? path : '../$path'; 1280 new File(path).existsSync() ? path : '../$path';
1228 1281
1229 // Main test entrypoint. 1282 // Main test entrypoint.
1230 static testMain() { 1283 static testMain() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 testAppend(); 1322 testAppend();
1270 testAppendSync(); 1323 testAppendSync();
1271 testWriteAppend(); 1324 testWriteAppend();
1272 testOutputStreamWriteAppend(); 1325 testOutputStreamWriteAppend();
1273 testOutputStreamWriteString(); 1326 testOutputStreamWriteString();
1274 testWriteVariousLists(); 1327 testWriteVariousLists();
1275 testDirectory(); 1328 testDirectory();
1276 testDirectorySync(); 1329 testDirectorySync();
1277 testWriteStringUtf8(); 1330 testWriteStringUtf8();
1278 testWriteStringUtf8Sync(); 1331 testWriteStringUtf8Sync();
1332 testRename();
1333 testRenameSync();
1279 }); 1334 });
1280 } 1335 }
1281 } 1336 }
1282 1337
1283 main() { 1338 main() {
1284 FileTest.testMain(); 1339 FileTest.testMain();
1285 } 1340 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698