From fdc7c0a37223a974f9effa5b1e473463579aae47 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Wed, 18 Dec 2024 14:43:39 +1100 Subject: [PATCH] Unify native code for global_test and global_native_test --- .../global_native_config.yaml | 8 ++--- .../native_objc_test/global_native_test.dart | 29 ++++++++++--------- .../native_objc_test/global_native_test.h | 10 ------- .../native_objc_test/global_native_test.m | 11 ------- .../test/native_objc_test/global_test.dart | 1 + 5 files changed, 20 insertions(+), 39 deletions(-) delete mode 100644 pkgs/ffigen/test/native_objc_test/global_native_test.h delete mode 100644 pkgs/ffigen/test/native_objc_test/global_native_test.m diff --git a/pkgs/ffigen/test/native_objc_test/global_native_config.yaml b/pkgs/ffigen/test/native_objc_test/global_native_config.yaml index f3700c69d..30a4afe22 100644 --- a/pkgs/ffigen/test/native_objc_test/global_native_config.yaml +++ b/pkgs/ffigen/test/native_objc_test/global_native_config.yaml @@ -6,11 +6,11 @@ exclude-all-by-default: true ffi-native: globals: include: - - globalNativeString - - globalNativeObject - - globalNativeBlock + - globalString + - globalObject + - globalBlock headers: entry-points: - - 'global_native_test.h' + - 'global_test.h' preamble: | // ignore_for_file: camel_case_types, non_constant_identifier_names, unnecessary_non_null_assertion, unused_element, unused_field diff --git a/pkgs/ffigen/test/native_objc_test/global_native_test.dart b/pkgs/ffigen/test/native_objc_test/global_native_test.dart index db59062a5..5b797a22f 100644 --- a/pkgs/ffigen/test/native_objc_test/global_native_test.dart +++ b/pkgs/ffigen/test/native_objc_test/global_native_test.dart @@ -26,23 +26,24 @@ void main() { final dylib = File('test/native_objc_test/objc_test.dylib'); verifySetupFile(dylib); DynamicLibrary.open(dylib.absolute.path); - generateBindingsForCoverage('global_native'); + generateBindingsForCoverage('global'); }); test('Global string', () { - expect(globalNativeString.toString(), 'Hello World'); - globalNativeString = 'Something else'.toNSString(); - expect(globalNativeString.toString(), 'Something else'); + expect(globalString.toString(), 'Hello World'); + globalString = 'Something else'.toNSString(); + expect(globalString.toString(), 'Something else'); + globalString = 'Hello World'.toNSString(); }); (Pointer, Pointer) globalObjectRefCountingInner() { final obj1 = NSObject.new1(); - globalNativeObject = obj1; + globalObject = obj1; final obj1raw = obj1.ref.pointer; expect(objectRetainCount(obj1raw), 2); // obj1, and the global variable. final obj2 = NSObject.new1(); - globalNativeObject = obj2; + globalObject = obj2; final obj2raw = obj2.ref.pointer; expect(objectRetainCount(obj2raw), 2); // obj2, and the global variable. expect(objectRetainCount(obj1raw), 1); // Just obj1. @@ -59,28 +60,28 @@ void main() { expect(objectRetainCount(obj2raw), 1); // Just the global variable. expect(objectRetainCount(obj1raw), 0); - globalNativeObject = null; + globalObject = null; expect(objectRetainCount(obj2raw), 0); expect(objectRetainCount(obj1raw), 0); }, skip: !canDoGC); test('Global block', () { - globalNativeBlock = ObjCBlock_Int32_Int32.fromFunction((int x) => x * 10); - expect(globalNativeBlock!(123), 1230); - globalNativeBlock = + globalBlock = ObjCBlock_Int32_Int32.fromFunction((int x) => x * 10); + expect(globalBlock!(123), 1230); + globalBlock = ObjCBlock_Int32_Int32.fromFunction((int x) => x + 1000); - expect(globalNativeBlock!(456), 1456); + expect(globalBlock!(456), 1456); }); (Pointer, Pointer) globalBlockRefCountingInner() { final blk1 = ObjCBlock_Int32_Int32.fromFunction((int x) => x * 10); - globalNativeBlock = blk1; + globalBlock = blk1; final blk1raw = blk1.ref.pointer; expect(blockRetainCount(blk1raw), 2); // blk1, and the global variable. final blk2 = ObjCBlock_Int32_Int32.fromFunction((int x) => x + 1000); - globalNativeBlock = blk2; + globalBlock = blk2; final blk2raw = blk2.ref.pointer; expect(blockRetainCount(blk2raw), 2); // blk2, and the global variable. expect(blockRetainCount(blk1raw), 1); // Just blk1. @@ -97,7 +98,7 @@ void main() { expect(blockRetainCount(blk2raw), 1); // Just the global variable. expect(blockRetainCount(blk1raw), 0); - globalNativeBlock = null; + globalBlock = null; expect(blockRetainCount(blk2raw), 0); expect(blockRetainCount(blk1raw), 0); }, skip: !canDoGC); diff --git a/pkgs/ffigen/test/native_objc_test/global_native_test.h b/pkgs/ffigen/test/native_objc_test/global_native_test.h deleted file mode 100644 index 8c60e4989..000000000 --- a/pkgs/ffigen/test/native_objc_test/global_native_test.h +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2024, 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 -#import - -NSString* globalNativeString; -NSObject* _Nullable globalNativeObject; -int32_t (^_Nullable globalNativeBlock)(int32_t); diff --git a/pkgs/ffigen/test/native_objc_test/global_native_test.m b/pkgs/ffigen/test/native_objc_test/global_native_test.m deleted file mode 100644 index 32d439e0c..000000000 --- a/pkgs/ffigen/test/native_objc_test/global_native_test.m +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2024, 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 - -#include "global_native_test.h" - -NSString* globalNativeString = @"Hello World"; -NSObject* _Nullable globalNativeObject = nil; -int32_t (^_Nullable globalNativeBlock)(int32_t) = nil; diff --git a/pkgs/ffigen/test/native_objc_test/global_test.dart b/pkgs/ffigen/test/native_objc_test/global_test.dart index 06ba084b1..a875d279e 100644 --- a/pkgs/ffigen/test/native_objc_test/global_test.dart +++ b/pkgs/ffigen/test/native_objc_test/global_test.dart @@ -35,6 +35,7 @@ void main() { expect(lib.globalString.toString(), 'Hello World'); lib.globalString = 'Something else'.toNSString(); expect(lib.globalString.toString(), 'Something else'); + lib.globalString = 'Hello World'.toNSString(); }); (Pointer, Pointer) globalObjectRefCountingInner() {