GDTCORTransportFake.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "SharedTestUtilities/GDTCORTransportFake.h"
  17. @interface GDTCORTransportFake ()
  18. /**
  19. * Internal array that stores all log events that have been logged.
  20. * All access to this array is protected by @synchronized.
  21. */
  22. @property(nonatomic, readonly) NSMutableArray<GDTCOREvent *> *events;
  23. @end
  24. @implementation GDTCORTransportFake
  25. - (instancetype)initWithMappingID:(NSString *)mappingID
  26. transformers:(nullable NSArray<id<GDTCOREventTransformer>> *)transformers
  27. target:(GDTCORTarget)target {
  28. self = [super initWithMappingID:mappingID transformers:transformers target:target];
  29. if (self) {
  30. _events = [NSMutableArray array];
  31. }
  32. return self;
  33. }
  34. - (void)sendDataEvent:(GDTCOREvent *)event {
  35. @synchronized(self.events) {
  36. [self.events addObject:event];
  37. }
  38. }
  39. - (NSArray<GDTCOREvent *> *)logEvents {
  40. @synchronized(self.events) {
  41. return [self.events copy];
  42. }
  43. }
  44. - (void)reset {
  45. @synchronized(self.events) {
  46. [self.events removeAllObjects];
  47. }
  48. }
  49. @end