FIRCLSContextManagerTests.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // Copyright 2022 Google LLC
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #import <XCTest/XCTest.h>
  16. #import "Crashlytics/Crashlytics/Controllers/FIRCLSContextManager.h"
  17. #import "Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h"
  18. #import "Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter_Private.h"
  19. #import "Crashlytics/Crashlytics/Settings/Models/FIRCLSApplicationIdentifierModel.h"
  20. #import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
  21. #import "Crashlytics/UnitTests/Mocks/FIRCLSMockFileManager.h"
  22. #import "Crashlytics/UnitTests/Mocks/FIRCLSMockSettings.h"
  23. #import "Crashlytics/UnitTests/Mocks/FIRMockInstallations.h"
  24. NSString *const TestContextReportID = @"TestContextReportID";
  25. NSString *const TestContextSessionID = @"TestContextSessionID";
  26. NSString *const TestContextSessionID2 = @"TestContextSessionID2";
  27. @interface FIRCLSContextManagerTests : XCTestCase
  28. @property(nonatomic, strong) FIRCLSMockFileManager *fileManager;
  29. @property(nonatomic, strong) FIRCLSMockSettings *mockSettings;
  30. @property(nonatomic, strong) FIRCLSContextManager *contextManager;
  31. @property(nonatomic, strong) FIRCLSInternalReport *report;
  32. @property(nonatomic, strong) FIRCLSInstallIdentifierModel *installIDModel;
  33. @end
  34. @implementation FIRCLSContextManagerTests
  35. - (void)setUp {
  36. self.fileManager = [[FIRCLSMockFileManager alloc] init];
  37. [self.fileManager createReportDirectories];
  38. [self.fileManager setupNewPathForExecutionIdentifier:TestContextReportID];
  39. FIRCLSApplicationIdentifierModel *appIDModel = [[FIRCLSApplicationIdentifierModel alloc] init];
  40. _mockSettings = [[FIRCLSMockSettings alloc] initWithFileManager:self.fileManager
  41. appIDModel:appIDModel];
  42. // NSString *name = @"exception_model_report";
  43. NSString *reportPath =
  44. [self.fileManager.activePath stringByAppendingPathComponent:TestContextReportID];
  45. self.report = [[FIRCLSInternalReport alloc] initWithPath:reportPath
  46. executionIdentifier:TestContextReportID];
  47. self.contextManager = [[FIRCLSContextManager alloc] init];
  48. FIRMockInstallations *iid = [[FIRMockInstallations alloc] initWithFID:@"test_token"];
  49. self.installIDModel = [[FIRCLSInstallIdentifierModel alloc] initWithInstallations:iid];
  50. }
  51. - (void)tearDown {
  52. [[NSFileManager defaultManager] removeItemAtPath:self.fileManager.rootPath error:nil];
  53. [super tearDown];
  54. }
  55. - (void)test_notSettingSessionID_protoHasNilSessionID {
  56. [self.contextManager setupContextWithReport:self.report
  57. settings:self.mockSettings
  58. fileManager:self.fileManager];
  59. FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
  60. googleAppId:@"TestGoogleAppID"
  61. installIDModel:self.installIDModel
  62. fiid:@"TestFIID"
  63. authToken:@"TestAuthToken"];
  64. XCTAssertEqualObjects(adapter.identity.app_quality_session_id, @"");
  65. }
  66. - (void)test_settingSessionIDMultipleTimes_protoHasLastSessionID {
  67. [self.contextManager setAppQualitySessionId:TestContextSessionID];
  68. [self.contextManager setupContextWithReport:self.report
  69. settings:self.mockSettings
  70. fileManager:self.fileManager];
  71. [self.contextManager setAppQualitySessionId:TestContextSessionID2];
  72. FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
  73. googleAppId:@"TestGoogleAppID"
  74. installIDModel:self.installIDModel
  75. fiid:@"TestFIID"
  76. authToken:@"TestAuthToken"];
  77. NSLog(@"reportPath: %@", self.report.path);
  78. XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);
  79. }
  80. - (void)test_settingSessionIDOutOfOrder_protoHasLastSessionID {
  81. [self.contextManager setupContextWithReport:self.report
  82. settings:self.mockSettings
  83. fileManager:self.fileManager];
  84. [self.contextManager setAppQualitySessionId:TestContextSessionID];
  85. [self.contextManager setAppQualitySessionId:TestContextSessionID2];
  86. FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
  87. googleAppId:@"TestGoogleAppID"
  88. installIDModel:self.installIDModel
  89. fiid:@"TestFIID"
  90. authToken:@"TestAuthToken"];
  91. NSLog(@"reportPath: %@", self.report.path);
  92. XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);
  93. }
  94. @end