-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
Tests/KSCrashFiltersTests/KSCrashReportFilterDoctor_Tests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#import <XCTest/XCTest.h> | ||
|
||
#import "KSCrashReportFilterDoctor.h" | ||
#import "KSCrashReport.h" | ||
#import "KSCrashReportFields.h" | ||
#import "KSTestModuleConfig.h" | ||
|
||
@interface KSCrashDoctor_Tests : XCTestCase | ||
@end | ||
|
||
@implementation KSCrashDoctor_Tests | ||
|
||
- (KSCrashReportDictionary *)_crashReportAsJSON:(NSString *)filename | ||
{ | ||
NSURL *url = [KS_TEST_MODULE_BUNDLE URLForResource:filename withExtension:@"json"]; | ||
NSData *data = [NSData dataWithContentsOfURL:url]; | ||
NSDictionary *reportDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; | ||
return [KSCrashReportDictionary reportWithValue:reportDict]; | ||
} | ||
|
||
- (KSCrashReportDictionary *)_filteredReport:(KSCrashReportDictionary *)report | ||
{ | ||
KSCrashReportDictionary *__block result = nil; | ||
KSCrashReportFilterDoctor *filter = [KSCrashReportFilterDoctor new]; | ||
[filter filterReports:@[report] onCompletion:^(NSArray<id<KSCrashReport>> *filteredReports, NSError *error) { | ||
Check failure on line 25 in Tests/KSCrashFiltersTests/KSCrashReportFilterDoctor_Tests.m GitHub Actions / Formatting Check
Check failure on line 25 in Tests/KSCrashFiltersTests/KSCrashReportFilterDoctor_Tests.m GitHub Actions / Formatting Check
Check failure on line 25 in Tests/KSCrashFiltersTests/KSCrashReportFilterDoctor_Tests.m GitHub Actions / Formatting Check
|
||
result = filteredReports.firstObject; | ||
XCTAssertNil(error); | ||
}]; | ||
return result; | ||
} | ||
|
||
- (void)testGracefulTermination | ||
{ | ||
KSCrashReportDictionary *report = [self _crashReportAsJSON:@"sigterm"]; | ||
KSCrashReportDictionary *resultReport = [self _filteredReport:report]; | ||
NSString *diagnostic = resultReport.value[KSCrashField_Crash][KSCrashField_Diagnosis]; | ||
XCTAssertEqual(diagnostic, @"The OS request the app be gracefully terminated."); | ||
} | ||
|
||
- (void)testOOM | ||
{ | ||
KSCrashReportDictionary *report = [self _crashReportAsJSON:@"oom"]; | ||
KSCrashReportDictionary *resultReport = [self _filteredReport:report]; | ||
NSString *diagnostic = resultReport.value[KSCrashField_Crash][KSCrashField_Diagnosis]; | ||
XCTAssertEqual(diagnostic, @"The app was terminated due to running out of memory (OOM)."); | ||
} | ||
|
||
@end |