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

Unified 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: Fix Windows failures. 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/io/file_system_entity.dart ('K') | « sdk/lib/io/file_system_entity.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/file_stat_test.dart
diff --git a/tests/standalone/io/file_stat_test.dart b/tests/standalone/io/file_stat_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..901b848911a8f33127ff72af402108d5037fca51
--- /dev/null
+++ b/tests/standalone/io/file_stat_test.dart
@@ -0,0 +1,85 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// Dart test program for testing dart:io FileSystemEntity.Stat().
+
+import "package:expect/expect.dart";
+import 'dart:async';
+import 'dart:io';
+import 'dart:isolate';
+
+void testStat() {
+ Directory directory = new Directory("").createTempSync();
+ File file = new File.fromPath(new Path(directory.path).append("file"));
+ FileStat nonExistent = FileStat.statSync(file.path);
+ Expect.equals(FileSystemEntityType.NOT_FOUND, nonExistent.type);
+ file.writeAsStringSync("Dart IO library test of FileStat");
+ new Timer(const Duration(seconds: 2), () {
+ file.readAsStringSync();
+ directory.listSync();
+ FileStat fileStat = FileStat.statSync(file.path);
+ Expect.equals(FileSystemEntityType.FILE, fileStat.type);
+ Expect.equals(32, fileStat.size);
+ if (Platform.operatingSystem != 'windows') {
+ Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
+ Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
+ }
+ Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
+ FileStat directoryStat = FileStat.statSync(directory.path);
+ Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type);
+ if (Platform.operatingSystem != 'windows') {
+ Expect.isTrue(
+ directoryStat.modified.compareTo(directoryStat.accessed) < 0);
+ Expect.isTrue(
+ directoryStat.changed.compareTo(directoryStat.accessed) < 0);
+ }
+ Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
+ directory.deleteSync(recursive: true);
+ });
+}
+
+
+Future testStatAsync() {
+ return new Directory("").createTemp()
+ .then((directory) {
+ File file = new File.fromPath(new Path(directory.path).append("file"));
+ return FileStat.stat(file.path)
+ .then((missingStat) {
+ Expect.equals(FileSystemEntityType.NOT_FOUND, missingStat.type);
+ })
+ .then((_) => file.writeAsString("Dart IO library test of FileStat"))
+ .then((_) => new Future.delayed(const Duration(seconds: 2)))
+ .then((_) => file.readAsString())
+ .then((_) => directory.list().last)
+ .then((_) => FileStat.stat(file.path))
+ .then((FileStat fileStat) {
+ Expect.equals(FileSystemEntityType.FILE, fileStat.type);
+ Expect.equals(32, fileStat.size);
+ if (Platform.operatingSystem != 'windows') {
+ Expect.isTrue(fileStat.modified.compareTo(fileStat.accessed) < 0);
+ Expect.isTrue(fileStat.changed.compareTo(fileStat.accessed) < 0);
+ }
+ Expect.equals(6 << 6, fileStat.mode & (6 << 6)); // Mode includes +urw.
+ return FileStat.stat(directory.path);
+ })
+ .then((FileStat directoryStat) {
+ Expect.equals(FileSystemEntityType.DIRECTORY, directoryStat.type);
+ if (Platform.operatingSystem != 'windows') {
+ Expect.isTrue(
+ directoryStat.modified.compareTo(directoryStat.accessed) < 0);
+ Expect.isTrue(
+ directoryStat.changed.compareTo(directoryStat.accessed) < 0);
+ }
+ Expect.equals(7 << 6, directoryStat.mode & (7 << 6)); // Includes +urwx.
+ return directory.delete(recursive: true);
+ });
+ });
+}
+
+
+void main() {
+ ReceivePort keepAlive = new ReceivePort();
+ testStat();
+ testStatAsync().then((_) => keepAlive.close());
+}
« sdk/lib/io/file_system_entity.dart ('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