diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-06-04 14:46:59 +0300 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-06-05 00:03:13 -0700 |
commit | a71ccae141a61c9b82d921c44d51d3ca5b425f42 (patch) | |
tree | 0ebb8a2c91a8557c8bd78a8b7557bd2c07287e9d | |
parent | 0ba0b8c04069718e476457d39fd7dc0f085ab734 (diff) | |
download | qtlocation-mapboxgl-a71ccae141a61c9b82d921c44d51d3ca5b425f42.tar.gz |
[ios] Add integtation test that verifies MGLMapViewImpl size
-rw-r--r-- | platform/ios/Integration Tests/MBGLIntegrationTests.mm (renamed from platform/ios/Integration Tests/MBGLIntegrationTests.m) | 50 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 8 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 5 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView_Private.h | 4 |
4 files changed, 63 insertions, 4 deletions
diff --git a/platform/ios/Integration Tests/MBGLIntegrationTests.m b/platform/ios/Integration Tests/MBGLIntegrationTests.mm index c1a3833fb5..d0f5f6a79d 100644 --- a/platform/ios/Integration Tests/MBGLIntegrationTests.m +++ b/platform/ios/Integration Tests/MBGLIntegrationTests.mm @@ -1,4 +1,8 @@ #import "MGLMapViewIntegrationTest.h" +#import "MGLMapView_Private.h" +#import "MGLMapView+Impl.h" + +#include <mbgl/gfx/renderable.hpp> @interface MBGLIntegrationTests : MGLMapViewIntegrationTest @end @@ -198,5 +202,51 @@ XCTAssertNil(weakLayer); } +- (void)testMGLMapViewImplHasCorrectSize { + NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; + self.styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."]; + [self.mapView setStyleURL:styleURL]; + [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(9.6315313, 52.4133574) animated:NO]; + [self waitForExpectations:@[self.styleLoadingExpectation] timeout:1]; + + MGLMapViewImpl *mapViewImpl = [self.mapView viewImpl]; + CGFloat scaleFactor = [UIScreen mainScreen].scale; + mbgl::Size renderableSize = mapViewImpl->getRendererBackend().getDefaultRenderable().getSize(); + mbgl::Size viewSize = { + static_cast<uint32_t>(self.mapView.bounds.size.width * scaleFactor), + static_cast<uint32_t>(self.mapView.bounds.size.height * scaleFactor) + }; + + // Test that mapView and default renderable have the same size. + XCTAssertTrue(renderableSize == viewSize); + + CLLocationCoordinate2D coordinates[] = { + CLLocationCoordinate2DMake(9.6315313, 52.4133574), + CLLocationCoordinate2DMake(24.9410248, 60.1733244)}; + + MGLPointCollectionFeature *points = [MGLPointCollectionFeature pointCollectionWithCoordinates:coordinates count:sizeof(coordinates)/sizeof(coordinates[0])]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"heatmap" shape:points options:nil]; + [self.style addSource:source]; + + MGLHeatmapStyleLayer *heatmapLayer = [[MGLHeatmapStyleLayer alloc] initWithIdentifier:@"lineLayer" source:source]; + [self.style addLayer:heatmapLayer]; + + // Test that heatmap layer can create a texture and be successfully rendered. + [self waitForMapViewToBeRendered]; + + // Resize frame of the view. + [self.mapView setFrame: CGRect{self.mapView.bounds.origin, {256, 256}}]; + + // Force sync re-layout. + [self.mapView layoutIfNeeded]; + + // Test that mapView and default renderable have the same size after re-layout. + renderableSize = mapViewImpl->getRendererBackend().getDefaultRenderable().getSize(); + viewSize = { static_cast<uint32_t>(self.mapView.bounds.size.width * scaleFactor), + static_cast<uint32_t>(self.mapView.bounds.size.height * scaleFactor) }; + XCTAssertTrue(renderableSize == viewSize); + [self waitForMapViewToBeRendered]; +} + @end diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 0bdb3706dd..666bda0be9 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -22,7 +22,7 @@ 07D8C6FB1F67560100381808 /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0778DD411F67555F00A73B34 /* MGLComputedShapeSource.mm */; }; 07D8C6FF1F67562C00381808 /* MGLComputedShapeSourceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 07D8C6FD1F67562800381808 /* MGLComputedShapeSourceTests.m */; }; 07D947531F67488E00E37934 /* MGLComputedShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 07D9474E1F67487E00E37934 /* MGLComputedShapeSource_Private.h */; }; - 16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 16376B091FFD9DAF0000563E /* MBGLIntegrationTests.m */; }; + 16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 16376B091FFD9DAF0000563E /* MBGLIntegrationTests.mm */; }; 16376B331FFDB4B40000563E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 16376B321FFDB4B40000563E /* AppDelegate.m */; }; 16376B3B1FFDB4B40000563E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 16376B3A1FFDB4B40000563E /* Assets.xcassets */; }; 16376B3E1FFDB4B40000563E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 16376B3C1FFDB4B40000563E /* LaunchScreen.storyboard */; }; @@ -832,7 +832,7 @@ 07D8C6FD1F67562800381808 /* MGLComputedShapeSourceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MGLComputedShapeSourceTests.m; path = ../../darwin/test/MGLComputedShapeSourceTests.m; sourceTree = "<group>"; }; 07D9474E1F67487E00E37934 /* MGLComputedShapeSource_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource_Private.h; sourceTree = "<group>"; }; 16376B071FFD9DAF0000563E /* integration.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = integration.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 16376B091FFD9DAF0000563E /* MBGLIntegrationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBGLIntegrationTests.m; sourceTree = "<group>"; }; + 16376B091FFD9DAF0000563E /* MBGLIntegrationTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MBGLIntegrationTests.mm; sourceTree = "<group>"; }; 16376B0B1FFD9DAF0000563E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 16376B2F1FFDB4B40000563E /* Integration Test Harness.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Integration Test Harness.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 16376B311FFDB4B40000563E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; @@ -1470,7 +1470,7 @@ CA6914B320E67F07002DB0EE /* Annotations */, CAE7AD5320F46EF5003B6782 /* integration-Bridging-Header.h */, CA1B4A4F2099FA2800EDD491 /* Snapshotter Tests */, - 16376B091FFD9DAF0000563E /* MBGLIntegrationTests.m */, + 16376B091FFD9DAF0000563E /* MBGLIntegrationTests.mm */, 16376B0B1FFD9DAF0000563E /* Info.plist */, CA34C9C2207FD272005C1A06 /* MGLCameraTransitionTests.mm */, CA0C27912076C804001CE5B7 /* MGLShapeSourceTests.m */, @@ -3041,7 +3041,7 @@ CA4EB8C720863487006AB465 /* MGLStyleLayerIntegrationTests.m in Sources */, CA7766842229C11A0008DE9E /* SMCalloutView.m in Sources */, CA34C9C3207FD272005C1A06 /* MGLCameraTransitionTests.mm in Sources */, - 16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.m in Sources */, + 16376B0A1FFD9DAF0000563E /* MBGLIntegrationTests.mm in Sources */, CA88DC3021C85D900059ED5A /* MGLStyleURLIntegrationTest.m in Sources */, CA0C27942076CA19001CE5B7 /* MGLMapViewIntegrationTest.m in Sources */, CA7766832229C10E0008DE9E /* MGLCompactCalloutView.m in Sources */, diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 5074b783ba..85a2e3be92 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -776,6 +776,11 @@ public: self.lastSnapshotImage = nil; } +- (MGLMapViewImpl *)viewImpl +{ + return _mbglView.get(); +} + #pragma mark - Layout - + (BOOL)requiresConstraintBasedLayout diff --git a/platform/ios/src/MGLMapView_Private.h b/platform/ios/src/MGLMapView_Private.h index eff3f464a4..08c1ff410d 100644 --- a/platform/ios/src/MGLMapView_Private.h +++ b/platform/ios/src/MGLMapView_Private.h @@ -9,6 +9,7 @@ namespace mbgl { class Renderer; } +class MGLMapViewImpl; @class MGLSource; /// Minimum size of an annotation’s accessibility element. @@ -57,6 +58,9 @@ FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const _Nonnull MGLUnderlyingMapUna /** Empties the in-memory tile cache. */ - (void)didReceiveMemoryWarning; +/** Returns an instance of MGLMapView implementation. Used for integration testing. */ +- (nonnull MGLMapViewImpl *) viewImpl; + - (void)pauseRendering:(nonnull NSNotification *)notification; - (void)resumeRendering:(nonnull NSNotification *)notification; @property (nonatomic, nonnull) MGLUserLocationAnnotationView *userLocationAnnotationView; |