Skip to content

Commit 428a03e

Browse files
committed
Add unittests to Dart bindings for Client
1 parent 4c7304d commit 428a03e

File tree

1 file changed

+127
-7
lines changed

1 file changed

+127
-7
lines changed
Lines changed: 127 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,138 @@
1+
import 'dart:typed_data';
2+
13
import 'package:vdd/errors.dart';
4+
import 'package:vdd/test.dart';
25
import 'package:vdd/vdd.dart';
36
import 'package:test/test.dart';
47

58
void main() {
9+
final monitor = Monitor(
10+
id: 0,
11+
enabled: true,
12+
modes: [
13+
Mode(
14+
width: 1920,
15+
height: 1080,
16+
refreshRates: Uint32List.fromList([60]),
17+
),
18+
],
19+
);
20+
621
setUpAll(() async {
722
await init();
823
});
924

10-
test('Client.connect throws correct error', () async {
11-
try {
12-
await Client.connect(pipeName: "nonexisting");
13-
fail("Expected ConnectionError");
14-
} catch (e) {
15-
expect(e, isA<ConnectionError_Failed>());
16-
}
25+
group('Client', () {
26+
test('Client.connect throws correct error', () async {
27+
try {
28+
await Client.connect(pipeName: "nonexisting");
29+
fail("Expected ConnectionError");
30+
} catch (e) {
31+
expect(e, isA<ConnectionError_Failed>());
32+
}
33+
});
34+
35+
test('Client can connect', () async {
36+
final server = await MockServer.create(pipeName: "client_can_connect");
37+
38+
await Client.connect(pipeName: server.pipeName);
39+
});
40+
41+
test('Client can notify', () async {
42+
final server = await MockServer.create(pipeName: "client_can_notify");
43+
44+
final client = await Client.connect(pipeName: server.pipeName);
45+
46+
await client.notify(monitors: [monitor]);
47+
48+
await server.pump();
49+
50+
expect(server.state, [monitor]);
51+
52+
await client.notify(monitors: []);
53+
54+
await server.pump();
55+
56+
expect(server.state, []);
57+
});
58+
59+
test('Client can remove', () async {
60+
final server = await MockServer.create(pipeName: "client_can_remove");
61+
62+
final client = await Client.connect(pipeName: server.pipeName);
63+
64+
await client.notify(
65+
monitors: List.generate(5, (i) => monitor.copyWith(id: i)));
66+
67+
await server.pump();
68+
69+
expect(server.state, List.generate(5, (i) => monitor.copyWith(id: i)));
70+
71+
await client.remove(ids: [2, 3]);
72+
73+
await server.pump();
74+
75+
expect(server.state, [
76+
monitor.copyWith(id: 0),
77+
monitor.copyWith(id: 1),
78+
monitor.copyWith(id: 4),
79+
]);
80+
81+
await client.removeAll();
82+
83+
await server.pump();
84+
85+
expect(server.state, []);
86+
});
87+
88+
test('Client can receive events', () async {
89+
final server = await MockServer.create(pipeName: "client_can_receive");
90+
91+
final client = await Client.connect(pipeName: server.pipeName);
92+
93+
final stream = client.receiveEvents();
94+
95+
await client.notify(monitors: [monitor]);
96+
97+
await server.pump();
98+
99+
await client.notify(monitors: [monitor.copyWith(enabled: false)]);
100+
101+
await server.pump();
102+
103+
await client.notify(monitors: [monitor.copyWith(id: 1)]);
104+
105+
await server.pump();
106+
107+
expect(await stream.take(3).toList(), [
108+
[monitor],
109+
[monitor.copyWith(enabled: false)],
110+
[monitor.copyWith(id: 1)],
111+
]);
112+
});
113+
114+
test('Client can request state', () async {
115+
final server = await MockServer.create(pipeName: "client_can_request");
116+
117+
final client = await Client.connect(pipeName: server.pipeName);
118+
119+
await Future.wait([
120+
Future(() async {
121+
expect(await client.requestState(), []);
122+
}),
123+
server.pump(),
124+
]);
125+
126+
await client.notify(monitors: [monitor]);
127+
128+
await server.pump();
129+
130+
await Future.wait([
131+
Future(() async {
132+
expect(await client.requestState(), [monitor]);
133+
}),
134+
server.pump(),
135+
]);
136+
});
17137
});
18138
}

0 commit comments

Comments
 (0)