From 49850c328cd4ba9c0ddeb0e8763bf13718188433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Terelius?= Date: Wed, 4 May 2022 10:59:56 +0200 Subject: [PATCH] Fork test/ios/google_test_runner.mm from Chromium's //base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebRTC should not depend on Chromium's //base. Bug: webrtc:13662 Change-Id: I7ce7036c96b26a79de46a519ed24dd660a298433 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260925 Commit-Queue: Björn Terelius Reviewed-by: Mirko Bonadei Reviewed-by: Andrey Logvin Cr-Commit-Position: refs/heads/main@{#36754} --- test/BUILD.gn | 18 +++++++++--- test/ios/google_test_runner.mm | 40 ++++++++++++++++++++++++++ test/ios/google_test_runner_delegate.h | 4 +-- webrtc.gni | 4 +-- 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 test/ios/google_test_runner.mm diff --git a/test/BUILD.gn b/test/BUILD.gn index 9157a9e9ad..9787c76201 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -298,7 +298,10 @@ rtc_library("perf_test") { if (is_ios) { rtc_library("test_support_objc") { testonly = true - visibility = [ ":test_support" ] + visibility = [ + ":google_test_runner_objc", + ":test_support", + ] sources = [ "ios/coverage_util_ios.h", "ios/coverage_util_ios.mm", @@ -314,6 +317,15 @@ if (is_ios) { configs += [ ":test_support_objc_config" ] } + rtc_library("google_test_runner_objc") { + testonly = true + visibility = [ "*" ] + sources = [ "ios/google_test_runner.mm" ] + deps = [ ":test_support_objc" ] + configs += [ "//build/config/ios:xctest_config" ] + frameworks = [ "UIKit.framework" ] + } + config("test_support_objc_config") { defines = [] @@ -976,9 +988,7 @@ if (is_mac) { "mac/video_renderer_mac.h", "mac/video_renderer_mac.mm", ] - deps = [ - ":test_renderer_generic", - ] + deps = [ ":test_renderer_generic" ] frameworks = [ "Cocoa.framework", "OpenGL.framework", diff --git a/test/ios/google_test_runner.mm b/test/ios/google_test_runner.mm new file mode 100644 index 0000000000..87b7f7dfd7 --- /dev/null +++ b/test/ios/google_test_runner.mm @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +// Copied from Chromium base/test/ios/google_test_runner.mm to avoid +// the //base dependency. The protocol is required to run iOS Unittest. + +#import +#import + +#import "test/ios/google_test_runner_delegate.h" + +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + +@interface GoogleTestRunner : XCTestCase +@end + +@implementation GoogleTestRunner + +- (void)testRunGoogleTests { + self.continueAfterFailure = false; + + id appDelegate = UIApplication.sharedApplication.delegate; + XCTAssertTrue([appDelegate conformsToProtocol:@protocol(GoogleTestRunnerDelegate)]); + + id runnerDelegate = + static_cast>(appDelegate); + XCTAssertTrue(runnerDelegate.supportsRunningGoogleTests); + XCTAssertTrue([runnerDelegate runGoogleTests] == 0); +} + +@end diff --git a/test/ios/google_test_runner_delegate.h b/test/ios/google_test_runner_delegate.h index bb3493aea6..78ee59e028 100644 --- a/test/ios/google_test_runner_delegate.h +++ b/test/ios/google_test_runner_delegate.h @@ -12,8 +12,8 @@ #define TEST_IOS_GOOGLE_TEST_RUNNER_DELEGATE_H_ // Copied from Chromium base/test/ios/google_test_runner_delegate.h -// The WebRTC test cannot depend on //base, but this protocol is required -// to run iOS Unittest, so it is a workaround for the dependency. +// to avoid the //base dependency. This protocol is required +// to run iOS Unittest. @protocol GoogleTestRunnerDelegate // Returns YES if this delegate supports running GoogleTests via a call to diff --git a/webrtc.gni b/webrtc.gni index d52497d151..264f0d6863 100644 --- a/webrtc.gni +++ b/webrtc.gni @@ -498,10 +498,10 @@ template("rtc_test") { ] } - # Build //base/test:google_test_runner when the test is not a real XCTest. + # Build //test:google_test_runner_objc when the test is not a real XCTest. if (is_ios && rtc_include_tests) { if (!defined(invoker.is_xctest) || !invoker.is_xctest) { - xctest_module_target = "//base/test:google_test_runner" + xctest_module_target = "//test:google_test_runner_objc" } }