FIRCLSMockOnDemandModel.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2022 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 "Crashlytics/UnitTests/Mocks/FIRCLSMockOnDemandModel.h"
  15. #import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
  16. @interface FIRCLSMockOnDemandModel ()
  17. @property(nonatomic, readonly) FIRCLSSettings *settings;
  18. @property(nonatomic, readonly) FIRCLSFileManager *fileManager;
  19. @end
  20. @implementation FIRCLSMockOnDemandModel
  21. - (instancetype)initWithFIRCLSSettings:(FIRCLSSettings *)settings
  22. fileManager:(FIRCLSFileManager *)fileManager
  23. sleepBlock:(void (^)(int))sleepBlock {
  24. self = [super initWithFIRCLSSettings:settings fileManager:fileManager];
  25. if (!self) {
  26. return nil;
  27. }
  28. _settings = settings;
  29. _fileManager = fileManager;
  30. _sleepBlock = sleepBlock;
  31. return self;
  32. }
  33. - (void)setQueueToFull {
  34. [self setQueuedOperationsCount:self.settings.onDemandUploadRate];
  35. }
  36. - (void)setQueueToEmpty {
  37. [self setQueuedOperationsCount:0];
  38. }
  39. - (int)getQueueMax {
  40. return self.settings.onDemandUploadRate;
  41. }
  42. - (void)implementOnDemandUploadDelay:(int)delay {
  43. _sleepBlock(delay);
  44. }
  45. - (NSString *)recordOnDemandExceptionWithModel:(FIRExceptionModel *)exceptionModel {
  46. int randomSuffix = arc4random_uniform(10000);
  47. NSString *activePath = [_fileManager activePath];
  48. NSString *exceptionName =
  49. [activePath stringByAppendingPathComponent:[NSString stringWithFormat:@"test_exception_%d",
  50. randomSuffix]];
  51. NSData *data = [exceptionName dataUsingEncoding:NSUTF8StringEncoding];
  52. [self.fileManager createFileAtPath:exceptionName contents:data attributes:nil];
  53. return exceptionName;
  54. }
  55. @end