summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-02-20 13:10:01 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-02-20 14:36:27 +0100
commitf8ab327874d32c77e591be82fd46c8cb741c130c (patch)
treeb026a8520566a0d01e3d4074e6abe170a7ca413c /platform/darwin/test
parentf0ec9fb74b18d3346a477798af72c4c37c976d4e (diff)
downloadqtlocation-mapboxgl-f8ab327874d32c77e591be82fd46c8cb741c130c.tar.gz
[macos,ios] add tests for MGLOfflineStorageDelegate
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLOfflineStorageTests.mm (renamed from platform/darwin/test/MGLOfflineStorageTests.m)52
1 files changed, 44 insertions, 8 deletions
diff --git a/platform/darwin/test/MGLOfflineStorageTests.m b/platform/darwin/test/MGLOfflineStorageTests.mm
index de2831d8de..28c6633028 100644
--- a/platform/darwin/test/MGLOfflineStorageTests.m
+++ b/platform/darwin/test/MGLOfflineStorageTests.mm
@@ -1,8 +1,12 @@
#import <Mapbox/Mapbox.h>
+#import "MGLOfflineStorage_Private.h"
+
#import <XCTest/XCTest.h>
-@interface MGLOfflineStorageTests : XCTestCase
+#include <mbgl/util/run_loop.hpp>
+
+@interface MGLOfflineStorageTests : XCTestCase <MGLOfflineStorageDelegate>
@end
@@ -14,8 +18,8 @@
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
XCTestExpectation *expectation = [self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) {
- NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue];
- return changeKind = NSKeyValueChangeSetting;
+ const auto changeKind = static_cast<NSKeyValueChange>([change[NSKeyValueChangeKindKey] unsignedLongValue]);
+ return changeKind == NSKeyValueChangeSetting;
}];
if ([MGLOfflineStorage sharedOfflineStorage].packs) {
[expectation fulfill];
@@ -53,7 +57,7 @@
__block MGLOfflinePack *pack;
[self keyValueObservingExpectationForObject:[MGLOfflineStorage sharedOfflineStorage] keyPath:@"packs" handler:^BOOL(id _Nonnull observedObject, NSDictionary * _Nonnull change) {
- NSKeyValueChange changeKind = [change[NSKeyValueChangeKindKey] unsignedIntegerValue];
+ const auto changeKind = static_cast<NSKeyValueChange>([change[NSKeyValueChangeKindKey] unsignedLongValue]);
NSIndexSet *indices = change[NSKeyValueChangeIndexesKey];
return changeKind == NSKeyValueChangeInsertion && indices.count == 1;
}];
@@ -80,8 +84,8 @@
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];
+ const auto changeKind = static_cast<NSKeyValueChange>([change[NSKeyValueChangeKindKey] unsignedLongValue]);
+ const auto state = static_cast<MGLOfflinePackState>([change[NSKeyValueChangeNewKey] longValue]);
return changeKind == NSKeyValueChangeSetting && state == MGLOfflinePackStateInactive;
}];
[self expectationForNotification:MGLOfflinePackProgressChangedNotification object:pack handler:^BOOL(NSNotification * _Nonnull notification) {
@@ -136,9 +140,9 @@
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];
+ const auto changeKind = static_cast<NSKeyValueChange>([change[NSKeyValueChangeKindKey] unsignedLongValue]);
NSIndexSet *indices = change[NSKeyValueChangeIndexesKey];
- return changeKind = NSKeyValueChangeRemoval && indices.count == 1;
+ return changeKind == NSKeyValueChangeRemoval && indices.count == 1;
}];
XCTestExpectation *completionHandlerExpectation = [self expectationWithDescription:@"remove pack completion handler"];
[[MGLOfflineStorage sharedOfflineStorage] removePack:pack withCompletionHandler:^(NSError * _Nullable error) {
@@ -156,4 +160,36 @@
XCTAssertGreaterThan([MGLOfflineStorage sharedOfflineStorage].countOfBytesCompleted, 0);
}
+- (NSURL *)offlineStorage:(MGLOfflineStorage *)storage
+ URLForResourceOfKind:(MGLResourceKind)kind
+ withURL:(NSURL *)url {
+ if ([url.scheme isEqual: @"test"] && [url.host isEqual: @"api"]) {
+ return [NSURL URLWithString:@"https://api.mapbox.com"];
+ } else {
+ return url;
+ }
+}
+
+- (void)testResourceTransform {
+ MGLOfflineStorage *os = [MGLOfflineStorage sharedOfflineStorage];
+ [os setDelegate:self];
+
+ auto fs = os.mbglFileSource;
+
+ // Delegate returns "https://api.mapbox.com" as a replacement URL.
+ const mbgl::Resource resource { mbgl::Resource::Unknown, "test://api" };
+ std::unique_ptr<mbgl::AsyncRequest> req;
+ req = fs->request(resource, [&](mbgl::Response res) {
+ req.reset();
+ XCTAssertFalse(res.error.get(), @"Request should not return an error");
+ XCTAssertTrue(res.data.get(), @"Request should return data");
+ XCTAssertEqual("{\"api\":\"mapbox\"}", *res.data, @"Request did not return expected data");
+ CFRunLoopStop(CFRunLoopGetCurrent());
+ });
+
+ CFRunLoopRun();
+
+ [os setDelegate:nil];
+}
+
@end