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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
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 // OtherResources=readline_test1.dat 5 // OtherResources=readline_test1.dat
6 // 6 //
7 // VMOptions= 7 // VMOptions=
8 // VMOptions=--short_socket_read 8 // VMOptions=--short_socket_read
9 // VMOptions=--short_socket_write 9 // VMOptions=--short_socket_write
10 // VMOptions=--short_socket_read --short_socket_write 10 // VMOptions=--short_socket_read --short_socket_write
11 11
12 library ServerTest; 12 library ServerTest;
13 13
14 import "package:expect/expect.dart"; 14 import "package:expect/expect.dart";
15 import "package:async_helper/async_helper.dart"; 15 import "package:async_helper/async_helper.dart";
16 import "dart:async"; 16 import "dart:async";
17 import "dart:io"; 17 import "dart:io";
18 import "dart:isolate"; 18 import "dart:isolate";
19 part "testing_server.dart"; 19 part "testing_server.dart";
20 20
21
22 String getDataFilename(String path) => 21 String getDataFilename(String path) =>
23 Platform.script.resolve(path).toFilePath(); 22 Platform.script.resolve(path).toFilePath();
24 23
25
26 bool compareFileContent(String fileName1, String fileName2) { 24 bool compareFileContent(String fileName1, String fileName2) {
27 var contents1 = new File(fileName1).readAsStringSync(); 25 var contents1 = new File(fileName1).readAsStringSync();
28 var contents2 = new File(fileName2).readAsStringSync(); 26 var contents2 = new File(fileName2).readAsStringSync();
29 return contents1 == contents2; 27 return contents1 == contents2;
30 } 28 }
31 29
32
33 // This test does: 30 // This test does:
34 // 1. Opens a socket to the testing server. 31 // 1. Opens a socket to the testing server.
35 // 2. Pipes the content of a file to that sockets input stream. 32 // 2. Pipes the content of a file to that sockets input stream.
36 // 3. Creates a temp file. 33 // 3. Creates a temp file.
37 // 4. Pipes the socket output stream to the temp file. 34 // 4. Pipes the socket output stream to the temp file.
38 // 5. Expects the original file and the temp file to be equal. 35 // 5. Expects the original file and the temp file to be equal.
39 class PipeServerGame { 36 class PipeServerGame {
40
41 int count = 0; 37 int count = 0;
42 38
43 PipeServerGame.start() 39 PipeServerGame.start() : _messages = 0 {
44 : _messages = 0 {
45 initialize(); 40 initialize();
46 } 41 }
47 42
48 void runTest() { 43 void runTest() {
49
50 void connectHandler() { 44 void connectHandler() {
51 String srcFileName = 45 String srcFileName = getDataFilename("readline_test1.dat");
52 getDataFilename("readline_test1.dat");
53 Stream fileInput = new File(srcFileName).openRead(); 46 Stream fileInput = new File(srcFileName).openRead();
54 fileInput.pipe(_socket).then((_) { 47 fileInput.pipe(_socket).then((_) {
55 var tempDir = Directory.systemTemp.createTempSync('dart_pipe_server'); 48 var tempDir = Directory.systemTemp.createTempSync('dart_pipe_server');
56 var dstFileName = tempDir.path + "/readline_test1.dat"; 49 var dstFileName = tempDir.path + "/readline_test1.dat";
57 var dstFile = new File(dstFileName); 50 var dstFile = new File(dstFileName);
58 dstFile.createSync(); 51 dstFile.createSync();
59 var fileOutput = dstFile.openWrite(); 52 var fileOutput = dstFile.openWrite();
60 _socket.pipe(fileOutput).then((_) { 53 _socket.pipe(fileOutput).then((_) {
61 // Check that the resulting file is equal to the initial 54 // Check that the resulting file is equal to the initial
62 // file. 55 // file.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 _closeSendPort.send(null); 89 _closeSendPort.send(null);
97 asyncEnd(); 90 asyncEnd();
98 } 91 }
99 92
100 int _port; 93 int _port;
101 SendPort _closeSendPort; 94 SendPort _closeSendPort;
102 Socket _socket; 95 Socket _socket;
103 int _messages; 96 int _messages;
104 } 97 }
105 98
106
107 void startPipeServer(SendPort replyPort) { 99 void startPipeServer(SendPort replyPort) {
108 var server = new PipeServer(); 100 var server = new PipeServer();
109 server.init().then((port) { 101 server.init().then((port) {
110 replyPort.send([port, server.closeSendPort]); 102 replyPort.send([port, server.closeSendPort]);
111 }); 103 });
112 } 104 }
113 105
114
115 // The testing server will simply pipe each connecting sockets input 106 // The testing server will simply pipe each connecting sockets input
116 // stream to its output stream. 107 // stream to its output stream.
117 class PipeServer extends TestingServer { 108 class PipeServer extends TestingServer {
118 void onConnection(Socket connection) { 109 void onConnection(Socket connection) {
119 connection.pipe(connection); 110 connection.pipe(connection);
120 } 111 }
121 } 112 }
122 113
123
124 main() { 114 main() {
125 asyncStart(); 115 asyncStart();
126 PipeServerGame echoServerGame = new PipeServerGame.start(); 116 PipeServerGame echoServerGame = new PipeServerGame.start();
127 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698