FIRCLSProcessReportOperationTests.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "FIRCLSProcessReportOperation.h"
  15. #import <Foundation/Foundation.h>
  16. #import <XCTest/XCTest.h>
  17. #import "FIRCLSFile.h"
  18. #import "FIRCLSFileManager.h"
  19. #import "FIRCLSInternalReport.h"
  20. #import "FIRCLSMockSymbolResolver.h"
  21. #import "FIRStackFrame_Private.h"
  22. @interface FIRCLSProcessReportOperationTests : XCTestCase
  23. @end
  24. @implementation FIRCLSProcessReportOperationTests
  25. - (void)setUp {
  26. [super setUp];
  27. // Put setup code here. This method is called before the invocation of each test method in the
  28. // class.
  29. }
  30. - (void)tearDown {
  31. // Put teardown code here. This method is called after the invocation of each test method in the
  32. // class.
  33. [super tearDown];
  34. }
  35. - (NSString *)resourcePath {
  36. return [[NSBundle bundleForClass:[self class]] resourcePath];
  37. }
  38. - (NSString *)pathForResource:(NSString *)name {
  39. return [[self resourcePath] stringByAppendingPathComponent:name];
  40. }
  41. - (FIRCLSInternalReport *)createReportAndPath {
  42. NSString *reportPath =
  43. [NSTemporaryDirectory() stringByAppendingPathComponent:@"execution_identifier"];
  44. FIRCLSInternalReport *report =
  45. [[FIRCLSInternalReport alloc] initWithPath:reportPath
  46. executionIdentifier:@"execution_identifier"];
  47. // create the directory path
  48. assert([[NSFileManager defaultManager] createDirectoryAtPath:[report path]
  49. withIntermediateDirectories:YES
  50. attributes:nil
  51. error:nil]);
  52. return report;
  53. }
  54. #if TARGET_OS_IPHONE
  55. #else
  56. - (void)testExceptionSymbolication {
  57. // Setup a resolver that will work for the contents of the file
  58. FIRCLSMockSymbolResolver *resolver = [[FIRCLSMockSymbolResolver alloc] init];
  59. FIRStackFrame *frame = nil;
  60. frame = [FIRStackFrame stackFrameWithSymbol:@"testSymbolA"];
  61. [frame setLibrary:@"libA"];
  62. [frame setOffset:10];
  63. [resolver addMockFrame:frame atAddress:4321599284];
  64. // create a report and symbolicate
  65. FIRCLSInternalReport *report = [self createReportAndPath];
  66. NSFileManager *fileManager = [NSFileManager defaultManager];
  67. // put an exception in place
  68. XCTAssertTrue([fileManager copyItemAtPath:[self pathForResource:FIRCLSReportExceptionFile]
  69. toPath:[report pathForContentFile:FIRCLSReportExceptionFile]
  70. error:nil],
  71. @"");
  72. FIRCLSProcessReportOperation *operation =
  73. [[FIRCLSProcessReportOperation alloc] initWithReport:report resolver:resolver];
  74. [operation start];
  75. // Read the symbolicated output and verify
  76. NSArray *sections = FIRCLSFileReadSections(
  77. [[report pathForContentFile:@"exception.clsrecord.symbolicated"] fileSystemRepresentation],
  78. false, nil);
  79. XCTAssertEqual([sections count], 1, @"");
  80. XCTAssertEqualObjects(sections[0][@"threads"][0][0][@"library"], @"libA", @"");
  81. XCTAssertEqualObjects(sections[0][@"threads"][0][0][@"offset"], @(10), @"");
  82. XCTAssertEqualObjects(sections[0][@"threads"][0][0][@"symbol"], @"testSymbolA", @"");
  83. }
  84. #endif
  85. @end