From dc9176b063bee1d29885f70768946b10af1aae56 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Wed, 15 Apr 2020 10:33:31 -0400 Subject: [PATCH] =?UTF-8?q?iOS:=20=E2=80=9Cnamespace=E2=80=9D=C2=A0Objecti?= =?UTF-8?q?ve-C=20test=20classes=20by=20prefixing=20with=20CPTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re: https://chromium-review.googlesource.com/c/2028183/4/test/ios/crash_type_xctest.mm#13 We previously discussed using the CP prefix for Objective-C class and protocol names, and CPTest for those restricted to tests. This is intended to parallel our C++ code’s use of the crashpad and crashpad::test namespaces, but with name prefixing because Objective-C doesn’t support any other form of namespacing. These class names are changed: ApplicationDelegate→CPTestApplicationDelegate CrashViewController→CPTestCrashViewController CrashpadUnitTestDelegate→CPTestUnitTestApplicationDelegate Filenames and #include guards are also adjusted to match. This also has include-what-you-use fixes and more modern pointer handling in CPTestSharedObject, which was already named correctly. Bug: crashpad:31 Change-Id: I3645ee830a30eccb594d679e0d52ba1a2dd1225d Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2144453 Commit-Queue: Mark Mentovai Reviewed-by: Justin Cohen --- test/ios/google_test_setup.mm | 9 ++++---- test/ios/host/BUILD.gn | 8 +++---- ...roller.h => cptest_application_delegate.h} | 8 +++---- ...gate.mm => cptest_application_delegate.mm} | 21 ++++++++++++------- ...egate.h => cptest_crash_view_controller.h} | 8 +++---- ...ler.mm => cptest_crash_view_controller.mm} | 4 ++-- test/ios/host/main.mm | 4 ++-- 7 files changed, 35 insertions(+), 27 deletions(-) rename test/ios/host/{crash_view_controller.h => cptest_application_delegate.h} (71%) rename test/ios/host/{application_delegate.mm => cptest_application_delegate.mm} (87%) rename test/ios/host/{application_delegate.h => cptest_crash_view_controller.h} (72%) rename test/ios/host/{crash_view_controller.mm => cptest_crash_view_controller.mm} (90%) diff --git a/test/ios/google_test_setup.mm b/test/ios/google_test_setup.mm index b2211903..109c4b68 100644 --- a/test/ios/google_test_setup.mm +++ b/test/ios/google_test_setup.mm @@ -53,12 +53,13 @@ void RegisterTestEndListener() { } // namespace -@interface CrashpadUnitTestDelegate : NSObject +@interface CPTestUnitTestApplicationDelegate + : NSObject @property(nonatomic, readwrite, strong) UIWindow* window; - (void)runTests; @end -@implementation CrashpadUnitTestDelegate +@implementation CPTestUnitTestApplicationDelegate - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { @@ -123,8 +124,8 @@ namespace test { void IOSLaunchApplicationAndRunTests(int argc, char* argv[]) { @autoreleasepool { - int exit_status = - UIApplicationMain(argc, argv, nil, @"CrashpadUnitTestDelegate"); + int exit_status = UIApplicationMain( + argc, argv, nil, @"CPTestUnitTestApplicationDelegate"); exit(exit_status); } } diff --git a/test/ios/host/BUILD.gn b/test/ios/host/BUILD.gn index e0d289d4..cd6995a9 100644 --- a/test/ios/host/BUILD.gn +++ b/test/ios/host/BUILD.gn @@ -31,10 +31,10 @@ source_set("app_shared_sources") { static_library("app_host_sources") { testonly = true sources = [ - "application_delegate.h", - "application_delegate.mm", - "crash_view_controller.h", - "crash_view_controller.mm", + "cptest_application_delegate.h", + "cptest_application_delegate.mm", + "cptest_crash_view_controller.h", + "cptest_crash_view_controller.mm", "main.mm", ] configs += [ "../../..:crashpad_config" ] diff --git a/test/ios/host/crash_view_controller.h b/test/ios/host/cptest_application_delegate.h similarity index 71% rename from test/ios/host/crash_view_controller.h rename to test/ios/host/cptest_application_delegate.h index fdbdfc1a..ca835f12 100644 --- a/test/ios/host/crash_view_controller.h +++ b/test/ios/host/cptest_application_delegate.h @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CRASHPAD_TEST_IOS_HOST_CRASH_VIEW_CONTROLLER_H_ -#define CRASHPAD_TEST_IOS_HOST_CRASH_VIEW_CONTROLLER_H_ +#ifndef CRASHPAD_TEST_IOS_HOST_CPTEST_APPLICATION_DELEGATE_H_ +#define CRASHPAD_TEST_IOS_HOST_CPTEST_APPLICATION_DELEGATE_H_ #import -@interface CrashViewController : UIViewController +@interface CPTestApplicationDelegate : UIResponder @end -#endif // CRASHPAD_TEST_IOS_HOST_CRASH_VIEW_CONTROLLER_H_ +#endif // CRASHPAD_TEST_IOS_HOST_CPTEST_APPLICATION_DELEGATE_H_ diff --git a/test/ios/host/application_delegate.mm b/test/ios/host/cptest_application_delegate.mm similarity index 87% rename from test/ios/host/application_delegate.mm rename to test/ios/host/cptest_application_delegate.mm index c74229a8..80baf8b3 100644 --- a/test/ios/host/application_delegate.mm +++ b/test/ios/host/cptest_application_delegate.mm @@ -12,23 +12,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "test/ios/host/application_delegate.h" +#import "test/ios/host/cptest_application_delegate.h" #include +#include +#include +#include +#include #include #import "Service/Sources/EDOHostNamingService.h" #import "Service/Sources/EDOHostService.h" #include "client/crashpad_client.h" +#import "test/ios/host/cptest_crash_view_controller.h" #import "test/ios/host/cptest_shared_object.h" -#import "test/ios/host/crash_view_controller.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "This file requires ARC support." #endif -@implementation ApplicationDelegate +@implementation CPTestApplicationDelegate + @synthesize window = _window; - (BOOL)application:(UIApplication*)application @@ -41,7 +46,8 @@ [self.window makeKeyAndVisible]; self.window.backgroundColor = UIColor.greenColor; - CrashViewController* controller = [[CrashViewController alloc] init]; + CPTestCrashViewController* controller = + [[CPTestCrashViewController alloc] init]; self.window.rootViewController = controller; // Start up EDO. @@ -54,12 +60,13 @@ @end @implementation CPTestSharedObject + - (NSString*)testEDO { return @"crashpad"; } - (void)crashBadAccess { - strcpy(0, "bla"); + strcpy(nullptr, "bla"); } - (void)crashKillAbort { @@ -67,8 +74,8 @@ } - (void)crashSegv { - long zero = 0; - *(long*)zero = 0xC045004d; + long* zero = nullptr; + *zero = 0xc045004d; } - (void)crashTrap { diff --git a/test/ios/host/application_delegate.h b/test/ios/host/cptest_crash_view_controller.h similarity index 72% rename from test/ios/host/application_delegate.h rename to test/ios/host/cptest_crash_view_controller.h index 3405e7a8..2a41e129 100644 --- a/test/ios/host/application_delegate.h +++ b/test/ios/host/cptest_crash_view_controller.h @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CRASHPAD_TEST_IOS_HOST_APPLICATION_DELEGATE_H_ -#define CRASHPAD_TEST_IOS_HOST_APPLICATION_DELEGATE_H_ +#ifndef CRASHPAD_TEST_IOS_HOST_CPTEST_CRASH_VIEW_CONTROLLER_H_ +#define CRASHPAD_TEST_IOS_HOST_CPTEST_CRASH_VIEW_CONTROLLER_H_ #import -@interface ApplicationDelegate : UIResponder +@interface CPTestCrashViewController : UIViewController @end -#endif // CRASHPAD_TEST_IOS_HOST_APPLICATION_DELEGATE_H_ +#endif // CRASHPAD_TEST_IOS_HOST_CPTEST_CRASH_VIEW_CONTROLLER_H_ diff --git a/test/ios/host/crash_view_controller.mm b/test/ios/host/cptest_crash_view_controller.mm similarity index 90% rename from test/ios/host/crash_view_controller.mm rename to test/ios/host/cptest_crash_view_controller.mm index f8c05f76..90f92dae 100644 --- a/test/ios/host/crash_view_controller.mm +++ b/test/ios/host/cptest_crash_view_controller.mm @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "test/ios/host/crash_view_controller.h" +#import "test/ios/host/cptest_crash_view_controller.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "This file requires ARC support." #endif -@implementation CrashViewController +@implementation CPTestCrashViewController - (void)loadView { self.view = [[UIView alloc] init]; diff --git a/test/ios/host/main.mm b/test/ios/host/main.mm index 932cd897..a0ae5c46 100644 --- a/test/ios/host/main.mm +++ b/test/ios/host/main.mm @@ -14,7 +14,7 @@ #import -#import "test/ios/host/application_delegate.h" +#import "test/ios/host/cptest_application_delegate.h" #if !defined(__has_feature) || !__has_feature(objc_arc) #error "This file requires ARC support." @@ -24,7 +24,7 @@ int main(int argc, char* argv[]) { NSString* appDelegateClassName; @autoreleasepool { // Setup code that might create autoreleased objects goes here. - appDelegateClassName = NSStringFromClass([ApplicationDelegate class]); + appDelegateClassName = NSStringFromClass([CPTestApplicationDelegate class]); } return UIApplicationMain(argc, argv, nil, appDelegateClassName); }