-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c352d8
commit 61a5092
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
example/integration_test/iris_method_channel_smoke_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ffi.Void>.fromAddress(123456)); | ||
} | ||
|
||
@override | ||
CreateApiEngineResult createApiEngine(List<Object> args) { | ||
return CreateApiEngineResult( | ||
IrisApiEngineHandle(ffi.Pointer<ffi.Void>.fromAddress(100)), | ||
extraData: <String, Object>{'extra_handle': 1000}, | ||
); | ||
} | ||
|
||
@override | ||
void destroyIrisEventHandler( | ||
IrisEventHandlerHandle handler, | ||
) {} | ||
|
||
@override | ||
void destroyNativeApiEngine(IrisApiEngineHandle apiEnginePtr) {} | ||
|
||
@override | ||
void initialize() {} | ||
|
||
@override | ||
Future<CallApiResult> 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); | ||
}); | ||
} |