diff --git a/example/integration_test/iris_method_channel_smoke_test.dart b/example/integration_test/iris_method_channel_smoke_test.dart new file mode 100644 index 0000000..784752a --- /dev/null +++ b/example/integration_test/iris_method_channel_smoke_test.dart @@ -0,0 +1,88 @@ +import 'dart:isolate'; +import 'dart:ffi' as ffi; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:iris_method_channel/iris_method_channel.dart'; +import 'package:iris_method_channel/src/platform/io/iris_method_channel_internal_io.dart'; + +class _FakeNativeBindingDelegate extends PlatformBindingsDelegateInterface { + _FakeNativeBindingDelegate(); + + @override + int callApi( + IrisMethodCall methodCall, + IrisApiEngineHandle apiEnginePtr, + IrisApiParamHandle param, + ) { + return 0; + } + + @override + IrisEventHandlerHandle createIrisEventHandler( + IrisCEventHandlerHandle eventHandler, + ) { + return IrisEventHandlerHandle(ffi.Pointer.fromAddress(123456)); + } + + @override + CreateApiEngineResult createApiEngine(List args) { + return CreateApiEngineResult( + IrisApiEngineHandle(ffi.Pointer.fromAddress(100)), + extraData: {'extra_handle': 1000}, + ); + } + + @override + void destroyIrisEventHandler( + IrisEventHandlerHandle handler, + ) {} + + @override + void destroyNativeApiEngine(IrisApiEngineHandle apiEnginePtr) {} + + @override + void initialize() {} + + @override + Future callApiAsync(IrisMethodCall methodCall, + IrisApiEngineHandle apiEnginePtr, IrisApiParamHandle param) async { + return CallApiResult(irisReturnCode: 0, data: {}); + } +} + +class _FakeNativeBindingDelegateProvider extends PlatformBindingsProvider { + _FakeNativeBindingDelegateProvider(this.nativeBindingDelegate); + + final PlatformBindingsDelegateInterface nativeBindingDelegate; + + @override + PlatformBindingsDelegateInterface provideNativeBindingDelegate() { + return nativeBindingDelegate; + } +} + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('IrisMethodChannel should call hot restart listener', + (tester) async { + final irisMethodChannel = IrisMethodChannel( + _FakeNativeBindingDelegateProvider(_FakeNativeBindingDelegate())); + await irisMethodChannel.initilize([]); + + bool hotRestartListenerCalled = false; + irisMethodChannel.addHotRestartListener((message) { + hotRestartListenerCalled = true; + }); + + (irisMethodChannel.getIrisMethodChannelInternal() + as IrisMethodChannelInternalIO) + .workerIsolate + .kill(priority: Isolate.immediate); + // Delayed 1 second to ensure `irisMethodChannel.workerIsolate.kill` done + await Future.delayed(const Duration(seconds: 1)); + + expect(hotRestartListenerCalled, true); + }); +}