Chromium Code Reviews| 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) |
| 30 int errors = 0; | 30 .then((socket) { |
|
Mads Ager (google)
2013/01/31 07:53:30
I would move this to the line above and remove som
Søren Gjesse
2013/01/31 12:12:01
Done.
| |
| 31 socket.listen( | 31 int errors = 0; |
| 32 (data) {}, | 32 socket.done.catchError((e) { errors++; }); |
| 33 onError: (error) { | 33 socket.listen( |
| 34 errors++; | 34 (_) { }, |
| 35 }, | 35 onError: (error) { |
| 36 onDone: () { | 36 Expect.fail("Error on stream"); |
| 37 Expect.equals(1, errors); | 37 }, |
| 38 server.close(); | 38 onDone: () { |
| 39 }); | 39 Expect.equals(1, errors); |
| 40 socket.add(buffer); | 40 socket.destroy(); |
| 41 }); | 41 server.close(); |
| 42 }); | |
| 43 socket.add(buffer); | |
| 44 }); | |
| 45 }); | |
| 42 } | 46 } |
| 43 | 47 |
| 44 testServerSocketCreation(address, port, backlog) { | 48 testServerSocketCreation(address, port, backlog) { |
| 45 var server; | 49 var server; |
| 46 var port = new ReceivePort(); | 50 var port = new ReceivePort(); |
| 47 try { | 51 try { |
| 48 server = new ServerSocket(address, port, backlog); | 52 ServerSocket.bind(address, port, backlog) |
| 53 .then((_) { Expect.fail("ServerSocket bound"); }); | |
| 49 } catch (e) { | 54 } catch (e) { |
| 50 port.close(); | 55 port.close(); |
| 51 } | 56 } |
| 52 } | 57 } |
| 53 | 58 |
| 54 main() { | 59 main() { |
| 55 testSocketCreation(123, 123); | 60 testSocketCreation(123, 123); |
| 56 testSocketCreation("string", null); | 61 testSocketCreation("string", null); |
| 57 testSocketCreation(null, null); | 62 testSocketCreation(null, null); |
| 58 testAdd(null); | 63 testAdd(null); |
| 59 testAdd(new NotAList()); | 64 testAdd(new NotAList()); |
| 60 testAdd(42); | 65 testAdd(42); |
| 61 // TODO(ajohnsen): the following two fails. | 66 // TODO(ajohnsen): the following two fails. |
|
Mads Ager (google)
2013/01/31 07:53:30
Is this still the case?
Søren Gjesse
2013/01/31 12:12:01
It is still the case (I even added more with negat
| |
| 62 testAdd([1, 2, 3, null]); | 67 testAdd([1, 2, 3, null]); |
| 63 testAdd([new NotAnInteger()]); | 68 testAdd([new NotAnInteger()]); |
| 64 testServerSocketCreation(123, 123, 123); | 69 testServerSocketCreation(123, 123, 123); |
| 65 testServerSocketCreation("string", null, null); | 70 testServerSocketCreation("string", null, null); |
| 66 testServerSocketCreation("string", 123, null); | 71 testServerSocketCreation("string", 123, null); |
| 67 } | 72 } |
| OLD | NEW |