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

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

Issue 12328104: Change new List(n) to return fixed length list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head. Created 7 years, 9 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) 2013, 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "dart:async"; 10 import "dart:async";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 void testSimpleReadWrite() { 136 void testSimpleReadWrite() {
137 // This test creates a server and a client connects. The client then 137 // This test creates a server and a client connects. The client then
138 // writes and the server echos. When the server has finished its 138 // writes and the server echos. When the server has finished its
139 // echo it half-closes. When the client gets the close event is 139 // echo it half-closes. When the client gets the close event is
140 // closes fully. 140 // closes fully.
141 ReceivePort port = new ReceivePort(); 141 ReceivePort port = new ReceivePort();
142 142
143 const messageSize = 1000; 143 const messageSize = 1000;
144 144
145 List<int> createTestData() { 145 List<int> createTestData() {
146 List<int> data = new List.fixedLength(messageSize); 146 List<int> data = new List<int>(messageSize);
147 for (int i = 0; i < messageSize; i++) { 147 for (int i = 0; i < messageSize; i++) {
148 data[i] = i & 0xff; 148 data[i] = i & 0xff;
149 } 149 }
150 return data; 150 return data;
151 } 151 }
152 152
153 void verifyTestData(List<int> data) { 153 void verifyTestData(List<int> data) {
154 Expect.equals(messageSize, data.length); 154 Expect.equals(messageSize, data.length);
155 List<int> expected = createTestData(); 155 List<int> expected = createTestData();
156 for (int i = 0; i < messageSize; i++) { 156 for (int i = 0; i < messageSize; i++) {
157 Expect.equals(expected[i], data[i]); 157 Expect.equals(expected[i], data[i]);
158 } 158 }
159 } 159 }
160 160
161 RawSecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) { 161 RawSecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) {
162 server.listen((client) { 162 server.listen((client) {
163 int bytesRead = 0; 163 int bytesRead = 0;
164 int bytesWritten = 0; 164 int bytesWritten = 0;
165 List<int> data = new List.fixedLength(messageSize); 165 List<int> data = new List<int>(messageSize);
166 166
167 client.writeEventsEnabled = false; 167 client.writeEventsEnabled = false;
168 client.listen((event) { 168 client.listen((event) {
169 switch (event) { 169 switch (event) {
170 case RawSocketEvent.READ: 170 case RawSocketEvent.READ:
171 Expect.isTrue(bytesWritten == 0); 171 Expect.isTrue(bytesWritten == 0);
172 Expect.isTrue(client.available() > 0); 172 Expect.isTrue(client.available() > 0);
173 var buffer = client.read(); 173 var buffer = client.read();
174 if (buffer != null) { 174 if (buffer != null) {
175 data.setRange(bytesRead, buffer.length, buffer); 175 data.setRange(bytesRead, buffer.length, buffer);
(...skipping 29 matching lines...) Expand all
205 break; 205 break;
206 default: throw "Unexpected event $event"; 206 default: throw "Unexpected event $event";
207 } 207 }
208 }); 208 });
209 }); 209 });
210 210
211 RawSecureSocket.connect(HOST_NAME, server.port).then((socket) { 211 RawSecureSocket.connect(HOST_NAME, server.port).then((socket) {
212 int bytesRead = 0; 212 int bytesRead = 0;
213 int bytesWritten = 0; 213 int bytesWritten = 0;
214 List<int> dataSent = createTestData(); 214 List<int> dataSent = createTestData();
215 List<int> dataReceived = new List<int>.fixedLength(dataSent.length); 215 List<int> dataReceived = new List<int>(dataSent.length);
216 socket.listen((event) { 216 socket.listen((event) {
217 switch (event) { 217 switch (event) {
218 case RawSocketEvent.READ: 218 case RawSocketEvent.READ:
219 Expect.isTrue(socket.available() > 0); 219 Expect.isTrue(socket.available() > 0);
220 var buffer = socket.read(); 220 var buffer = socket.read();
221 if (buffer != null) { 221 if (buffer != null) {
222 dataReceived.setRange(bytesRead, buffer.length, buffer); 222 dataReceived.setRange(bytesRead, buffer.length, buffer);
223 bytesRead += buffer.length; 223 bytesRead += buffer.length;
224 } 224 }
225 break; 225 break;
(...skipping 27 matching lines...) Expand all
253 testArguments(); 253 testArguments();
254 testSimpleBind(); 254 testSimpleBind();
255 testInvalidBind(); 255 testInvalidBind();
256 testSimpleConnect(CERTIFICATE); 256 testSimpleConnect(CERTIFICATE);
257 testSimpleConnect("CN=localhost"); 257 testSimpleConnect("CN=localhost");
258 testSimpleConnectFail("not_a_nickname"); 258 testSimpleConnectFail("not_a_nickname");
259 testSimpleConnectFail("CN=notARealDistinguishedName"); 259 testSimpleConnectFail("CN=notARealDistinguishedName");
260 testServerListenAfterConnect(); 260 testServerListenAfterConnect();
261 testSimpleReadWrite(); 261 testSimpleReadWrite();
262 } 262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698