flutter_stockfish_plugin/test/stockfish_test.dart

47 lines
1.3 KiB
Dart
Raw 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
/// 1. run the example (example/lib/main.dart) in windows,
/// 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");
});
}