Files
dmc/app/test/transport/loopback_transport_test.dart
T

71 lines
2.0 KiB
Dart

import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:dmc_app/transport/link_transport.dart';
import 'package:dmc_app/transport/loopback/loopback_transport.dart';
void main() {
test('connect() durchlaeuft connecting -> connected', () async {
final transport = LoopbackTransport();
final states = <LinkState>[];
transport.state.listen(states.add);
await transport.connect();
await Future<void>.delayed(Duration.zero);
expect(states, [LinkState.connecting, LinkState.connected]);
transport.dispose();
});
test('feed() eingespeiste Bytes kommen ueber incoming an', () async {
final transport = LoopbackTransport();
await transport.connect();
final received = <Uint8List>[];
transport.incoming.listen(received.add);
transport.feed(Uint8List.fromList([1, 2, 3]));
await Future<void>.delayed(Duration.zero);
expect(received, [
Uint8List.fromList([1, 2, 3]),
]);
transport.dispose();
});
test('send() sammelt gesendete Bytes in sentData', () async {
final transport = LoopbackTransport();
await transport.connect();
await transport.send(Uint8List.fromList([9, 9]));
expect(transport.sentData, [
Uint8List.fromList([9, 9]),
]);
transport.dispose();
});
test('simulateError() meldet Grund/Nachricht und LinkState.error', () async {
final transport = LoopbackTransport();
await transport.connect();
transport.simulateError(LinkErrorReason.connectionFailed, 'Testfehler');
expect(transport.lastErrorReason, LinkErrorReason.connectionFailed);
expect(transport.lastErrorMessage, 'Testfehler');
expect(transport.currentState, LinkState.error);
transport.dispose();
});
test('disconnect() setzt LinkState.disconnected', () async {
final transport = LoopbackTransport();
await transport.connect();
await transport.disconnect();
expect(transport.currentState, LinkState.disconnected);
transport.dispose();
});
}