From c2976f7ad8eec386bc2a60b55233de3b0db34ace Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 12 Sep 2023 12:17:01 -0700 Subject: [PATCH] Reland "Build iOS unittest target in unopt builds" (#44356)"" (#45346)" (flutter/engine#45519) Reland https://github.com/flutter/engine/pull/44821 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- engine/src/flutter/BUILD.gn | 4 + .../shell/platform/darwin/ios/BUILD.gn | 2 +- .../Source/FlutterChannelKeyResponderTest.mm | 15 +- .../Source/FlutterEmbedderKeyResponderTest.mm | 6 +- .../Source/FlutterEngineGroupTest.mm | 1 + .../framework/Source/FlutterEngineTest_mrc.mm | 1 + .../framework/Source/FlutterFakeKeyEvents.h | 31 +++-- .../framework/Source/FlutterFakeKeyEvents.mm | 5 + .../Source/FlutterKeyboardManagerTest.mm | 2 + .../Source/FlutterPlatformViewsTest.mm | 131 +++++++++--------- .../Source/FlutterTextureRegistryRelayTest.mm | 1 + .../Source/FlutterUndoManagerPluginTest.mm | 2 +- .../Source/FlutterViewControllerTest.mm | 22 +-- .../Source/FlutterViewControllerTest_mrc.mm | 84 +++++------ .../ios/framework/Source/FlutterViewTest.mm | 15 +- .../framework/Source/SemanticsObjectTest.mm | 20 +-- .../framework/Source/VsyncWaiterIosTest.mm | 9 +- .../Source/accessibility_bridge_test.mm | 6 +- .../ios/platform_message_handler_ios_test.mm | 2 +- 19 files changed, 188 insertions(+), 171 deletions(-) diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 05fbbb0933..704c0f2c86 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -149,6 +149,10 @@ group("unittests") { [ "//flutter/shell/platform/android:flutter_shell_native_unittests" ] } + if (is_ios) { + public_deps += [ "//flutter/shell/platform/darwin/ios:ios_test_flutter" ] + } + # Compile all unittests targets if enabled. if (enable_unittests) { public_deps += [ diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index f726f41f23..fe180c2af4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -270,7 +270,7 @@ source_set("ios_test_flutter_mrc") { shared_library("ios_test_flutter") { testonly = true - visibility = [ ":*" ] + visibility = [ "*" ] cflags = [ "-fvisibility=default", "-F$platform_frameworks_path", diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterChannelKeyResponderTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterChannelKeyResponderTest.mm index fcdcb37cb0..16b26ceabd 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterChannelKeyResponderTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterChannelKeyResponderTest.mm @@ -16,10 +16,7 @@ FLUTTER_ASSERT_ARC; XCTAssertTrue([value isEqualToString:expected], \ @"String \"%@\" not equal to the expected value of \"%@\"", value, expected) -namespace { -API_AVAILABLE(ios(13.4)) -constexpr UIKeyboardHIDUsage keyACode = (UIKeyboardHIDUsage)0x4; // KeyA iOS scan code. -} // namespace +using namespace flutter::testing; API_AVAILABLE(ios(13.4)) @interface FlutterChannelKeyResponderTest : XCTestCase @@ -35,8 +32,8 @@ API_AVAILABLE(ios(13.4)) } else { XCTSkip(@"Required API not present for test."); } - _testKeyDownEvent = keyDownEvent(keyACode, 0x0, 0.0f, "a", "a"); - _testKeyUpEvent = keyUpEvent(keyACode, 0x0, 0.0f); + _testKeyDownEvent = keyDownEvent(UIKeyboardHIDUsageKeyboardA, 0x0, 0.0f, "a", "a"); + _testKeyUpEvent = keyUpEvent(UIKeyboardHIDUsageKeyboardA, 0x0, 0.0f); } - (void)tearDown API_AVAILABLE(ios(13.4)) { @@ -76,7 +73,7 @@ API_AVAILABLE(ios(13.4)) XCTAssertEqual([messages count], 1u); XCTAssertStrEqual([messages lastObject][@"keymap"], @"ios"); XCTAssertStrEqual([messages lastObject][@"type"], @"keydown"); - XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], keyACode); + XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA); XCTAssertEqual([[messages lastObject][@"modifiers"] intValue], 0x0); XCTAssertStrEqual([messages lastObject][@"characters"], @"a"); XCTAssertStrEqual([messages lastObject][@"charactersIgnoringModifiers"], @"a"); @@ -97,7 +94,7 @@ API_AVAILABLE(ios(13.4)) XCTAssertEqual([messages count], 1u); XCTAssertStrEqual([messages lastObject][@"keymap"], @"ios"); XCTAssertStrEqual([messages lastObject][@"type"], @"keyup"); - XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], keyACode); + XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA); XCTAssertEqual([[messages lastObject][@"modifiers"] intValue], 0x0); XCTAssertEqual([responses count], 1u); @@ -134,7 +131,7 @@ API_AVAILABLE(ios(13.4)) XCTAssertEqual([messages count], 1u); XCTAssertStrEqual([messages lastObject][@"keymap"], @"ios"); XCTAssertStrEqual([messages lastObject][@"type"], @"keydown"); - XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], keyACode); + XCTAssertEqual([[messages lastObject][@"keyCode"] intValue], UIKeyboardHIDUsageKeyboardA); XCTAssertEqual([[messages lastObject][@"modifiers"] intValue], 0x0); XCTAssertStrEqual([messages lastObject][@"characters"], @"a"); XCTAssertStrEqual([messages lastObject][@"charactersIgnoringModifiers"], @"a"); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponderTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponderTest.mm index f29d3b2d13..0aac9fdaf3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponderTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponderTest.mm @@ -15,6 +15,7 @@ #include "flutter/shell/platform/embedder/test_utils/key_codes.g.h" using namespace flutter::testing::keycodes; +using namespace flutter::testing; FLUTTER_ASSERT_ARC; @@ -43,7 +44,7 @@ FLUTTER_ASSERT_ARC; if (event->character != nullptr) { size_t len = strlen(event->character); char* character = new char[len + 1]; - strcpy(character, event->character); + strlcpy(character, event->character, len + 1); _data->character = character; } _callback = callback; @@ -63,8 +64,9 @@ FLUTTER_ASSERT_ARC; } - (void)dealloc { - if (_data->character != nullptr) + if (_data->character != nullptr) { delete[] _data->character; + } delete _data; } @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineGroupTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineGroupTest.mm index db43205c05..77929ea6b4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineGroupTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineGroupTest.mm @@ -132,6 +132,7 @@ FLUTTER_ASSERT_ARC FlutterDartProject* mockProject = OCMClassMock([FlutterDartProject class]); FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo" project:mockProject]; + XCTAssertNotNil(group); weakProject = mockProject; XCTAssertNotNil(weakProject); group = nil; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm index 1acf3755f0..35ad2c4c21 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm @@ -60,6 +60,7 @@ FLUTTER_ASSERT_NOT_ARC engine.ensureSemanticsEnabledCalled = NO; [engine flutterViewAccessibilityDidCall]; XCTAssertTrue(engine.ensureSemanticsEnabledCalled); + [engine release]; } @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h index 387ec5a7bb..d2996c1e4a 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h @@ -47,26 +47,29 @@ API_AVAILABLE(ios(13.4)) @property(readwrite, nonatomic) NSString* dataCharactersIgnoringModifiers; @end -FlutterUIPressProxy* keyDownEvent(UIKeyboardHIDUsage keyCode, - UIKeyModifierFlags modifierFlags = 0x0, - NSTimeInterval timestamp = 0.0f, - const char* characters = "", - const char* charactersIgnoringModifiers = "") +namespace flutter { +namespace testing { +extern FlutterUIPressProxy* keyDownEvent(UIKeyboardHIDUsage keyCode, + UIKeyModifierFlags modifierFlags = 0x0, + NSTimeInterval timestamp = 0.0f, + const char* characters = "", + const char* charactersIgnoringModifiers = "") API_AVAILABLE(ios(13.4)); -FlutterUIPressProxy* keyUpEvent(UIKeyboardHIDUsage keyCode, - UIKeyModifierFlags modifierFlags = 0x0, - NSTimeInterval timestamp = 0.0f, - const char* characters = "", - const char* charactersIgnoringModifiers = "") - API_AVAILABLE(ios(13.4)); - -FlutterUIPressProxy* keyEventWithPhase(UIPressPhase phase, - UIKeyboardHIDUsage keyCode, +extern FlutterUIPressProxy* keyUpEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags = 0x0, NSTimeInterval timestamp = 0.0f, const char* characters = "", const char* charactersIgnoringModifiers = "") API_AVAILABLE(ios(13.4)); +extern FlutterUIPressProxy* keyEventWithPhase(UIPressPhase phase, + UIKeyboardHIDUsage keyCode, + UIKeyModifierFlags modifierFlags = 0x0, + NSTimeInterval timestamp = 0.0f, + const char* characters = "", + const char* charactersIgnoringModifiers = "") + API_AVAILABLE(ios(13.4)); +} // namespace testing +} // namespace flutter #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTER_FAKE_KEY_EVENTS_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.mm index abbdbc0626..aaca2b8985 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.mm @@ -84,6 +84,9 @@ FLUTTER_ASSERT_ARC; } @end +namespace flutter { +namespace testing { + FlutterUIPressProxy* keyDownEvent(UIKeyboardHIDUsage keyCode, UIKeyModifierFlags modifierFlags, NSTimeInterval timestamp, @@ -123,3 +126,5 @@ FlutterUIPressProxy* keyEventWithPhase(UIPressPhase phase, type:UIEventTypePresses timestamp:timestamp]; } +} // namespace testing +} // namespace flutter diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm index 764a64b242..5568c38016 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterKeyboardManagerTest.mm @@ -21,6 +21,8 @@ namespace flutter { class PointerDataPacket {}; } // namespace flutter +using namespace flutter::testing; + /// Sometimes we have to use a custom mock to avoid retain cycles in ocmock. @interface FlutterEnginePartialMock : FlutterEngine @property(nonatomic, strong) FlutterBasicMessageChannel* lifecycleChannel; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index bba4502177..1e6dad5608 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -125,7 +125,7 @@ class FlutterPlatformViewsTestMockPlatformViewDelegate : public PlatformView::De } // namespace flutter namespace { -fml::RefPtr CreateNewThread(std::string name) { +fml::RefPtr CreateNewThread(const std::string& name) { auto thread = std::make_unique(name); auto runner = thread->GetTaskRunner(); return runner; @@ -155,7 +155,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -211,7 +211,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -265,7 +265,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -337,7 +337,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -409,7 +409,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -482,7 +482,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -595,7 +595,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -732,7 +732,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1009,7 +1009,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1208,29 +1208,29 @@ fml::RefPtr CreateNewThread(std::string name) { // The gaussianBlur filter is extracted from UIVisualEffectView. // Each test requires a new PlatformViewFilter // Valid UIVisualEffectView API - UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + UIVisualEffectView* visualEffectView = [[[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]] autorelease]; PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:visualEffectView]; + [[[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:visualEffectView] autorelease]; XCTAssertNotNil(platformViewFilter); } - (void)testApplyBackdropFilterAPIChangedInvalidUIVisualEffectView { [PlatformViewFilter resetPreparation]; - UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] init]; + UIVisualEffectView* visualEffectView = [[[UIVisualEffectView alloc] init] autorelease]; PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:visualEffectView]; + [[[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:visualEffectView] autorelease]; XCTAssertNil(platformViewFilter); } - (void)testApplyBackdropFilterAPIChangedNoGaussianBlurFilter { [PlatformViewFilter resetPreparation]; - UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + UIVisualEffectView* editedUIVisualEffectView = [[[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]] autorelease]; NSArray* subviews = editedUIVisualEffectView.subviews; for (UIView* view in subviews) { if ([NSStringFromClass([view class]) hasSuffix:@"BackdropView"]) { @@ -1244,16 +1244,16 @@ fml::RefPtr CreateNewThread(std::string name) { } } PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:editedUIVisualEffectView]; + [[[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:editedUIVisualEffectView] autorelease]; XCTAssertNil(platformViewFilter); } - (void)testApplyBackdropFilterAPIChangedInvalidInputRadius { [PlatformViewFilter resetPreparation]; - UIVisualEffectView* editedUIVisualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + UIVisualEffectView* editedUIVisualEffectView = [[[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]] autorelease]; NSArray* subviews = editedUIVisualEffectView.subviews; for (UIView* view in subviews) { if ([NSStringFromClass([view class]) hasSuffix:@"BackdropView"]) { @@ -1268,20 +1268,20 @@ fml::RefPtr CreateNewThread(std::string name) { } PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:editedUIVisualEffectView]; + [[[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:editedUIVisualEffectView] autorelease]; XCTAssertNil(platformViewFilter); } - (void)testBackdropFilterVisualEffectSubviewBackgroundColor { - UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc] - initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; + UIVisualEffectView* visualEffectView = [[[UIVisualEffectView alloc] + initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]] autorelease]; PlatformViewFilter* platformViewFilter = - [[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) - blurRadius:5 - visualEffectView:visualEffectView]; - CGColorRef visualEffectSubviewBackgroundColor; + [[[PlatformViewFilter alloc] initWithFrame:CGRectMake(0, 0, 10, 10) + blurRadius:5 + visualEffectView:visualEffectView] autorelease]; + CGColorRef visualEffectSubviewBackgroundColor = nil; for (UIView* view in [platformViewFilter backdropFilterView].subviews) { if ([NSStringFromClass([view class]) hasSuffix:@"VisualEffectSubview"]) { visualEffectSubviewBackgroundColor = view.layer.backgroundColor; @@ -1309,7 +1309,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1365,7 +1365,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1459,7 +1459,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1530,7 +1530,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1597,7 +1597,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1663,7 +1663,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1736,7 +1736,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1809,7 +1809,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1883,7 +1883,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -1947,7 +1947,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2068,7 +2068,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2179,7 +2179,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2241,7 +2241,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2306,7 +2306,7 @@ fml::RefPtr CreateNewThread(std::string name) { flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2356,7 +2356,7 @@ fml::RefPtr CreateNewThread(std::string name) { flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2412,7 +2412,7 @@ fml::RefPtr CreateNewThread(std::string name) { flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2510,7 +2510,7 @@ fml::RefPtr CreateNewThread(std::string name) { flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2608,7 +2608,7 @@ fml::RefPtr CreateNewThread(std::string name) { flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2645,8 +2645,8 @@ fml::RefPtr CreateNewThread(std::string name) { // Unmerge threads before the end of the test // TaskRunners are required to be unmerged before destruction. - while (raster_thread_merger->DecrementLease() != fml::RasterThreadStatus::kUnmergedNow) - ; + while (raster_thread_merger->DecrementLease() != fml::RasterThreadStatus::kUnmergedNow) { + } } - (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view { @@ -2668,8 +2668,8 @@ fml::RefPtr CreateNewThread(std::string name) { - (void)testHasFirstResponderInViewHierarchySubtree_viewItselfBecomesFirstResponder { // For view to become the first responder, it must be a descendant of a UIWindow - UIWindow* window = [[UIWindow alloc] init]; - UITextField* textField = [[UITextField alloc] init]; + UIWindow* window = [[[UIWindow alloc] init] autorelease]; + UITextField* textField = [[[UITextField alloc] init] autorelease]; [window addSubview:textField]; [textField becomeFirstResponder]; @@ -2682,10 +2682,10 @@ fml::RefPtr CreateNewThread(std::string name) { - (void)testHasFirstResponderInViewHierarchySubtree_descendantViewBecomesFirstResponder { // For view to become the first responder, it must be a descendant of a UIWindow - UIWindow* window = [[UIWindow alloc] init]; - UIView* view = [[UIView alloc] init]; - UIView* childView = [[UIView alloc] init]; - UITextField* textField = [[UITextField alloc] init]; + UIWindow* window = [[[UIWindow alloc] init] autorelease]; + UIView* view = [[[UIView alloc] init] autorelease]; + UIView* childView = [[[UIView alloc] init] autorelease]; + UITextField* textField = [[[UITextField alloc] init] autorelease]; [window addSubview:view]; [view addSubview:childView]; [childView addSubview:textField]; @@ -2738,6 +2738,7 @@ fml::RefPtr CreateNewThread(std::string name) { // The only retain left is our manual retain called inside the autorelease pool, meaning the // maskViews are dealloc'd. XCTAssertEqual(retainedView.retainCount, 1u); + [retainedView release]; } - (void)testClipMaskViewIsReused { @@ -2758,7 +2759,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2840,7 +2841,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -2943,7 +2944,7 @@ fml::RefPtr CreateNewThread(std::string name) { flutterPlatformViewsController->SetFlutterView(mockFlutterView); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -3048,7 +3049,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*is_gpu_disabled_sync_switch=*/nil); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = - [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + [[[FlutterPlatformViewsTestMockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelayTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelayTest.mm index 36b473dea8..790b484075 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelayTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelayTest.mm @@ -61,6 +61,7 @@ FLUTTER_ASSERT_ARC weakEngine = engine; } XCTAssertNil(weakEngine); + XCTAssertNotNil(strongRelay); } @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm index 0a30cb1dfb..24f9bba023 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm @@ -41,7 +41,7 @@ FLUTTER_ASSERT_ARC self.undoManagerPlugin = [[FlutterUndoManagerPluginForTest alloc] initWithDelegate:self.engine]; - self.viewController = [FlutterViewController new]; + self.viewController = [[FlutterViewController alloc] init]; self.undoManagerPlugin.viewController = self.viewController; self.undoManager = OCMClassMock([NSUndoManager class]); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index e348978f51..35ffaac68b 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -22,6 +22,8 @@ FLUTTER_ASSERT_ARC +using namespace flutter::testing; + @interface FlutterEngine () - (FlutterTextInputPlugin*)textInputPlugin; - (void)sendKeyEvent:(const FlutterKeyEvent&)event @@ -57,8 +59,9 @@ FLUTTER_ASSERT_ARC - (void)sendKeyEvent:(const FlutterKeyEvent&)event callback:(FlutterKeyEventCallback)callback userData:(void*)userData API_AVAILABLE(ios(9.0)) { - if (callback == nil) + if (callback == nil) { return; + } // NSAssert(callback != nullptr, @"Invalid callback"); // Response is async, so we have to post it to the run loop instead of calling // it directly. @@ -1179,10 +1182,6 @@ extern NSNotificationName const FlutterViewControllerWillDealloc; // Setup test. id settingsChannel = OCMClassMock([FlutterBasicMessageChannel class]); OCMStub([self.mockEngine settingsChannel]).andReturn(settingsChannel); - - FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine - nibName:nil - bundle:nil]; id mockTraitCollection = [self fakeTraitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark]; @@ -1190,7 +1189,9 @@ extern NSNotificationName const FlutterViewControllerWillDealloc; // the UITraitCollection of our choice. Mocking the object under test is not // desirable, but given that the OS does not offer a DI approach to providing // our own UITraitCollection, this seems to be the least bad option. - id partialMockVC = OCMPartialMock(realVC); + id partialMockVC = OCMPartialMock([[FlutterViewController alloc] initWithEngine:self.mockEngine + nibName:nil + bundle:nil]); OCMStub([partialMockVC traitCollection]).andReturn(mockTraitCollection); // Exercise behavior under test. @@ -1283,16 +1284,15 @@ extern NSNotificationName const FlutterViewControllerWillDealloc; id settingsChannel = OCMClassMock([FlutterBasicMessageChannel class]); OCMStub([self.mockEngine settingsChannel]).andReturn(settingsChannel); - FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine - nibName:nil - bundle:nil]; id mockTraitCollection = [self fakeTraitCollectionWithContrast:UIAccessibilityContrastHigh]; // We partially mock the real FlutterViewController to act as the OS and report // the UITraitCollection of our choice. Mocking the object under test is not // desirable, but given that the OS does not offer a DI approach to providing // our own UITraitCollection, this seems to be the least bad option. - id partialMockVC = OCMPartialMock(realVC); + id partialMockVC = OCMPartialMock([[FlutterViewController alloc] initWithEngine:self.mockEngine + nibName:nil + bundle:nil]); OCMStub([partialMockVC traitCollection]).andReturn(mockTraitCollection); // Exercise behavior under test. @@ -1575,6 +1575,7 @@ extern NSNotificationName const FlutterViewControllerWillDealloc; [[XCTestExpectation alloc] initWithDescription:@"notification called"]; id engine = [[MockEngine alloc] init]; @autoreleasepool { + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; @@ -1584,6 +1585,7 @@ extern NSNotificationName const FlutterViewControllerWillDealloc; usingBlock:^(NSNotification* _Nonnull note) { [expectation fulfill]; }]; + XCTAssertNotNil(realVC); realVC = nil; } [self waitForExpectations:@[ expectation ] timeout:1.0]; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest_mrc.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest_mrc.mm index bb691f033e..c0bd4ea9af 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest_mrc.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest_mrc.mm @@ -51,11 +51,10 @@ FLUTTER_ASSERT_NOT_ARC id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; double maxFrameRate = 120; [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; - FlutterEngine* engine = [[FlutterEngine alloc] init]; + FlutterEngine* engine = [[[FlutterEngine alloc] init] autorelease]; [engine runWithEntrypoint:nil]; - FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine - nibName:nil - bundle:nil]; + FlutterViewController* viewController = + [[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease]; FlutterKeyboardAnimationCallback callback = ^(fml::TimePoint targetTime) { }; [viewController setUpKeyboardAnimationVsyncClient:callback]; @@ -76,11 +75,10 @@ FLUTTER_ASSERT_NOT_ARC id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; double maxFrameRate = 120; [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; - FlutterEngine* engine = [[FlutterEngine alloc] init]; + FlutterEngine* engine = [[[FlutterEngine alloc] init] autorelease]; [engine runWithEntrypoint:nil]; - FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine - nibName:nil - bundle:nil]; + FlutterViewController* viewController = + [[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease]; [viewController createTouchRateCorrectionVSyncClientIfNeeded]; XCTAssertNotNil(viewController.touchRateCorrectionVSyncClient); } @@ -90,11 +88,10 @@ FLUTTER_ASSERT_NOT_ARC double maxFrameRate = 120; [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; - FlutterEngine* engine = [[FlutterEngine alloc] init]; + FlutterEngine* engine = [[[FlutterEngine alloc] init] autorelease]; [engine runWithEntrypoint:nil]; - FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine - nibName:nil - bundle:nil]; + FlutterViewController* viewController = + [[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease]; [viewController createTouchRateCorrectionVSyncClientIfNeeded]; VSyncClient* clientBefore = viewController.touchRateCorrectionVSyncClient; XCTAssertNotNil(clientBefore); @@ -110,11 +107,10 @@ FLUTTER_ASSERT_NOT_ARC id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; double maxFrameRate = 60; [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; - FlutterEngine* engine = [[FlutterEngine alloc] init]; + FlutterEngine* engine = [[[FlutterEngine alloc] init] autorelease]; [engine runWithEntrypoint:nil]; - FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine - nibName:nil - bundle:nil]; + FlutterViewController* viewController = + [[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease]; [viewController createTouchRateCorrectionVSyncClientIfNeeded]; XCTAssertNil(viewController.touchRateCorrectionVSyncClient); } @@ -123,67 +119,72 @@ FLUTTER_ASSERT_NOT_ARC id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; double maxFrameRate = 120; [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; - FlutterEngine* engine = [[FlutterEngine alloc] init]; + FlutterEngine* engine = [[[FlutterEngine alloc] init] autorelease]; [engine runWithEntrypoint:nil]; - FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine - nibName:nil - bundle:nil]; + FlutterViewController* viewController = + [[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease]; [viewController loadView]; [viewController viewDidLoad]; VSyncClient* client = viewController.touchRateCorrectionVSyncClient; CADisplayLink* link = [client getDisplayLink]; - UITouch* fakeTouchBegan = [[UITouch alloc] init]; + UITouch* fakeTouchBegan = [[[UITouch alloc] init] autorelease]; fakeTouchBegan.phase = UITouchPhaseBegan; - UITouch* fakeTouchMove = [[UITouch alloc] init]; + UITouch* fakeTouchMove = [[[UITouch alloc] init] autorelease]; fakeTouchMove.phase = UITouchPhaseMoved; - UITouch* fakeTouchEnd = [[UITouch alloc] init]; + UITouch* fakeTouchEnd = [[[UITouch alloc] init] autorelease]; fakeTouchEnd.phase = UITouchPhaseEnded; - UITouch* fakeTouchCancelled = [[UITouch alloc] init]; + UITouch* fakeTouchCancelled = [[[UITouch alloc] init] autorelease]; fakeTouchCancelled.phase = UITouchPhaseCancelled; [viewController - triggerTouchRateCorrectionIfNeeded:[[NSSet alloc] initWithObjects:fakeTouchBegan, nil]]; + triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchBegan, nil] + autorelease]]; XCTAssertFalse(link.isPaused); [viewController - triggerTouchRateCorrectionIfNeeded:[[NSSet alloc] initWithObjects:fakeTouchEnd, nil]]; + triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchEnd, nil] + autorelease]]; XCTAssertTrue(link.isPaused); [viewController - triggerTouchRateCorrectionIfNeeded:[[NSSet alloc] initWithObjects:fakeTouchMove, nil]]; + triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchMove, nil] + autorelease]]; XCTAssertFalse(link.isPaused); [viewController - triggerTouchRateCorrectionIfNeeded:[[NSSet alloc] initWithObjects:fakeTouchCancelled, nil]]; + triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchCancelled, nil] + autorelease]]; XCTAssertTrue(link.isPaused); [viewController - triggerTouchRateCorrectionIfNeeded:[[NSSet alloc] - initWithObjects:fakeTouchBegan, fakeTouchEnd, nil]]; + triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] + initWithObjects:fakeTouchBegan, fakeTouchEnd, nil] + autorelease]]; XCTAssertFalse(link.isPaused); [viewController - triggerTouchRateCorrectionIfNeeded:[[NSSet alloc] initWithObjects:fakeTouchEnd, - fakeTouchCancelled, nil]]; + triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] + initWithObjects:fakeTouchEnd, fakeTouchCancelled, nil] + autorelease]]; XCTAssertTrue(link.isPaused); [viewController - triggerTouchRateCorrectionIfNeeded:[[NSSet alloc] - initWithObjects:fakeTouchMove, fakeTouchEnd, nil]]; + triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] + initWithObjects:fakeTouchMove, fakeTouchEnd, nil] + autorelease]]; XCTAssertFalse(link.isPaused); } - (void)testFlutterViewControllerStartKeyboardAnimationWillCreateVsyncClientCorrectly { - FlutterEngine* engine = [[FlutterEngine alloc] init]; + FlutterEngine* engine = [[[FlutterEngine alloc] init] autorelease]; [engine runWithEntrypoint:nil]; - FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine - nibName:nil - bundle:nil]; + FlutterViewController* viewController = + [[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease]; viewController.targetViewInsetBottom = 100; [viewController startKeyBoardAnimation:0.25]; XCTAssertNotNil(viewController.keyboardAnimationVSyncClient); @@ -191,11 +192,10 @@ FLUTTER_ASSERT_NOT_ARC - (void) testSetupKeyboardAnimationVsyncClientWillNotCreateNewVsyncClientWhenKeyboardAnimationCallbackIsNil { - FlutterEngine* engine = [[FlutterEngine alloc] init]; + FlutterEngine* engine = [[[FlutterEngine alloc] init] autorelease]; [engine runWithEntrypoint:nil]; - FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine - nibName:nil - bundle:nil]; + FlutterViewController* viewController = + [[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease]; [viewController setUpKeyboardAnimationVsyncClient:nil]; XCTAssertNil(viewController.keyboardAnimationVSyncClient); } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm index 23d9b2dc52..78f95210e3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm @@ -43,23 +43,26 @@ @implementation FlutterViewTest - (void)testFlutterViewEnableSemanticsWhenIsAccessibilityElementIsCalled { - FakeDelegate* delegate = [[FakeDelegate alloc] init]; - FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:NO]; + FakeDelegate* delegate = [[[FakeDelegate alloc] init] autorelease]; + FlutterView* view = [[[FlutterView alloc] initWithDelegate:delegate opaque:NO + enableWideGamut:NO] autorelease]; delegate.callbackCalled = NO; XCTAssertFalse(view.isAccessibilityElement); XCTAssertTrue(delegate.callbackCalled); } - (void)testFlutterViewBackgroundColorIsNotNil { - FakeDelegate* delegate = [[FakeDelegate alloc] init]; - FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:NO]; + FakeDelegate* delegate = [[[FakeDelegate alloc] init] autorelease]; + FlutterView* view = [[[FlutterView alloc] initWithDelegate:delegate opaque:NO + enableWideGamut:NO] autorelease]; XCTAssertNotNil(view.backgroundColor); } - (void)testIgnoreWideColorWithoutImpeller { - FakeDelegate* delegate = [[FakeDelegate alloc] init]; + FakeDelegate* delegate = [[[FakeDelegate alloc] init] autorelease]; delegate.isUsingImpeller = NO; - FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:YES]; + FlutterView* view = [[[FlutterView alloc] initWithDelegate:delegate opaque:NO + enableWideGamut:YES] autorelease]; [view layoutSubviews]; XCTAssertTrue([view.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]); CAMetalLayer* layer = (CAMetalLayer*)view.layer; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm index c2200af6a6..2a3f7e799e 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm @@ -660,9 +660,11 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { [scrollable accessibilityBridgeDidFinishUpdate]; UIScrollView* scrollView = [scrollable nativeAccessibility]; XCTAssertTrue(scrollView.isAccessibilityElement); - XCTAssertTrue([scrollView.accessibilityLabel isEqualToString:@"label"]); - XCTAssertTrue([scrollView.accessibilityValue isEqualToString:@"value"]); - XCTAssertTrue([scrollView.accessibilityHint isEqualToString:@"hint"]); + XCTAssertTrue( + [scrollView.accessibilityLabel isEqualToString:NSLocalizedString(@"label", @"test")]); + XCTAssertTrue( + [scrollView.accessibilityValue isEqualToString:NSLocalizedString(@"value", @"test")]); + XCTAssertTrue([scrollView.accessibilityHint isEqualToString:NSLocalizedString(@"hint", @"test")]); } - (void)testFlutterSemanticsObjectMergeTooltipToLabel { @@ -788,7 +790,7 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { FlutterSemanticsObject* object = [[FlutterSemanticsObject alloc] initWithBridge:bridge uid:0]; [object setSemanticsNode:&node]; NSMutableAttributedString* expectedAttributedLabel = - [[NSMutableAttributedString alloc] initWithString:@"label"]; + [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"label", @"test")]; NSDictionary* attributeDict = @{ UIAccessibilitySpeechAttributeSpellOut : @YES, }; @@ -797,7 +799,7 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { [object.accessibilityAttributedLabel isEqualToAttributedString:expectedAttributedLabel]); NSMutableAttributedString* expectedAttributedValue = - [[NSMutableAttributedString alloc] initWithString:@"value"]; + [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"value", @"test")]; attributeDict = @{ UIAccessibilitySpeechAttributeSpellOut : @YES, }; @@ -806,7 +808,7 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { [object.accessibilityAttributedValue isEqualToAttributedString:expectedAttributedValue]); NSMutableAttributedString* expectedAttributedHint = - [[NSMutableAttributedString alloc] initWithString:@"hint"]; + [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"hint", @"test")]; attributeDict = @{ UIAccessibilitySpeechAttributeLanguage : @"en-MX", }; @@ -935,7 +937,7 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { nativeSwitch.on = YES; XCTAssertEqual(object.accessibilityTraits, nativeSwitch.accessibilityTraits); - XCTAssertEqual(object.accessibilityValue, nativeSwitch.accessibilityValue); + XCTAssertEqualObjects(object.accessibilityValue, nativeSwitch.accessibilityValue); // Set the toggled to false; flutter::SemanticsNode update; @@ -947,7 +949,7 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { nativeSwitch.on = NO; XCTAssertEqual(object.accessibilityTraits, nativeSwitch.accessibilityTraits); - XCTAssertEqual(object.accessibilityValue, nativeSwitch.accessibilityValue); + XCTAssertEqualObjects(object.accessibilityValue, nativeSwitch.accessibilityValue); } - (void)testFlutterSemanticsObjectOfRadioButton { @@ -987,7 +989,7 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { nativeSwitch.enabled = NO; XCTAssertEqual(object.accessibilityTraits, nativeSwitch.accessibilityTraits); - XCTAssertEqual(object.accessibilityValue, nativeSwitch.accessibilityValue); + XCTAssertEqualObjects(object.accessibilityValue, nativeSwitch.accessibilityValue); } - (void)testSemanticsObjectDeallocated { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm index eace658519..39fc0341fc 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm @@ -13,7 +13,7 @@ FLUTTER_ASSERT_NOT_ARC namespace { -fml::RefPtr CreateNewThread(std::string name) { +fml::RefPtr CreateNewThread(const std::string& name) { auto thread = std::make_unique(name); auto runner = thread->GetTaskRunner(); return runner; @@ -48,8 +48,6 @@ fml::RefPtr CreateNewThread(std::string name) { [vsyncClient await]; [vsyncClient onDisplayLink:link]; XCTAssertTrue(link.isPaused); - - [vsyncClient release]; } - (void)testSetCorrectVariableRefreshRates { @@ -72,7 +70,6 @@ fml::RefPtr CreateNewThread(std::string name) { } else { XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, maxFrameRate, 0.1); } - [vsyncClient release]; } - (void)testDoNotSetVariableRefreshRatesIfCADisableMinimumFrameDurationOnPhoneIsNotOn { @@ -95,7 +92,6 @@ fml::RefPtr CreateNewThread(std::string name) { } else { XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, 0, 0.1); } - [vsyncClient release]; } - (void)testDoNotSetVariableRefreshRatesIfCADisableMinimumFrameDurationOnPhoneIsNotSet { @@ -114,7 +110,6 @@ fml::RefPtr CreateNewThread(std::string name) { } else { XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, 0, 0.1); } - [vsyncClient release]; } - (void)testAwaitAndPauseWillWorkCorrectly { @@ -132,8 +127,6 @@ fml::RefPtr CreateNewThread(std::string name) { [vsyncClient pause]; XCTAssertTrue(link.isPaused); - - [vsyncClient release]; } - (void)testRefreshRateUpdatedTo80WhenThraedsMerge { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm index 283d4fe02d..ac44da5370 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm @@ -125,7 +125,7 @@ class MockIosDelegate : public AccessibilityBridge::IosDelegate { } // namespace flutter namespace { -fml::RefPtr CreateNewThread(std::string name) { +fml::RefPtr CreateNewThread(const std::string& name) { auto thread = std::make_unique(name); auto runner = thread->GetTaskRunner(); return runner; @@ -288,7 +288,7 @@ fml::RefPtr CreateNewThread(std::string name) { std::string label = "some label"; flutterPlatformViewsController->SetFlutterView(mockFlutterView); - MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease]; + MockFlutterPlatformFactory* factory = [[[MockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); @@ -342,7 +342,7 @@ fml::RefPtr CreateNewThread(std::string name) { /*worker_task_runner=*/nil, /*is_gpu_disabled_sync_switch=*/nil); - MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease]; + MockFlutterPlatformFactory* factory = [[[MockFlutterPlatformFactory alloc] init] autorelease]; flutterPlatformViewsController->RegisterViewFactory( factory, @"MockFlutterPlatformView", FlutterPlatformViewGestureRecognizersBlockingPolicyEager); diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios_test.mm b/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios_test.mm index 9216457765..c1988bc215 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios_test.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_message_handler_ios_test.mm @@ -18,7 +18,7 @@ FLUTTER_ASSERT_NOT_ARC namespace { using namespace flutter; -fml::RefPtr CreateNewThread(std::string name) { +fml::RefPtr CreateNewThread(const std::string& name) { auto thread = std::make_unique(name); auto runner = thread->GetTaskRunner(); return runner;