diff --git a/platform/darwin/test/MGLOfflineStorageTests.mm b/platform/darwin/test/MGLOfflineStorageTests.mm index ee4bcc2c65c..0af5b169587 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.mm +++ b/platform/darwin/test/MGLOfflineStorageTests.mm @@ -220,9 +220,29 @@ - (void)testInvalidatePack { [[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError * _Nullable) { XCTAssertNotNil(pack); XCTAssertNil(error); - [expectation fulfill]; }]; }]; + +// MGLCoordinateBounds columbus = MGLCoordinateBoundsMake(CLLocationCoordinate2DMake(39.916, -83.044), CLLocationCoordinate2DMake(40.004, -82.946)); +// +// NSString *nameKey2 = @"Name"; +// NSString *name2 = @"Paris square"; +// +// NSData *context2 = [NSKeyedArchiver archivedDataWithRootObject:@{nameKey2: name2}]; +// MGLTilePyramidOfflineRegion *region2 = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:styleURL bounds:columbus fromZoomLevel:10 toZoomLevel:11]; +// +// [[MGLOfflineStorage sharedOfflineStorage] addPackForRegion:region2 withContext:context2 completionHandler:^(MGLOfflinePack * _Nullable pack, NSError * _Nullable error) { +// [[MGLOfflineStorage sharedOfflineStorage] removePack:pack withCompletionHandler:^(NSError * _Nullable error) { +// [[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError * _Nullable error) { +// XCTAssertNotNil(error); +// [expectation fulfill]; +// }]; +// }]; +// }]; + +// + + [self waitForExpectationsWithTimeout:10 handler:nil]; } @@ -251,6 +271,8 @@ - (void)testClearCache { XCTAssertNil(error); [expectation fulfill]; }]; + + [self waitForExpectationsWithTimeout:10 handler:nil]; } @@ -260,6 +282,26 @@ - (void)testResetDatabase { XCTAssertNil(error); [expectation fulfill]; }]; + + MGLCoordinateBounds bounds = { + { .latitude = 48.8660, .longitude = 2.3306 }, + { .latitude = 48.8603, .longitude = 2.3213 }, + }; + + NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; + + // Attempting to reset the database while an offline pack is downloading should lead to an error. + MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:styleURL bounds:bounds fromZoomLevel:10 toZoomLevel:11]; + + NSString *nameKey = @"Name"; + NSString *name = @"Paris square"; + + NSData *context = [NSKeyedArchiver archivedDataWithRootObject:@{nameKey: name}]; + [[MGLOfflineStorage sharedOfflineStorage] addPackForRegion:region withContext:context completionHandler:nil]; + [[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError * _Nullable error) { + XCTAssertNotNil(error); + [expectation fulfill]; + }]; [self waitForExpectationsWithTimeout:10 handler:nil]; } diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 2fb95e1b17f..ad2dce4e454 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -49,7 +49,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsDebugToolsRows) { MBXSettingsDebugToolsOverdrawVisualization, MBXSettingsDebugToolsShowZoomLevel, MBXSettingsDebugToolsShowFrameTimeGraph, - MBXSettingsDebugToolsShowReuseQueueStats + MBXSettingsDebugToolsShowReuseQueueStats, + MBXSettingsDebugToolsInvalidateAmbientCache, + MBXSettingsDebugToolsClearAmbientCache, + MBXSettingsDebugToolsResetDatabase }; typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) { @@ -375,7 +378,10 @@ - (void)dismissSettings:(__unused id)sender (debugMask & MGLMapDebugOverdrawVisualizationMask ? @"Hide" :@"Show")], [NSString stringWithFormat:@"%@ zoom level ornament", (self.zoomLevelOrnamentEnabled ? @"Hide" :@"Show")], [NSString stringWithFormat:@"%@ frame time graph", (self.frameTimeGraphEnabled ? @"Hide" :@"Show")], - [NSString stringWithFormat:@"%@ reuse queue stats", (self.reuseQueueStatsEnabled ? @"Hide" :@"Show")] + [NSString stringWithFormat:@"%@ reuse queue stats", (self.reuseQueueStatsEnabled ? @"Hide" :@"Show")], + @"Invalidate Ambient Cache", + @"Clear Ambient Cache", + @"Reset Database", ]]; break; case MBXSettingsAnnotations: @@ -508,11 +514,19 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath [self updateHUD]; break; } + case MBXSettingsDebugToolsInvalidateAmbientCache: + [self invalidateAmbientCache]; + break; + case MBXSettingsDebugToolsClearAmbientCache: + [self clearAmbientCache]; + break; + case MBXSettingsDebugToolsResetDatabase: + [self resetDatabase]; + break; default: NSAssert(NO, @"All debug tools setting rows should be implemented"); break; } - self.mapView.debugMask = self.currentState.debugMask; break; @@ -1765,6 +1779,61 @@ - (NSString *)telemetryDebugLogFilePath return filePath; } +#pragma mark: +- (void)invalidateAmbientCache { + CFTimeInterval start = CACurrentMediaTime(); + [[MGLOfflineStorage sharedOfflineStorage] invalidateAmbientCacheWithCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Ambient cache invalidated in %f seconds", difference); + } + }]; +} + +- (void)invalidateOfflinePack { + CFTimeInterval start = CACurrentMediaTime(); + MGLOfflinePack *pack = [MGLOfflineStorage sharedOfflineStorage].packs.firstObject; + + [[MGLOfflineStorage sharedOfflineStorage] invalidatePack:pack withCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Offline pack invalidated in %f seconds", difference); + } + }]; +} + +- (void)clearAmbientCache { + CFTimeInterval start = CACurrentMediaTime(); + [[MGLOfflineStorage sharedOfflineStorage] clearAmbientCacheWithCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Ambient cache cleared in %f seconds", difference); + } + }]; +} + +- (void)resetDatabase { + CFTimeInterval start = CACurrentMediaTime(); + [[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error: %@", error.localizedDescription); + return; + } else { + CFTimeInterval difference = CACurrentMediaTime() - start; + NSLog(@"Database reset in %f seconds", difference); + } + }]; +} + #pragma mark - Random World Tour - (void)addAnnotations:(NSInteger)numAnnotations aroundCoordinate:(CLLocationCoordinate2D)coordinate radius:(CLLocationDistance)radius {