summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLSourceQueryTests.m
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-03-05 14:12:37 -0800
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-03-09 13:11:23 -0800
commit12568f21a39dfec7788ebee2815c4c0b2ee964d8 (patch)
tree6184a8e741c3658c6ef672866f882b1a72c9c51b /platform/darwin/test/MGLSourceQueryTests.m
parent0d10d2df1c6d246004e7291511f3aab7a8781d59 (diff)
downloadqtlocation-mapboxgl-12568f21a39dfec7788ebee2815c4c0b2ee964d8.tar.gz
[macos, ios] query source features
Diffstat (limited to 'platform/darwin/test/MGLSourceQueryTests.m')
-rw-r--r--platform/darwin/test/MGLSourceQueryTests.m73
1 files changed, 73 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLSourceQueryTests.m b/platform/darwin/test/MGLSourceQueryTests.m
new file mode 100644
index 0000000000..28e968146b
--- /dev/null
+++ b/platform/darwin/test/MGLSourceQueryTests.m
@@ -0,0 +1,73 @@
+#import <Mapbox/Mapbox.h>
+
+#import "NSBundle+MGLAdditions.h"
+
+#import <XCTest/XCTest.h>
+#if TARGET_OS_IPHONE
+ #import <UIKit/UIKit.h>
+#else
+ #import <Cocoa/Cocoa.h>
+#endif
+
+@interface MGLSourceQueryTests : XCTestCase <MGLMapViewDelegate>
+
+@property (nonatomic) MGLMapView *mapView;
+@property (nonatomic) MGLStyle *style;
+
+@end
+
+@implementation MGLSourceQueryTests {
+ XCTestExpectation *_styleLoadingExpectation;
+}
+
+- (void)setUp {
+ [super setUp];
+
+ [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"];
+ NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"query-style" withExtension:@"json"];
+ self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) styleURL:styleURL];
+ self.mapView.delegate = self;
+ if (!self.mapView.style) {
+ _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."];
+ [self waitForExpectationsWithTimeout:1 handler:nil];
+ }
+}
+
+- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
+ XCTAssertNotNil(mapView.style);
+ XCTAssertEqual(mapView.style, style);
+
+ [_styleLoadingExpectation fulfill];
+}
+
+- (void)tearDown {
+ _styleLoadingExpectation = nil;
+ self.mapView = nil;
+
+ [super tearDown];
+}
+
+- (MGLStyle *)style {
+ return self.mapView.style;
+}
+
+- (void) testQueryVectorSource {
+ MGLVectorSource *source = (MGLVectorSource *)[self.style sourceWithIdentifier:@"source5"];
+
+ NSSet *sourceLayers = [NSSet setWithObjects:@"buildings", @"water", nil];
+ NSArray* features = [source featuresInSourceLayersWithIdentifiers:sourceLayers predicate:nil];
+ // Source won't be loaded yet, so features is 0
+ XCTAssertEqual([features count], 0);
+}
+
+- (void) testQueryShapeSource {
+ MGLShapeSource *source = (MGLShapeSource *)[self.style sourceWithIdentifier:@"source4"];
+
+ NSPredicate *eqPredicate = [NSPredicate predicateWithFormat:@"key1 == 'value1'"];
+ NSArray* features = [source featuresMatchingPredicate:eqPredicate];
+ // Source won't be loaded yet, so features is 0
+ XCTAssertEqual([features count], 0);
+
+}
+
+@end