GDTCOREventGenerator.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "GDTCORLibrary/Private/GDTCOREvent_Private.h"
  20. #import "GDTCORTests/Unit/Helpers/GDTCORDataObjectTesterClasses.h"
  21. @implementation GDTCOREventGenerator
  22. + (NSMutableSet<GDTCOREvent *> *)generate3Events {
  23. static NSUInteger counter = 0;
  24. int howManyToGenerate = 3;
  25. NSMutableSet<GDTCOREvent *> *set = [[NSMutableSet alloc] initWithCapacity:howManyToGenerate];
  26. for (int i = 0; i < howManyToGenerate; i++) {
  27. GDTCOREvent *event = [[GDTCOREvent alloc] initWithMappingID:@"1337" target:50];
  28. event.clockSnapshot = [GDTCORClock snapshot];
  29. event.qosTier = GDTCOREventQosDefault;
  30. event.dataObject = [[GDTCORDataObjectTesterSimple alloc] initWithString:@"testing!"];
  31. NSString *filePath = [NSString stringWithFormat:@"test-%ld.txt", (unsigned long)counter];
  32. [[NSFileManager defaultManager] createFileAtPath:filePath
  33. contents:[NSData data]
  34. attributes:nil];
  35. NSError *error = nil;
  36. [event writeToGDTPath:filePath error:&error];
  37. [set addObject:event];
  38. counter++;
  39. }
  40. return set;
  41. }
  42. @end