summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-09-14 12:04:25 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2018-09-14 23:36:11 -0700
commit230f2d24820ac5dd9cbb88f30271021ad259392d (patch)
treee98fecabbce7260cd7f79cede1d2ad908c67e8a9
parent2545c81be788dfbc9450fe5dce168669cad2f75b (diff)
downloadqtlocation-mapboxgl-upstream/fabian-offline-merge-12693.tar.gz
[ios, macos] Fix MGLOfflineStorageTest point to a writable directory.upstream/fabian-offline-merge-12693
-rw-r--r--platform/darwin/src/MGLOfflineStorage.mm6
-rw-r--r--platform/darwin/test/MGLOfflineStorageTests.mm43
2 files changed, 44 insertions, 5 deletions
diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm
index fbfa9b3e2f..6aee391123 100644
--- a/platform/darwin/src/MGLOfflineStorage.mm
+++ b/platform/darwin/src/MGLOfflineStorage.mm
@@ -306,7 +306,11 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
}
}];
- [mutablePacks replaceObjectsAtIndexes:replaceIndexSet withObjects:packs];
+
+ if (replaceIndexSet.count > 0) {
+ [mutablePacks replaceObjectsAtIndexes:replaceIndexSet withObjects:packs];
+ }
+
[mutablePacks addObjectsFromArray:packsByIdentifier.allValues];
}
if (completion) {
diff --git a/platform/darwin/test/MGLOfflineStorageTests.mm b/platform/darwin/test/MGLOfflineStorageTests.mm
index a4953f9e2a..d8866c153d 100644
--- a/platform/darwin/test/MGLOfflineStorageTests.mm
+++ b/platform/darwin/test/MGLOfflineStorageTests.mm
@@ -12,6 +12,23 @@
@implementation MGLOfflineStorageTests
++ (void)tearDown {
+ NSURL *cacheDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
+ inDomain:NSUserDomainMask
+ appropriateForURL:nil
+ create:NO
+ error:nil];
+ // Unit tests don't use the main bundle; use com.mapbox.ios.sdk instead.
+ NSString *bundleIdentifier = [NSBundle bundleForClass:[MGLMapView class]].bundleIdentifier;
+ cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:bundleIdentifier];
+ cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:@".mapbox"];
+ XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:cacheDirectoryURL.path], @"Cache subdirectory should exist.");
+
+ NSURL *cacheURL = [cacheDirectoryURL URLByAppendingPathComponent:@"cache.db"];
+
+ [[NSFileManager defaultManager] removeItemAtURL:cacheURL error:nil];
+}
+
- (void)setUp {
[super setUp];
@@ -264,8 +281,9 @@
[os setDelegate:nil];
}
-- (void)testAddingFileContent {
- NSUInteger countOfPacks = [MGLOfflineStorage sharedOfflineStorage].packs.count;
+- (void)testAddFileContent {
+
+
// Valid database
{
NSURL *resourceURL = [NSURL fileURLWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"barcelona" ofType:@"db"]];
@@ -281,6 +299,20 @@
NSError *error;
[fileManager moveItemAtURL:resourceURL toURL:[NSURL fileURLWithPath:filePath] error:&error];
+ NSDictionary *atributes = @{ NSFilePosixPermissions: @0777 };
+ error = nil;
+ [fileManager setAttributes:atributes ofItemAtPath:filePath error:&error];
+ XCTAssertNil(error, @"Changing the file's permissions:%@ should not return an error.", filePath);
+ error = nil;
+ NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:filePath error:&error];
+
+ NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
+ long long fileSize = [fileSizeNumber longLongValue];
+ long long dabaseFileSize = 32391168;
+ XCTAssertEqual(fileSize, dabaseFileSize, @"The dabase file size must be:%l actual size:%l", dabaseFileSize, fileSize);
+
+ NSUInteger countOfPacks = [MGLOfflineStorage sharedOfflineStorage].packs.count;
+
XCTestExpectation *fileAdditionCompletionHandlerExpectation = [self expectationWithDescription:@"add database content completion handler"];
MGLOfflineStorage *os = [MGLOfflineStorage sharedOfflineStorage];
@@ -288,11 +320,14 @@
XCTAssertNotNil(fileURL, @"The fileURL should not be nil.");
XCTAssertNotNil(packs, @"Adding the contents of the barcelona.db should update one pack.");
XCTAssertNil(error, @"Adding contents to a file should not return an error.");
+ for (MGLOfflinePack *pack in [MGLOfflineStorage sharedOfflineStorage].packs) {
+ NSLog(@"PACK:%@", pack);
+ }
[fileAdditionCompletionHandlerExpectation fulfill];
}];
[self waitForExpectationsWithTimeout:2 handler:nil];
- // Depending on the database it may update or add a pack. For this case specifically the offline database updates the current pack.
- XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage].packs.count, countOfPacks, @"Adding contents of barcelona.db should not add any new pack.");
+ // Depending on the database it may update or add a pack. For this case specifically the offline database adds one pack.
+ XCTAssertEqual([MGLOfflineStorage sharedOfflineStorage].packs.count, countOfPacks + 1, @"Adding contents of barcelona.db should add one pack.");
}
// Invalid database type
{