flutter_stockfish_plugin/test/stockfish_test.dart

47 lines
1.3 KiB
Dart
Raw Permalink Normal View History

2023-11-22 21:08:27 +01:00
// Import the test package and Counter class
import 'dart:async';
import 'package:flutter_stockfish_plugin/stockfish.dart';
import 'package:flutter_test/flutter_test.dart';
/// To run the test, you have to
2023-11-28 23:12:31 +01:00
/// 1. run the example (example/lib/main.dart) on desktop (linux/windows),
2023-11-22 21:08:27 +01:00
/// so everything gets build
2023-11-22 21:10:28 +01:00
/// 2. copy flutter_stockfish_plugin.dll to root-directory
/// (directly to flutter_stockfish_plugin) manually
2023-11-22 21:08:27 +01:00
void main() {
2023-11-22 21:10:28 +01:00
test('Start Stockfish and uci init', () async {
2023-11-22 21:08:27 +01:00
final fish1 = Stockfish();
List<String> received = [];
Completer readyCompleter = Completer();
Completer uciOkCompleter = Completer();
fish1.stdout.listen((event) {
print(event);
received.add(event);
if (event == "uciok") {
uciOkCompleter.complete();
}
});
fish1.state.addListener(() {
if (fish1.state.value.name == "ready") {
readyCompleter.complete();
} else if (fish1.state.value.name == "error") {
readyCompleter.completeError("ERROR: CANNOT INIT STOCKFISH");
}
});
// wait for stockfish startup
await readyCompleter.future;
// then init uci
fish1.stdin = "uci";
// then wait for uciok
await uciOkCompleter.future;
expect(received.last, "uciok");
});
}