GDTCOREventGenerator.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/GDTCORStoredEvent.h>
  20. #import "GDTCORLibrary/Private/GDTCOREvent_Private.h"
  21. @implementation GDTCOREventGenerator
  22. + (NSMutableSet<GDTCORStoredEvent *> *)generate3StoredEvents {
  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<GDTCORStoredEvent *> *set =
  30. [[NSMutableSet alloc] initWithCapacity:howManyToGenerate];
  31. for (int i = 0; i < howManyToGenerate; i++) {
  32. GDTCOREvent *event = [[GDTCOREvent alloc] initWithMappingID:@"1337" target:50];
  33. event.clockSnapshot = [GDTCORClock snapshot];
  34. event.qosTier = GDTCOREventQosDefault;
  35. event.dataObjectTransportBytes = [@"testing!" dataUsingEncoding:NSUTF8StringEncoding];
  36. [[NSFileManager defaultManager] createFileAtPath:filePath
  37. contents:[NSData data]
  38. attributes:nil];
  39. GDTCORDataFuture *dataFuture =
  40. [[GDTCORDataFuture alloc] initWithFileURL:[NSURL fileURLWithPath:filePath]];
  41. [set addObject:[event storedEventWithDataFuture:dataFuture]];
  42. counter++;
  43. }
  44. return set;
  45. }
  46. @end