summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLTileSetTests.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-12-13 17:36:15 -0800
committerGitHub <noreply@github.com>2016-12-13 17:36:15 -0800
commitef71597932820fa09426d43a4e86e025d0628738 (patch)
treef8e0af2fc235859eb75bc00d97ea180ee68c9d73 /platform/darwin/test/MGLTileSetTests.mm
parentb221b6c5fb8ed3360c74a38266b4321e94c10659 (diff)
downloadqtlocation-mapboxgl-ef71597932820fa09426d43a4e86e025d0628738.tar.gz
[ios, macos] Simplify MGLSource and subclasses (#7377)
* [ios, macos] Audited source headers for nullability * [macos] Made MGLTileSet public * [ios, macos] Replaced MGLTileSet with MGLTileSource MGLRasterSource and MGLVectorSource now share a common abstract superclass, MGLTileSource. MGLTileSet has been removed. MGLTileSource is modeled after mbgl::style::RasterSource and mbgl::style::VectorSource. It has initializers that incorporate the parameters of MGLTileSet’s initializers, but it lacks getters for everything but the attribution string. MGLTileSet’s properties have been converted into options that can be passed into MGLTileSource’s initializers in a dictionary. Properly implement rawSource as a covariant property so that it doesn’t end up getting autosynthesized as a shadow ivar. This prevents concrete subclasses of MGLSource from setting _rawSource directly but getting a different value out of self.rawSource. Marked -[MGLSource init] as unavailable and ensured that concrete subclasses of MGLSource have the right set of initializers marked as designated initializers. Documentation comments for each concrete source class identify the corresponding source type in the style specification. Clarified the purpose of MGLTileSetScheme, now known as MGLTileCoordinateSystem. * [ios, macos] Clarified tile size interpretation Sticking to a default value of 256 for mapbox: URLs, but other URLs get the standard 512 value. * [ios, macos] rawSource is always set * [ios, macos] Cleaned up MGLShapeSource initialization rawSource is never nil, so there’s no need for a -commonInit method. Extracted -geoJSONOptions from MGLShapeSource into a standalone function for easier testing. * [ios, macos] Synchronized headers in project Realphabetized headers in groups. Added headers missing from one project or the other. * [ios, macos] Added MGLShape methods to (de)serialize GeoJSON data Added a class initializer and instance method to MGLShape that deserialize and serialize the shape as GeoJSON data, respectively. The new initializer handles parsing errors gracefully. Removed methods specific to GeoJSON data from MGLShapeSource, in an effort to reduce parallel state. Developers are now expected to go through the new MGLShape initializer to get an MGLShape representation. Alternatively, a local file URL can be passed into the other MGLShapeSource initializer. * [ios, macos] Typo in assertion message * [ios, macos] Simplified GeoJSON serialization Every MGLShape now knows its most specific mbgl::GeoJSON representation. * [ios, macos] Reremoved MGLFeaturePrivate mbgl::GeoJSON, which is a variant, allows a single GeoJSON representation method to traffic in whatever type is needed for a particular shape class. This change removes some hidden private protocols, which are a bug waiting to happen. * [ios, macos] Fixed covariant rawLayer property Properly implement rawLayer as a covariant property so that it doesn’t end up getting autosynthesized as a shadow ivar. This prevents concrete subclasses of MGLStyleLayer from setting _rawLayer directly but getting a different value out of self.rawLayer. * [ios, macos] Use MGLAttributionInfo for source attribution Made MGLAttributionInfo public. Replaced MGLTileSource’s attribution property with an attributionInfos property set to an array of MGLAttributionInfo objects. Added an MGLTileSourceOption for specifying an array of MGLAttributionInfo objects instead of an HTML string (either is acceptable when creating an MGLTileSource). * [ios, macos] Corrected method references in documentation
Diffstat (limited to 'platform/darwin/test/MGLTileSetTests.mm')
-rw-r--r--platform/darwin/test/MGLTileSetTests.mm103
1 files changed, 61 insertions, 42 deletions
diff --git a/platform/darwin/test/MGLTileSetTests.mm b/platform/darwin/test/MGLTileSetTests.mm
index d77046928c..06901a0e96 100644
--- a/platform/darwin/test/MGLTileSetTests.mm
+++ b/platform/darwin/test/MGLTileSetTests.mm
@@ -1,7 +1,7 @@
#import <XCTest/XCTest.h>
#import <Mapbox/Mapbox.h>
-#import "MGLTileSet_Private.h"
+#import "MGLTileSource_Private.h"
#include <mbgl/util/tileset.hpp>
@@ -11,72 +11,91 @@
@implementation MGLTileSetTests
-- (void)testTileSet {
+- (void)testTileSetFromTileURLTemplates {
// a tile set that provides an mbgl tile set
- MGLTileSet *tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1",
- @"tile.2",
- @"tile.3"]];
- mbgl::Tileset mbglTileset = [tileSet mbglTileset];
+ NSArray *tileURLTemplates = @[@"tile.1", @"tile.2", @"tile.3"];
+ mbgl::Tileset tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, nil);
// has the correct URL templates
- XCTAssertEqual(mbglTileset.tiles.size(), 3);
- XCTAssertEqual(mbglTileset.tiles[0], "tile.1");
- XCTAssertEqual(mbglTileset.tiles[1], "tile.2");
- XCTAssertEqual(mbglTileset.tiles[2], "tile.3");
+ XCTAssertEqual(tileSet.tiles.size(), 3);
+ XCTAssertEqual(tileSet.tiles[0], "tile.1");
+ XCTAssertEqual(tileSet.tiles[1], "tile.2");
+ XCTAssertEqual(tileSet.tiles[2], "tile.3");
// has the default scheme
- XCTAssertEqual(mbglTileset.scheme, mbgl::Tileset::Scheme::XYZ);
+ XCTAssertEqual(tileSet.scheme, mbgl::Tileset::Scheme::XYZ);
// when the tile set has no min or max zoom level set
- tileSet.minimumZoomLevel = nil;
- tileSet.maximumZoomLevel = nil;
-
// the mbgl object has default values for min and max zoom level
- XCTAssertEqual([tileSet mbglTileset].zoomRange.min, 0);
- XCTAssertEqual([tileSet mbglTileset].zoomRange.max, 22);
+ XCTAssertEqual(tileSet.zoomRange.min, 0);
+ XCTAssertEqual(tileSet.zoomRange.max, 22);
// when the tile set has min and/or max zoom level set
- tileSet.minimumZoomLevel = @(1);
- tileSet.maximumZoomLevel = @(2);
+ tileSet = MGLTileSetFromTileURLTemplates(@[@"tile.1"], @{
+ MGLTileSourceOptionMinimumZoomLevel: @1,
+ MGLTileSourceOptionMaximumZoomLevel: @2,
+ });
// the mbgl object reflects the set values for min and max zoom level
- XCTAssertEqual([tileSet mbglTileset].zoomRange.min, 1);
- XCTAssertEqual([tileSet mbglTileset].zoomRange.max, 2);
+ XCTAssertEqual(tileSet.zoomRange.min, 1);
+ XCTAssertEqual(tileSet.zoomRange.max, 2);
// when the tile set has an attribution
- tileSet.attribution = @"my tileset © ©️🎈";
+ NSString *attribution = @"my tileset © ©️🎈";
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionAttributionHTMLString: attribution,
+ });
// the attribution is reflected by the mbgl tileset
- XCTAssertEqual([tileSet mbglTileset].attribution, tileSet.attribution.UTF8String);
+ XCTAssertEqual(tileSet.attribution, attribution.UTF8String);
+
+ // when the tile set has attribution infos
+ MGLAttributionInfo *mapboxInfo = [[MGLAttributionInfo alloc] initWithTitle:[[NSAttributedString alloc] initWithString:@"Mapbox"]
+ URL:[NSURL URLWithString:@"https://www.mapbox.com/"]];
+ NSAttributedString *gl = [[NSAttributedString alloc] initWithString:@"GL" attributes:@{
+ NSBackgroundColorAttributeName: [MGLColor redColor],
+ }];
+ MGLAttributionInfo *glInfo = [[MGLAttributionInfo alloc] initWithTitle:gl URL:nil];
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionAttributionInfos: @[mapboxInfo, glInfo],
+ });
- // when the scheme is changed
- tileSet.scheme = MGLTileSetSchemeTMS;
+ // the attribution is reflected by the mbgl tileset
+#if TARGET_OS_IPHONE
+ NSString *html = (@"<font style=\"font-family: 'Helvetica'; font-weight: normal; font-style: normal; font-size: 12.00pt\">"
+ @"<a href=\"https://www.mapbox.com/\">Mapbox</a> </font>"
+ @"<font style=\"font-family: 'Helvetica'; font-weight: normal; font-style: normal; font-size: 12.00pt; background-color: #ff0000\">GL</font>\n");
+#else
+ NSString *html = (@"<font face=\"Helvetica\" size=\"3\" style=\"font: 12.0px Helvetica\">"
+ @"<a href=\"https://www.mapbox.com/\">Mapbox</a> </font>"
+ @"<font face=\"Helvetica\" size=\"3\" style=\"font: 12.0px Helvetica; background-color: #ff2600\">GL</font>\n");
+#endif
+ XCTAssertEqualObjects(@(tileSet.attribution.c_str()), html);
+
+ // when the tile coordinate system is changed using an NSNumber
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionTileCoordinateSystem: @(MGLTileCoordinateSystemTMS),
+ });
// the scheme is reflected by the mbgl tileset
- XCTAssertEqual([tileSet mbglTileset].scheme , mbgl::Tileset::Scheme::TMS);
+ XCTAssertEqual(tileSet.scheme, mbgl::Tileset::Scheme::TMS);
- // a tile set that provides an mbgl tile set and minimum and maximum zoom levels
- tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1"] minimumZoomLevel:15 maximumZoomLevel:20];
+ // when the tile coordinate system is changed using an NSValue
+ MGLTileCoordinateSystem tms = MGLTileCoordinateSystemTMS;
+ tileSet = MGLTileSetFromTileURLTemplates(tileURLTemplates, @{
+ MGLTileSourceOptionTileCoordinateSystem: [NSValue value:&tms withObjCType:@encode(MGLTileCoordinateSystem)],
+ });
- // the zoom levels are reflected by the mbgl tileset
- XCTAssertEqual([tileSet mbglTileset].zoomRange.min, 15);
- XCTAssertEqual([tileSet mbglTileset].zoomRange.max, 20);
+ // the scheme is reflected by the mbgl tileset
+ XCTAssertEqual(tileSet.scheme, mbgl::Tileset::Scheme::TMS);
}
- (void)testInvalidTileSet {
// a tile set that provides an mbgl tile set and invalid (crossed) minimum and maximum zoom levels throws an exception
- XCTAssertThrowsSpecificNamed([[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1"] minimumZoomLevel:10 maximumZoomLevel:9], NSException, @"Invalid minimumZoomLevel");
-
- // a tile set that provides an mbgl tile set
- MGLTileSet *tileSet = [[MGLTileSet alloc] initWithTileURLTemplates:@[@"tile.1"]];
- tileSet.maximumZoomLevel = @(10);
-
- // when the minimum zoom level is set higher than the maximum zoom level
- XCTAssertThrowsSpecificNamed(tileSet.minimumZoomLevel = @(11), NSException, @"Invalid minimumZoomLevel");
-
- // when the maximum zoom level is set lower than the minimum zoom level
- tileSet.minimumZoomLevel = @(5);
- XCTAssertThrowsSpecificNamed(tileSet.maximumZoomLevel = @(4), NSException, @"Invalid minimumZoomLevel");
+ XCTAssertThrowsSpecificNamed(MGLTileSetFromTileURLTemplates(@[@"tile.1"], @{
+ MGLTileSourceOptionMinimumZoomLevel: @10,
+ MGLTileSourceOptionMaximumZoomLevel: @9,
+ }), NSException, NSInvalidArgumentException);
}
@end