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

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

Issue 10829459: Deprecate Math object in corelib in favor of dart:math library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 4 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #import('dart:math');
6
5 #source("../../../runtime/bin/http_parser.dart"); 7 #source("../../../runtime/bin/http_parser.dart");
6 8
7 class HttpParserTest { 9 class HttpParserTest {
8 static void runAllTests() { 10 static void runAllTests() {
9 testParseRequest(); 11 testParseRequest();
10 testParseResponse(); 12 testParseResponse();
11 testParseInvalidRequest(); 13 testParseInvalidRequest();
12 testParseInvalidResponse(); 14 testParseInvalidResponse();
13 } 15 }
14 16
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 bytesReceived = 0; 76 bytesReceived = 0;
75 } 77 }
76 78
77 void testWrite(List<int> requestData, [int chunkSize = -1]) { 79 void testWrite(List<int> requestData, [int chunkSize = -1]) {
78 if (chunkSize == -1) chunkSize = requestData.length; 80 if (chunkSize == -1) chunkSize = requestData.length;
79 reset(); 81 reset();
80 int written = 0; 82 int written = 0;
81 int unparsed; 83 int unparsed;
82 for (int pos = 0; pos < requestData.length; pos += chunkSize) { 84 for (int pos = 0; pos < requestData.length; pos += chunkSize) {
83 int remaining = requestData.length - pos; 85 int remaining = requestData.length - pos;
84 int writeLength = Math.min(chunkSize, remaining); 86 int writeLength = min(chunkSize, remaining);
85 written += writeLength; 87 written += writeLength;
86 int parsed = httpParser.writeList(requestData, pos, writeLength); 88 int parsed = httpParser.writeList(requestData, pos, writeLength);
87 unparsed = writeLength - parsed; 89 unparsed = writeLength - parsed;
88 if (httpParser.upgrade) { 90 if (httpParser.upgrade) {
89 unparsed += requestData.length - written; 91 unparsed += requestData.length - written;
90 break; 92 break;
91 } else { 93 } else {
92 Expect.equals(0, unparsed); 94 Expect.equals(0, unparsed);
93 } 95 }
94 } 96 }
(...skipping 30 matching lines...) Expand all
125 }; 127 };
126 128
127 errorCalled = false; 129 errorCalled = false;
128 } 130 }
129 131
130 void testWrite(List<int> requestData, [int chunkSize = -1]) { 132 void testWrite(List<int> requestData, [int chunkSize = -1]) {
131 if (chunkSize == -1) chunkSize = requestData.length; 133 if (chunkSize == -1) chunkSize = requestData.length;
132 reset(); 134 reset();
133 for (int pos = 0; pos < requestData.length; pos += chunkSize) { 135 for (int pos = 0; pos < requestData.length; pos += chunkSize) {
134 int remaining = requestData.length - pos; 136 int remaining = requestData.length - pos;
135 int writeLength = Math.min(chunkSize, remaining); 137 int writeLength = min(chunkSize, remaining);
136 httpParser.writeList(requestData, pos, writeLength); 138 httpParser.writeList(requestData, pos, writeLength);
137 } 139 }
138 Expect.isTrue(errorCalled); 140 Expect.isTrue(errorCalled);
139 } 141 }
140 142
141 // Test parsing the request three times delivering the data in 143 // Test parsing the request three times delivering the data in
142 // different chunks. 144 // different chunks.
143 List<int> requestData = request.charCodes(); 145 List<int> requestData = request.charCodes();
144 testWrite(requestData); 146 testWrite(requestData);
145 testWrite(requestData, 10); 147 testWrite(requestData, 10);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 bytesReceived = 0; 220 bytesReceived = 0;
219 } 221 }
220 222
221 void testWrite(List<int> requestData, [int chunkSize = -1]) { 223 void testWrite(List<int> requestData, [int chunkSize = -1]) {
222 if (chunkSize == -1) chunkSize = requestData.length; 224 if (chunkSize == -1) chunkSize = requestData.length;
223 reset(); 225 reset();
224 int written = 0; 226 int written = 0;
225 int unparsed; 227 int unparsed;
226 for (int pos = 0; pos < requestData.length; pos += chunkSize) { 228 for (int pos = 0; pos < requestData.length; pos += chunkSize) {
227 int remaining = requestData.length - pos; 229 int remaining = requestData.length - pos;
228 int writeLength = Math.min(chunkSize, remaining); 230 int writeLength = min(chunkSize, remaining);
229 written += writeLength; 231 written += writeLength;
230 int parsed = httpParser.writeList(requestData, pos, writeLength); 232 int parsed = httpParser.writeList(requestData, pos, writeLength);
231 unparsed = writeLength - parsed; 233 unparsed = writeLength - parsed;
232 if (httpParser.upgrade) { 234 if (httpParser.upgrade) {
233 unparsed += requestData.length - written; 235 unparsed += requestData.length - written;
234 break; 236 break;
235 } else { 237 } else {
236 Expect.equals(0, unparsed); 238 Expect.equals(0, unparsed);
237 } 239 }
238 } 240 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 httpParser.error = (e) => errorCalled = true; 274 httpParser.error = (e) => errorCalled = true;
273 275
274 errorCalled = false; 276 errorCalled = false;
275 } 277 }
276 278
277 void testWrite(List<int> requestData, [int chunkSize = -1]) { 279 void testWrite(List<int> requestData, [int chunkSize = -1]) {
278 if (chunkSize == -1) chunkSize = requestData.length; 280 if (chunkSize == -1) chunkSize = requestData.length;
279 reset(); 281 reset();
280 for (int pos = 0; pos < requestData.length; pos += chunkSize) { 282 for (int pos = 0; pos < requestData.length; pos += chunkSize) {
281 int remaining = requestData.length - pos; 283 int remaining = requestData.length - pos;
282 int writeLength = Math.min(chunkSize, remaining); 284 int writeLength = min(chunkSize, remaining);
283 httpParser.writeList(requestData, pos, writeLength); 285 httpParser.writeList(requestData, pos, writeLength);
284 } 286 }
285 if (close) httpParser.connectionClosed(); 287 if (close) httpParser.connectionClosed();
286 Expect.isTrue(errorCalled); 288 Expect.isTrue(errorCalled);
287 } 289 }
288 290
289 // Test parsing the request three times delivering the data in 291 // Test parsing the request three times delivering the data in
290 // different chunks. 292 // different chunks.
291 List<int> responseData = response.charCodes(); 293 List<int> responseData = response.charCodes();
292 testWrite(responseData); 294 testWrite(responseData);
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 0123456789012345678901234567890\r 836 0123456789012345678901234567890\r
835 0\r\n\r\n"""; 837 0\r\n\r\n""";
836 _testParseInvalidResponse(response); 838 _testParseInvalidResponse(response);
837 } 839 }
838 } 840 }
839 841
840 842
841 void main() { 843 void main() {
842 HttpParserTest.runAllTests(); 844 HttpParserTest.runAllTests();
843 } 845 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_headers_test.dart ('k') | tests/standalone/io/http_server_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698