FIRCLSMockReportUploader.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/FIRCLSMockReportUploader.h"
  15. #import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
  16. #import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
  17. @interface FIRCLSMockReportUploader () {
  18. NSMutableArray *_prepareAndSubmitReportArray;
  19. NSMutableArray *_uploadReportArray;
  20. }
  21. @end
  22. @implementation FIRCLSMockReportUploader
  23. - (instancetype)initWithQueue:(NSOperationQueue *)queue
  24. dataSource:(id<FIRCLSReportUploaderDataSource>)dataSource
  25. fileManager:(FIRCLSFileManager *)fileManager
  26. analytics:(id<FIRAnalyticsInterop>)analytics {
  27. self = [super initWithQueue:queue
  28. dataSource:dataSource
  29. fileManager:fileManager
  30. analytics:analytics];
  31. if (!self) {
  32. return nil;
  33. }
  34. _prepareAndSubmitReportArray = [[NSMutableArray alloc] init];
  35. _uploadReportArray = [[NSMutableArray alloc] init];
  36. return self;
  37. }
  38. - (void)prepareAndSubmitReport:(FIRCLSInternalReport *)report
  39. dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken
  40. asUrgent:(BOOL)urgent
  41. withProcessing:(BOOL)shouldProcess {
  42. [_prepareAndSubmitReportArray
  43. addObject:@{@"report" : report, @"urgent" : @(urgent), @"process" : @(shouldProcess)}];
  44. // report should be from active/processing here. We just need to "move" it.
  45. [self.fileManager removeItemAtPath:report.path];
  46. return;
  47. }
  48. - (void)uploadPackagedReportAtPath:(NSString *)path
  49. dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken
  50. asUrgent:(BOOL)urgent {
  51. [_uploadReportArray addObject:@{@"path" : path, @"urgent" : @(urgent)}];
  52. // After upload, the file should be removed.
  53. [self.fileManager removeItemAtPath:path];
  54. return;
  55. }
  56. @end