Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
Anders Johnsen
2013/10/24 08:30:08
Move test to e.g. tests/lib/platform/os_test.dart.
Bill Hesse
2013/10/24 13:43:43
Done.
| |
| 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 import "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
|
Anders Johnsen
2013/10/24 08:30:08
Remove io import.
Bill Hesse
2013/10/24 13:43:43
Done.
| |
| 7 import "dart:isolate"; | 7 import "dart:isolate"; |
| 8 import "dart:platform" as platform; | |
| 8 | 9 |
| 9 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
| 10 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
| 11 | 12 |
| 12 test() { | 13 test() { |
| 13 Expect.isTrue(Platform.numberOfProcessors > 0); | 14 Expect.isTrue(platform.numberOfProcessors > 0); |
| 14 var os = Platform.operatingSystem; | 15 var os = platform.operatingSystem; |
| 15 Expect.isTrue(os == "android" || os == "linux" || os == "macos" || | 16 Expect.isTrue(os == "android" || os == "linux" || os == "macos" || |
| 16 os == "windows"); | 17 os == "windows"); |
| 17 Expect.equals(Platform.isLinux, Platform.operatingSystem == "linux"); | 18 Expect.equals(platform.isLinux, platform.operatingSystem == "linux"); |
| 18 Expect.equals(Platform.isMacOS, Platform.operatingSystem == "macos"); | 19 Expect.equals(platform.isMacOS, platform.operatingSystem == "macos"); |
| 19 Expect.equals(Platform.isWindows, Platform.operatingSystem == "windows"); | 20 Expect.equals(platform.isWindows, platform.operatingSystem == "windows"); |
| 20 Expect.equals(Platform.isAndroid, Platform.operatingSystem == "android"); | 21 Expect.equals(platform.isAndroid, platform.operatingSystem == "android"); |
| 21 var sep = Platform.pathSeparator; | 22 var sep = platform.pathSeparator; |
| 22 Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\')); | 23 Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\')); |
| 23 var hostname = Platform.localHostname; | 24 var hostname = platform.localHostname; |
| 24 Expect.isTrue(hostname is String && hostname != ""); | 25 Expect.isTrue(hostname is String && hostname != ""); |
| 25 var environment = Platform.environment; | 26 var environment = platform.environment; |
| 26 Expect.isTrue(environment is Map<String, String>); | 27 Expect.isTrue(environment is Map<String, String>); |
| 27 Expect.isTrue(Platform.executable.contains('dart')); | 28 Expect.isTrue(platform.executable.contains('dart')); |
| 28 Expect.isTrue(Platform.script.replaceAll('\\', '/'). | 29 Expect.isTrue(platform.script.replaceAll('\\', '/'). |
| 29 endsWith('tests/standalone/io/platform_test.dart')); | 30 endsWith('tests/standalone/io/platform_test.dart')); |
| 30 Directory packageRoot = new Directory(Platform.packageRoot); | 31 Directory packageRoot = new Directory(platform.packageRoot); |
| 31 Expect.isTrue(packageRoot.existsSync()); | 32 Expect.isTrue(packageRoot.existsSync()); |
| 32 Expect.isTrue(new Directory("${packageRoot.path}/expect").existsSync()); | 33 Expect.isTrue(new Directory("${packageRoot.path}/expect").existsSync()); |
| 33 Expect.isTrue(Platform.executableArguments.any( | 34 Expect.isTrue(platform.executableArguments.any( |
| 34 (arg) => arg.contains(Platform.packageRoot))); | 35 (arg) => arg.contains(platform.packageRoot))); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void f() { | 38 void f() { |
| 38 port.receive((msg, reply) { | 39 port.receive((msg, reply) { |
| 39 if (msg == "Platform.executable") { | 40 if (msg == "platform.executable") { |
| 40 reply.send(Platform.executable); | 41 reply.send(platform.executable); |
| 41 } | 42 } |
| 42 if (msg == "Platform.script") { | 43 if (msg == "platform.script") { |
| 43 reply.send(Platform.script); | 44 reply.send(platform.script); |
| 44 } | 45 } |
| 45 if (msg == "Platform.packageRoot") { | 46 if (msg == "platform.packageRoot") { |
| 46 reply.send(Platform.packageRoot); | 47 reply.send(platform.packageRoot); |
| 47 } | 48 } |
| 48 if (msg == "Platform.executableArguments") { | 49 if (msg == "platform.executableArguments") { |
| 49 reply.send(Platform.executableArguments); | 50 reply.send(platform.executableArguments); |
| 50 } | 51 } |
| 51 if (msg == "close") { | 52 if (msg == "close") { |
| 52 reply.send("closed"); | 53 reply.send("closed"); |
| 53 port.close(); | 54 port.close(); |
| 54 } | 55 } |
| 55 }); | 56 }); |
| 56 } | 57 } |
| 57 | 58 |
| 58 testIsolate() { | 59 testIsolate() { |
| 59 asyncStart(); | 60 asyncStart(); |
| 60 var sendPort = spawnFunction(f); | 61 var sendPort = spawnFunction(f); |
| 61 Future.wait([sendPort.call("Platform.executable"), | 62 Future.wait([sendPort.call("platform.executable"), |
| 62 sendPort.call("Platform.script"), | 63 sendPort.call("platform.script"), |
| 63 sendPort.call("Platform.packageRoot"), | 64 sendPort.call("platform.packageRoot"), |
| 64 sendPort.call("Platform.executableArguments")]) | 65 sendPort.call("platform.executableArguments")]) |
| 65 .then((results) { | 66 .then((results) { |
| 66 Expect.equals(Platform.executable, results[0]); | 67 Expect.equals(platform.executable, results[0]); |
| 67 Uri uri = Uri.parse(results[1]); | 68 Uri uri = Uri.parse(results[1]); |
| 68 Expect.equals("file", uri.scheme); | 69 Expect.equals("file", uri.scheme); |
| 69 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart')); | 70 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart')); |
| 70 Expect.equals(Platform.packageRoot, results[2]); | 71 Expect.equals(platform.packageRoot, results[2]); |
| 71 Expect.listEquals(Platform.executableArguments, results[3]); | 72 Expect.listEquals(platform.executableArguments, results[3]); |
| 72 sendPort.call("close").then((_) => asyncEnd()); | 73 sendPort.call("close").then((_) => asyncEnd()); |
| 73 }); | 74 }); |
| 74 } | 75 } |
| 75 | 76 |
| 76 main() { | 77 main() { |
| 77 test(); | 78 test(); |
| 78 testIsolate(); | 79 testIsolate(); |
| 79 } | 80 } |
| OLD | NEW |