GDTCOREventGenerator.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. NSString *cachePath = NSTemporaryDirectory();
  25. NSString *filePath =
  26. [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"test-%ld.txt",
  27. (unsigned long)counter]];
  28. int howManyToGenerate = 3;
  29. NSMutableSet<GDTCOREvent *> *set = [[NSMutableSet alloc] initWithCapacity:howManyToGenerate];
  30. for (int i = 0; i < howManyToGenerate; i++) {
  31. GDTCOREvent *event = [[GDTCOREvent alloc] initWithMappingID:@"1337" target:50];
  32. event.clockSnapshot = [GDTCORClock snapshot];
  33. event.qosTier = GDTCOREventQosDefault;
  34. event.dataObject = [[GDTCORDataObjectTesterSimple alloc] initWithString:@"testing!"];
  35. [[NSFileManager defaultManager] createFileAtPath:filePath
  36. contents:[NSData data]
  37. attributes:nil];
  38. NSError *error = nil;
  39. [event writeToURL:[NSURL fileURLWithPath:filePath] error:&error];
  40. [set addObject:event];
  41. counter++;
  42. }
  43. return set;
  44. }
  45. @end