summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLOfflinePackTests.mm
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-09-06 10:56:12 -0400
committerJulian Rex <julian.rex@mapbox.com>2019-09-18 16:50:25 -0400
commit940b46a42a06a33f26878d4537e4cd574a806aee (patch)
tree1e111d69dd200b5944afc1113fa87503ed9f45ef /platform/darwin/test/MGLOfflinePackTests.mm
parent30f2de6c2010c4991825f529b519b8669d340e7a (diff)
downloadqtlocation-mapboxgl-940b46a42a06a33f26878d4537e4cd574a806aee.tar.gz
[ios] Adds invalidate test, and test that reloads packs during removal
Diffstat (limited to 'platform/darwin/test/MGLOfflinePackTests.mm')
-rw-r--r--platform/darwin/test/MGLOfflinePackTests.mm57
1 files changed, 57 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLOfflinePackTests.mm b/platform/darwin/test/MGLOfflinePackTests.mm
new file mode 100644
index 0000000000..1306b182d1
--- /dev/null
+++ b/platform/darwin/test/MGLOfflinePackTests.mm
@@ -0,0 +1,57 @@
+#import <Mapbox/Mapbox.h>
+#import <XCTest/XCTest.h>
+#import "MGLOfflinePack_Private.h"
+#import "MGLTestAssertionHandler.h"
+
+@interface MGLOfflinePackTests : XCTestCase
+
+@end
+
+@implementation MGLOfflinePackTests
+
+- (void)testInvalidation {
+ MGLOfflinePack *invalidPack = [[MGLOfflinePack alloc] init];
+
+ XCTAssertEqual(invalidPack.state, MGLOfflinePackStateInvalid, @"Offline pack should be invalid when initialized independently of MGLOfflineStorage.");
+
+ XCTAssertThrowsSpecificNamed(invalidPack.region, NSException, MGLInvalidOfflinePackException, @"Invalid offline pack should raise an exception when accessing its region.");
+ XCTAssertThrowsSpecificNamed(invalidPack.context, NSException, MGLInvalidOfflinePackException, @"Invalid offline pack should raise an exception when accessing its context.");
+ XCTAssertThrowsSpecificNamed([invalidPack resume], NSException, MGLInvalidOfflinePackException, @"Invalid offline pack should raise an exception when being resumed.");
+ XCTAssertThrowsSpecificNamed([invalidPack suspend], NSException, MGLInvalidOfflinePackException, @"Invalid offline pack should raise an exception when being suspended.");
+}
+
+- (void)testInvalidatingAnInvalidPack {
+ MGLOfflinePack *invalidPack = [[MGLOfflinePack alloc] init];
+
+ XCTAssertThrowsSpecificNamed([invalidPack invalidate], NSException, NSInternalInconsistencyException, @"Invalid offline pack should raise an exception when being invalidated.");
+
+ // Now try again, without asserts
+ NSAssertionHandler *oldHandler = [NSAssertionHandler currentHandler];
+ [[[NSThread currentThread] threadDictionary] setValue:[[MGLTestAssertionHandler alloc] init] forKey:NSAssertionHandlerKey];
+
+ // Make sure this doesn't crash without asserts
+ [invalidPack invalidate];
+
+ [[[NSThread currentThread] threadDictionary] setValue:oldHandler forKey:NSAssertionHandlerKey];
+}
+
+- (void)testProgressBoxing {
+ MGLOfflinePackProgress progress = {
+ .countOfResourcesCompleted = 3,
+ .countOfResourcesExpected = 2,
+ .countOfBytesCompleted = 7,
+ .countOfTilesCompleted = 1,
+ .countOfTileBytesCompleted = 6,
+ .maximumResourcesExpected = UINT64_MAX,
+ };
+ MGLOfflinePackProgress roundTrippedProgress = [NSValue valueWithMGLOfflinePackProgress:progress].MGLOfflinePackProgressValue;
+
+ XCTAssertEqual(progress.countOfResourcesCompleted, roundTrippedProgress.countOfResourcesCompleted, @"Completed resources should round-trip.");
+ XCTAssertEqual(progress.countOfResourcesExpected, roundTrippedProgress.countOfResourcesExpected, @"Expected resources should round-trip.");
+ XCTAssertEqual(progress.countOfBytesCompleted, roundTrippedProgress.countOfBytesCompleted, @"Completed bytes should round-trip.");
+ XCTAssertEqual(progress.countOfTilesCompleted, roundTrippedProgress.countOfTilesCompleted, @"Completed tiles should round-trip.");
+ XCTAssertEqual(progress.countOfTileBytesCompleted, roundTrippedProgress.countOfTileBytesCompleted, @"Completed tile bytes should round-trip.");
+ XCTAssertEqual(progress.maximumResourcesExpected, roundTrippedProgress.maximumResourcesExpected, @"Maximum expected resources should round-trip.");
+}
+
+@end