GDTCOREventGenerator.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/Unit/Helpers/GDTCOREventGenerator.h"
  17. #import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCORClock.h"
  18. #import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCOREvent.h"
  19. #import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCORTargets.h"
  20. #import "GoogleDataTransport/GDTCORLibrary/Private/GDTCOREvent_Private.h"
  21. #import "GoogleDataTransport/GDTCORTests/Unit/Helpers/GDTCORDataObjectTesterClasses.h"
  22. @implementation GDTCOREventGenerator
  23. + (NSMutableSet<GDTCOREvent *> *)generate3Events {
  24. static NSUInteger counter = 0;
  25. int howManyToGenerate = 3;
  26. NSMutableSet<GDTCOREvent *> *set = [[NSMutableSet alloc] initWithCapacity:howManyToGenerate];
  27. for (int i = 0; i < howManyToGenerate; i++) {
  28. GDTCOREvent *event = [[GDTCOREvent alloc] initWithMappingID:@"1337" target:kGDTCORTargetTest];
  29. event.clockSnapshot = [GDTCORClock snapshot];
  30. event.qosTier = GDTCOREventQosDefault;
  31. event.dataObject = [[GDTCORDataObjectTesterSimple alloc] initWithString:@"testing!"];
  32. NSString *filePath = [NSString stringWithFormat:@"test-%ld.txt", (unsigned long)counter];
  33. [[NSFileManager defaultManager] createFileAtPath:filePath
  34. contents:[NSData data]
  35. attributes:nil];
  36. [set addObject:event];
  37. counter++;
  38. }
  39. return set;
  40. }
  41. + (GDTCOREvent *)generateEventForTarget:(GDTCORTarget)target
  42. qosTier:(nullable NSNumber *)qosTier
  43. mappingID:(nullable NSString *)mappingID {
  44. GDTCOREventQoS determinedQosTier =
  45. qosTier == nil ? arc4random_uniform(GDTCOREventQoSWifiOnly) : qosTier.intValue;
  46. NSString *determinedMappingID = mappingID == nil ? [NSDate date].description : mappingID;
  47. GDTCOREvent *event = [[GDTCOREvent alloc] initWithMappingID:determinedMappingID target:target];
  48. event.clockSnapshot = [GDTCORClock snapshot];
  49. event.qosTier = determinedQosTier;
  50. event.dataObject = [[GDTCORDataObjectTesterSimple alloc] initWithString:@"testing!"];
  51. return event;
  52. }
  53. @end