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: I3645ee830a30eccb594d679e0d52ba1a2dd1225d
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>
This commit is contained in:
Mark Mentovai 2020-04-15 10:33:31 -04:00 committed by Commit Bot
parent 24b4105d00
commit dc9176b063
7 changed files with 35 additions and 27 deletions

View File

@ -53,12 +53,13 @@ void RegisterTestEndListener() {
} // 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 @@ 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);
}
}

View File

@ -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" ]

View File

@ -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 <UIKit/UIKit.h>
@interface CrashViewController : UIViewController
@interface CPTestApplicationDelegate : UIResponder <UIApplicationDelegate>
@end
#endif // CRASHPAD_TEST_IOS_HOST_CRASH_VIEW_CONTROLLER_H_
#endif // CRASHPAD_TEST_IOS_HOST_CPTEST_APPLICATION_DELEGATE_H_

View File

@ -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 {

View File

@ -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 <UIKit/UIKit.h>
@interface ApplicationDelegate : UIResponder <UIApplicationDelegate>
@interface CPTestCrashViewController : UIViewController
@end
#endif // CRASHPAD_TEST_IOS_HOST_APPLICATION_DELEGATE_H_
#endif // CRASHPAD_TEST_IOS_HOST_CPTEST_CRASH_VIEW_CONTROLLER_H_

View File

@ -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];

View File

@ -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 @@ 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);
}