@@ -83,6 +83,7 @@ - (void)testStoreEvent {
83
83
@autoreleasepool {
84
84
GDTEvent *event = [[GDTEvent alloc ] initWithMappingID: @" 404" target: target];
85
85
event.dataObjectTransportBytes = [@" testString" dataUsingEncoding: NSUTF8StringEncoding];
86
+ event.clockSnapshot = [GDTClock snapshot ];
86
87
XCTAssertNoThrow ([[GDTStorage sharedInstance ] storeEvent: event]);
87
88
}
88
89
dispatch_sync ([GDTStorage sharedInstance ].storageQueue , ^{
@@ -103,6 +104,7 @@ - (void)testRemoveEvent {
103
104
@autoreleasepool {
104
105
GDTEvent *event = [[GDTEvent alloc ] initWithMappingID: @" 404" target: target];
105
106
event.dataObjectTransportBytes = [@" testString" dataUsingEncoding: NSUTF8StringEncoding];
107
+ event.clockSnapshot = [GDTClock snapshot ];
106
108
XCTAssertNoThrow ([[GDTStorage sharedInstance ] storeEvent: event]);
107
109
}
108
110
__block NSURL *eventFile;
@@ -223,7 +225,7 @@ - (void)testEventDeallocationIsEnforced {
223
225
GDTEvent *event = [[GDTEvent alloc ] initWithMappingID: @" 404" target: target];
224
226
weakEvent = event;
225
227
event.dataObjectTransportBytes = [@" testString" dataUsingEncoding: NSUTF8StringEncoding];
226
-
228
+ event. clockSnapshot = [GDTClock snapshot ];
227
229
// Store the event and wait for the expectation.
228
230
[[GDTStorage sharedInstance ] storeEvent: event];
229
231
GDTDataFuture *dataFuture =
@@ -256,38 +258,75 @@ - (void)testEventDeallocationIsEnforced {
256
258
- (void )testNSSecureCoding {
257
259
XCTAssertTrue ([GDTStorage supportsSecureCoding ]);
258
260
GDTEvent *event = [[GDTEvent alloc ] initWithMappingID: @" 404" target: target];
261
+ event.clockSnapshot = [GDTClock snapshot ];
259
262
event.dataObjectTransportBytes = [@" testString" dataUsingEncoding: NSUTF8StringEncoding];
260
263
XCTAssertNoThrow ([[GDTStorage sharedInstance ] storeEvent: event]);
261
264
event = nil ;
262
- NSData *storageData = [NSKeyedArchiver archivedDataWithRootObject: [GDTStorage sharedInstance ]];
265
+ NSData *storageData;
266
+ if (@available (macOS 10.13 , iOS 11.0 , tvOS 11.0 , *)) {
267
+ storageData = [NSKeyedArchiver archivedDataWithRootObject: [GDTStorage sharedInstance ]
268
+ requiringSecureCoding: YES
269
+ error: nil ];
270
+ } else {
271
+ #if !defined(TARGET_OS_MACCATALYST)
272
+ storageData = [NSKeyedArchiver archivedDataWithRootObject: [GDTStorage sharedInstance ]];
273
+ #endif
274
+ }
263
275
dispatch_sync ([GDTStorage sharedInstance ].storageQueue , ^{
264
276
XCTAssertNotNil ([[GDTStorage sharedInstance ].storedEvents lastObject ]);
265
277
});
266
278
[[GDTStorage sharedInstance ] removeEvents: [GDTStorage sharedInstance ].storedEvents.set];
267
279
dispatch_sync ([GDTStorage sharedInstance ].storageQueue , ^{
268
280
XCTAssertNil ([[GDTStorage sharedInstance ].storedEvents lastObject ]);
269
281
});
270
-
271
- GDTStorage *unarchivedStorage = [NSKeyedUnarchiver unarchiveObjectWithData: storageData];
282
+ GDTStorage *unarchivedStorage;
283
+ NSError *error;
284
+ if (@available (macOS 10.13 , iOS 11.0 , tvOS 11.0 , *)) {
285
+ unarchivedStorage = [NSKeyedUnarchiver unarchivedObjectOfClass: [GDTStorage class ]
286
+ fromData: storageData
287
+ error: &error];
288
+ } else {
289
+ #if !defined(TARGET_OS_MACCATALYST)
290
+ unarchivedStorage = [NSKeyedUnarchiver unarchiveObjectWithData: storageData];
291
+ #endif
292
+ }
272
293
XCTAssertNotNil ([unarchivedStorage.storedEvents lastObject ]);
273
294
}
274
295
275
296
/* * Tests encoding and decoding the storage singleton when calling -sharedInstance. */
276
297
- (void )testNSSecureCodingWithSharedInstance {
277
298
GDTEvent *event = [[GDTEvent alloc ] initWithMappingID: @" 404" target: target];
278
299
event.dataObjectTransportBytes = [@" testString" dataUsingEncoding: NSUTF8StringEncoding];
300
+ event.clockSnapshot = [GDTClock snapshot ];
279
301
XCTAssertNoThrow ([[GDTStorage sharedInstance ] storeEvent: event]);
280
302
event = nil ;
281
- NSData *storageData = [NSKeyedArchiver archivedDataWithRootObject: [GDTStorage sharedInstance ]];
303
+ NSData *storageData;
304
+ if (@available (macOS 10.13 , iOS 11.0 , tvOS 11.0 , *)) {
305
+ storageData = [NSKeyedArchiver archivedDataWithRootObject: [GDTStorage sharedInstance ]
306
+ requiringSecureCoding: YES
307
+ error: nil ];
308
+ } else {
309
+ #if !defined(TARGET_OS_MACCATALYST)
310
+ storageData = [NSKeyedArchiver archivedDataWithRootObject: [GDTStorage sharedInstance ]];
311
+ #endif
312
+ }
282
313
dispatch_sync ([GDTStorage sharedInstance ].storageQueue , ^{
283
314
XCTAssertNotNil ([[GDTStorage sharedInstance ].storedEvents lastObject ]);
284
315
});
285
316
[[GDTStorage sharedInstance ] removeEvents: [GDTStorage sharedInstance ].storedEvents.set];
286
317
dispatch_sync ([GDTStorage sharedInstance ].storageQueue , ^{
287
318
XCTAssertNil ([[GDTStorage sharedInstance ].storedEvents lastObject ]);
288
319
});
289
-
290
- GDTStorage *unarchivedStorage = [NSKeyedUnarchiver unarchiveObjectWithData: storageData];
320
+ GDTStorage *unarchivedStorage;
321
+ if (@available (macOS 10.13 , iOS 11.0 , tvOS 11.0 , *)) {
322
+ unarchivedStorage = [NSKeyedUnarchiver unarchivedObjectOfClass: [GDTStorage class ]
323
+ fromData: storageData
324
+ error: nil ];
325
+ } else {
326
+ #if !defined(TARGET_OS_MACCATALYST)
327
+ unarchivedStorage = [NSKeyedUnarchiver unarchiveObjectWithData: storageData];
328
+ #endif
329
+ }
291
330
XCTAssertNotNil ([unarchivedStorage.storedEvents lastObject ]);
292
331
}
293
332
@@ -298,6 +337,7 @@ - (void)testQoSTierFast {
298
337
GDTEvent *event = [[GDTEvent alloc ] initWithMappingID: @" 404" target: target];
299
338
event.dataObjectTransportBytes = [@" testString" dataUsingEncoding: NSUTF8StringEncoding];
300
339
event.qosTier = GDTEventQoSFast;
340
+ event.clockSnapshot = [GDTClock snapshot ];
301
341
XCTAssertFalse (self.uploaderFake .forceUploadCalled );
302
342
XCTAssertNoThrow ([[GDTStorage sharedInstance ] storeEvent: event]);
303
343
}
0 commit comments