diff options
Diffstat (limited to 'platform/darwin/test/MGLOfflineStorageTests.m')
-rw-r--r-- | platform/darwin/test/MGLOfflineStorageTests.m | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.m index 07540b5645..de2831d8de 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.m +++ b/platform/darwin/test/MGLOfflineStorageTests.m @@ -10,7 +10,7 @@ - (void)setUp { [super setUp]; - + static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ XCTestExpectation *expectation = [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { @@ -23,7 +23,7 @@ } else { [self waitForExpectationsWithTimeout:2 handler:nil]; } - + XCTAssertNotNil([MGLOfflineStorage sharedOfflineStorage].packs, @"Shared offline storage object should have a non-nil collection of packs by this point."); }); } @@ -34,7 +34,7 @@ - (void)testAddPack { NSUInteger countOfPacks = [MGLOfflineStorage sharedOfflineStorage].packs.count; - + NSURL *styleURL = [MGLStyle lightStyleURLWithVersion:8]; /// Somewhere near Grape Grove, Ohio, United States. MGLCoordinateBounds bounds = { @@ -43,14 +43,14 @@ }; double zoomLevel = 20; MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:styleURL bounds:bounds fromZoomLevel:zoomLevel toZoomLevel:zoomLevel]; - + NSString *nameKey = @"Name"; NSString *name = @"🍇 Grape Grove"; - + NSData *context = [NSKeyedArchiver archivedDataWithRootObject:@{ nameKey: name, }]; - + __block MGLOfflinePack *pack; [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; @@ -65,20 +65,20 @@ [additionCompletionHandlerExpectation fulfill]; }]; [self waitForExpectationsWithTimeout:2 handler:nil]; - + XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage].packs.count, countOfPacks + 1, @"Added pack should have been added to the canonical collection of packs owned by the shared offline storage object. This assertion can fail if this test is run before -testAAALoadPacks."); - + XCTAssertEqual(pack, [MGLOfflineStorage sharedOfflineStorage].packs.lastObject, @"Pack should be appended to end of packs array."); - + XCTAssertEqualObjects(pack.region, region, @"Added pack’s region has changed."); - + NSDictionary *userInfo = [NSKeyedUnarchiver unarchiveObjectWithData:pack.context]; XCTAssert([userInfo isKindOfClass:[NSDictionary class]], @"Context of offline pack isn’t a dictionary."); XCTAssert([userInfo[nameKey] isKindOfClass:[NSString class]], @"Name of offline pack isn’t a string."); XCTAssertEqualObjects(userInfo[nameKey], name, @"Name of offline pack has changed."); - + XCTAssertEqual(pack.state, MGLOfflinePackStateInactive, @"New pack should initially have inactive state."); - + [self keyValueObservingExpectationForObject:pack keyPath:@"state" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; MGLOfflinePackState state = [change[NSKeyValueChangeNewKey] integerValue]; @@ -87,18 +87,18 @@ [self expectationForNotification:MGLOfflinePackProgressChangedNotification object:pack handler:^BOOL(NSNotification * _Nonnull notification) { MGLOfflinePack *notificationPack = notification.object; XCTAssert([notificationPack isKindOfClass:[MGLOfflinePack class]], @"Object of notification should be an MGLOfflinePack."); - + NSDictionary *userInfo = notification.userInfo; XCTAssertNotNil(userInfo, @"Progress change notification should have a userInfo dictionary."); - + NSNumber *stateNumber = userInfo[MGLOfflinePackUserInfoKeyState]; XCTAssert([stateNumber isKindOfClass:[NSNumber class]], @"Progress change notification’s state should be an NSNumber."); XCTAssertEqual(stateNumber.integerValue, pack.state, @"State in a progress change notification should match the pack’s state."); - + NSValue *progressValue = userInfo[MGLOfflinePackUserInfoKeyProgress]; XCTAssert([progressValue isKindOfClass:[NSValue class]], @"Progress change notification’s progress should be an NSValue."); XCTAssertEqualObjects(progressValue, [NSValue valueWithMGLOfflinePackProgress:pack.progress], @"Progress change notification’s progress should match pack’s progress."); - + return notificationPack == pack && pack.state == MGLOfflinePackStateInactive; }]; [pack requestProgress]; @@ -131,10 +131,10 @@ - (void)testRemovePack { NSUInteger countOfPacks = [MGLOfflineStorage sharedOfflineStorage].packs.count; - + MGLOfflinePack *pack = [MGLOfflineStorage sharedOfflineStorage].packs.lastObject; XCTAssertNotNil(pack, @"Added pack should still exist."); - + [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) { NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue]; NSIndexSet *indices = change[NSKeyValueChangeIndexesKey]; @@ -146,9 +146,9 @@ [completionHandlerExpectation fulfill]; }]; [self waitForExpectationsWithTimeout:1 handler:nil]; - + XCTAssertEqual(pack.state, MGLOfflinePackStateInvalid, @"Removed pack should have been invalidated synchronously."); - + XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage].packs.count, countOfPacks - 1, @"Removed pack should have been removed from the canonical collection of packs owned by the shared offline storage object. This assertion can fail if this test is run before -testAAALoadPacks or -testAddPack."); } |