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

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

Issue 10441078: Add test that passes invalid arguments to socket methods and fix (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: tests/standalone/io/socket_invalid_arguments_test.dart
diff --git a/tests/standalone/io/socket_invalid_arguments_test.dart b/tests/standalone/io/socket_invalid_arguments_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4a3d0a6c4c10f69c7f9441d9c359ac039c4385c5
--- /dev/null
+++ b/tests/standalone/io/socket_invalid_arguments_test.dart
@@ -0,0 +1,71 @@
+// 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");
+
+class NotAnInteger {
+ operator==(other) => other == 1;
+ operator<(other) => other > 1;
+ operator+(other) => 1;
+}
+
+class NotAList {
+ get length() => 10;
+ operator[](index) => 1;
+}
+
+testSocketCreation(host, port) {
+ var s = new Socket(host, port);
+ s.onError = (e) => null;
+ s.onConnect = () => Expect.fail("Shouldn't get connected");
+}
+
+testReadList(buffer, offset, length) {
+ var server = new ServerSocket("127.0.0.1", 0, 5);
+ var s = new Socket("127.0.0.1", server.port);
+ s.onConnect = () {
+ try { s.readList(buffer, offset, length); } catch (var e) {}
+ s.close();
+ };
+ s.onError = (e) => null;
+}
+
+testWriteList(buffer, offset, length) {
+ var server = new ServerSocket("127.0.0.1", 0, 5);
+ var s = new Socket("127.0.0.1", server.port);
+ s.onConnect = () {
+ try { s.writeList(buffer, offset, length); } catch (var e) {}
+ s.close();
+ };
+ s.onError = (e) => null;
+}
+
+testServerSocketCreation(address, port, backlog) {
+ var server;
+ try {
+ server = new ServerSocket(address, port, backlog);
+ server.onError = (e) => null;
+ server.onConnection = (c) => Expect.fail("Shouldn't get connection");
+ } catch (var e) {
+ // ignore
+ }
+}
+
+main() {
+ testSocketCreation(123, 123);
+ testSocketCreation("string", null);
+ testSocketCreation(null, null);
+ testReadList(null, 123, 123);
+ testReadList(new NotAList(), 1, 1);
+ testReadList([1, 2, 3], new NotAnInteger(), new NotAnInteger());
+ testReadList([1, 2, 3], 1, new NotAnInteger());
+ testWriteList(null, 123, 123);
+ testWriteList(new NotAList(), 1, 1);
+ testWriteList([1, 2, 3], new NotAnInteger(), new NotAnInteger());
+ testWriteList([1, 2, 3], 1, new NotAnInteger());
+ testWriteList([1, 2, 3], new NotAnInteger(), 1);
+ testServerSocketCreation(123, 123, 123);
+ testServerSocketCreation("string", null, null);
+ testServerSocketCreation("string", 123, null);
+}

Powered by Google App Engine
This is Rietveld 408576698