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

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

Issue 10441078: Add test that passes invalid arguments to socket methods and fix (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #import("dart:io");
6
7 class NotAnInteger {
8 operator==(other) => other == 1;
9 operator<(other) => other > 1;
10 operator+(other) => 1;
11 }
12
13 class NotAList {
14 get length() => 10;
15 operator[](index) => 1;
16 }
17
18 testSocketCreation(host, port) {
19 var s = new Socket(host, port);
20 s.onError = (e) => null;
21 s.onConnect = () => Expect.fail("Shouldn't get connected");
22 }
23
24 testReadList(buffer, offset, length) {
25 var server = new ServerSocket("127.0.0.1", 0, 5);
26 var s = new Socket("127.0.0.1", server.port);
27 s.onConnect = () {
28 try { s.readList(buffer, offset, length); } catch (var e) {}
29 s.close();
30 };
31 s.onError = (e) => null;
32 }
33
34 testWriteList(buffer, offset, length) {
35 var server = new ServerSocket("127.0.0.1", 0, 5);
36 var s = new Socket("127.0.0.1", server.port);
37 s.onConnect = () {
38 try { s.writeList(buffer, offset, length); } catch (var e) {}
39 s.close();
40 };
41 s.onError = (e) => null;
42 }
43
44 testServerSocketCreation(address, port, backlog) {
45 var server;
46 try {
47 server = new ServerSocket(address, port, backlog);
48 server.onError = (e) => null;
49 server.onConnection = (c) => Expect.fail("Shouldn't get connection");
50 } catch (var e) {
51 // ignore
52 }
53 }
54
55 main() {
56 testSocketCreation(123, 123);
57 testSocketCreation("string", null);
58 testSocketCreation(null, null);
59 testReadList(null, 123, 123);
60 testReadList(new NotAList(), 1, 1);
61 testReadList([1, 2, 3], new NotAnInteger(), new NotAnInteger());
62 testReadList([1, 2, 3], 1, new NotAnInteger());
63 testWriteList(null, 123, 123);
64 testWriteList(new NotAList(), 1, 1);
65 testWriteList([1, 2, 3], new NotAnInteger(), new NotAnInteger());
66 testWriteList([1, 2, 3], 1, new NotAnInteger());
67 testWriteList([1, 2, 3], new NotAnInteger(), 1);
68 testServerSocketCreation(123, 123, 123);
69 testServerSocketCreation("string", null, null);
70 testServerSocketCreation("string", 123, null);
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698