| OLD | NEW |
| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 void testSimpleReadWrite() { | 135 void testSimpleReadWrite() { |
| 136 // This test creates a server and a client connects. The client then | 136 // This test creates a server and a client connects. The client then |
| 137 // writes and the server echos. When the server has finished its | 137 // writes and the server echos. When the server has finished its |
| 138 // echo it half-closes. When the client gets the close event is | 138 // echo it half-closes. When the client gets the close event is |
| 139 // closes fully. | 139 // closes fully. |
| 140 ReceivePort port = new ReceivePort(); | 140 ReceivePort port = new ReceivePort(); |
| 141 | 141 |
| 142 const messageSize = 1000; | 142 const messageSize = 1000; |
| 143 | 143 |
| 144 List<int> createTestData() { | 144 List<int> createTestData() { |
| 145 List<int> data = new List.fixedLength(messageSize); | 145 List<int> data = new List<int>(messageSize); |
| 146 for (int i = 0; i < messageSize; i++) { | 146 for (int i = 0; i < messageSize; i++) { |
| 147 data[i] = i & 0xff; | 147 data[i] = i & 0xff; |
| 148 } | 148 } |
| 149 return data; | 149 return data; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void verifyTestData(List<int> data) { | 152 void verifyTestData(List<int> data) { |
| 153 Expect.equals(messageSize, data.length); | 153 Expect.equals(messageSize, data.length); |
| 154 List<int> expected = createTestData(); | 154 List<int> expected = createTestData(); |
| 155 for (int i = 0; i < messageSize; i++) { | 155 for (int i = 0; i < messageSize; i++) { |
| 156 Expect.equals(expected[i], data[i]); | 156 Expect.equals(expected[i], data[i]); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) { | 160 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) { |
| 161 server.listen((client) { | 161 server.listen((client) { |
| 162 int bytesRead = 0; | 162 int bytesRead = 0; |
| 163 int bytesWritten = 0; | 163 int bytesWritten = 0; |
| 164 List<int> data = new List.fixedLength(messageSize); | 164 List<int> data = new List<int>(messageSize); |
| 165 | 165 |
| 166 client.listen( | 166 client.listen( |
| 167 (buffer) { | 167 (buffer) { |
| 168 Expect.isTrue(bytesWritten == 0); | 168 Expect.isTrue(bytesWritten == 0); |
| 169 data.setRange(bytesRead, buffer.length, buffer); | 169 data.setRange(bytesRead, buffer.length, buffer); |
| 170 bytesRead += buffer.length; | 170 bytesRead += buffer.length; |
| 171 if (bytesRead == data.length) { | 171 if (bytesRead == data.length) { |
| 172 verifyTestData(data); | 172 verifyTestData(data); |
| 173 client.add(data); | 173 client.add(data); |
| 174 client.close(); | 174 client.close(); |
| 175 } | 175 } |
| 176 }, | 176 }, |
| 177 onDone: () { | 177 onDone: () { |
| 178 server.close(); | 178 server.close(); |
| 179 }); | 179 }); |
| 180 }); | 180 }); |
| 181 | 181 |
| 182 SecureSocket.connect(HOST_NAME, server.port).then((socket) { | 182 SecureSocket.connect(HOST_NAME, server.port).then((socket) { |
| 183 int bytesRead = 0; | 183 int bytesRead = 0; |
| 184 int bytesWritten = 0; | 184 int bytesWritten = 0; |
| 185 List<int> dataSent = createTestData(); | 185 List<int> dataSent = createTestData(); |
| 186 List<int> dataReceived = new List<int>.fixedLength(dataSent.length); | 186 List<int> dataReceived = new List<int>(dataSent.length); |
| 187 socket.add(dataSent); | 187 socket.add(dataSent); |
| 188 socket.close(); // Can also be delayed. | 188 socket.close(); // Can also be delayed. |
| 189 socket.listen( | 189 socket.listen( |
| 190 (List<int> buffer) { | 190 (List<int> buffer) { |
| 191 dataReceived.setRange(bytesRead, buffer.length, buffer); | 191 dataReceived.setRange(bytesRead, buffer.length, buffer); |
| 192 bytesRead += buffer.length; | 192 bytesRead += buffer.length; |
| 193 }, | 193 }, |
| 194 onDone: () { | 194 onDone: () { |
| 195 verifyTestData(dataReceived); | 195 verifyTestData(dataReceived); |
| 196 socket.close(); | 196 socket.close(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 209 testArguments(); | 209 testArguments(); |
| 210 testSimpleBind(); | 210 testSimpleBind(); |
| 211 testInvalidBind(); | 211 testInvalidBind(); |
| 212 testSimpleConnect(CERTIFICATE); | 212 testSimpleConnect(CERTIFICATE); |
| 213 testSimpleConnect("CN=localhost"); | 213 testSimpleConnect("CN=localhost"); |
| 214 testSimpleConnectFail("not_a_nickname"); | 214 testSimpleConnectFail("not_a_nickname"); |
| 215 testSimpleConnectFail("CN=notARealDistinguishedName"); | 215 testSimpleConnectFail("CN=notARealDistinguishedName"); |
| 216 testServerListenAfterConnect(); | 216 testServerListenAfterConnect(); |
| 217 testSimpleReadWrite(); | 217 testSimpleReadWrite(); |
| 218 } | 218 } |
| OLD | NEW |