Skip to content

Commit 4acb137

Browse files
committed
Tests added.
1 parent 925a09f commit 4acb137

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion Future<int> length
8+
* Counts the elements in the stream.
9+
*
10+
* @description Checks that property length returns the number of elements
11+
* in the socket when this RawDatagramSocket is closed (returns 1).
12+
13+
*/
14+
import "dart:io";
15+
import "../../../Utils/expect.dart";
16+
import "../../../Utils/async_utils.dart";
17+
18+
check([bool no_write_events = false]) {
19+
asyncStart();
20+
var address = InternetAddress.LOOPBACK_IP_V4;
21+
RawDatagramSocket.bind(address, 0).then((producer) {
22+
RawDatagramSocket.bind(address, 0).then((receiver) {
23+
if (no_write_events) {
24+
receiver.writeEventsEnabled = false;
25+
}
26+
int sent = 0;
27+
var rValue;
28+
29+
producer.send([sent++], address, receiver.port);
30+
producer.send([sent++], address, receiver.port);
31+
producer.send([sent], address, receiver.port);
32+
producer.close();
33+
receiver.close();
34+
35+
void action() {
36+
Expect.equals(1, rValue);
37+
asyncEnd();
38+
}
39+
40+
receiver.length.then((value) {
41+
rValue = value;
42+
}).whenComplete (action);
43+
});
44+
});
45+
}
46+
47+
main() {
48+
check();
49+
check(true);
50+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion int multicastHops
8+
* Set or get, the maximum network hops for multicast packages originating from
9+
* this socket.
10+
*
11+
* For IPv4 this is referred to as TTL (time to live).
12+
*
13+
* By default this value is 1 causing multicast traffic to stay on the local
14+
* network.
15+
*
16+
* @description Checks that multicastHops value by default is 1.
17+
18+
*/
19+
import "dart:io";
20+
import "../../../Utils/expect.dart";
21+
import "../../../Utils/async_utils.dart";
22+
23+
check(InternetAddress address) {
24+
asyncStart();
25+
RawDatagramSocket.bind(address, 0).then((socket) {
26+
var v1 = socket.multicastHops;
27+
Expect.equals(1, v1);
28+
socket.close();
29+
asyncEnd();
30+
});
31+
}
32+
33+
main() {
34+
check(InternetAddress.ANY_IP_V4);
35+
check(InternetAddress.ANY_IP_V6);
36+
check(InternetAddress.LOOPBACK_IP_V4);
37+
check(InternetAddress.LOOPBACK_IP_V6);
38+
}

0 commit comments

Comments
 (0)