| // Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| import 'dylib_utils.dart'; |
| final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions"); |
| typedef NativeAsyncCallbackTest = Void Function(Pointer); |
| typedef NativeAsyncCallbackTestFn = void Function(Pointer); |
| class AsyncCallbackTest { |
| final Future<void> Function() afterCallbackChecks; |
| // Either a NativeCallable or a Pointer.fromFunction. |
| AsyncCallbackTest(this.name, this.callback, this.afterCallbackChecks) {} |
| Future<void> run() async { |
| final NativeAsyncCallbackTestFn tester = ffiTestFunctions.lookupFunction< |
| NativeAsyncCallbackTest, NativeAsyncCallbackTestFn>("TestAsync$name"); |
| tester(cb is NativeCallable ? cb.nativeFunction : cb as Pointer); |
| await afterCallbackChecks(); |
| if (cb is NativeCallable) { |
| Future<void> noChecksAsync() async {} |