Files
sdk/tests/standalone/io/socket_invalid_arguments_test.dart
Robert Nystrom a323c55162 Format tests/standalone/ using 3.8 style.
Change-Id: I4d492a63a41880ef8cd69321372a4853825b9efd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426321
Reviewed-by: Liam Appelbe <liama@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2025-05-04 17:45:09 -07:00

56 lines
1.4 KiB
Dart

// Copyright (c) 2013, 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 "package:expect/async_helper.dart";
import "package:expect/expect.dart";
class NotAnInteger {
operator ==(other) => other == 1;
operator <(other) => other > 1;
operator +(other) => 1;
}
testSocketCreation(host, port) {
asyncStart();
try {
Socket.connect(
host,
port,
).then((socket) => Expect.fail("Shouldn't get connected")).catchError((e) {
Expect.isTrue(e is ArgumentError || e is SocketException);
asyncEnd();
});
} catch (e) {
Expect.isTrue(e is ArgumentError || e is SocketException);
asyncEnd();
}
}
testServerSocketCreation(address, port, backlog) {
asyncStart();
var server;
try {
ServerSocket.bind(address, port, backlog: backlog)
.then((_) {
Expect.fail("ServerSocket bound");
})
.catchError((e) => asyncEnd());
} catch (e) {
asyncEnd();
}
}
main() {
asyncStart();
testSocketCreation("localhost", -1);
testSocketCreation("localhost", 65536);
testServerSocketCreation("string", null, null);
testServerSocketCreation("string", 123, null);
testServerSocketCreation("localhost", -1, 123);
testServerSocketCreation("localhost", 65536, 123);
asyncEnd();
}