FIRCLSTempMockFileManager.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. // The mock file manager class should not write out to the file system as it causes reliability
  15. // issues in tests. Instead, FIRCLSMockFileManager should be used. This class cannot be removed yet
  16. // because the file system is tightly coupled throughout the SDK code. File system manipulations are
  17. // done through NSFileManager, NSData, NSString and other APIs.
  18. //
  19. // Once the experiment to upload to the new reporting endpoint using GDT is complete,
  20. // old legacy classes and logic (ie FIRCLSInternalReport, FIRCLSPackageReportsOperation) used for
  21. // processing reports can be removed. At that point, this mock class should be removed.
  22. #import "Crashlytics/UnitTests/Mocks/FIRCLSTempMockFileManager.h"
  23. @implementation FIRCLSTempMockFileManager
  24. - (instancetype)init {
  25. self = [super init];
  26. if (!self) {
  27. return nil;
  28. }
  29. // Should be set by the tests when needed
  30. _removeExpectation = nil;
  31. return self;
  32. }
  33. - (BOOL)removeItemAtPath:(NSString *)path {
  34. self.removedItemAtPath_path = path;
  35. [super removeItemAtPath:path];
  36. self.removeCount += 1;
  37. // If we set up the expectation, and we went over the expected count or removes, fulfill the
  38. // expectation
  39. if (self.removeExpectation && self.removeCount >= self.expectedRemoveCount) {
  40. [self.removeExpectation fulfill];
  41. }
  42. return YES;
  43. }
  44. - (NSNumber *)fileSizeAtPath:(NSString *)path {
  45. if (self.fileSizeAtPathResult != nil) {
  46. return self.fileSizeAtPathResult;
  47. }
  48. return [super fileSizeAtPath:path];
  49. }
  50. - (BOOL)moveItemAtPath:(NSString *)path toDirectory:(NSString *)destDir {
  51. self.moveItemAtPath_path = path;
  52. self.moveItemAtPath_destDir = destDir;
  53. if (self.moveItemAtPathResult != nil) {
  54. return self.moveItemAtPathResult.intValue > 0;
  55. }
  56. return [super moveItemAtPath:path toDirectory:destDir];
  57. }
  58. @end