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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:math'; | 6 import 'dart:math'; |
7 | 7 |
8 part '../../../sdk/lib/io/io_sink.dart'; | 8 part '../../../sdk/lib/io/io_sink.dart'; |
9 part "../../../sdk/lib/io/http.dart"; | 9 part "../../../sdk/lib/io/http.dart"; |
10 part "../../../sdk/lib/io/http_impl.dart"; | 10 part "../../../sdk/lib/io/http_impl.dart"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 partCount = 0; | 61 partCount = 0; |
62 headers = new Map(); | 62 headers = new Map(); |
63 currentPart = null; | 63 currentPart = null; |
64 lastPartCalled = false; | 64 lastPartCalled = false; |
65 } | 65 } |
66 | 66 |
67 void testWrite(List<int> data, [int chunkSize = -1]) { | 67 void testWrite(List<int> data, [int chunkSize = -1]) { |
68 if (chunkSize == -1) chunkSize = data.length; | 68 if (chunkSize == -1) chunkSize = data.length; |
69 reset(); | 69 reset(); |
70 int written = 0; | 70 int written = 0; |
71 int unparsed; | |
72 for (int pos = 0; pos < data.length; pos += chunkSize) { | 71 for (int pos = 0; pos < data.length; pos += chunkSize) { |
73 int remaining = data.length - pos; | 72 int remaining = data.length - pos; |
74 int writeLength = min(chunkSize, remaining); | 73 int writeLength = min(chunkSize, remaining); |
| 74 int parsed = |
| 75 parser.update(data.sublist(pos, pos + writeLength), 0, writeLength); |
| 76 Expect.equals(writeLength, parsed); |
75 written += writeLength; | 77 written += writeLength; |
76 int parsed = | |
77 parser.update(data.getRange(pos, writeLength), 0, writeLength); | |
78 unparsed = writeLength - parsed; | |
79 Expect.equals(0, unparsed); | |
80 } | 78 } |
81 Expect.isTrue(lastPartCalled); | 79 Expect.isTrue(lastPartCalled); |
82 } | 80 } |
83 | 81 |
84 // Test parsing the data three times delivering the data in | 82 // Test parsing the data three times delivering the data in |
85 // different chunks. | 83 // different chunks. |
86 List<int> data = message.codeUnits; | 84 List<int> data = message.codeUnits; |
87 testWrite(data); | 85 testWrite(data); |
88 testWrite(data, 10); | 86 testWrite(data, 10); |
89 testWrite(data, 2); | 87 testWrite(data, 2); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 \r | 334 \r |
337 Body2\r | 335 Body2\r |
338 --xxx\r\n"""; | 336 --xxx\r\n"""; |
339 Expect.throws(() => testParse(message, "xxx", null, [null, null])); | 337 Expect.throws(() => testParse(message, "xxx", null, [null, null])); |
340 } | 338 } |
341 | 339 |
342 void main() { | 340 void main() { |
343 testParseValid(); | 341 testParseValid(); |
344 testParseInvalid(); | 342 testParseInvalid(); |
345 } | 343 } |
OLD | NEW |