Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e5a6551

Browse files
committed
Add broken test
1 parent b1746f7 commit e5a6551

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

testing/dart/plugin_utilities_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:isolate';
56
import 'dart:ui';
67

78
import 'package:litetest/litetest.dart';
@@ -19,6 +20,34 @@ class Foo {
1920

2021
const Foo foo = Foo();
2122

23+
@pragma('vm:entry-point')
24+
Future<void> included() async {
25+
26+
}
27+
28+
Future<void> excluded() async {
29+
30+
}
31+
32+
@pragma('vm:entry-point')
33+
Future<void> runCallback(IsolateParam param) async {
34+
try {
35+
final Future<dynamic> Function() func = PluginUtilities.getCallbackFromHandle(CallbackHandle.fromRawHandle(param.rawHandle))! as Future<dynamic> Function();
36+
await func.call();
37+
param.sendPort.send(true);
38+
}
39+
catch (e) {
40+
print(e);
41+
param.sendPort.send(false);
42+
}
43+
}
44+
45+
class IsolateParam {
46+
const IsolateParam(this.sendPort, this.rawHandle);
47+
final SendPort sendPort;
48+
final int rawHandle;
49+
}
50+
2251
void main() {
2352
test('PluginUtilities Callback Handles', () {
2453
// Top level callback.
@@ -43,4 +72,15 @@ void main() {
4372
final Function anon = (int a, int b) => a + b; // ignore: prefer_function_declarations_over_variables
4473
expect(PluginUtilities.getCallbackHandle(anon), isNull);
4574
});
75+
76+
test('PluginUtilities Callback Handles in Isolate', () async {
77+
ReceivePort port = ReceivePort();
78+
await Isolate.spawn(runCallback, IsolateParam(port.sendPort, PluginUtilities.getCallbackHandle(included)!.toRawHandle()));
79+
expect(await port.first, true);
80+
port.close();
81+
port = ReceivePort();
82+
await Isolate.spawn(runCallback, IsolateParam(port.sendPort, PluginUtilities.getCallbackHandle(excluded)!.toRawHandle()));
83+
expect(await port.first, false);
84+
port.close();
85+
});
4686
}

0 commit comments

Comments
 (0)