Files
sdk/tests/ffi_2/callback_tests_utils.dart
T
Daco Harkes b62e715073 [test/ffi] Passing structs by value test generator
Split off from https://dart-review.googlesource.com/c/sdk/+/140290/33
to make that CL smaller and review the test generator separately.

Because of the amount of corner cases in the calling conventions that
need to be covered, the tests are generated, rather than hand-written.

The tests are tested in the dependent CL. Tests are ignored in status
file and are un-ignored in dependent CL.

Change-Id: I5507f52229793fdf07da3066b49045fdb703a69d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168829
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-10-26 12:01:16 +00:00

39 lines
1.1 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;
CallbackTest(this.name, this.callback) : afterCallbackChecks = noChecks {}
CallbackTest.withCheck(this.name, this.callback, this.afterCallbackChecks) {}
void run() {
final NativeCallbackTestFn tester = ffiTestFunctions
.lookupFunction<NativeCallbackTest, NativeCallbackTestFn>("Test$name");
final int testCode = tester(callback);
if (testCode != 0) {
Expect.fail("Test $name failed.");
}
afterCallbackChecks();
}
}
void noChecks() {}