FIRCLSProcessReportOperationTests.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "Crashlytics/Crashlytics/Operations/Reports/FIRCLSProcessReportOperation.h"
  15. #import <Foundation/Foundation.h>
  16. #import <XCTest/XCTest.h>
  17. #import "Crashlytics/Crashlytics/Helpers/FIRCLSFile.h"
  18. #import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
  19. #import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
  20. #import "Crashlytics/Crashlytics/Private/FIRStackFrame_Private.h"
  21. #import "Crashlytics/UnitTests/Mocks/FIRCLSMockSymbolResolver.h"
  22. @interface FIRCLSProcessReportOperationTests : XCTestCase
  23. @end
  24. @implementation FIRCLSProcessReportOperationTests
  25. - (void)setUp {
  26. [super setUp];
  27. [[NSFileManager defaultManager] removeItemAtPath:self.reportPath error:nil];
  28. }
  29. - (void)tearDown {
  30. [[NSFileManager defaultManager] removeItemAtPath:self.reportPath error:nil];
  31. [super tearDown];
  32. }
  33. - (NSString *)resourcePath {
  34. return [[NSBundle bundleForClass:[self class]] resourcePath];
  35. }
  36. - (NSString *)reportPath {
  37. return [NSTemporaryDirectory() stringByAppendingPathComponent:@"execution_identifier"];
  38. }
  39. - (NSString *)pathForResource:(NSString *)name {
  40. return [[self resourcePath] stringByAppendingPathComponent:name];
  41. }
  42. - (FIRCLSInternalReport *)createReportAndPath {
  43. FIRCLSInternalReport *report =
  44. [[FIRCLSInternalReport alloc] initWithPath:self.reportPath
  45. executionIdentifier:@"execution_identifier"];
  46. // create the directory path
  47. assert([[NSFileManager defaultManager] createDirectoryAtPath:[report path]
  48. withIntermediateDirectories:YES
  49. attributes:nil
  50. error:nil]);
  51. return report;
  52. }
  53. #if TARGET_OS_IPHONE
  54. #else
  55. - (void)testExceptionSymbolication {
  56. // Setup a resolver that will work for the contents of the file
  57. FIRCLSMockSymbolResolver *resolver = [[FIRCLSMockSymbolResolver alloc] init];
  58. FIRStackFrame *frame = nil;
  59. frame = [FIRStackFrame stackFrameWithSymbol:@"testSymbolA"];
  60. [frame setLibrary:@"libA"];
  61. [frame setOffset:10];
  62. [resolver addMockFrame:frame atAddress:4321599284];
  63. // create a report and symbolicate
  64. FIRCLSInternalReport *report = [self createReportAndPath];
  65. NSFileManager *fileManager = [NSFileManager defaultManager];
  66. // put an exception in place
  67. XCTAssertTrue([fileManager copyItemAtPath:[self pathForResource:FIRCLSReportExceptionFile]
  68. toPath:[report pathForContentFile:FIRCLSReportExceptionFile]
  69. error:nil],
  70. @"");
  71. FIRCLSProcessReportOperation *operation =
  72. [[FIRCLSProcessReportOperation alloc] initWithReport:report resolver:resolver];
  73. [operation start];
  74. // Read the symbolicated output and verify
  75. NSArray *sections = FIRCLSFileReadSections(
  76. [[report pathForContentFile:@"exception.clsrecord.symbolicated"] fileSystemRepresentation],
  77. false, nil);
  78. XCTAssertEqual([sections count], 1, @"");
  79. XCTAssertEqualObjects(sections[0][@"threads"][0][0][@"library"], @"libA", @"");
  80. XCTAssertEqualObjects(sections[0][@"threads"][0][0][@"offset"], @(10), @"");
  81. XCTAssertEqualObjects(sections[0][@"threads"][0][0][@"symbol"], @"testSymbolA", @"");
  82. }
  83. #endif
  84. @end