dart-sdk/tests/ffi/callback_tests_utils.dart
Alexander Thomas 2a035279af [3.0 alpha] Use equals for default values in the SDK
The colons cause test failures when the language version is bumped to 3.0. This CL can be landed before the 3.0 version bump.

Bug: https://github.com/dart-lang/language/issues/2357
Change-Id: Id8396034b16adc18b476689314e28b9617d25f18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272200
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2022-11-30 10:33:31 +00:00

45 lines
1.3 KiB
Dart

// Copyright (c) 2019, 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 'dart:ffi';
import 'dylib_utils.dart';
import "package:expect/expect.dart";
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
typedef NativeCallbackTest = Int32 Function(Pointer);
typedef NativeCallbackTestFn = int Function(Pointer);
class CallbackTest {
final String name;
final Pointer callback;
final void Function() afterCallbackChecks;
final bool isLeaf;
CallbackTest(this.name, this.callback, {this.isLeaf = false})
: afterCallbackChecks = noChecks {}
CallbackTest.withCheck(this.name, this.callback, this.afterCallbackChecks,
{this.isLeaf = false}) {}
void run() {
final NativeCallbackTestFn tester = isLeaf
? ffiTestFunctions.lookupFunction<NativeCallbackTest,
NativeCallbackTestFn>("Test$name", isLeaf: true)
: ffiTestFunctions.lookupFunction<NativeCallbackTest,
NativeCallbackTestFn>("Test$name", isLeaf: false);
final int testCode = tester(callback);
if (testCode != 0) {
Expect.fail("Test $name failed.");
}
afterCallbackChecks();
}
}
void noChecks() {}