| OLD | NEW |
| 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 import "dart:io"; | 5 import "dart:io"; |
| 6 | 6 |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 class NotAnInteger { | 10 class NotAnInteger { |
| 11 operator==(other) => other == 1; | 11 operator==(other) => other == 1; |
| 12 operator<(other) => other > 1; | 12 operator<(other) => other > 1; |
| 13 operator+(other) => 1; | 13 operator+(other) => 1; |
| 14 } | 14 } |
| 15 | 15 |
| 16 class NotAList { | 16 class NotAList { |
| 17 get length => 10; | 17 get length => 10; |
| 18 operator[](index) => 1; | 18 operator[](index) => 1; |
| 19 } | 19 } |
| 20 | 20 |
| 21 testSocketCreation(host, port) { | 21 testSocketCreation(host, port) { |
| 22 asyncStart(); | 22 asyncStart(); |
| 23 Socket.connect(host, port) | 23 try { |
| 24 .then((socket) => Expect.fail("Shouldn't get connected")) | 24 Socket.connect(host, port) |
| 25 .catchError((e) { | 25 .then((socket) => Expect.fail("Shouldn't get connected")) |
| 26 Expect.isTrue(e is ArgumentError || e is SocketException); | 26 .catchError((e) { |
| 27 asyncEnd(); | 27 Expect.isTrue(e is ArgumentError || e is SocketException); |
| 28 }); | 28 asyncEnd(); |
| 29 }); |
| 30 } catch (e) { |
| 31 Expect.isTrue(e is ArgumentError || e is SocketException); |
| 32 asyncEnd(); |
| 33 } |
| 29 } | 34 } |
| 30 | 35 |
| 31 testAdd(buffer) { | 36 testAdd(buffer) { |
| 32 asyncStart(); | 37 asyncStart(); |
| 33 asyncStart(); | 38 asyncStart(); |
| 34 ServerSocket.bind("127.0.0.1", 0).then((server) { | 39 ServerSocket.bind("127.0.0.1", 0).then((server) { |
| 35 server.listen((socket) => socket.destroy()); | 40 server.listen((socket) => socket.destroy()); |
| 36 Socket.connect("127.0.0.1", server.port).then((socket) { | 41 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 37 int errors = 0; | 42 int errors = 0; |
| 38 socket.done | 43 socket.done |
| (...skipping 25 matching lines...) Expand all Loading... |
| 64 .catchError((e) => asyncEnd()); | 69 .catchError((e) => asyncEnd()); |
| 65 } catch (e) { | 70 } catch (e) { |
| 66 asyncEnd(); | 71 asyncEnd(); |
| 67 } | 72 } |
| 68 } | 73 } |
| 69 | 74 |
| 70 main() { | 75 main() { |
| 71 testSocketCreation(123, 123); | 76 testSocketCreation(123, 123); |
| 72 testSocketCreation("string", null); | 77 testSocketCreation("string", null); |
| 73 testSocketCreation(null, null); | 78 testSocketCreation(null, null); |
| 79 testSocketCreation("localhost", -1); |
| 80 testSocketCreation("localhost", 65536); |
| 74 testAdd(null); | 81 testAdd(null); |
| 75 testAdd(new NotAList()); | 82 testAdd(new NotAList()); |
| 76 testAdd(42); | 83 testAdd(42); |
| 77 // TODO(8233): Throw ArgumentError from API implementation. | 84 // TODO(8233): Throw ArgumentError from API implementation. |
| 78 // testAdd([-1]); | 85 // testAdd([-1]); |
| 79 // testAdd([2222222222222222222222222222222]); | 86 // testAdd([2222222222222222222222222222222]); |
| 80 // testAdd([1, 2, 3, null]); | 87 // testAdd([1, 2, 3, null]); |
| 81 // testAdd([new NotAnInteger()]); | 88 // testAdd([new NotAnInteger()]); |
| 82 testServerSocketCreation(123, 123, 123); | 89 testServerSocketCreation(123, 123, 123); |
| 83 testServerSocketCreation("string", null, null); | 90 testServerSocketCreation("string", null, null); |
| 84 testServerSocketCreation("string", 123, null); | 91 testServerSocketCreation("string", 123, null); |
| 92 testServerSocketCreation("localhost", -1, 123); |
| 93 testServerSocketCreation("localhost", 65536, 123); |
| 85 } | 94 } |
| OLD | NEW |