iOS: “namespace” Objective-C test classes by prefixing with CPTest
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: Ibf5f59de3ede212899f4fd264e2c79b47e91a1dc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2144453
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
GitOrigin-RevId: dc9176b063bee1d29885f70768946b10af1aae56
diff --git a/test/ios/google_test_setup.mm b/test/ios/google_test_setup.mm
index b221190..109c4b6 100644
--- a/test/ios/google_test_setup.mm
+++ b/test/ios/google_test_setup.mm
@@ -53,12 +53,13 @@
} // namespace
-@interface CrashpadUnitTestDelegate : NSObject <CPTestGoogleTestRunnerDelegate>
+@interface CPTestUnitTestApplicationDelegate
+ : NSObject <CPTestGoogleTestRunnerDelegate>
@property(nonatomic, readwrite, strong) UIWindow* window;
- (void)runTests;
@end
-@implementation CrashpadUnitTestDelegate
+@implementation CPTestUnitTestApplicationDelegate
- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
@@ -123,8 +124,8 @@
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 e0d289d..cd6995a 100644
--- a/test/ios/host/BUILD.gn
+++ b/test/ios/host/BUILD.gn
@@ -31,10 +31,10 @@
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/application_delegate.h b/test/ios/host/cptest_application_delegate.h
similarity index 71%
rename from test/ios/host/application_delegate.h
rename to test/ios/host/cptest_application_delegate.h
index 3405e7a..ca835f1 100644
--- a/test/ios/host/application_delegate.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_APPLICATION_DELEGATE_H_
-#define CRASHPAD_TEST_IOS_HOST_APPLICATION_DELEGATE_H_
+#ifndef CRASHPAD_TEST_IOS_HOST_CPTEST_APPLICATION_DELEGATE_H_
+#define CRASHPAD_TEST_IOS_HOST_CPTEST_APPLICATION_DELEGATE_H_
#import <UIKit/UIKit.h>
-@interface ApplicationDelegate : UIResponder <UIApplicationDelegate>
+@interface CPTestApplicationDelegate : UIResponder <UIApplicationDelegate>
@end
-#endif // CRASHPAD_TEST_IOS_HOST_APPLICATION_DELEGATE_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 c74229a..80baf8b 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 <dispatch/dispatch.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <vector>
#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/crash_view_controller.h b/test/ios/host/cptest_crash_view_controller.h
similarity index 72%
rename from test/ios/host/crash_view_controller.h
rename to test/ios/host/cptest_crash_view_controller.h
index fdbdfc1..2a41e12 100644
--- a/test/ios/host/crash_view_controller.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_CRASH_VIEW_CONTROLLER_H_
-#define CRASHPAD_TEST_IOS_HOST_CRASH_VIEW_CONTROLLER_H_
+#ifndef CRASHPAD_TEST_IOS_HOST_CPTEST_CRASH_VIEW_CONTROLLER_H_
+#define CRASHPAD_TEST_IOS_HOST_CPTEST_CRASH_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
-@interface CrashViewController : UIViewController
+@interface CPTestCrashViewController : UIViewController
@end
-#endif // CRASHPAD_TEST_IOS_HOST_CRASH_VIEW_CONTROLLER_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 f8c05f7..90f92da 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 932cd89..a0ae5c4 100644
--- a/test/ios/host/main.mm
+++ b/test/ios/host/main.mm
@@ -14,7 +14,7 @@
#import <UIKit/UIKit.h>
-#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 @@
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);
}