Index: tests/standalone/io/tls_server_stream_test.dart |
diff --git a/tests/standalone/io/tls_server_test.dart b/tests/standalone/io/tls_server_stream_test.dart |
similarity index 58% |
copy from tests/standalone/io/tls_server_test.dart |
copy to tests/standalone/io/tls_server_stream_test.dart |
index 372b114cb3f85c5e7826adcbd80b59ee172d21c2..ffed889751af877cdb1a23c851cd236562f78b34 100644 |
--- a/tests/standalone/io/tls_server_test.dart |
+++ b/tests/standalone/io/tls_server_stream_test.dart |
@@ -4,21 +4,17 @@ |
import "dart:io"; |
-const SERVER_ADDRESS = "127.0.0.1"; |
-const HOST_NAME = "localhost"; |
+const CLIENT_NAMES = const ['able', 'baker', 'camera', 'donut', 'echo']; |
+const HOST = "127.0.0.1"; |
class TlsTestServer { |
void onConnection(Socket connection) { |
- connection.onConnect = () { |
- numConnections++; |
- }; |
- connection.onData = () { |
- var data = connection.read(); |
- var received = new String.fromCharCodes(data); |
+ var input = connection.inputStream; |
+ input.onData = () { |
+ var received = new String.fromCharCodes(input.read()); |
Expect.isTrue(received.contains("Hello from client ")); |
- string name = received.substring(received.indexOf("client ") + 7); |
- var reply_bytes = "Welcome, client $name".charCodes; |
- connection.writeList(reply_bytes, 0, reply_bytes.length); |
+ String name = received.substring(received.indexOf("client ") + 7); |
+ connection.outputStream.write("Welcome, client $name".charCodes); |
}; |
} |
@@ -27,8 +23,8 @@ class TlsTestServer { |
} |
int start() { |
- server = new TlsServerSocket(SERVER_ADDRESS, 0, 10, "CN=$HOST_NAME"); |
- Expect.isNotNull(server); |
+ server = new TlsServerSocket(HOST, 8080, 10, "CN=localhost"); |
+ Expect.equals(true, server != null); |
server.onConnection = onConnection; |
server.onError = errorHandlerServer; |
return server.port; |
@@ -38,29 +34,20 @@ class TlsTestServer { |
server.close(); |
} |
- int numConnections = 0; |
TlsServerSocket server; |
} |
class TlsTestClient { |
TlsTestClient(int this.port, String this.name) { |
- socket = new TlsSocket(HOST_NAME, port); |
- socket.onConnect = this.onConnect; |
- socket.onData = this.onData; |
- reply = ""; |
- } |
- |
- void onConnect() { |
+ socket = new TlsSocket("localhost", port); |
numRequests++; |
- var request_bytes = |
- "Hello from client $name".charCodes; |
- socket.writeList(request_bytes, 0, request_bytes.length); |
+ socket.outputStream.write("Hello from client $name".charCodes); |
+ socket.inputStream.onData = this.onData; |
+ reply = ""; |
} |
void onData() { |
- var data = socket.read(); |
- var received = new String.fromCharCodes(data); |
- reply = reply.concat(received); |
+ reply = reply.concat(new String.fromCharCodes(socket.inputStream.read())); |
if (reply.contains("Welcome") && reply.contains(name)) { |
done(); |
} |
@@ -68,7 +55,7 @@ class TlsTestClient { |
void done() { |
Expect.equals("Welcome, client $name", reply); |
- socket.close(true); |
+ socket.outputStream.close(); |
numReplies++; |
if (numReplies == CLIENT_NAMES.length) { |
Expect.equals(numRequests, numReplies); |
@@ -87,19 +74,16 @@ class TlsTestClient { |
Function EndTest; |
-const CLIENT_NAMES = const ['able', 'baker', 'camera', 'donut', 'echo']; |
- |
void main() { |
Path scriptDir = new Path.fromNative(new Options().script).directoryPath; |
- Path certificateDatabase = scriptDir.append('pkcert'); |
+ Path certificateDatabase = scriptDir.append('pkcert_dev/'); |
TlsSocket.setCertificateDatabase(certificateDatabase.toNativePath(), |
- 'dartdart'); |
+ "dartdart"); |
var server = new TlsTestServer(); |
int port = server.start(); |
EndTest = () { |
- Expect.equals(CLIENT_NAMES.length, server.numConnections); |
server.stop(); |
}; |