Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/standalone/io/socket_invalid_arguments_test.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 7
7 class NotAnInteger { 8 class NotAnInteger {
8 operator==(other) => other == 1; 9 operator==(other) => other == 1;
9 operator<(other) => other > 1; 10 operator<(other) => other > 1;
10 operator+(other) => 1; 11 operator+(other) => 1;
11 } 12 }
12 13
13 class NotAList { 14 class NotAList {
14 get length => 10; 15 get length => 10;
15 operator[](index) => 1; 16 operator[](index) => 1;
16 } 17 }
17 18
18 testSocketCreation(host, port) { 19 testSocketCreation(host, port) {
19 var s = new Socket(host, port); 20 Socket.connect(host, port)
20 s.onError = (e) => null; 21 .then((socket) => Expect.fail("Shouldn't get connected"))
21 s.onConnect = () => Expect.fail("Shouldn't get connected"); 22 .catchError((e) => null, test: (e) => e is SocketIOException)
23 .catchError((e) => null, test: (e) => e is ArgumentError);
22 } 24 }
23 25
24 testReadList(buffer, offset, length) { 26 testAdd(buffer) {
25 var server = new ServerSocket("127.0.0.1", 0, 5); 27 ServerSocket.bind("127.0.0.1", 0, 5).then((server) {
26 var s = new Socket("127.0.0.1", server.port); 28 server.listen((socket) => socket.destroy());
27 s.onConnect = () { 29 Socket.connect("127.0.0.1", server.port).then((socket) {
28 try { s.readList(buffer, offset, length); } catch (e) {} 30 int errors = 0;
29 s.close(); 31 socket.done.catchError((e) { errors++; });
30 }; 32 socket.listen(
31 s.onError = (e) => null; 33 (_) { },
32 } 34 onError: (error) {
33 35 Expect.fail("Error on stream");
34 testWriteList(buffer, offset, length) { 36 },
35 var server = new ServerSocket("127.0.0.1", 0, 5); 37 onDone: () {
36 var s = new Socket("127.0.0.1", server.port); 38 Expect.equals(1, errors);
37 s.onConnect = () { 39 socket.destroy();
38 try { s.writeList(buffer, offset, length); } catch (e) {} 40 server.close();
39 s.close(); 41 });
40 }; 42 socket.add(buffer);
41 s.onError = (e) => null; 43 });
44 });
42 } 45 }
43 46
44 testServerSocketCreation(address, port, backlog) { 47 testServerSocketCreation(address, port, backlog) {
45 var server; 48 var server;
49 var port = new ReceivePort();
46 try { 50 try {
47 server = new ServerSocket(address, port, backlog); 51 ServerSocket.bind(address, port, backlog)
48 server.onError = (e) => null; 52 .then((_) { Expect.fail("ServerSocket bound"); });
49 server.onConnection = (c) => Expect.fail("Shouldn't get connection");
50 } catch (e) { 53 } catch (e) {
51 // ignore 54 port.close();
52 } 55 }
53 } 56 }
54 57
55 main() { 58 main() {
56 testSocketCreation(123, 123); 59 testSocketCreation(123, 123);
57 testSocketCreation("string", null); 60 testSocketCreation("string", null);
58 testSocketCreation(null, null); 61 testSocketCreation(null, null);
59 testReadList(null, 123, 123); 62 testAdd(null);
60 testReadList(new NotAList(), 1, 1); 63 testAdd(new NotAList());
61 testReadList([1, 2, 3], new NotAnInteger(), new NotAnInteger()); 64 testAdd(42);
62 testReadList([1, 2, 3], 1, new NotAnInteger()); 65 // TODO(8233): Throw ArgumentError from API implementation.
63 testWriteList(null, 123, 123); 66 // testAdd([-1]);
64 testWriteList(new NotAList(), 1, 1); 67 // testAdd([2222222222222222222222222222222]);
65 testWriteList([1, 2, 3], new NotAnInteger(), new NotAnInteger()); 68 // testAdd([1, 2, 3, null]);
66 testWriteList([1, 2, 3], 1, new NotAnInteger()); 69 // testAdd([new NotAnInteger()]);
67 testWriteList([1, 2, 3], new NotAnInteger(), 1);
68 testServerSocketCreation(123, 123, 123); 70 testServerSocketCreation(123, 123, 123);
69 testServerSocketCreation("string", null, null); 71 testServerSocketCreation("string", null, null);
70 testServerSocketCreation("string", 123, null); 72 testServerSocketCreation("string", 123, null);
71 } 73 }
OLDNEW
« no previous file with comments | « tests/standalone/io/socket_info_test.dart ('k') | tests/standalone/io/socket_many_connections_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698