diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-10-16 14:44:16 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-10-17 12:53:24 -0700 |
commit | c66f92f4529b25d031f9c93687761647c48d8ae8 (patch) | |
tree | 4016b7291f3541861b79c8700fb9f3cd616ce871 | |
parent | 3f98d6a8219237967f87b5a096afefc74605d460 (diff) | |
download | qtlocation-mapboxgl-c66f92f4529b25d031f9c93687761647c48d8ae8.tar.gz |
[test] Test[ MGLOfflineStorage putResourceForURL]
-rw-r--r-- | platform/darwin/test/MGLOfflineStorageTests.mm | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLOfflineStorageTests.mm b/platform/darwin/test/MGLOfflineStorageTests.mm index 4d17ef0455..cc396814d0 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.mm +++ b/platform/darwin/test/MGLOfflineStorageTests.mm @@ -1,6 +1,7 @@ #import <Mapbox/Mapbox.h> #import "MGLOfflineStorage_Private.h" +#import "NSDate+MGLAdditions.h" #import <XCTest/XCTest.h> @@ -394,4 +395,56 @@ } +-(void) testPutResourceForURL { + NSURL *styleURL = [NSURL URLWithString:@"https://api.mapbox.com/some/thing"]; + + MGLOfflineStorage *os = [MGLOfflineStorage sharedOfflineStorage]; + std::string testData("test data"); + [os putResourceWithUrl:styleURL data:[NSData dataWithBytes:testData.c_str() length:testData.length()] modified:nil expires:nil etag:nil]; + + auto fs = os.mbglFileSource; + const mbgl::Resource resource { mbgl::Resource::Unknown, "https://api.mapbox.com/some/thing" }; + 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"); + XCTAssertFalse(res.modified, @"Request should not have a modification timestamp"); + XCTAssertFalse(res.expires, @"Request should not have an expiration timestamp"); + XCTAssertFalse(res.etag, @"Request should not have an entity tag"); + XCTAssertEqual("test data", *res.data, @"Request did not return expected data"); + CFRunLoopStop(CFRunLoopGetCurrent()); + }); + + CFRunLoopRun(); +} + +-(void) testPutResourceForURLWithTimestamps { + NSURL *styleURL = [NSURL URLWithString:@"https://api.mapbox.com/some/thing"]; + + MGLOfflineStorage *os = [MGLOfflineStorage sharedOfflineStorage]; + std::string testData("test data"); + NSDate* now = [NSDate date]; + [os putResourceWithUrl:styleURL data:[NSData dataWithBytes:testData.c_str() length:testData.length()] modified:now expires:now etag:@"some etag"]; + + auto fs = os.mbglFileSource; + const mbgl::Resource resource { mbgl::Resource::Unknown, "https://api.mapbox.com/some/thing" }; + 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"); + XCTAssertTrue(res.modified, @"Request should have a modification timestamp"); + XCTAssertEqual(MGLTimeIntervalFromDuration(res.modified->time_since_epoch()), floor(now.timeIntervalSince1970), @"Modification timestamp should roundtrip"); + XCTAssertTrue(res.expires, @"Request should have an expiration timestamp"); + XCTAssertEqual(MGLTimeIntervalFromDuration(res.expires->time_since_epoch()), floor(now.timeIntervalSince1970), @"Expiration timestamp should roundtrip"); + XCTAssertTrue(res.etag, @"Request should have an entity tag"); + XCTAssertEqual(*res.etag, "some etag", @"Entity tag should roundtrip"); + XCTAssertEqual("test data", *res.data, @"Request did not return expected data"); + CFRunLoopStop(CFRunLoopGetCurrent()); + }); + + CFRunLoopRun(); +} + @end |