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

Unified Diff: tests/standalone/src/EchoServerStreamTest.dart

Issue 8662038: Refactor some of the duplicated code in the tests using a socket server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/src/EchoServerTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/EchoServerStreamTest.dart
diff --git a/tests/standalone/src/EchoServerStreamTest.dart b/tests/standalone/src/EchoServerStreamTest.dart
index a132f3568b28c6dc2e95ba5fe6295df208dd7697..66ea572bdb27b8ec4a8789fd138d181efe2406c0 100644
--- a/tests/standalone/src/EchoServerStreamTest.dart
+++ b/tests/standalone/src/EchoServerStreamTest.dart
@@ -9,18 +9,11 @@
// VMOptions=--short_socket_write
// VMOptions=--short_socket_read --short_socket_write
-class EchoServerStreamTest {
-
- static void testMain() {
- EchoServerGame echoServerGame = new EchoServerGame.start();
- }
-}
+#source("TestingServer.dart");
class EchoServerGame {
static final MSGSIZE = 10;
- static final SERVERINIT = 0;
- static final SERVERSHUTDOWN = -1;
static final MESSAGES = 100;
static final FIRSTCHAR = 65;
@@ -112,7 +105,7 @@ class EchoServerGame {
dataSent();
}
- _socket = new Socket(EchoServer.HOST, _port);
+ _socket = new Socket(TestingServer.HOST, _port);
if (_socket !== null) {
_socket.connectHandler = connectHandler;
} else {
@@ -125,11 +118,11 @@ class EchoServerGame {
_port = message;
sendData();
});
- _sendPort.send(SERVERINIT, _receivePort.toSendPort());
+ _sendPort.send(TestingServer.INIT, _receivePort.toSendPort());
}
void shutdown() {
- _sendPort.send(SERVERSHUTDOWN, _receivePort.toSendPort());
+ _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort());
_receivePort.close();
}
@@ -141,67 +134,45 @@ class EchoServerGame {
int _messages;
}
-class EchoServer extends Isolate {
-
- static final HOST = "127.0.0.1";
- static final int MSGSIZE = EchoServerGame.MSGSIZE;
- void main() {
+class EchoServer extends TestingServer {
- void connectionHandler() {
- Socket _client;
- InputStream inputStream;
- List<int> buffer = new List<int>(MSGSIZE);
- int offset = 0;
+ static final int MSGSIZE = EchoServerGame.MSGSIZE;
- void dataReceived() {
- SocketOutputStream outputStream;
- int bytesRead;
- outputStream = _client.outputStream;
- bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset);
- if (bytesRead > 0) {
- offset += bytesRead;
- for (int i = 0; i < offset; i++) {
- Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]);
- }
- if (offset == MSGSIZE) {
- outputStream.write(buffer);
- outputStream.close();
- }
+ void connectionHandler() {
+ Socket _client;
+ InputStream inputStream;
+ List<int> buffer = new List<int>(MSGSIZE);
+ int offset = 0;
+
+ void dataReceived() {
+ SocketOutputStream outputStream;
+ int bytesRead;
+ outputStream = _client.outputStream;
+ bytesRead = inputStream.readInto(buffer, offset, MSGSIZE - offset);
+ if (bytesRead > 0) {
+ offset += bytesRead;
+ for (int i = 0; i < offset; i++) {
+ Expect.equals(EchoServerGame.FIRSTCHAR + i, buffer[i]);
+ }
+ if (offset == MSGSIZE) {
+ outputStream.write(buffer);
+ outputStream.close();
}
}
-
- void errorHandler() {
- Expect.fail("Socket error");
- }
-
- _client = _server.accept();
- inputStream = _client.inputStream;
- inputStream.dataHandler = dataReceived;
- _client.errorHandler = errorHandler;
}
- void errorHandlerServer() {
- Expect.fail("Server socket error");
+ void errorHandler() {
+ Expect.fail("Socket error");
}
- this.port.receive((message, SendPort replyTo) {
- if (message == EchoServerGame.SERVERINIT) {
- _server = new ServerSocket(HOST, 0, 10);
- Expect.equals(true, _server !== null);
- _server.connectionHandler = connectionHandler;
- _server.errorHandler = errorHandlerServer;
- replyTo.send(_server.port, null);
- } else if (message == EchoServerGame.SERVERSHUTDOWN) {
- _server.close();
- this.port.close();
- }
- });
+ _client = _server.accept();
+ inputStream = _client.inputStream;
+ inputStream.dataHandler = dataReceived;
+ _client.errorHandler = errorHandler;
}
-
- ServerSocket _server;
}
main() {
- EchoServerStreamTest.testMain();
+ EchoServerGame echoServerGame = new EchoServerGame.start();
}
« no previous file with comments | « no previous file | tests/standalone/src/EchoServerTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698