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

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

Issue 10891020: Update almost all tests (except co19) to use the new try-catch syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge. Created 8 years, 3 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) 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 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 // Tests socket exceptions. 5 // Tests socket exceptions.
6 6
7 #import("dart:isolate"); 7 #import("dart:isolate");
8 #import("dart:io"); 8 #import("dart:io");
9 9
10 class SocketExceptionTest { 10 class SocketExceptionTest {
11 11
12 static const PORT = 0; 12 static const PORT = 0;
13 static const HOST = "127.0.0.1"; 13 static const HOST = "127.0.0.1";
14 14
15 static void serverSocketExceptionTest() { 15 static void serverSocketExceptionTest() {
16 bool exceptionCaught = false; 16 bool exceptionCaught = false;
17 bool wrongExceptionCaught = false; 17 bool wrongExceptionCaught = false;
18 18
19 ServerSocket server = new ServerSocket(HOST, PORT, 10); 19 ServerSocket server = new ServerSocket(HOST, PORT, 10);
20 Expect.equals(true, server !== null); 20 Expect.equals(true, server !== null);
21 server.close(); 21 server.close();
22 try { 22 try {
23 server.close(); 23 server.close();
24 } catch (SocketIOException ex) { 24 } on SocketIOException catch(ex) {
25 exceptionCaught = true; 25 exceptionCaught = true;
26 } catch (Exception ex) { 26 } on Exception catch (ex) {
27 wrongExceptionCaught = true; 27 wrongExceptionCaught = true;
28 } 28 }
29 Expect.equals(false, exceptionCaught); 29 Expect.equals(false, exceptionCaught);
30 Expect.equals(true, !wrongExceptionCaught); 30 Expect.equals(true, !wrongExceptionCaught);
31 } 31 }
32 32
33 static void clientSocketExceptionTest() { 33 static void clientSocketExceptionTest() {
34 bool exceptionCaught = false; 34 bool exceptionCaught = false;
35 bool wrongExceptionCaught = false; 35 bool wrongExceptionCaught = false;
36 36
37 ServerSocket server = new ServerSocket(HOST, PORT, 10); 37 ServerSocket server = new ServerSocket(HOST, PORT, 10);
38 Expect.equals(true, server !== null); 38 Expect.equals(true, server !== null);
39 int port = server.port; 39 int port = server.port;
40 Socket client = new Socket(HOST, port); 40 Socket client = new Socket(HOST, port);
41 client.onConnect = () { 41 client.onConnect = () {
42 Expect.equals(true, client !== null); 42 Expect.equals(true, client !== null);
43 InputStream input = client.inputStream; 43 InputStream input = client.inputStream;
44 OutputStream output = client.outputStream; 44 OutputStream output = client.outputStream;
45 client.close(); 45 client.close();
46 try { 46 try {
47 client.close(); 47 client.close();
48 } catch (SocketIOException ex) { 48 } on SocketIOException catch(ex) {
49 exceptionCaught = true; 49 exceptionCaught = true;
50 } catch (Exception ex) { 50 } on Exception catch (ex) {
51 wrongExceptionCaught = true; 51 wrongExceptionCaught = true;
52 } 52 }
53 Expect.equals(false, exceptionCaught); 53 Expect.equals(false, exceptionCaught);
54 Expect.equals(true, !wrongExceptionCaught); 54 Expect.equals(true, !wrongExceptionCaught);
55 exceptionCaught = false; 55 exceptionCaught = false;
56 try { 56 try {
57 client.available(); 57 client.available();
58 } catch (SocketIOException ex) { 58 } on SocketIOException catch(ex) {
59 exceptionCaught = true; 59 exceptionCaught = true;
60 } catch (Exception ex) { 60 } on Exception catch (ex) {
61 wrongExceptionCaught = true; 61 wrongExceptionCaught = true;
62 } 62 }
63 Expect.equals(true, exceptionCaught); 63 Expect.equals(true, exceptionCaught);
64 Expect.equals(true, !wrongExceptionCaught); 64 Expect.equals(true, !wrongExceptionCaught);
65 exceptionCaught = false; 65 exceptionCaught = false;
66 try { 66 try {
67 List<int> buffer = new List<int>(10); 67 List<int> buffer = new List<int>(10);
68 client.readList(buffer, 0 , 10); 68 client.readList(buffer, 0 , 10);
69 } catch (SocketIOException ex) { 69 } on SocketIOException catch(ex) {
70 exceptionCaught = true; 70 exceptionCaught = true;
71 } catch (Exception ex) { 71 } on Exception catch (ex) {
72 wrongExceptionCaught = true; 72 wrongExceptionCaught = true;
73 } 73 }
74 Expect.equals(true, exceptionCaught); 74 Expect.equals(true, exceptionCaught);
75 Expect.equals(true, !wrongExceptionCaught); 75 Expect.equals(true, !wrongExceptionCaught);
76 exceptionCaught = false; 76 exceptionCaught = false;
77 try { 77 try {
78 List<int> buffer = new List<int>(10); 78 List<int> buffer = new List<int>(10);
79 client.writeList(buffer, 0, 10); 79 client.writeList(buffer, 0, 10);
80 } catch (SocketIOException ex) { 80 } on SocketIOException catch(ex) {
81 exceptionCaught = true; 81 exceptionCaught = true;
82 } catch (Exception ex) { 82 } on Exception catch (ex) {
83 wrongExceptionCaught = true; 83 wrongExceptionCaught = true;
84 } 84 }
85 Expect.equals(true, exceptionCaught); 85 Expect.equals(true, exceptionCaught);
86 Expect.equals(true, !wrongExceptionCaught); 86 Expect.equals(true, !wrongExceptionCaught);
87 exceptionCaught = false; 87 exceptionCaught = false;
88 try { 88 try {
89 List<int> buffer = new List<int>(42); 89 List<int> buffer = new List<int>(42);
90 input.readInto(buffer, 0, 12); 90 input.readInto(buffer, 0, 12);
91 } catch (SocketIOException ex) { 91 } on SocketIOException catch(ex) {
92 exceptionCaught = true; 92 exceptionCaught = true;
93 } catch (Exception ex) { 93 } on Exception catch (ex) {
94 wrongExceptionCaught = true; 94 wrongExceptionCaught = true;
95 } 95 }
96 Expect.equals(true, exceptionCaught); 96 Expect.equals(true, exceptionCaught);
97 Expect.equals(true, !wrongExceptionCaught); 97 Expect.equals(true, !wrongExceptionCaught);
98 exceptionCaught = false; 98 exceptionCaught = false;
99 try { 99 try {
100 List<int> buffer = new List<int>(42); 100 List<int> buffer = new List<int>(42);
101 output.writeFrom(buffer, 0, 12); 101 output.writeFrom(buffer, 0, 12);
102 } catch (SocketIOException ex) { 102 } on SocketIOException catch(ex) {
103 exceptionCaught = true; 103 exceptionCaught = true;
104 } catch (Exception ex) { 104 } on Exception catch (ex) {
105 wrongExceptionCaught = true; 105 wrongExceptionCaught = true;
106 } 106 }
107 Expect.equals(true, exceptionCaught); 107 Expect.equals(true, exceptionCaught);
108 Expect.equals(true, !wrongExceptionCaught); 108 Expect.equals(true, !wrongExceptionCaught);
109 109
110 server.close(); 110 server.close();
111 }; 111 };
112 } 112 }
113 113
114 static void indexOutOfRangeExceptionTest() { 114 static void indexOutOfRangeExceptionTest() {
115 bool exceptionCaught = false; 115 bool exceptionCaught = false;
116 bool wrongExceptionCaught = false; 116 bool wrongExceptionCaught = false;
117 117
118 ServerSocket server = new ServerSocket(HOST, PORT, 10); 118 ServerSocket server = new ServerSocket(HOST, PORT, 10);
119 Expect.equals(true, server !== null); 119 Expect.equals(true, server !== null);
120 int port = server.port; 120 int port = server.port;
121 Socket client = new Socket(HOST, port); 121 Socket client = new Socket(HOST, port);
122 client.onConnect = () { 122 client.onConnect = () {
123 Expect.equals(true, client !== null); 123 Expect.equals(true, client !== null);
124 try { 124 try {
125 List<int> buffer = new List<int>(10); 125 List<int> buffer = new List<int>(10);
126 client.readList(buffer, -1, 1); 126 client.readList(buffer, -1, 1);
127 } catch (IndexOutOfRangeException ex) { 127 } on IndexOutOfRangeException catch (ex) {
128 exceptionCaught = true; 128 exceptionCaught = true;
129 } catch (Exception ex) { 129 } on Exception catch (ex) {
130 wrongExceptionCaught = true; 130 wrongExceptionCaught = true;
131 } 131 }
132 Expect.equals(true, exceptionCaught); 132 Expect.equals(true, exceptionCaught);
133 Expect.equals(true, !wrongExceptionCaught); 133 Expect.equals(true, !wrongExceptionCaught);
134 exceptionCaught = false; 134 exceptionCaught = false;
135 135
136 try { 136 try {
137 List<int> buffer = new List<int>(10); 137 List<int> buffer = new List<int>(10);
138 client.readList(buffer, 0, -1); 138 client.readList(buffer, 0, -1);
139 } catch (IndexOutOfRangeException ex) { 139 } on IndexOutOfRangeException catch (ex) {
140 exceptionCaught = true; 140 exceptionCaught = true;
141 } catch (Exception ex) { 141 } on Exception catch (ex) {
142 wrongExceptionCaught = true; 142 wrongExceptionCaught = true;
143 } 143 }
144 Expect.equals(true, exceptionCaught); 144 Expect.equals(true, exceptionCaught);
145 Expect.equals(true, !wrongExceptionCaught); 145 Expect.equals(true, !wrongExceptionCaught);
146 exceptionCaught = false; 146 exceptionCaught = false;
147 147
148 try { 148 try {
149 List<int> buffer = new List<int>(10); 149 List<int> buffer = new List<int>(10);
150 client.writeList(buffer, -1, 1); 150 client.writeList(buffer, -1, 1);
151 } catch (IndexOutOfRangeException ex) { 151 } on IndexOutOfRangeException catch (ex) {
152 exceptionCaught = true; 152 exceptionCaught = true;
153 } catch (Exception ex) { 153 } on Exception catch (ex) {
154 wrongExceptionCaught = true; 154 wrongExceptionCaught = true;
155 } 155 }
156 Expect.equals(true, exceptionCaught); 156 Expect.equals(true, exceptionCaught);
157 Expect.equals(true, !wrongExceptionCaught); 157 Expect.equals(true, !wrongExceptionCaught);
158 exceptionCaught = false; 158 exceptionCaught = false;
159 159
160 try { 160 try {
161 List<int> buffer = new List<int>(10); 161 List<int> buffer = new List<int>(10);
162 client.writeList(buffer, 0, -1); 162 client.writeList(buffer, 0, -1);
163 } catch (IndexOutOfRangeException ex) { 163 } on IndexOutOfRangeException catch (ex) {
164 exceptionCaught = true; 164 exceptionCaught = true;
165 } catch (Exception ex) { 165 } on Exception catch (ex) {
166 wrongExceptionCaught = true; 166 wrongExceptionCaught = true;
167 } 167 }
168 Expect.equals(true, exceptionCaught); 168 Expect.equals(true, exceptionCaught);
169 Expect.equals(true, !wrongExceptionCaught); 169 Expect.equals(true, !wrongExceptionCaught);
170 170
171 server.close(); 171 server.close();
172 client.close(); 172 client.close();
173 }; 173 };
174 } 174 }
175 175
(...skipping 23 matching lines...) Expand all
199 indexOutOfRangeExceptionTest(); 199 indexOutOfRangeExceptionTest();
200 unknownHostTest(); 200 unknownHostTest();
201 // TODO(sgjesse): This test seems to fail on the buildbot. 201 // TODO(sgjesse): This test seems to fail on the buildbot.
202 //unresponsiveHostTest(); 202 //unresponsiveHostTest();
203 } 203 }
204 } 204 }
205 205
206 main() { 206 main() {
207 SocketExceptionTest.testMain(); 207 SocketExceptionTest.testMain();
208 } 208 }
OLDNEW
« no previous file with comments | « tests/standalone/io/read_into_const_list_test.dart ('k') | tests/standalone/io/socket_invalid_arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698