|
16 | 16 |
|
17 | 17 | import 'dart:ffi';
|
18 | 18 |
|
19 |
| -import "package:expect/expect.dart"; |
20 |
| - |
21 |
| -import 'dylib_utils.dart'; |
22 |
| - |
23 |
| -typedef NativeCallbackTest = Int32 Function(Pointer); |
24 |
| -typedef NativeCallbackTestFn = int Function(Pointer); |
25 |
| - |
26 |
| -final DynamicLibrary testLibrary = dlopenPlatformSpecific("ffi_test_functions"); |
27 |
| - |
28 |
| -class Test { |
29 |
| - final String name; |
30 |
| - final Pointer callback; |
31 |
| - final bool skip; |
32 |
| - |
33 |
| - Test(this.name, this.callback, {bool skipIf: false}) : skip = skipIf {} |
34 |
| - |
35 |
| - void run() { |
36 |
| - if (skip) return; |
37 |
| - |
38 |
| - final NativeCallbackTestFn tester = testLibrary |
39 |
| - .lookupFunction<NativeCallbackTest, NativeCallbackTestFn>("Test$name"); |
40 |
| - final int testCode = tester(callback); |
41 |
| - if (testCode != 0) { |
42 |
| - Expect.fail("Test $name failed."); |
43 |
| - } |
44 |
| - } |
45 |
| -} |
| 19 | +import 'callback_tests_utils.dart'; |
46 | 20 |
|
47 | 21 | typedef SimpleAdditionType = Int32 Function(Int32, Int32);
|
48 | 22 | int simpleAddition(int x, int y) {
|
@@ -212,34 +186,36 @@ int returnMaxUint8v2() {
|
212 | 186 | return 0xabcff;
|
213 | 187 | }
|
214 | 188 |
|
215 |
| -final List<Test> testcases = [ |
216 |
| - Test("SimpleAddition", |
| 189 | +final testcases = [ |
| 190 | + CallbackTest("SimpleAddition", |
217 | 191 | Pointer.fromFunction<SimpleAdditionType>(simpleAddition, 0)),
|
218 |
| - Test("IntComputation", |
| 192 | + CallbackTest("IntComputation", |
219 | 193 | Pointer.fromFunction<IntComputationType>(intComputation, 0)),
|
220 |
| - Test("UintComputation", |
| 194 | + CallbackTest("UintComputation", |
221 | 195 | Pointer.fromFunction<UintComputationType>(uintComputation, 0)),
|
222 |
| - Test("SimpleMultiply", |
| 196 | + CallbackTest("SimpleMultiply", |
223 | 197 | Pointer.fromFunction<SimpleMultiplyType>(simpleMultiply, 0.0)),
|
224 |
| - Test("SimpleMultiplyFloat", |
| 198 | + CallbackTest("SimpleMultiplyFloat", |
225 | 199 | Pointer.fromFunction<SimpleMultiplyFloatType>(simpleMultiplyFloat, 0.0)),
|
226 |
| - Test("ManyInts", Pointer.fromFunction<ManyIntsType>(manyInts, 0)), |
227 |
| - Test("ManyDoubles", Pointer.fromFunction<ManyDoublesType>(manyDoubles, 0.0)), |
228 |
| - Test("ManyArgs", Pointer.fromFunction<ManyArgsType>(manyArgs, 0.0)), |
229 |
| - Test("Store", Pointer.fromFunction<StoreType>(store)), |
230 |
| - Test("NullPointers", Pointer.fromFunction<NullPointersType>(nullPointers)), |
231 |
| - Test("ReturnVoid", Pointer.fromFunction<ReturnVoid>(returnVoid)), |
232 |
| - Test("ThrowExceptionDouble", |
| 200 | + CallbackTest("ManyInts", Pointer.fromFunction<ManyIntsType>(manyInts, 0)), |
| 201 | + CallbackTest( |
| 202 | + "ManyDoubles", Pointer.fromFunction<ManyDoublesType>(manyDoubles, 0.0)), |
| 203 | + CallbackTest("ManyArgs", Pointer.fromFunction<ManyArgsType>(manyArgs, 0.0)), |
| 204 | + CallbackTest("Store", Pointer.fromFunction<StoreType>(store)), |
| 205 | + CallbackTest( |
| 206 | + "NullPointers", Pointer.fromFunction<NullPointersType>(nullPointers)), |
| 207 | + CallbackTest("ReturnVoid", Pointer.fromFunction<ReturnVoid>(returnVoid)), |
| 208 | + CallbackTest("ThrowExceptionDouble", |
233 | 209 | Pointer.fromFunction<ThrowExceptionDouble>(throwExceptionDouble, 42.0)),
|
234 |
| - Test("ThrowExceptionPointer", |
| 210 | + CallbackTest("ThrowExceptionPointer", |
235 | 211 | Pointer.fromFunction<ThrowExceptionPointer>(throwExceptionPointer)),
|
236 |
| - Test("ThrowException", |
| 212 | + CallbackTest("ThrowException", |
237 | 213 | Pointer.fromFunction<ThrowExceptionInt>(throwExceptionInt, 42)),
|
238 |
| - Test("TakeMaxUint8x10", |
| 214 | + CallbackTest("TakeMaxUint8x10", |
239 | 215 | Pointer.fromFunction<TakeMaxUint8x10Type>(takeMaxUint8x10, 0)),
|
240 |
| - Test("ReturnMaxUint8", |
| 216 | + CallbackTest("ReturnMaxUint8", |
241 | 217 | Pointer.fromFunction<ReturnMaxUint8Type>(returnMaxUint8, 0)),
|
242 |
| - Test("ReturnMaxUint8", |
| 218 | + CallbackTest("ReturnMaxUint8", |
243 | 219 | Pointer.fromFunction<ReturnMaxUint8Type>(returnMaxUint8v2, 0)),
|
244 | 220 | ];
|
245 | 221 |
|
|
0 commit comments