Peter 76e5a7fab6 Add 'submodules/HockeySDK-iOS/' from commit 'c7d0c7026303253e2ac576c02655691e5d314fe2'
git-subtree-dir: submodules/HockeySDK-iOS
git-subtree-mainline: 085acd26c4432939403765234266e3c1be0f3dd9
git-subtree-split: c7d0c7026303253e2ac576c02655691e5d314fe2
2019-06-11 18:53:14 +01:00

81 lines
2.6 KiB
Objective-C

#import "BITTestHelper.h"
#import "HockeySDKPrivate.h"
@implementation BITTestHelper
// loads test fixture from json file
// http://blog.roberthoglund.com/2010/12/ios-unit-testing-loading-bundle.html
+ (NSString *)jsonFixture:(NSString *)fixture {
NSString *path = [[NSBundle bundleForClass:self.class] pathForResource:fixture ofType:@"json"];
NSError *error = nil;
NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
return content;
}
+ (BOOL)createTempDirectory:(NSString *)directory {
NSFileManager *fm = [[NSFileManager alloc] init];
if (![fm fileExistsAtPath:directory]) {
NSDictionary *attributes = [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedLong: 0755] forKey: NSFilePosixPermissions];
NSError *theError = NULL;
[fm createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:attributes error:&theError];
if (theError)
return NO;
}
return YES;
}
+ (BOOL)copyFixtureCrashReportWithFileName:(NSString *)filename {
NSFileManager *fm = [[NSFileManager alloc] init];
// the bundle identifier when running with unit tets is "otest"
const char *progname = getprogname();
if (progname == NULL) {
return NO;
}
NSString *bundleIdentifierPathString = [NSString stringWithUTF8String: progname];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
// create the PLCR cache dir
NSString *plcrRootCrashesDir = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"com.plausiblelabs.crashreporter.data"];
if (![BITTestHelper createTempDirectory:plcrRootCrashesDir])
return NO;
NSString *plcrCrashesDir = [plcrRootCrashesDir stringByAppendingPathComponent:bundleIdentifierPathString];
if (![BITTestHelper createTempDirectory:plcrCrashesDir])
return NO;
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:filename ofType:@"plcrash"];
NSError *theError = NULL;
if (!filePath) return NO;
[fm copyItemAtPath:filePath toPath:[plcrCrashesDir stringByAppendingPathComponent:@"live_report.plcrash"] error:&theError];
if (theError)
return NO;
else
return YES;
}
+ (NSData *)dataOfFixtureCrashReportWithFileName:(NSString *)filename {
// the bundle identifier when running with unit tets is "otest"
const char *progname = getprogname();
if (progname == NULL) {
return nil;
}
NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:filename ofType:@"plcrash"];
if (!filePath) return nil;
NSData *data = [NSData dataWithContentsOfFile:filePath];
return data;
}
@end