| 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 import "package:test/test.dart"; | 8 import "package:test/test.dart"; |
| 9 import "package:mime/mime.dart"; | 9 import "package:mime/mime.dart"; |
| 10 | 10 |
| 11 void _writeInChunks( | 11 void _writeInChunks( |
| 12 List<int> data, int chunkSize, StreamController<List<int>> controller) { | 12 List<int> data, int chunkSize, StreamController<List<int>> controller) { |
| 13 if (chunkSize == -1) chunkSize = data.length; | 13 if (chunkSize == -1) chunkSize = data.length; |
| 14 | 14 |
| 15 int written = 0; | |
| 16 for (int pos = 0; pos < data.length; pos += chunkSize) { | 15 for (int pos = 0; pos < data.length; pos += chunkSize) { |
| 17 int remaining = data.length - pos; | 16 int remaining = data.length - pos; |
| 18 int writeLength = min(chunkSize, remaining); | 17 int writeLength = min(chunkSize, remaining); |
| 19 controller.add(data.sublist(pos, pos + writeLength)); | 18 controller.add(data.sublist(pos, pos + writeLength)); |
| 20 written += writeLength; | |
| 21 } | 19 } |
| 22 controller.close(); | 20 controller.close(); |
| 23 } | 21 } |
| 24 | 22 |
| 25 enum TestMode { IMMEDIATE_LISTEN, DELAY_LISTEN, PAUSE_RESUME } | 23 enum TestMode { IMMEDIATE_LISTEN, DELAY_LISTEN, PAUSE_RESUME } |
| 26 | 24 |
| 27 void _runParseTest(String message, String boundary, TestMode mode, | 25 void _runParseTest(String message, String boundary, TestMode mode, |
| 28 [List<Map> expectedHeaders, List expectedParts, bool expectError = false]) { | 26 [List<Map> expectedHeaders, List expectedParts, bool expectError = false]) { |
| 29 Future testWrite(List<int> data, [int chunkSize = -1]) { | 27 Future testWrite(List<int> data, [int chunkSize = -1]) { |
| 30 StreamController controller = new StreamController(sync: true); | 28 StreamController controller = new StreamController(sync: true); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 return completer.future; | 89 return completer.future; |
| 92 } | 90 } |
| 93 | 91 |
| 94 Future testFirstPartOnly(List<int> data, [int chunkSize = -1]) { | 92 Future testFirstPartOnly(List<int> data, [int chunkSize = -1]) { |
| 95 var completer = new Completer(); | 93 var completer = new Completer(); |
| 96 var controller = new StreamController(sync: true); | 94 var controller = new StreamController(sync: true); |
| 97 | 95 |
| 98 var stream = | 96 var stream = |
| 99 controller.stream.transform(new MimeMultipartTransformer(boundary)); | 97 controller.stream.transform(new MimeMultipartTransformer(boundary)); |
| 100 | 98 |
| 101 var subscription; | 99 stream.first.then((multipart) { |
| 102 subscription = stream.first.then((multipart) { | |
| 103 if (expectedHeaders != null) { | 100 if (expectedHeaders != null) { |
| 104 expect(multipart.headers, equals(expectedHeaders[0])); | 101 expect(multipart.headers, equals(expectedHeaders[0])); |
| 105 } | 102 } |
| 106 return (multipart.fold([], (b, d) => b..addAll(d)).then((data) { | 103 return (multipart.fold([], (b, d) => b..addAll(d)).then((data) { |
| 107 if (expectedParts != null && expectedParts[0] != null) { | 104 if (expectedParts != null && expectedParts[0] != null) { |
| 108 expect(data, equals(expectedParts[0].codeUnits)); | 105 expect(data, equals(expectedParts[0].codeUnits)); |
| 109 } | 106 } |
| 110 })); | 107 })); |
| 111 }).then((_) { | 108 }).then((_) { |
| 112 completer.complete(); | 109 completer.complete(); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 \r | 444 \r |
| 448 Body2\r | 445 Body2\r |
| 449 --xxx\r\n"""; | 446 --xxx\r\n"""; |
| 450 _testParse(message, "xxx", null, [null, null], true); | 447 _testParse(message, "xxx", null, [null, null], true); |
| 451 } | 448 } |
| 452 | 449 |
| 453 void main() { | 450 void main() { |
| 454 _testParseValid(); | 451 _testParseValid(); |
| 455 _testParseInvalid(); | 452 _testParseInvalid(); |
| 456 } | 453 } |
| OLD | NEW |