| // Copyright (c) 2022, 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. | |
| // Objective C support is only available on mac. | |
| @TestOn('mac-os') | |
| import 'dart:ffi'; | |
| import 'dart:io'; | |
| import 'package:ffi/ffi.dart'; | |
| import 'package:path/path.dart' as path; | |
| import 'package:test/test.dart'; | |
| import '../test_utils.dart'; | |
| import 'method_test_bindings.dart'; | |
| import 'util.dart'; | |
| void main() { | |
| group('method calls', () { | |
| late MethodInterface testInterface; | |
| setUpAll(() { | |
| testInterface = MethodInterface.alloc().init(); | |
| }); | |
| group('Instance methods', () { | |
| test('No arguments', () { | |
| expect(testInterface.add(), 5); | |
| }); | |
| test('One argument', () { | |
| expect(testInterface.add$1(23), 23); | |
| }); | |
| test('Two arguments', () { | |
| expect(testInterface.add$2(23, Y: 17), 40); | |
| }); | |
| test('Three arguments', () { | |
| expect(testInterface.add$3(23, Y: 17, Z: 60), 100); | |
| }); | |
| }); | |
| group('Class methods', () { | |
| test('No arguments', () { | |
| expect(MethodInterface.sub(), -5); | |
| }); | |
| test('One argument', () { | |
| expect(MethodInterface.sub$1(7), -7); | |
| }); | |
| test('Two arguments', () { | |
| expect(MethodInterface.sub$2(7, Y: 3), -10); | |
| }); | |
| test('Three arguments', () { | |
| expect(MethodInterface.sub$3(10, Y: 7, Z: 3), -20); | |
| }); | |
| }); | |
| group('Regress #608', () { | |
| test('Structs', () { | |
| final inputPtr = calloc<Vec4>(); | |
| final input = inputPtr.ref; | |
| input.x = 1.2; | |
| input.y = 3.4; | |
| input.z = 5.6; | |
| input.w = 7.8; | |
| final result = testInterface.twiddleVec4Components(input); | |
| expect(result.x, 3.4); | |
| expect(result.y, 5.6); | |
| expect(result.z, 7.8); | |
| expect(result.w, 1.2); | |
| calloc.free(inputPtr); | |
| }); | |
| test('Floats', () { | |
| expect(testInterface.addFloats(1.23, Y: 4.56), closeTo(5.79, 1e-6)); | |
| }); | |
| test('Doubles', () { | |
| expect(testInterface.addDoubles(1.23, Y: 4.56), closeTo(5.79, 1e-6)); | |
| }); | |
| test('Method with same name as a type', () { | |
| // Test for https://github.com/dart-lang/native/issues/1007 | |
| final result = testInterface.Vec4$1(); | |
| expect(result.x, 1); | |
| expect(result.y, 2); | |
| expect(result.z, 3); | |
| expect(result.w, 4); | |
| }); | |
| }); | |
| test('Instance and static methods with same name', () { | |
| // Test for https://github.com/dart-lang/native/issues/1136 | |
| expect(testInterface.instStaticSameName(), 123); | |
| expect(MethodInterface.instStaticSameName$1(), 456); | |
| }); | |
| }); | |
| } |