FIRCLSMockExistingReportManager.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/UnitTests/Mocks/FIRCLSMockExistingReportManager.h"
  15. #import "Crashlytics/Crashlytics/Controllers/FIRCLSManagerData.h"
  16. #import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
  17. #import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
  18. #import "Crashlytics/Crashlytics/Private/FIRCrashlyticsReport_Private.h"
  19. #import "Crashlytics/Crashlytics/Public/FirebaseCrashlytics/FIRCrashlyticsReport.h"
  20. @interface FIRCLSMockExistingReportManager ()
  21. @property(nonatomic, strong) FIRCLSFileManager *fileManager;
  22. @property(nonatomic) BOOL shouldHaveExistingReport;
  23. @end
  24. @implementation FIRCLSMockExistingReportManager
  25. - (instancetype)initWithManagerData:(FIRCLSManagerData *)managerData
  26. reportUploader:(FIRCLSReportUploader *)reportUploader {
  27. self = [super initWithManagerData:managerData reportUploader:reportUploader];
  28. if (!self) {
  29. return nil;
  30. }
  31. _fileManager = managerData.fileManager;
  32. _shouldHaveExistingReport = NO;
  33. return self;
  34. }
  35. - (FIRCrashlyticsReport *)newestUnsentReport {
  36. if (!self.shouldHaveExistingReport) return [super newestUnsentReport];
  37. NSString *reportPath =
  38. [self.fileManager.activePath stringByAppendingPathComponent:@"my_session_id"];
  39. FIRCLSInternalReport *report = [[FIRCLSInternalReport alloc] initWithPath:reportPath
  40. executionIdentifier:@"my_session_id"];
  41. return [[FIRCrashlyticsReport alloc] initWithInternalReport:report];
  42. }
  43. - (void)setShouldHaveExistingReport {
  44. self.shouldHaveExistingReport = YES;
  45. }
  46. @end