| OLD | NEW |
| 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'; | 5 import 'dart:math'; |
| 6 | 6 |
| 7 part "../../../sdk/lib/io/http_parser.dart"; | 7 part "../../../sdk/lib/io/http_parser.dart"; |
| 8 part "../../../sdk/lib/io/mime_multipart_parser.dart"; | 8 part "../../../sdk/lib/io/mime_multipart_parser.dart"; |
| 9 | 9 |
| 10 void testParse(String message, | 10 void testParse(String message, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 parser.partDataReceived = (List<int> data) { | 35 parser.partDataReceived = (List<int> data) { |
| 36 if (currentPart == null) currentPart = new List<int>(); | 36 if (currentPart == null) currentPart = new List<int>(); |
| 37 currentPart.addAll(data); | 37 currentPart.addAll(data); |
| 38 }; | 38 }; |
| 39 parser.partEnd = (lastPart) { | 39 parser.partEnd = (lastPart) { |
| 40 Expect.isFalse(lastPartCalled); | 40 Expect.isFalse(lastPartCalled); |
| 41 lastPartCalled = lastPart; | 41 lastPartCalled = lastPart; |
| 42 if (expectedParts[partCount] != null) { | 42 if (expectedParts[partCount] != null) { |
| 43 List<int> expectedPart; | 43 List<int> expectedPart; |
| 44 if (expectedParts[partCount] is String) { | 44 if (expectedParts[partCount] is String) { |
| 45 expectedPart = expectedParts[partCount].charCodes; | 45 expectedPart = expectedParts[partCount].codeUnits; |
| 46 } else { | 46 } else { |
| 47 expectedPart = expectedParts[partCount]; | 47 expectedPart = expectedParts[partCount]; |
| 48 } | 48 } |
| 49 Expect.listEquals(expectedPart, currentPart); | 49 Expect.listEquals(expectedPart, currentPart); |
| 50 } | 50 } |
| 51 currentPart = null; | 51 currentPart = null; |
| 52 partCount++; | 52 partCount++; |
| 53 if (lastPart) Expect.equals(expectedParts.length, partCount); | 53 if (lastPart) Expect.equals(expectedParts.length, partCount); |
| 54 }; | 54 }; |
| 55 | 55 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 71 int parsed = | 71 int parsed = |
| 72 parser.update(data.getRange(pos, writeLength), 0, writeLength); | 72 parser.update(data.getRange(pos, writeLength), 0, writeLength); |
| 73 unparsed = writeLength - parsed; | 73 unparsed = writeLength - parsed; |
| 74 Expect.equals(0, unparsed); | 74 Expect.equals(0, unparsed); |
| 75 } | 75 } |
| 76 Expect.isTrue(lastPartCalled); | 76 Expect.isTrue(lastPartCalled); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Test parsing the data three times delivering the data in | 79 // Test parsing the data three times delivering the data in |
| 80 // different chunks. | 80 // different chunks. |
| 81 List<int> data = message.charCodes; | 81 List<int> data = message.codeUnits; |
| 82 testWrite(data); | 82 testWrite(data); |
| 83 testWrite(data, 10); | 83 testWrite(data, 10); |
| 84 testWrite(data, 2); | 84 testWrite(data, 2); |
| 85 testWrite(data, 1); | 85 testWrite(data, 1); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void testParseValid() { | 88 void testParseValid() { |
| 89 String message; | 89 String message; |
| 90 Map headers; | 90 Map headers; |
| 91 Map headers1; | 91 Map headers1; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 \r | 331 \r |
| 332 Body2\r | 332 Body2\r |
| 333 --xxx\r\n"""; | 333 --xxx\r\n"""; |
| 334 Expect.throws(() => testParse(message, "xxx", null, [null, null])); | 334 Expect.throws(() => testParse(message, "xxx", null, [null, null])); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void main() { | 337 void main() { |
| 338 testParseValid(); | 338 testParseValid(); |
| 339 testParseInvalid(); | 339 testParseInvalid(); |
| 340 } | 340 } |
| OLD | NEW |