OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // |
| 5 // Dart test program for testing dart:io FileSystemEntity.Stat(). |
| 6 |
| 7 import "package:expect/expect.dart"; |
| 8 import 'dart:async'; |
| 9 import 'dart:io'; |
| 10 import 'dart:isolate'; |
| 11 |
| 12 void testStat() { |
| 13 Directory directory = new Directory("").createTempSync(); |
| 14 File file = new File.fromPath(new Path(directory.path).append("file")); |
| 15 FileStat nonExistent = FileStat.statSync(file.path); |
| 16 Expect.equals(FileSystemEntityType.NOT_FOUND, nonExistent.type); |
| 17 file.writeAsStringSync("Dart IO library test of FileStat"); |
| 18 new Timer(const Duration(seconds: 2), () { |
| 19 file.readAsStringSync(); |
| 20 directory.listSync(); |
| 21 FileStat fileStat = FileStat.statSync(file.path); |
| 22 Expect.equals(FileSystemEntityType.FILE, fileStat.type); |
| 23 Expect.equals(32, fileStat.size); |
| 24 if (Platform.operatingSystem != 'windows') { |
| 25 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0); |
| 26 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0); |
| 27 } |
| 28 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw. |
| 29 FileStat directoryStat = FileStat.statSync(directory.path); |
| 30 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type); |
| 31 if (Platform.operatingSystem != 'windows') { |
| 32 Expect.isTrue( |
| 33 directoryStat.modified.compareTo(directoryStat.accessed) < 0); |
| 34 Expect.isTrue( |
| 35 directoryStat.changed.compareTo(directoryStat.accessed) < 0); |
| 36 } |
| 37 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. |
| 38 directory.deleteSync(recursive: true); |
| 39 }); |
| 40 } |
| 41 |
| 42 |
| 43 Future testStatAsync() { |
| 44 return new Directory("").createTemp() |
| 45 .then((directory) { |
| 46 File file = new File.fromPath(new Path(directory.path).append("file")); |
| 47 return FileStat.stat(file.path) |
| 48 .then((missingStat) { |
| 49 Expect.equals(FileSystemEntityType.NOT_FOUND, missingStat.type); |
| 50 }) |
| 51 .then((_) => file.writeAsString("Dart IO library test of FileStat")) |
| 52 .then((_) => new Future.delayed(const Duration(seconds: 2))) |
| 53 .then((_) => file.readAsString()) |
| 54 .then((_) => directory.list().last) |
| 55 .then((_) => FileStat.stat(file.path)) |
| 56 .then((FileStat fileStat) { |
| 57 Expect.equals(FileSystemEntityType.FILE, fileStat.type); |
| 58 Expect.equals(32, fileStat.size); |
| 59 if (Platform.operatingSystem != 'windows') { |
| 60 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0); |
| 61 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0); |
| 62 } |
| 63 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw. |
| 64 return FileStat.stat(directory.path); |
| 65 }) |
| 66 .then((FileStat directoryStat) { |
| 67 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type); |
| 68 if (Platform.operatingSystem != 'windows') { |
| 69 Expect.isTrue( |
| 70 directoryStat.modified.compareTo(directoryStat.accessed) < 0); |
| 71 Expect.isTrue( |
| 72 directoryStat.changed.compareTo(directoryStat.accessed) < 0); |
| 73 } |
| 74 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. |
| 75 return directory.delete(recursive: true); |
| 76 }); |
| 77 }); |
| 78 } |
| 79 |
| 80 |
| 81 void main() { |
| 82 ReceivePort keepAlive = new ReceivePort(); |
| 83 testStat(); |
| 84 testStatAsync().then((_) => keepAlive.close()); |
| 85 } |
OLD | NEW |