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