| OLD | NEW |
| 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 dart:io FileSystemEntity.Stat(). | 5 // Dart test program for testing dart:io FileSystemEntity.Stat(). |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "package:path/path.dart"; |
| 8 import 'dart:async'; | 9 import 'dart:async'; |
| 9 import 'dart:io'; | 10 import 'dart:io'; |
| 10 import 'dart:isolate'; | 11 import 'dart:isolate'; |
| 11 | 12 |
| 12 void testStat() { | 13 void testStat() { |
| 13 Directory directory = new Directory("").createTempSync(); | 14 Directory directory = new Directory("").createTempSync(); |
| 14 File file = new File.fromPath(new Path(directory.path).append("file")); | 15 File file = new File(join(directory.path, "file")); |
| 15 Expect.throws(file.statSync); | 16 Expect.throws(file.statSync); |
| 16 Expect.throws(() => FileStat.statSync(file.path)); | 17 Expect.throws(() => FileStat.statSync(file.path)); |
| 17 file.writeAsStringSync("Dart IO library test of FileStat"); | 18 file.writeAsStringSync("Dart IO library test of FileStat"); |
| 18 new Timer(const Duration(seconds: 2), () { | 19 new Timer(const Duration(seconds: 2), () { |
| 19 file.readAsStringSync(); | 20 file.readAsStringSync(); |
| 20 directory.listSync(); | 21 directory.listSync(); |
| 21 FileStat fileStat = FileStat.statSync(file.path); | 22 FileStat fileStat = FileStat.statSync(file.path); |
| 22 FileStat fileStatDirect = file.statSync(); | 23 FileStat fileStatDirect = file.statSync(); |
| 23 Expect.equals(FileSystemEntityType.FILE, fileStat.type); | 24 Expect.equals(FileSystemEntityType.FILE, fileStat.type); |
| 24 Expect.equals(32, fileStat.size); | 25 Expect.equals(32, fileStat.size); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 41 } | 42 } |
| 42 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. | 43 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. |
| 43 directory.deleteSync(recursive: true); | 44 directory.deleteSync(recursive: true); |
| 44 }); | 45 }); |
| 45 } | 46 } |
| 46 | 47 |
| 47 | 48 |
| 48 Future testStatAsync() { | 49 Future testStatAsync() { |
| 49 return new Directory("").createTemp() | 50 return new Directory("").createTemp() |
| 50 .then((directory) { | 51 .then((directory) { |
| 51 File file = new File.fromPath(new Path(directory.path).append("file")); | 52 File file = new File(join(directory.path, "file")); |
| 52 return FileStat.stat(file.path) | 53 return FileStat.stat(file.path) |
| 53 .then((_) => Expect.fail("FileStat.stat should throw an exception.")) | 54 .then((_) => Expect.fail("FileStat.stat should throw an exception.")) |
| 54 .catchError((e) => null) | 55 .catchError((e) => null) |
| 55 .then((_) => file.stat()) | 56 .then((_) => file.stat()) |
| 56 .then((_) => Expect.fail("File.stat should throw an exception.")) | 57 .then((_) => Expect.fail("File.stat should throw an exception.")) |
| 57 .catchError((e) => null) | 58 .catchError((e) => null) |
| 58 .then((_) => file.writeAsString("Dart IO library test of FileStat")) | 59 .then((_) => file.writeAsString("Dart IO library test of FileStat")) |
| 59 .then((_) => new Future.delayed(const Duration(seconds: 2))) | 60 .then((_) => new Future.delayed(const Duration(seconds: 2))) |
| 60 .then((_) => file.readAsString()) | 61 .then((_) => file.readAsString()) |
| 61 .then((_) => directory.list().last) | 62 .then((_) => directory.list().last) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 }); | 116 }); |
| 116 }); | 117 }); |
| 117 } | 118 } |
| 118 | 119 |
| 119 | 120 |
| 120 void main() { | 121 void main() { |
| 121 ReceivePort keepAlive = new ReceivePort(); | 122 ReceivePort keepAlive = new ReceivePort(); |
| 122 testStat(); | 123 testStat(); |
| 123 testStatAsync().then((_) => keepAlive.close()); | 124 testStatAsync().then((_) => keepAlive.close()); |
| 124 } | 125 } |
| OLD | NEW |