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

Unified Diff: tests/standalone/io/regress_7097_test.dart

Issue 11447013: Correctly handle optional length in HTTP output stream writeFrom (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/regress_7097_test.dart
diff --git a/tests/standalone/io/regress_7097_test.dart b/tests/standalone/io/regress_7097_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..28b0e9f0e8dd0a9213172f943d1fb4fe569b3159
--- /dev/null
+++ b/tests/standalone/io/regress_7097_test.dart
@@ -0,0 +1,81 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+import 'dart:uri';
+
+void main() {
+ var client = new HttpClient();
+ var server = new HttpServer();
+
+ var count = 0;
+ server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
+ List<int> data = [];
+ request.inputStream.onData = () {
+ data.addAll(request.inputStream.read());
+ };
+ request.inputStream.onClosed = () {
+ count++;
+ Expect.equals(count, data.length);
+ switch (count - 1) {
+ case 0:
+ response.outputStream.writeFrom([65, 66, 67], 1, 1);
+ break;
+ case 1:
+ response.outputStream.writeFrom([65, 66, 67], 1);
+ break;
+ case 2:
+ response.outputStream.writeFrom([65, 66, 67]);
+ break;
+ default:
+ Expect.fail("Unexpected state");
+ }
+ response.outputStream.close();
+ };
+ };
+ server.listen('127.0.0.1', 0);
+
+ Future makeRequest(int n) {
+ var completer = new Completer();
+ var url = new Uri.fromString("http://localhost:${server.port}");
+ var connection = client.openUrl("POST", url);
+ connection.onRequest = (HttpClientRequest request) {
+ request.contentLength = n + 1;
+ switch (n) {
+ case 0:
+ request.outputStream.writeFrom([65, 66, 67], 1, 1);
+ break;
+ case 1:
+ request.outputStream.writeFrom([65, 66, 67], 1);
+ break;
+ case 2:
+ request.outputStream.writeFrom([65, 66, 67]);
+ break;
+ default:
+ Expect.fail("Unexpected state");
+ }
+ request.outputStream.close();
+ };
+ connection.onResponse = (HttpClientResponse response) {
+ List<int> data = [];
+ response.inputStream.onData = () {
+ data.addAll(response.inputStream.read());
+ };
+ response.inputStream.onClosed = () {
+ Expect.equals(count, data.length);
+ completer.complete(null);
+ };
+ };
+ return completer.future;
+ }
+
+ makeRequest(0).then((_) {
+ makeRequest(1).then((_) {
+ makeRequest(2).then((_) {
+ client.shutdown();
+ server.close();
+ });
+ });
+ });
+}
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698