Add test
diff --git a/lib/ffi.dart b/lib/ffi.dart index e66c090..e4e19ef 100644 --- a/lib/ffi.dart +++ b/lib/ffi.dart
@@ -5,5 +5,6 @@ export 'src/allocation.dart' show calloc, malloc; export 'src/arena.dart'; export 'src/c_type.dart'; +export 'src/objective_c.dart'; export 'src/utf8.dart'; export 'src/utf16.dart';
diff --git a/lib/src/objective_c.dart b/lib/src/objective_c.dart new file mode 100644 index 0000000..7a41584 --- /dev/null +++ b/lib/src/objective_c.dart
@@ -0,0 +1,30 @@ +// 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. + +/// This library defines [NativeType]s for some core Objective C types. + +import 'dart:ffi'; + +/// The Objective C `NSObject` type. +/// +/// `NSObject` is always passed around by pointer, so use `Pointer<ObjCObject>`. +/// The `id` type also maps to `Pointer<ObjCObject>`. +class ObjCObject extends Opaque {} + +/// The Objective C `Class` type. +/// +/// `Class` is always passed around by pointer, so use `Pointer<ObjCClass>`. +class ObjCClass extends ObjCObject {} + +/// The Objective C `Block` type. +/// +/// `Block` is always passed around by pointer, so use `Pointer<ObjCBlock>`. The +/// type parameter describes the call signature of the `Block`. +class ObjCBlock<F extends Function> extends ObjCObject {} + +/// The implementation of the Objective C `SEL` type. +/// +/// This type is not used directly. Instead, the `SEL` type maps to +/// `Pointer<ObjCSel>`. +class ObjCSel extends Opaque {}
diff --git a/test/objective_c_test.dart b/test/objective_c_test.dart new file mode 100644 index 0000000..6f267b3 --- /dev/null +++ b/test/objective_c_test.dart
@@ -0,0 +1,30 @@ +// 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. + +import 'dart:ffi'; + +import 'package:ffi/ffi.dart'; +import 'package:test/test.dart'; + +void main() { + test('ObjCObject', () { + expect(Pointer<ObjCObject>.fromAddress(0), isA<Pointer<Opaque>>()); + }); + + test('ObjCClass', () { + expect(Pointer<ObjCClass>.fromAddress(0), isA<Pointer<ObjCObject>>()); + }); + + test('ObjCBlock', () { + expect(Pointer<ObjCBlock<int Function(String)>>.fromAddress(0), + isA<Pointer<ObjCObject>>()); + expect(Pointer<ObjCBlock<int Function(String)>>.fromAddress(0), + isNot(isA<Pointer<ObjCBlock<String Function(int, int)>>>())); + }); + + test('ObjCSel', () { + expect(Pointer<ObjCSel>.fromAddress(0), isA<Pointer<Opaque>>()); + expect(Pointer<ObjCSel>.fromAddress(0), isNot(isA<Pointer<ObjCObject>>())); + }); +}