summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@gmail.com>2019-01-14 15:17:13 -0500
committerGitHub <noreply@github.com>2019-01-14 15:17:13 -0500
commitc8c664fbf376b615b3f1e4b2a4d7f1c99b6097be (patch)
tree414451567862d1bca08bcff1798ebb6b6501ad8d /platform/darwin/test
parent2342b8ee936b9ecce33e152d109a091e505488e6 (diff)
downloadqtlocation-mapboxgl-c8c664fbf376b615b3f1e4b2a4d7f1c99b6097be.tar.gz
[ios, macos] Support getLeaves (and related) clustering methods (#12952) following feature extension API (#13382)
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLCodingTests.mm (renamed from platform/darwin/test/MGLCodingTests.m)33
-rw-r--r--platform/darwin/test/MGLDocumentationExampleTests.swift57
-rw-r--r--platform/darwin/test/MGLFeatureTests.mm21
3 files changed, 110 insertions, 1 deletions
diff --git a/platform/darwin/test/MGLCodingTests.m b/platform/darwin/test/MGLCodingTests.mm
index ac61672b76..e6417c99f5 100644
--- a/platform/darwin/test/MGLCodingTests.m
+++ b/platform/darwin/test/MGLCodingTests.mm
@@ -1,6 +1,9 @@
#import <Mapbox/Mapbox.h>
#import <XCTest/XCTest.h>
+#import "MGLFoundation_Private.h"
+#import "MGLCluster.h"
+
#if TARGET_OS_IPHONE
#import "MGLUserLocation_Private.h"
#endif
@@ -41,6 +44,36 @@
XCTAssertEqualObjects(pointFeature, unarchivedPointFeature);
}
+- (void)testPointFeatureCluster {
+ MGLPointFeature *pointFeature = [[MGLPointFeatureCluster alloc] init];
+ pointFeature.title = @"title";
+ pointFeature.subtitle = @"subtitle";
+ pointFeature.identifier = @(123);
+ pointFeature.attributes = @{
+ @"cluster" : @(YES),
+ @"cluster_id" : @(456),
+ @"point_count" : @(2),
+ };
+
+ XCTAssert([pointFeature isKindOfClass:[MGLPointFeature class]], @"");
+
+ NSString *filePath = [self temporaryFilePathForClass:MGLPointFeature.class];
+ [NSKeyedArchiver archiveRootObject:pointFeature toFile:filePath];
+ MGLPointFeature *unarchivedPointFeature = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
+
+ XCTAssertEqualObjects(pointFeature, unarchivedPointFeature);
+
+ // Unarchive process should ensure we still have a cluster
+ XCTAssert([unarchivedPointFeature isMemberOfClass:[MGLPointFeatureCluster class]]);
+
+ id<MGLCluster> cluster = MGL_OBJC_DYNAMIC_CAST_AS_PROTOCOL(unarchivedPointFeature, MGLCluster);
+
+ XCTAssert(cluster);
+ XCTAssert(cluster.clusterIdentifier == 456);
+ XCTAssert(cluster.clusterPointCount == 2);
+}
+
+
- (void)testPolyline {
CLLocationCoordinate2D coordinates[] = {
CLLocationCoordinate2DMake(0.129631234123, 1.7812739312551),
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift
index 028ee2e856..b59d297f97 100644
--- a/platform/darwin/test/MGLDocumentationExampleTests.swift
+++ b/platform/darwin/test/MGLDocumentationExampleTests.swift
@@ -374,7 +374,7 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
return MGLDocumentationExampleTests.styleURL
}
}
-
+
//#-example-code
let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), altitude: 100, pitch: 20, heading: 0)
@@ -394,6 +394,61 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
wait(for: [expectation], timeout: 5)
}
+ func testMGLCluster() {
+
+ enum ExampleError: Error {
+ case unexpectedFeatureType
+ case featureIsNotACluster
+ }
+
+ let geoJSON: [String: Any] = [
+ "type" : "Feature",
+ "geometry" : [
+ "coordinates" : [
+ -77.00896639534831,
+ 38.87031006108791,
+ 0.0
+ ],
+ "type" : "Point"
+ ],
+ "properties" : [
+ "cluster" : true,
+ "cluster_id" : 123,
+ "point_count" : 4567,
+ ]
+ ]
+
+ let clusterShapeData = try! JSONSerialization.data(withJSONObject: geoJSON, options: [])
+
+ do {
+ //#-example-code
+ let shape = try! MGLShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue)
+
+ guard let pointFeature = shape as? MGLPointFeature else {
+ throw ExampleError.unexpectedFeatureType
+ }
+
+ // Check for cluster conformance
+ guard let cluster = pointFeature as? MGLCluster else {
+ throw ExampleError.featureIsNotACluster
+ }
+
+ // Currently the only supported class that conforms to `MGLCluster` is
+ // `MGLPointFeatureCluster`
+ guard cluster is MGLPointFeatureCluster else {
+ throw ExampleError.unexpectedFeatureType
+ }
+
+ //#-end-example-code
+
+ XCTAssert(cluster.clusterIdentifier == 123)
+ XCTAssert(cluster.clusterPointCount == 4567)
+ }
+ catch let error {
+ XCTFail("Example failed with thrown error: \(error)")
+ }
+ }
+
// For testMGLMapView().
func myCustomFunction() {}
}
diff --git a/platform/darwin/test/MGLFeatureTests.mm b/platform/darwin/test/MGLFeatureTests.mm
index 67f2a9a45e..edc105bca4 100644
--- a/platform/darwin/test/MGLFeatureTests.mm
+++ b/platform/darwin/test/MGLFeatureTests.mm
@@ -2,6 +2,7 @@
#import <XCTest/XCTest.h>
#import <mbgl/util/geometry.hpp>
+#import "MGLFoundation_Private.h"
#import "../../darwin/src/MGLFeature_Private.h"
@interface MGLFeatureTests : XCTestCase
@@ -85,6 +86,26 @@
[NSValue valueWithMGLCoordinate:CLLocationCoordinate2DMake(3, 2)]);
}
+- (void)testClusterGeometryConversion {
+ mbgl::Point<double> point = { -90.066667, 29.95 };
+ mbgl::Feature pointFeature { point };
+ pointFeature.id = { UINT64_MAX };
+ pointFeature.properties["cluster"] = true;
+ pointFeature.properties["cluster_id"] = 1ULL;
+ pointFeature.properties["point_count"] = 5ULL;
+
+ id<MGLFeature> feature = MGLFeatureFromMBGLFeature(pointFeature);
+
+ XCTAssert([feature conformsToProtocol:@protocol(MGLFeature)]);
+
+ id<MGLCluster> cluster = MGL_OBJC_DYNAMIC_CAST_AS_PROTOCOL(feature, MGLCluster);
+ XCTAssert(cluster);
+ XCTAssert(cluster.clusterIdentifier == 1);
+ XCTAssert(cluster.clusterPointCount == 5);
+
+ XCTAssert([cluster isMemberOfClass:[MGLPointFeatureCluster class]]);
+}
+
- (void)testPropertyConversion {
std::vector<mbgl::Feature> features;