GDTCORStorageFake.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2019 Google
  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. */
  16. #import "GoogleDataTransport/GDTCORTests/Common/Fakes/GDTCORStorageFake.h"
  17. #import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCOREvent.h"
  18. @implementation GDTCORStorageFake {
  19. /** Store the events in memory. */
  20. NSMutableDictionary<NSString *, GDTCOREvent *> *_storedEvents;
  21. }
  22. - (void)storeEvent:(GDTCOREvent *)event
  23. onComplete:(void (^_Nullable)(BOOL wasWritten, NSError *_Nullable))completion {
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. self->_storedEvents = [[NSMutableDictionary alloc] init];
  27. });
  28. _storedEvents[event.eventID] = event;
  29. if (completion) {
  30. completion(YES, nil);
  31. }
  32. }
  33. - (void)removeEvents:(NSSet<NSString *> *)eventIDs {
  34. [_storedEvents removeObjectsForKeys:[eventIDs allObjects]];
  35. }
  36. - (void)batchWithEventSelector:(nonnull GDTCORStorageEventSelector *)eventSelector
  37. batchExpiration:(nonnull NSDate *)expiration
  38. onComplete:
  39. (nonnull void (^)(NSNumber *_Nullable batchID,
  40. NSSet<GDTCOREvent *> *_Nullable events))onComplete {
  41. }
  42. - (void)removeBatchWithID:(nonnull NSNumber *)batchID
  43. deleteEvents:(BOOL)deleteEvents
  44. onComplete:(void (^_Nullable)(void))onComplete {
  45. }
  46. - (void)libraryDataForKey:(nonnull NSString *)key
  47. onFetchComplete:(nonnull void (^)(NSData *_Nullable, NSError *_Nullable))onFetchComplete
  48. setNewValue:(NSData *_Nullable (^_Nullable)(void))setValueBlock {
  49. if (onFetchComplete) {
  50. onFetchComplete(nil, nil);
  51. }
  52. }
  53. - (void)storeLibraryData:(NSData *)data
  54. forKey:(nonnull NSString *)key
  55. onComplete:(nullable void (^)(NSError *_Nullable error))onComplete {
  56. if (onComplete) {
  57. onComplete(nil);
  58. }
  59. }
  60. - (void)removeLibraryDataForKey:(nonnull NSString *)key
  61. onComplete:(nonnull void (^)(NSError *_Nullable))onComplete {
  62. if (onComplete) {
  63. onComplete(nil);
  64. }
  65. }
  66. - (void)hasEventsForTarget:(GDTCORTarget)target onComplete:(void (^)(BOOL hasEvents))onComplete {
  67. if (onComplete) {
  68. onComplete(NO);
  69. }
  70. }
  71. - (void)storageSizeWithCallback:(void (^)(uint64_t storageSize))onComplete {
  72. }
  73. - (void)batchIDsForTarget:(GDTCORTarget)target
  74. onComplete:(nonnull void (^)(NSSet<NSNumber *> *_Nonnull))onComplete {
  75. }
  76. - (void)checkForExpirations {
  77. }
  78. @end