From 22b3834caa5fe3ae91cf957124a3f1ad1d165cee Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Wed, 4 Jan 2017 07:35:25 -0800 Subject: [ios, macos] Add support for data-driven property functions --- platform/darwin/test/MGLCircleStyleLayerTests.mm | 469 ++++++++++++++++------- 1 file changed, 321 insertions(+), 148 deletions(-) (limited to 'platform/darwin/test/MGLCircleStyleLayerTests.mm') diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.mm b/platform/darwin/test/MGLCircleStyleLayerTests.mm index b8eb84a567..2bf8aab195 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.mm +++ b/platform/darwin/test/MGLCircleStyleLayerTests.mm @@ -1,5 +1,5 @@ // This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLStyleLayerTests.h" @@ -49,26 +49,49 @@ @"circle-blur should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleBlur; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@0xff]; - layer.circleBlur = styleValue; - mbgl::style::PropertyValue propertyValue = { 0xff }; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:@0xff]; + layer.circleBlur = constantStyleValue; + mbgl::style::DataDrivenPropertyValue propertyValue = { 0xff }; XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, @"Setting circleBlur to a constant value should update circle-blur."); - XCTAssertEqualObjects(layer.circleBlur, styleValue, + XCTAssertEqualObjects(layer.circleBlur, constantStyleValue, @"circleBlur should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleBlur = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleBlur = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, 0xff}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + + XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, + @"Setting circleBlur to a camera function should update circle-blur."); + XCTAssertEqualObjects(layer.circleBlur, functionStyleValue, + @"circleBlur should round-trip camera functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.circleBlur = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, 0xff}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, + @"Setting circleBlur to a source function should update circle-blur."); + XCTAssertEqualObjects(layer.circleBlur, functionStyleValue, + @"circleBlur should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.circleBlur = functionStyleValue; + + mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; + std::map> compositeStops = { {10.0, innerStops} }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, - @"Setting circleBlur to a function should update circle-blur."); - XCTAssertEqualObjects(layer.circleBlur, styleValue, - @"circleBlur should round-trip functions."); + @"Setting circleBlur to a composite function should update circle-blur."); + XCTAssertEqualObjects(layer.circleBlur, functionStyleValue, + @"circleBlur should round-trip composite functions."); + layer.circleBlur = nil; XCTAssertTrue(rawLayer->getCircleBlur().isUndefined(), @@ -83,26 +106,49 @@ @"circle-color should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleColor; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:[MGLColor redColor]]; - layer.circleColor = styleValue; - mbgl::style::PropertyValue propertyValue = { { 1, 0, 0, 1 } }; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:[MGLColor redColor]]; + layer.circleColor = constantStyleValue; + mbgl::style::DataDrivenPropertyValue propertyValue = { { 1, 0, 0, 1 } }; XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, @"Setting circleColor to a constant value should update circle-color."); - XCTAssertEqualObjects(layer.circleColor, styleValue, + XCTAssertEqualObjects(layer.circleColor, constantStyleValue, @"circleColor should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleColor = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleColor = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, { 1, 0, 0, 1 }}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + + XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, + @"Setting circleColor to a camera function should update circle-color."); + XCTAssertEqualObjects(layer.circleColor, functionStyleValue, + @"circleColor should round-trip camera functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.circleColor = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, + @"Setting circleColor to a source function should update circle-color."); + XCTAssertEqualObjects(layer.circleColor, functionStyleValue, + @"circleColor should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.circleColor = functionStyleValue; + + mbgl::style::ExponentialStops innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 }; + std::map> compositeStops = { {10.0, innerStops} }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, - @"Setting circleColor to a function should update circle-color."); - XCTAssertEqualObjects(layer.circleColor, styleValue, - @"circleColor should round-trip functions."); + @"Setting circleColor to a composite function should update circle-color."); + XCTAssertEqualObjects(layer.circleColor, functionStyleValue, + @"circleColor should round-trip composite functions."); + layer.circleColor = nil; XCTAssertTrue(rawLayer->getCircleColor().isUndefined(), @@ -117,26 +163,49 @@ @"circle-opacity should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleOpacity; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@0xff]; - layer.circleOpacity = styleValue; - mbgl::style::PropertyValue propertyValue = { 0xff }; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:@0xff]; + layer.circleOpacity = constantStyleValue; + mbgl::style::DataDrivenPropertyValue propertyValue = { 0xff }; XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, @"Setting circleOpacity to a constant value should update circle-opacity."); - XCTAssertEqualObjects(layer.circleOpacity, styleValue, + XCTAssertEqualObjects(layer.circleOpacity, constantStyleValue, @"circleOpacity should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleOpacity = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleOpacity = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, 0xff}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + + XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, + @"Setting circleOpacity to a camera function should update circle-opacity."); + XCTAssertEqualObjects(layer.circleOpacity, functionStyleValue, + @"circleOpacity should round-trip camera functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.circleOpacity = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, 0xff}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, + @"Setting circleOpacity to a source function should update circle-opacity."); + XCTAssertEqualObjects(layer.circleOpacity, functionStyleValue, + @"circleOpacity should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.circleOpacity = functionStyleValue; + + mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; + std::map> compositeStops = { {10.0, innerStops} }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, - @"Setting circleOpacity to a function should update circle-opacity."); - XCTAssertEqualObjects(layer.circleOpacity, styleValue, - @"circleOpacity should round-trip functions."); + @"Setting circleOpacity to a composite function should update circle-opacity."); + XCTAssertEqualObjects(layer.circleOpacity, functionStyleValue, + @"circleOpacity should round-trip composite functions."); + layer.circleOpacity = nil; XCTAssertTrue(rawLayer->getCircleOpacity().isUndefined(), @@ -151,26 +220,49 @@ @"circle-radius should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleRadius; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@0xff]; - layer.circleRadius = styleValue; - mbgl::style::PropertyValue propertyValue = { 0xff }; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:@0xff]; + layer.circleRadius = constantStyleValue; + mbgl::style::DataDrivenPropertyValue propertyValue = { 0xff }; XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, @"Setting circleRadius to a constant value should update circle-radius."); - XCTAssertEqualObjects(layer.circleRadius, styleValue, + XCTAssertEqualObjects(layer.circleRadius, constantStyleValue, @"circleRadius should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleRadius = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleRadius = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, 0xff}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + + XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, + @"Setting circleRadius to a camera function should update circle-radius."); + XCTAssertEqualObjects(layer.circleRadius, functionStyleValue, + @"circleRadius should round-trip camera functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.circleRadius = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, 0xff}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, + @"Setting circleRadius to a source function should update circle-radius."); + XCTAssertEqualObjects(layer.circleRadius, functionStyleValue, + @"circleRadius should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.circleRadius = functionStyleValue; + + mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; + std::map> compositeStops = { {10.0, innerStops} }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, - @"Setting circleRadius to a function should update circle-radius."); - XCTAssertEqualObjects(layer.circleRadius, styleValue, - @"circleRadius should round-trip functions."); + @"Setting circleRadius to a composite function should update circle-radius."); + XCTAssertEqualObjects(layer.circleRadius, functionStyleValue, + @"circleRadius should round-trip composite functions."); + layer.circleRadius = nil; XCTAssertTrue(rawLayer->getCircleRadius().isUndefined(), @@ -185,32 +277,38 @@ @"circle-pitch-scale should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleScaleAlignment; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLCircleScaleAlignment:MGLCircleScaleAlignmentViewport]]; - layer.circleScaleAlignment = styleValue; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLCircleScaleAlignment:MGLCircleScaleAlignmentViewport]]; + layer.circleScaleAlignment = constantStyleValue; mbgl::style::PropertyValue propertyValue = { mbgl::style::CirclePitchScaleType::Viewport }; XCTAssertEqual(rawLayer->getCirclePitchScale(), propertyValue, @"Setting circleScaleAlignment to a constant value should update circle-pitch-scale."); - XCTAssertEqualObjects(layer.circleScaleAlignment, styleValue, + XCTAssertEqualObjects(layer.circleScaleAlignment, constantStyleValue, @"circleScaleAlignment should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleScaleAlignment = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleScaleAlignment = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, mbgl::style::CirclePitchScaleType::Viewport}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + XCTAssertEqual(rawLayer->getCirclePitchScale(), propertyValue, - @"Setting circleScaleAlignment to a function should update circle-pitch-scale."); - XCTAssertEqualObjects(layer.circleScaleAlignment, styleValue, - @"circleScaleAlignment should round-trip functions."); + @"Setting circleScaleAlignment to a camera function should update circle-pitch-scale."); + XCTAssertEqualObjects(layer.circleScaleAlignment, functionStyleValue, + @"circleScaleAlignment should round-trip camera functions."); + + layer.circleScaleAlignment = nil; XCTAssertTrue(rawLayer->getCirclePitchScale().isUndefined(), @"Unsetting circleScaleAlignment should return circle-pitch-scale to the default value."); XCTAssertEqualObjects(layer.circleScaleAlignment, defaultStyleValue, @"circleScaleAlignment should return the default value after being unset."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; + XCTAssertThrowsSpecificNamed(layer.circleScaleAlignment = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval compositeStops:@{@18: constantStyleValue} attributeName:@"" options:nil]; + XCTAssertThrowsSpecificNamed(layer.circleScaleAlignment = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } // circle-stroke-color @@ -219,26 +317,49 @@ @"circle-stroke-color should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleStrokeColor; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:[MGLColor redColor]]; - layer.circleStrokeColor = styleValue; - mbgl::style::PropertyValue propertyValue = { { 1, 0, 0, 1 } }; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:[MGLColor redColor]]; + layer.circleStrokeColor = constantStyleValue; + mbgl::style::DataDrivenPropertyValue propertyValue = { { 1, 0, 0, 1 } }; XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue, @"Setting circleStrokeColor to a constant value should update circle-stroke-color."); - XCTAssertEqualObjects(layer.circleStrokeColor, styleValue, + XCTAssertEqualObjects(layer.circleStrokeColor, constantStyleValue, @"circleStrokeColor should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleStrokeColor = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleStrokeColor = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, { 1, 0, 0, 1 }}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + + XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue, + @"Setting circleStrokeColor to a camera function should update circle-stroke-color."); + XCTAssertEqualObjects(layer.circleStrokeColor, functionStyleValue, + @"circleStrokeColor should round-trip camera functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.circleStrokeColor = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, { 1, 0, 0, 1 }}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue, + @"Setting circleStrokeColor to a source function should update circle-stroke-color."); + XCTAssertEqualObjects(layer.circleStrokeColor, functionStyleValue, + @"circleStrokeColor should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.circleStrokeColor = functionStyleValue; + + mbgl::style::ExponentialStops innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 }; + std::map> compositeStops = { {10.0, innerStops} }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + XCTAssertEqual(rawLayer->getCircleStrokeColor(), propertyValue, - @"Setting circleStrokeColor to a function should update circle-stroke-color."); - XCTAssertEqualObjects(layer.circleStrokeColor, styleValue, - @"circleStrokeColor should round-trip functions."); + @"Setting circleStrokeColor to a composite function should update circle-stroke-color."); + XCTAssertEqualObjects(layer.circleStrokeColor, functionStyleValue, + @"circleStrokeColor should round-trip composite functions."); + layer.circleStrokeColor = nil; XCTAssertTrue(rawLayer->getCircleStrokeColor().isUndefined(), @@ -253,26 +374,49 @@ @"circle-stroke-opacity should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleStrokeOpacity; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@0xff]; - layer.circleStrokeOpacity = styleValue; - mbgl::style::PropertyValue propertyValue = { 0xff }; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:@0xff]; + layer.circleStrokeOpacity = constantStyleValue; + mbgl::style::DataDrivenPropertyValue propertyValue = { 0xff }; XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, @"Setting circleStrokeOpacity to a constant value should update circle-stroke-opacity."); - XCTAssertEqualObjects(layer.circleStrokeOpacity, styleValue, + XCTAssertEqualObjects(layer.circleStrokeOpacity, constantStyleValue, @"circleStrokeOpacity should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleStrokeOpacity = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleStrokeOpacity = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, 0xff}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + + XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, + @"Setting circleStrokeOpacity to a camera function should update circle-stroke-opacity."); + XCTAssertEqualObjects(layer.circleStrokeOpacity, functionStyleValue, + @"circleStrokeOpacity should round-trip camera functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.circleStrokeOpacity = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, 0xff}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, + @"Setting circleStrokeOpacity to a source function should update circle-stroke-opacity."); + XCTAssertEqualObjects(layer.circleStrokeOpacity, functionStyleValue, + @"circleStrokeOpacity should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.circleStrokeOpacity = functionStyleValue; + + mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; + std::map> compositeStops = { {10.0, innerStops} }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + XCTAssertEqual(rawLayer->getCircleStrokeOpacity(), propertyValue, - @"Setting circleStrokeOpacity to a function should update circle-stroke-opacity."); - XCTAssertEqualObjects(layer.circleStrokeOpacity, styleValue, - @"circleStrokeOpacity should round-trip functions."); + @"Setting circleStrokeOpacity to a composite function should update circle-stroke-opacity."); + XCTAssertEqualObjects(layer.circleStrokeOpacity, functionStyleValue, + @"circleStrokeOpacity should round-trip composite functions."); + layer.circleStrokeOpacity = nil; XCTAssertTrue(rawLayer->getCircleStrokeOpacity().isUndefined(), @@ -287,26 +431,49 @@ @"circle-stroke-width should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleStrokeWidth; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@0xff]; - layer.circleStrokeWidth = styleValue; - mbgl::style::PropertyValue propertyValue = { 0xff }; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:@0xff]; + layer.circleStrokeWidth = constantStyleValue; + mbgl::style::DataDrivenPropertyValue propertyValue = { 0xff }; XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, @"Setting circleStrokeWidth to a constant value should update circle-stroke-width."); - XCTAssertEqualObjects(layer.circleStrokeWidth, styleValue, + XCTAssertEqualObjects(layer.circleStrokeWidth, constantStyleValue, @"circleStrokeWidth should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleStrokeWidth = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleStrokeWidth = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, 0xff}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + + XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, + @"Setting circleStrokeWidth to a camera function should update circle-stroke-width."); + XCTAssertEqualObjects(layer.circleStrokeWidth, functionStyleValue, + @"circleStrokeWidth should round-trip camera functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.circleStrokeWidth = functionStyleValue; + + mbgl::style::ExponentialStops exponentialStops = { {{18, 0xff}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, + @"Setting circleStrokeWidth to a source function should update circle-stroke-width."); + XCTAssertEqualObjects(layer.circleStrokeWidth, functionStyleValue, + @"circleStrokeWidth should round-trip source functions."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.circleStrokeWidth = functionStyleValue; + + mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; + std::map> compositeStops = { {10.0, innerStops} }; + + propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; + XCTAssertEqual(rawLayer->getCircleStrokeWidth(), propertyValue, - @"Setting circleStrokeWidth to a function should update circle-stroke-width."); - XCTAssertEqualObjects(layer.circleStrokeWidth, styleValue, - @"circleStrokeWidth should round-trip functions."); + @"Setting circleStrokeWidth to a composite function should update circle-stroke-width."); + XCTAssertEqualObjects(layer.circleStrokeWidth, functionStyleValue, + @"circleStrokeWidth should round-trip composite functions."); + layer.circleStrokeWidth = nil; XCTAssertTrue(rawLayer->getCircleStrokeWidth().isUndefined(), @@ -321,32 +488,32 @@ @"circle-translate should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleTranslation; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue: + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue: #if TARGET_OS_IPHONE [NSValue valueWithCGVector:CGVectorMake(1, 1)] #else [NSValue valueWithMGLVector:CGVectorMake(1, -1)] #endif ]; - layer.circleTranslation = styleValue; + layer.circleTranslation = constantStyleValue; mbgl::style::PropertyValue> propertyValue = { { 1, 1 } }; XCTAssertEqual(rawLayer->getCircleTranslate(), propertyValue, @"Setting circleTranslation to a constant value should update circle-translate."); - XCTAssertEqualObjects(layer.circleTranslation, styleValue, + XCTAssertEqualObjects(layer.circleTranslation, constantStyleValue, @"circleTranslation should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleTranslation = styleValue; - propertyValue = { mbgl::style::Function> { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleTranslation = functionStyleValue; + + mbgl::style::IntervalStops> intervalStops = { {{18, { 1, 1 }}} }; + propertyValue = mbgl::style::CameraFunction> { intervalStops }; + XCTAssertEqual(rawLayer->getCircleTranslate(), propertyValue, - @"Setting circleTranslation to a function should update circle-translate."); - XCTAssertEqualObjects(layer.circleTranslation, styleValue, - @"circleTranslation should round-trip functions."); + @"Setting circleTranslation to a camera function should update circle-translate."); + XCTAssertEqualObjects(layer.circleTranslation, functionStyleValue, + @"circleTranslation should round-trip camera functions."); + + layer.circleTranslation = nil; XCTAssertTrue(rawLayer->getCircleTranslate().isUndefined(), @@ -361,32 +528,38 @@ @"circle-translate-anchor should be unset initially."); MGLStyleValue *defaultStyleValue = layer.circleTranslationAnchor; - MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLCircleTranslationAnchor:MGLCircleTranslationAnchorViewport]]; - layer.circleTranslationAnchor = styleValue; + MGLStyleValue *constantStyleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLCircleTranslationAnchor:MGLCircleTranslationAnchorViewport]]; + layer.circleTranslationAnchor = constantStyleValue; mbgl::style::PropertyValue propertyValue = { mbgl::style::TranslateAnchorType::Viewport }; XCTAssertEqual(rawLayer->getCircleTranslateAnchor(), propertyValue, @"Setting circleTranslationAnchor to a constant value should update circle-translate-anchor."); - XCTAssertEqualObjects(layer.circleTranslationAnchor, styleValue, + XCTAssertEqualObjects(layer.circleTranslationAnchor, constantStyleValue, @"circleTranslationAnchor should round-trip constant values."); - styleValue = [MGLStyleValue valueWithStops:@{ - @18: styleValue, - }]; - layer.circleTranslationAnchor = styleValue; - propertyValue = { mbgl::style::Function { - {{ 18, propertyValue.asConstant() }}, - 1, - }}; + MGLStyleValue * functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.circleTranslationAnchor = functionStyleValue; + + mbgl::style::IntervalStops intervalStops = { {{18, mbgl::style::TranslateAnchorType::Viewport}} }; + propertyValue = mbgl::style::CameraFunction { intervalStops }; + XCTAssertEqual(rawLayer->getCircleTranslateAnchor(), propertyValue, - @"Setting circleTranslationAnchor to a function should update circle-translate-anchor."); - XCTAssertEqualObjects(layer.circleTranslationAnchor, styleValue, - @"circleTranslationAnchor should round-trip functions."); + @"Setting circleTranslationAnchor to a camera function should update circle-translate-anchor."); + XCTAssertEqualObjects(layer.circleTranslationAnchor, functionStyleValue, + @"circleTranslationAnchor should round-trip camera functions."); + + layer.circleTranslationAnchor = nil; XCTAssertTrue(rawLayer->getCircleTranslateAnchor().isUndefined(), @"Unsetting circleTranslationAnchor should return circle-translate-anchor to the default value."); XCTAssertEqualObjects(layer.circleTranslationAnchor, defaultStyleValue, @"circleTranslationAnchor should return the default value after being unset."); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; + XCTAssertThrowsSpecificNamed(layer.circleTranslationAnchor = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); + + functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval compositeStops:@{@18: constantStyleValue} attributeName:@"" options:nil]; + XCTAssertThrowsSpecificNamed(layer.circleTranslationAnchor = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } } -- cgit v1.2.1