summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLSymbolStyleLayerTests.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/test/MGLSymbolStyleLayerTests.mm')
-rw-r--r--platform/darwin/test/MGLSymbolStyleLayerTests.mm116
1 files changed, 116 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
index 2f4206a96b..083b12bcc3 100644
--- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm
+++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm
@@ -1741,6 +1741,75 @@
XCTAssertThrowsSpecificNamed(layer.textPitchAlignment = functionExpression, NSException, NSInvalidArgumentException, @"MGLSymbolLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes.");
}
+ // text-radial-offset
+ {
+ XCTAssertTrue(rawLayer->getTextRadialOffset().isUndefined(),
+ @"text-radial-offset should be unset initially.");
+ NSExpression *defaultExpression = layer.textRadialOffset;
+
+ NSExpression *constantExpression = [NSExpression expressionWithFormat:@"1"];
+ layer.textRadialOffset = constantExpression;
+ mbgl::style::PropertyValue<float> propertyValue = { 1.0 };
+ XCTAssertEqual(rawLayer->getTextRadialOffset(), propertyValue,
+ @"Setting textRadialOffset to a constant value expression should update text-radial-offset.");
+ XCTAssertEqualObjects(layer.textRadialOffset, constantExpression,
+ @"textRadialOffset should round-trip constant value expressions.");
+
+ constantExpression = [NSExpression expressionWithFormat:@"1"];
+ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
+ layer.textRadialOffset = functionExpression;
+
+ {
+ using namespace mbgl::style::expression::dsl;
+ propertyValue = mbgl::style::PropertyExpression<float>(
+ step(zoom(), literal(1.0), 18.0, literal(1.0))
+ );
+ }
+
+ XCTAssertEqual(rawLayer->getTextRadialOffset(), propertyValue,
+ @"Setting textRadialOffset to a camera expression should update text-radial-offset.");
+ XCTAssertEqualObjects(layer.textRadialOffset, functionExpression,
+ @"textRadialOffset should round-trip camera expressions.");
+
+ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(keyName, 'linear', nil, %@)", @{@18: constantExpression}];
+ layer.textRadialOffset = functionExpression;
+
+ {
+ using namespace mbgl::style::expression::dsl;
+ propertyValue = mbgl::style::PropertyExpression<float>(
+ interpolate(linear(), number(get("keyName")), 18.0, literal(1.0))
+ );
+ }
+
+ XCTAssertEqual(rawLayer->getTextRadialOffset(), propertyValue,
+ @"Setting textRadialOffset to a data expression should update text-radial-offset.");
+ NSExpression *pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(CAST(keyName, 'NSNumber'), 'linear', nil, %@)", @{@18: constantExpression}];
+ XCTAssertEqualObjects(layer.textRadialOffset, pedanticFunctionExpression,
+ @"textRadialOffset should round-trip data expressions.");
+
+ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}];
+ layer.textRadialOffset = functionExpression;
+
+ {
+ using namespace mbgl::style::expression::dsl;
+ propertyValue = mbgl::style::PropertyExpression<float>(
+ interpolate(linear(), zoom(), 10.0, interpolate(linear(), number(get("keyName")), 18.0, literal(1.0)))
+ );
+ }
+
+ XCTAssertEqual(rawLayer->getTextRadialOffset(), propertyValue,
+ @"Setting textRadialOffset to a camera-data expression should update text-radial-offset.");
+ pedanticFunctionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: pedanticFunctionExpression}];
+ XCTAssertEqualObjects(layer.textRadialOffset, pedanticFunctionExpression,
+ @"textRadialOffset should round-trip camera-data expressions.");
+
+ layer.textRadialOffset = nil;
+ XCTAssertTrue(rawLayer->getTextRadialOffset().isUndefined(),
+ @"Unsetting textRadialOffset should return text-radial-offset to the default value.");
+ XCTAssertEqualObjects(layer.textRadialOffset, defaultExpression,
+ @"textRadialOffset should return the default value after being unset.");
+ }
+
// text-rotate
{
XCTAssertTrue(rawLayer->getTextRotate().isUndefined(),
@@ -1892,6 +1961,50 @@
@"textTransform should return the default value after being unset.");
}
+ // text-variable-anchor
+ {
+ XCTAssertTrue(rawLayer->getTextVariableAnchor().isUndefined(),
+ @"text-variable-anchor should be unset initially.");
+ NSExpression *defaultExpression = layer.textVariableAnchor;
+
+ NSExpression *constantExpression = [NSExpression expressionWithFormat:@"{'top','bottom'}"];
+ layer.textVariableAnchor = constantExpression;
+ mbgl::style::PropertyValue<std::vector<mbgl::style::SymbolAnchorType>> propertyValue = { { mbgl::style::SymbolAnchorType::Top, mbgl::style::SymbolAnchorType::Bottom } };
+ XCTAssertEqual(rawLayer->getTextVariableAnchor(), propertyValue,
+ @"Setting textVariableAnchor to a constant value expression should update text-variable-anchor.");
+ XCTAssertEqualObjects(layer.textVariableAnchor, constantExpression,
+ @"textVariableAnchor should round-trip constant value expressions.");
+
+ constantExpression = [NSExpression expressionWithFormat:@"{'top','bottom'}"];
+ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
+ layer.textVariableAnchor = functionExpression;
+
+ {
+ using namespace mbgl::style::expression::dsl;
+ propertyValue = mbgl::style::PropertyExpression<std::vector<mbgl::style::SymbolAnchorType>>(
+ step(zoom(), literal({"top", "bottom"}), 18.0, literal({"top", "bottom"}))
+ );
+ }
+
+ XCTAssertEqual(rawLayer->getTextVariableAnchor(), propertyValue,
+ @"Setting textVariableAnchor to a camera expression should update text-variable-anchor.");
+ XCTAssertEqualObjects(layer.textVariableAnchor, functionExpression,
+ @"textVariableAnchor should round-trip camera expressions.");
+
+
+ layer.textVariableAnchor = nil;
+ XCTAssertTrue(rawLayer->getTextVariableAnchor().isUndefined(),
+ @"Unsetting textVariableAnchor should return text-variable-anchor to the default value.");
+ XCTAssertEqualObjects(layer.textVariableAnchor, defaultExpression,
+ @"textVariableAnchor should return the default value after being unset.");
+
+ functionExpression = [NSExpression expressionForKeyPath:@"bogus"];
+ XCTAssertThrowsSpecificNamed(layer.textVariableAnchor = functionExpression, NSException, NSInvalidArgumentException, @"MGLSymbolLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes.");
+ functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:(bogus, %@, %@)", constantExpression, @{@18: constantExpression}];
+ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}];
+ XCTAssertThrowsSpecificNamed(layer.textVariableAnchor = functionExpression, NSException, NSInvalidArgumentException, @"MGLSymbolLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes.");
+ }
+
// icon-color
{
XCTAssertTrue(rawLayer->getIconColor().isUndefined(),
@@ -2896,9 +3009,11 @@
[self testPropertyName:@"is-text-optional" isBoolean:YES];
[self testPropertyName:@"text-padding" isBoolean:NO];
[self testPropertyName:@"text-pitch-alignment" isBoolean:NO];
+ [self testPropertyName:@"text-radial-offset" isBoolean:NO];
[self testPropertyName:@"text-rotation" isBoolean:NO];
[self testPropertyName:@"text-rotation-alignment" isBoolean:NO];
[self testPropertyName:@"text-transform" isBoolean:NO];
+ [self testPropertyName:@"text-variable-anchor" isBoolean:NO];
[self testPropertyName:@"icon-color" isBoolean:NO];
[self testPropertyName:@"icon-halo-blur" isBoolean:NO];
[self testPropertyName:@"icon-halo-color" isBoolean:NO];
@@ -2949,6 +3064,7 @@
XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorTopRight].MGLTextAnchorValue, MGLTextAnchorTopRight);
XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorBottomLeft].MGLTextAnchorValue, MGLTextAnchorBottomLeft);
XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorBottomRight].MGLTextAnchorValue, MGLTextAnchorBottomRight);
+ XCTAssertEqual([NSValue valueWithMGLTextJustification:MGLTextJustificationAuto].MGLTextJustificationValue, MGLTextJustificationAuto);
XCTAssertEqual([NSValue valueWithMGLTextJustification:MGLTextJustificationLeft].MGLTextJustificationValue, MGLTextJustificationLeft);
XCTAssertEqual([NSValue valueWithMGLTextJustification:MGLTextJustificationCenter].MGLTextJustificationValue, MGLTextJustificationCenter);
XCTAssertEqual([NSValue valueWithMGLTextJustification:MGLTextJustificationRight].MGLTextJustificationValue, MGLTextJustificationRight);