| OLD | NEW |
| 1 // Copyright (c) 2012, 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 import "dart:isolate"; | 6 import "dart:isolate"; |
| 7 | 7 |
| 8 class NotAnInteger { | 8 class NotAnInteger { |
| 9 operator==(other) => other == 1; | 9 operator==(other) => other == 1; |
| 10 operator<(other) => other > 1; | 10 operator<(other) => other > 1; |
| 11 operator+(other) => 1; | 11 operator+(other) => 1; |
| 12 } | 12 } |
| 13 | 13 |
| 14 class NotAList { | 14 class NotAList { |
| 15 get length => 10; | 15 get length => 10; |
| 16 operator[](index) => 1; | 16 operator[](index) => 1; |
| 17 } | 17 } |
| 18 | 18 |
| 19 testSocketCreation(host, port) { | 19 testSocketCreation(host, port) { |
| 20 Socket.connect(host, port) | 20 Socket.connect(host, port) |
| 21 .then((socket) => Expect.fail("Shouldn't get connected")) | 21 .then((socket) => Expect.fail("Shouldn't get connected")) |
| 22 .catchError((e) => null, test: (e) => e is SocketIOException) | 22 .catchError((e) => null, test: (e) => e is SocketIOException) |
| 23 .catchError((e) => null, test: (e) => e is ArgumentError); | 23 .catchError((e) => null, test: (e) => e is ArgumentError); |
| 24 } | 24 } |
| 25 | 25 |
| 26 testAdd(buffer) { | 26 testAdd(buffer) { |
| 27 var server = new ServerSocket("127.0.0.1", 0, 5); | 27 ServerSocket.bind("127.0.0.1", 0, 5).then((server) { |
| 28 Socket.connect("127.0.0.1", server.port) | 28 server.listen((socket) => socket.destroy()); |
| 29 .then((socket) { | 29 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 30 int errors = 0; | 30 int errors = 0; |
| 31 socket.listen( | 31 socket.done.catchError((e) { errors++; }); |
| 32 (data) {}, | 32 socket.listen( |
| 33 onError: (error) { | 33 (_) { }, |
| 34 errors++; | 34 onError: (error) { |
| 35 }, | 35 Expect.fail("Error on stream"); |
| 36 onDone: () { | 36 }, |
| 37 Expect.equals(1, errors); | 37 onDone: () { |
| 38 server.close(); | 38 Expect.equals(1, errors); |
| 39 }); | 39 socket.destroy(); |
| 40 socket.add(buffer); | 40 server.close(); |
| 41 }); | 41 }); |
| 42 socket.add(buffer); |
| 43 }); |
| 44 }); |
| 42 } | 45 } |
| 43 | 46 |
| 44 testServerSocketCreation(address, port, backlog) { | 47 testServerSocketCreation(address, port, backlog) { |
| 45 var server; | 48 var server; |
| 46 var port = new ReceivePort(); | 49 var port = new ReceivePort(); |
| 47 try { | 50 try { |
| 48 server = new ServerSocket(address, port, backlog); | 51 ServerSocket.bind(address, port, backlog) |
| 52 .then((_) { Expect.fail("ServerSocket bound"); }); |
| 49 } catch (e) { | 53 } catch (e) { |
| 50 port.close(); | 54 port.close(); |
| 51 } | 55 } |
| 52 } | 56 } |
| 53 | 57 |
| 54 main() { | 58 main() { |
| 55 testSocketCreation(123, 123); | 59 testSocketCreation(123, 123); |
| 56 testSocketCreation("string", null); | 60 testSocketCreation("string", null); |
| 57 testSocketCreation(null, null); | 61 testSocketCreation(null, null); |
| 58 testAdd(null); | 62 testAdd(null); |
| 59 testAdd(new NotAList()); | 63 testAdd(new NotAList()); |
| 60 testAdd(42); | 64 testAdd(42); |
| 61 // TODO(ajohnsen): the following two fails. | 65 TODO(8233): Throw ArgumentError from API implementation. |
| 62 testAdd([1, 2, 3, null]); | 66 //testAdd([-1]); |
| 63 testAdd([new NotAnInteger()]); | 67 //testAdd([2222222222222222222222222222222]); |
| 68 //testAdd([1, 2, 3, null]); |
| 69 //testAdd([new NotAnInteger()]); |
| 64 testServerSocketCreation(123, 123, 123); | 70 testServerSocketCreation(123, 123, 123); |
| 65 testServerSocketCreation("string", null, null); | 71 testServerSocketCreation("string", null, null); |
| 66 testServerSocketCreation("string", 123, null); | 72 testServerSocketCreation("string", 123, null); |
| 67 } | 73 } |
| OLD | NEW |