Skip to content

Commit

Permalink
[Darwin] Enable ARC in darwin/common unit tests (flutter#44396)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cbracken authored Aug 4, 2023
1 parent 56cd9b1 commit 4f4734c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
4 changes: 4 additions & 0 deletions shell/platform/darwin/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ executable("framework_common_unittests") {
"framework/Source/flutter_standard_codec_unittest.mm",
]

cflags_objcc = flutter_cflags_objcc_arc

ldflags = [ "-ObjC" ]

deps = [
":framework_common",
":framework_common_fixtures",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if !__has_feature(objc_arc)
#error ARC must be enabled!
#endif

#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"

#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>

FLUTTER_ASSERT_ARC

@protocol FlutterTaskQueue <NSObject>
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include <Foundation/Foundation.h>

#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"

FLUTTER_ASSERT_ARC

NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL) {
NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager
enumeratorAtURL:searchURL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "gtest/gtest.h"

FLUTTER_ASSERT_ARC

TEST(FlutterStringCodec, CanEncodeAndDecodeNil) {
FlutterStringCodec* codec = [FlutterStringCodec sharedInstance];
ASSERT_TRUE([codec encode:nil] == nil);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "gtest/gtest.h"

FLUTTER_ASSERT_NOT_ARC
FLUTTER_ASSERT_ARC

@interface Pair : NSObject
@property(atomic, readonly, strong, nullable) NSObject* left;
Expand All @@ -18,17 +18,11 @@ @implementation Pair
- (instancetype)initWithLeft:(NSObject*)left right:(NSObject*)right {
self = [super init];
if (self) {
_left = [left retain];
_right = [right retain];
_left = left;
_right = right;
}
return self;
}

- (void)dealloc {
[_left release];
[_right release];
[super dealloc];
}
@end

static const UInt8 kDATE = 128;
Expand Down Expand Up @@ -71,7 +65,7 @@ - (id)readValueOfType:(UInt8)type {
return [NSDate dateWithTimeIntervalSince1970:time];
}
case kPAIR: {
return [[[Pair alloc] initWithLeft:[self readValue] right:[self readValue]] autorelease];
return [[Pair alloc] initWithLeft:[self readValue] right:[self readValue]];
}
default:
return [super readValueOfType:type];
Expand All @@ -86,10 +80,10 @@ - (FlutterStandardReader*)readerWithData:(NSData*)data;

@implementation ExtendedReaderWriter
- (FlutterStandardWriter*)writerWithData:(NSMutableData*)data {
return [[[ExtendedWriter alloc] initWithData:data] autorelease];
return [[ExtendedWriter alloc] initWithData:data];
}
- (FlutterStandardReader*)readerWithData:(NSData*)data {
return [[[ExtendedReader alloc] initWithData:data] autorelease];
return [[ExtendedReader alloc] initWithData:data];
}
@end

Expand Down Expand Up @@ -341,10 +335,10 @@ static void CheckEncodeDecode(id value) {
}

TEST(FlutterStandardCodec, HandlesSubclasses) {
ExtendedReaderWriter* extendedReaderWriter = [[[ExtendedReaderWriter alloc] init] autorelease];
ExtendedReaderWriter* extendedReaderWriter = [[ExtendedReaderWriter alloc] init];
FlutterStandardMessageCodec* codec =
[FlutterStandardMessageCodec codecWithReaderWriter:extendedReaderWriter];
Pair* pair = [[[Pair alloc] initWithLeft:@1 right:@2] autorelease];
Pair* pair = [[Pair alloc] initWithLeft:@1 right:@2];
NSData* encoded = [codec encode:pair];
Pair* decoded = [codec decode:encoded];
ASSERT_TRUE([pair.left isEqual:decoded.left]);
Expand Down

0 comments on commit 4f4734c

Please sign in to comment.