GDTCOREventGenerator.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 "GDTCORTests/Unit/Helpers/GDTCOREventGenerator.h"
  17. #import <GoogleDataTransport/GDTCORClock.h>
  18. #import <GoogleDataTransport/GDTCOREvent.h>
  19. #import <GoogleDataTransport/GDTCORTargets.h>
  20. #import "GDTCORLibrary/Private/GDTCOREvent_Private.h"
  21. #import "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. NSError *error = nil;
  37. [event writeToGDTPath:filePath error:&error];
  38. [set addObject:event];
  39. counter++;
  40. }
  41. return set;
  42. }
  43. @end