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" } }