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

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

Issue 16156009: dart:io | Add .stat() and .statSync() to FileSystemEntity and subclasses File, Directory, and Link. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/link.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 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 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
11 11
12 void testStat() { 12 void testStat() {
13 Directory directory = new Directory("").createTempSync(); 13 Directory directory = new Directory("").createTempSync();
14 File file = new File.fromPath(new Path(directory.path).append("file")); 14 File file = new File.fromPath(new Path(directory.path).append("file"));
15 FileStat nonExistent = FileStat.statSync(file.path); 15 FileStat nonExistent = FileStat.statSync(file.path);
16 Expect.equals(FileSystemEntityType.NOT_FOUND, nonExistent.type); 16 Expect.equals(FileSystemEntityType.NOT_FOUND, nonExistent.type);
17 file.writeAsStringSync("Dart IO library test of FileStat"); 17 file.writeAsStringSync("Dart IO library test of FileStat");
18 new Timer(const Duration(seconds: 2), () { 18 new Timer(const Duration(seconds: 2), () {
19 file.readAsStringSync(); 19 file.readAsStringSync();
20 directory.listSync(); 20 directory.listSync();
21 FileStat fileStat = FileStat.statSync(file.path); 21 FileStat fileStat = FileStat.statSync(file.path);
22 FileStat fileStatDirect = file.statSync();
22 Expect.equals(FileSystemEntityType.FILE, fileStat.type); 23 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
23 Expect.equals(32, fileStat.size); 24 Expect.equals(32, fileStat.size);
25 Expect.equals(FileSystemEntityType.FILE, fileStatDirect.type);
26 Expect.equals(32, fileStatDirect.size);
24 if (Platform.operatingSystem != 'windows') { 27 if (Platform.operatingSystem != 'windows') {
25 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0); 28 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
26 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0); 29 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
27 } 30 }
28 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw. 31 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
29 FileStat directoryStat = FileStat.statSync(directory.path); 32 FileStat directoryStat = FileStat.statSync(directory.path);
33 FileStat directoryStatDirect = directory.statSync();
30 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type); 34 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type);
35 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStatDirect.type);
31 if (Platform.operatingSystem != 'windows') { 36 if (Platform.operatingSystem != 'windows') {
32 Expect.isTrue( 37 Expect.isTrue(
33 directoryStat.modified.compareTo(directoryStat.accessed) < 0); 38 directoryStat.modified.compareTo(directoryStat.accessed) < 0);
34 Expect.isTrue( 39 Expect.isTrue(
35 directoryStat.changed.compareTo(directoryStat.accessed) < 0); 40 directoryStat.changed.compareTo(directoryStat.accessed) < 0);
36 } 41 }
37 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. 42 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
38 directory.deleteSync(recursive: true); 43 directory.deleteSync(recursive: true);
39 }); 44 });
40 } 45 }
(...skipping 13 matching lines...) Expand all
54 .then((_) => directory.list().last) 59 .then((_) => directory.list().last)
55 .then((_) => FileStat.stat(file.path)) 60 .then((_) => FileStat.stat(file.path))
56 .then((FileStat fileStat) { 61 .then((FileStat fileStat) {
57 Expect.equals(FileSystemEntityType.FILE, fileStat.type); 62 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
58 Expect.equals(32, fileStat.size); 63 Expect.equals(32, fileStat.size);
59 if (Platform.operatingSystem != 'windows') { 64 if (Platform.operatingSystem != 'windows') {
60 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0); 65 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
61 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0); 66 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
62 } 67 }
63 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw. 68 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
69 return file.stat();
70 })
71 .then((FileStat fileStat) {
72 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
73 Expect.equals(32, fileStat.size);
74 if (Platform.operatingSystem != 'windows') {
75 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
76 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
77 }
78 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
64 return FileStat.stat(directory.path); 79 return FileStat.stat(directory.path);
65 }) 80 })
66 .then((FileStat directoryStat) { 81 .then((FileStat directoryStat) {
67 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type); 82 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type);
68 if (Platform.operatingSystem != 'windows') { 83 if (Platform.operatingSystem != 'windows') {
69 Expect.isTrue( 84 Expect.isTrue(
70 directoryStat.modified.compareTo(directoryStat.accessed) < 0); 85 directoryStat.modified.compareTo(directoryStat.accessed) < 0);
71 Expect.isTrue( 86 Expect.isTrue(
72 directoryStat.changed.compareTo(directoryStat.accessed) < 0); 87 directoryStat.changed.compareTo(directoryStat.accessed) < 0);
73 } 88 }
74 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx. 89 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
90 return directory.stat();
91 })
92 .then((FileStat directoryStat) {
93 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type);
94 if (Platform.operatingSystem != 'windows') {
95 Expect.isTrue(
96 directoryStat.modified.compareTo(directoryStat.accessed) < 0);
97 Expect.isTrue(
98 directoryStat.changed.compareTo(directoryStat.accessed) < 0);
99 }
100 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
101 return new Link(directory.path).stat();
102 })
103 .then((FileStat linkStat) {
104 Expect.equals(FileSystemEntityType.DIRECTORY, linkStat.type);
105 if (Platform.operatingSystem != 'windows') {
106 Expect.isTrue(
107 linkStat.modified.compareTo(linkStat.accessed) < 0);
108 Expect.isTrue(
109 linkStat.changed.compareTo(linkStat.accessed) < 0);
110 }
111 Expect.equals(7 << 6, linkStat.mode & (7 << 6)); // Includes +urwx.
75 return directory.delete(recursive: true); 112 return directory.delete(recursive: true);
76 }); 113 });
77 }); 114 });
78 } 115 }
79 116
80 117
81 void main() { 118 void main() {
82 ReceivePort keepAlive = new ReceivePort(); 119 ReceivePort keepAlive = new ReceivePort();
83 testStat(); 120 testStat();
84 testStatAsync().then((_) => keepAlive.close()); 121 testStatAsync().then((_) => keepAlive.close());
85 } 122 }
OLDNEW
« no previous file with comments | « sdk/lib/io/link.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698