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

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

Issue 15018011: dart:io | Add FileSystemEntity.stat() and FileStat class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add implementation Created 7 years, 7 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
« runtime/bin/dartutils.h ('K') | « sdk/lib/io/file_system_entity.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
(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 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
25 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
26 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
27 FileStat directoryStat = FileStat.statSync(directory.path);
28 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type);
29 Expect.isTrue(directoryStat.modified.compareTo(directoryStat.accessed) < 0);
30 Expect.isTrue(directoryStat.changed.compareTo(directoryStat.accessed) < 0);
31 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
32 directory.deleteSync(recursive: true);
33 });
34 }
35
36
37 Future testStatAsync() {
38 return new Directory("").createTemp()
39 .then((directory) {
40 File file = new File.fromPath(new Path(directory.path).append("file"));
41 return FileStat.stat(file.path)
42 .then((missingStat) {
43 Expect.equals(FileSystemEntityType.NOT_FOUND, missingStat.type);
44 })
45 .then((_) => file.writeAsString("Dart IO library test of FileStat"))
46 .then((_) => new Future.delayed(const Duration(seconds: 2)))
47 .then((_) => file.readAsString())
48 .then((_) => directory.list().last)
49 .then((_) => FileStat.stat(file.path))
50 .then((FileStat fileStat) {
51 Expect.equals(FileSystemEntityType.FILE, fileStat.type);
52 Expect.equals(32, fileStat.size);
53 Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
54 Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
55 Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
56 return FileStat.stat(directory.path);
57 })
58 .then((FileStat directoryStat) {
59 Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type);
60 Expect.isTrue(
61 directoryStat.modified.compareTo(directoryStat.accessed) < 0);
62 Expect.isTrue(
63 directoryStat.changed.compareTo(directoryStat.accessed) < 0);
64 Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
65 return directory.delete(recursive: true);
66 });
67 });
68 }
69
70
71 void main() {
72 ReceivePort keepAlive = new ReceivePort();
73 testStat();
74 testStatAsync().then((_) => keepAlive.close());
75 }
OLDNEW
« runtime/bin/dartutils.h ('K') | « sdk/lib/io/file_system_entity.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698