Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4f4734c

Browse files
authored
[Darwin] Enable ARC in darwin/common unit tests (#44396)
The end goal is for all Objective-C code to be compiled with ARC enabled. The common framework code is already compiled with ARC enabled; this enables it for the tests as well. This is prework before migrating FlutterBinaryMessengerRelay to the common Darwin code. Issue: flutter/flutter#116445 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 56cd9b1 commit 4f4734c

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

shell/platform/darwin/common/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ executable("framework_common_unittests") {
7373
"framework/Source/flutter_standard_codec_unittest.mm",
7474
]
7575

76+
cflags_objcc = flutter_cflags_objcc_arc
77+
78+
ldflags = [ "-ObjC" ]
79+
7680
deps = [
7781
":framework_common",
7882
":framework_common_fixtures",

shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#if !__has_feature(objc_arc)
6-
#error ARC must be enabled!
7-
#endif
8-
95
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
106

117
#import <OCMock/OCMock.h>
128
#import <XCTest/XCTest.h>
139

10+
FLUTTER_ASSERT_ARC
11+
1412
@protocol FlutterTaskQueue <NSObject>
1513
@end
1614

shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
#include <Foundation/Foundation.h>
66

7+
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
8+
9+
FLUTTER_ASSERT_ARC
10+
711
NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL) {
812
NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager
913
enumeratorAtURL:searchURL

shell/platform/darwin/common/framework/Source/flutter_codecs_unittest.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "gtest/gtest.h"
88

9+
FLUTTER_ASSERT_ARC
10+
911
TEST(FlutterStringCodec, CanEncodeAndDecodeNil) {
1012
FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
1113
ASSERT_TRUE([codec encode:nil] == nil);

shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "gtest/gtest.h"
88

9-
FLUTTER_ASSERT_NOT_ARC
9+
FLUTTER_ASSERT_ARC
1010

1111
@interface Pair : NSObject
1212
@property(atomic, readonly, strong, nullable) NSObject* left;
@@ -18,17 +18,11 @@ @implementation Pair
1818
- (instancetype)initWithLeft:(NSObject*)left right:(NSObject*)right {
1919
self = [super init];
2020
if (self) {
21-
_left = [left retain];
22-
_right = [right retain];
21+
_left = left;
22+
_right = right;
2323
}
2424
return self;
2525
}
26-
27-
- (void)dealloc {
28-
[_left release];
29-
[_right release];
30-
[super dealloc];
31-
}
3226
@end
3327

3428
static const UInt8 kDATE = 128;
@@ -71,7 +65,7 @@ - (id)readValueOfType:(UInt8)type {
7165
return [NSDate dateWithTimeIntervalSince1970:time];
7266
}
7367
case kPAIR: {
74-
return [[[Pair alloc] initWithLeft:[self readValue] right:[self readValue]] autorelease];
68+
return [[Pair alloc] initWithLeft:[self readValue] right:[self readValue]];
7569
}
7670
default:
7771
return [super readValueOfType:type];
@@ -86,10 +80,10 @@ - (FlutterStandardReader*)readerWithData:(NSData*)data;
8680

8781
@implementation ExtendedReaderWriter
8882
- (FlutterStandardWriter*)writerWithData:(NSMutableData*)data {
89-
return [[[ExtendedWriter alloc] initWithData:data] autorelease];
83+
return [[ExtendedWriter alloc] initWithData:data];
9084
}
9185
- (FlutterStandardReader*)readerWithData:(NSData*)data {
92-
return [[[ExtendedReader alloc] initWithData:data] autorelease];
86+
return [[ExtendedReader alloc] initWithData:data];
9387
}
9488
@end
9589

@@ -341,10 +335,10 @@ static void CheckEncodeDecode(id value) {
341335
}
342336

343337
TEST(FlutterStandardCodec, HandlesSubclasses) {
344-
ExtendedReaderWriter* extendedReaderWriter = [[[ExtendedReaderWriter alloc] init] autorelease];
338+
ExtendedReaderWriter* extendedReaderWriter = [[ExtendedReaderWriter alloc] init];
345339
FlutterStandardMessageCodec* codec =
346340
[FlutterStandardMessageCodec codecWithReaderWriter:extendedReaderWriter];
347-
Pair* pair = [[[Pair alloc] initWithLeft:@1 right:@2] autorelease];
341+
Pair* pair = [[Pair alloc] initWithLeft:@1 right:@2];
348342
NSData* encoded = [codec encode:pair];
349343
Pair* decoded = [codec decode:encoded];
350344
ASSERT_TRUE([pair.left isEqual:decoded.left]);

0 commit comments

Comments
 (0)