FIRExceptionModelTests.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2020 Google LLC
  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 <XCTest/XCTest.h>
  15. #import "Crashlytics/Crashlytics/Private/FIRExceptionModel_Private.h"
  16. #import "Crashlytics/Crashlytics/Private/FIRStackFrame_Private.h"
  17. @interface FIRExceptionModelTests : XCTestCase
  18. @end
  19. @implementation FIRExceptionModelTests
  20. - (void)testBasicOwnership {
  21. NSArray *stackTrace = @[
  22. [FIRStackFrame stackFrameWithSymbol:@"CrashyFunc" file:@"AppLib.m" line:504],
  23. [FIRStackFrame stackFrameWithSymbol:@"ApplicationMain" file:@"AppleLib" line:1],
  24. [FIRStackFrame stackFrameWithSymbol:@"main()" file:@"main.m" line:201],
  25. ];
  26. NSString *name = @"FIRExceptionModelTestsCrash";
  27. NSString *reason = @"Programmer made an error";
  28. FIRExceptionModel *model = [FIRExceptionModel exceptionModelWithName:name reason:reason];
  29. model.stackTrace = stackTrace;
  30. name = @"NewName";
  31. reason = nil;
  32. stackTrace = @[];
  33. XCTAssertEqualObjects(model.name, @"FIRExceptionModelTestsCrash");
  34. XCTAssertEqualObjects(model.reason, @"Programmer made an error");
  35. XCTAssertEqual(model.stackTrace.count, 3);
  36. XCTAssertEqualObjects(model.stackTrace[0].symbol, @"CrashyFunc");
  37. XCTAssertEqualObjects(model.stackTrace[2].fileName, @"main.m");
  38. }
  39. - (void)testMutableArrayOwnership {
  40. NSMutableArray<FIRStackFrame *> *stackTrace = [[NSMutableArray alloc] initWithArray:@[
  41. [FIRStackFrame stackFrameWithSymbol:@"CrashyFunc" file:@"AppLib.m" line:504],
  42. [FIRStackFrame stackFrameWithSymbol:@"ApplicationMain" file:@"AppleLib" line:1],
  43. [FIRStackFrame stackFrameWithSymbol:@"main()" file:@"main.m" line:201],
  44. ]];
  45. NSString *name = @"FIRExceptionModelTestsCrash";
  46. NSString *reason = @"Programmer made an error";
  47. FIRExceptionModel *model = [FIRExceptionModel exceptionModelWithName:name reason:reason];
  48. model.stackTrace = stackTrace;
  49. stackTrace[0].symbol = @"NewSymbol";
  50. FIRStackFrame *newFrame = [FIRStackFrame stackFrameWithSymbol:@"NewMain"
  51. file:@"below_main.m"
  52. line:300];
  53. [stackTrace addObject:newFrame];
  54. [stackTrace insertObject:newFrame atIndex:1];
  55. XCTAssertEqual(model.stackTrace.count, 3);
  56. // Modifying underlying frames in the stack trace will be reflected in the Exception Model's copy
  57. // because we only shallow copy the array and not the contents.
  58. XCTAssertEqualObjects(model.stackTrace[0].symbol, @"NewSymbol");
  59. // Inserted frames into the mutable array after the fact do not impact the array passed to the
  60. // Exception Model.
  61. XCTAssertEqualObjects(model.stackTrace[1].symbol, @"ApplicationMain");
  62. }
  63. @end