5
5
// Objective C support is only available on mac.
6
6
@TestOn ('mac-os' )
7
7
8
- // TODO(https://github.com/dart-lang/native/issues/1435): Fix flakiness.
9
- @Retry (3 )
10
-
11
8
import 'dart:ffi' ;
12
9
import 'dart:io' ;
13
10
@@ -26,61 +23,49 @@ void main() {
26
23
final dylib = File ('test/native_objc_test/objc_test.dylib' );
27
24
verifySetupFile (dylib);
28
25
DynamicLibrary .open (dylib.absolute.path);
29
- generateBindingsForCoverage ('global_native ' );
26
+ generateBindingsForCoverage ('global ' );
30
27
});
31
28
32
29
test ('Global string' , () {
33
- expect (globalNativeString.toString (), 'Hello World' );
34
- globalNativeString = 'Something else' .toNSString ();
35
- expect (globalNativeString.toString (), 'Something else' );
30
+ expect (globalString.toString (), 'Hello World' );
31
+ globalString = 'Something else' .toNSString ();
32
+ expect (globalString.toString (), 'Something else' );
33
+ globalString = 'Hello World' .toNSString ();
36
34
});
37
35
38
- (Pointer <ObjCObject >, Pointer <ObjCObject >) globalObjectRefCountingInner () {
39
- final obj1 = NSObject .new1 ();
40
- globalNativeObject = obj1;
41
- final obj1raw = obj1.ref.pointer;
42
- expect (objectRetainCount (obj1raw), 2 ); // obj1, and the global variable.
43
-
44
- final obj2 = NSObject .new1 ();
45
- globalNativeObject = obj2;
46
- final obj2raw = obj2.ref.pointer;
47
- expect (objectRetainCount (obj2raw), 2 ); // obj2, and the global variable.
48
- expect (objectRetainCount (obj1raw), 1 ); // Just obj1.
49
- expect (obj1, isNotNull); // Force obj1 to stay in scope.
50
- expect (obj2, isNotNull); // Force obj2 to stay in scope.
51
-
52
- return (obj1raw, obj2raw);
36
+ Pointer <ObjCObject > globalObjectRefCountingInner () {
37
+ globalObject = NSObject .new1 ();
38
+ final obj1raw = globalObject! .ref.pointer;
39
+
40
+ // TODO(https://github.com/dart-lang/native/issues/1435): Fix flakiness.
41
+ // expect(objectRetainCount(obj1raw), greaterThan(0));
42
+
43
+ return obj1raw;
53
44
}
54
45
55
46
test ('Global object ref counting' , () {
56
- final (obj1raw, obj2raw) = globalObjectRefCountingInner ();
47
+ final obj1raw = globalObjectRefCountingInner ();
48
+ globalObject = null ;
57
49
doGC ();
58
-
59
- expect (objectRetainCount (obj2raw), 1 ); // Just the global variable.
60
- expect (objectRetainCount (obj1raw), 0 );
61
-
62
- globalNativeObject = null ;
63
- expect (objectRetainCount (obj2raw), 0 );
64
50
expect (objectRetainCount (obj1raw), 0 );
65
51
}, skip: ! canDoGC);
66
52
67
53
test ('Global block' , () {
68
- globalNativeBlock = ObjCBlock_Int32_Int32 .fromFunction ((int x) => x * 10 );
69
- expect (globalNativeBlock !(123 ), 1230 );
70
- globalNativeBlock =
71
- ObjCBlock_Int32_Int32 .fromFunction ((int x) => x + 1000 );
72
- expect (globalNativeBlock !(456 ), 1456 );
54
+ globalBlock = ObjCBlock_Int32_Int32 .fromFunction ((int x) => x * 10 );
55
+ expect (globalBlock !(123 ), 1230 );
56
+ globalBlock = ObjCBlock_Int32_Int32 .fromFunction ((int x) => x + 1000 );
57
+ expect (globalBlock !(456 ), 1456 );
73
58
});
74
59
75
60
(Pointer <ObjCBlockImpl >, Pointer <ObjCBlockImpl >)
76
61
globalBlockRefCountingInner () {
77
62
final blk1 = ObjCBlock_Int32_Int32 .fromFunction ((int x) => x * 10 );
78
- globalNativeBlock = blk1;
63
+ globalBlock = blk1;
79
64
final blk1raw = blk1.ref.pointer;
80
65
expect (blockRetainCount (blk1raw), 2 ); // blk1, and the global variable.
81
66
82
67
final blk2 = ObjCBlock_Int32_Int32 .fromFunction ((int x) => x + 1000 );
83
- globalNativeBlock = blk2;
68
+ globalBlock = blk2;
84
69
final blk2raw = blk2.ref.pointer;
85
70
expect (blockRetainCount (blk2raw), 2 ); // blk2, and the global variable.
86
71
expect (blockRetainCount (blk1raw), 1 ); // Just blk1.
@@ -97,7 +82,7 @@ void main() {
97
82
expect (blockRetainCount (blk2raw), 1 ); // Just the global variable.
98
83
expect (blockRetainCount (blk1raw), 0 );
99
84
100
- globalNativeBlock = null ;
85
+ globalBlock = null ;
101
86
expect (blockRetainCount (blk2raw), 0 );
102
87
expect (blockRetainCount (blk1raw), 0 );
103
88
}, skip: ! canDoGC);
0 commit comments