summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLSourceQueryTests.m
blob: 28e968146b4fa0184050a1f963c88a8e2ee52e4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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