#import #import @interface MGLStyleValueTests : XCTestCase @end @implementation MGLStyleValueTests - (void)testStoplessFunction { XCTAssertThrowsSpecificNamed([MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential cameraStops:@{} options:nil], NSException, NSInvalidArgumentException, @"Stopless function should raise an exception"); } - (void)testDeprecatedFunctions { MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"test" shape:nil options:nil]; MGLSymbolStyleLayer *symbolStyleLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbolLayer" source:shapeSource]; MGLCircleStyleLayer *circleStyleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circleLayer" source:shapeSource]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" // deprecated function, stops with float values NSDictionary *> *stops = @{ @1: [MGLStyleValue valueWithRawValue:@0], @2: [MGLStyleValue valueWithRawValue:@1], @3: [MGLStyleValue valueWithRawValue:@2], @4: [MGLStyleValue valueWithRawValue:@0], }; MGLStyleValue *iconHaloBlurStyleValue = [MGLStyleValue valueWithInterpolationBase:1.0 stops:stops]; symbolStyleLayer.iconHaloBlur = iconHaloBlurStyleValue; XCTAssertEqualObjects(symbolStyleLayer.iconHaloBlur, iconHaloBlurStyleValue); // deprecated function, stops with boolean values stops = @{ @1: [MGLStyleValue valueWithRawValue:@YES], @2: [MGLStyleValue valueWithRawValue:@NO], @3: [MGLStyleValue valueWithRawValue:@YES], @4: [MGLStyleValue valueWithRawValue:@NO], }; MGLStyleValue *iconAllowsOverlapStyleValue = [MGLStyleValue valueWithInterpolationBase:1.0 stops:stops]; symbolStyleLayer.iconAllowsOverlap = iconAllowsOverlapStyleValue; // iconAllowsOverlap is boolean so mgl and mbgl conversions will coerce the developers stops into interval stops MGLStyleValue *expectedIconAllowsOverlapStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:stops options:nil]; XCTAssertEqualObjects(symbolStyleLayer.iconAllowsOverlap, expectedIconAllowsOverlapStyleValue); /// // creating and using MGLStyleFunctions directly /// NSDictionary *> *circleRadiusStops = @{ @0: [MGLStyleValue valueWithRawValue:@10], @20: [MGLStyleValue valueWithRawValue:@5], }; MGLStyleFunction *circleRadiusFunction = [MGLStyleFunction functionWithInterpolationBase:1.0 stops:circleRadiusStops]; circleStyleLayer.circleRadius = circleRadiusFunction; MGLStyleValue *expectedCircleRadiusFunction = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential cameraStops:circleRadiusStops options:nil]; // setting a data driven property to an MGLStyleFunction should return an exponential camera function XCTAssertEqualObjects(circleStyleLayer.circleRadius, expectedCircleRadiusFunction); CGVector circleTranslationOne = CGVectorMake(100, 0); CGVector circleTranslationTwo = CGVectorMake(0, 0); #if TARGET_OS_IPHONE NSValue *circleTranslationValueOne = [NSValue valueWithCGVector:circleTranslationOne]; NSValue *circleTranslationValueTwo = [NSValue valueWithCGVector:circleTranslationTwo]; #else NSValue *circleTranslationValueOne = [NSValue value:&circleTranslationOne withObjCType:@encode(CGVector)]; NSValue *circleTranslationValueTwo = [NSValue value:&circleTranslationTwo withObjCType:@encode(CGVector)]; #endif NSDictionary *> *circleTranslationStops = @{ @0: [MGLStyleValue valueWithRawValue:circleTranslationValueOne], @10: [MGLStyleValue valueWithRawValue:circleTranslationValueTwo], }; MGLStyleFunction *circleTranslationFunction = [MGLStyleFunction functionWithInterpolationBase:1.0 stops:circleTranslationStops]; circleStyleLayer.circleTranslation = circleTranslationFunction; MGLStyleValue *expectedCircleTranslationFunction = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential cameraStops:circleTranslationStops options:nil]; // setting a non-data driven, interpolatable property to an MGLStyleFunction should return an exponential camera function XCTAssertEqualObjects(circleStyleLayer.circleTranslation, expectedCircleTranslationFunction); NSDictionary *> *iconOptionalStops = @{ @0: [MGLStyleValue valueWithRawValue:@NO], @20: [MGLStyleValue valueWithRawValue:@YES], }; MGLStyleFunction *iconOptionalFunction = [MGLStyleFunction valueWithInterpolationBase:1.0 stops:iconOptionalStops]; symbolStyleLayer.iconOptional = iconOptionalFunction; MGLStyleValue *expectedIconOptionalFunction = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:iconOptionalStops options:nil]; XCTAssertEqualObjects(symbolStyleLayer.iconOptional, expectedIconOptionalFunction); #pragma clang diagnostic pop } @end