diff options
Diffstat (limited to 'platform/darwin/test')
20 files changed, 3582 insertions, 920 deletions
diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.m b/platform/darwin/test/MGLBackgroundStyleLayerTests.m deleted file mode 100644 index 934021d6b8..0000000000 --- a/platform/darwin/test/MGLBackgroundStyleLayerTests.m +++ /dev/null @@ -1,44 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -#import "MGLStyleLayerTests.h" - -@interface MGLBackgroundLayerTests : MGLStyleLayerTests -@end - -@implementation MGLBackgroundLayerTests - -+ (NSString *)layerType { - return @"background"; -} - -- (void)testBackgroundLayer { - MGLBackgroundStyleLayer *layer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"layerID"]; - [self.mapView.style addLayer:layer]; - - layer.backgroundColor = [MGLRuntimeStylingHelper testColor]; - layer.backgroundOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.backgroundPattern = [MGLRuntimeStylingHelper testString]; - - MGLBackgroundStyleLayer *gLayer = (MGLBackgroundStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; - XCTAssertTrue([gLayer isKindOfClass:[MGLBackgroundStyleLayer class]]); - XCTAssertEqualObjects(gLayer.backgroundColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.backgroundOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.backgroundPattern, [MGLRuntimeStylingHelper testString]); - - layer.backgroundColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.backgroundOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.backgroundPattern = [MGLRuntimeStylingHelper testStringFunction]; - - XCTAssertEqualObjects(gLayer.backgroundColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.backgroundOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.backgroundPattern, [MGLRuntimeStylingHelper testStringFunction]); -} - -- (void)testPropertyNames { - [self testPropertyName:@"background-color" isBoolean:NO]; - [self testPropertyName:@"background-opacity" isBoolean:NO]; - [self testPropertyName:@"background-pattern" isBoolean:NO]; -} - -@end diff --git a/platform/darwin/test/MGLBackgroundStyleLayerTests.mm b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm new file mode 100644 index 0000000000..ec962ae502 --- /dev/null +++ b/platform/darwin/test/MGLBackgroundStyleLayerTests.mm @@ -0,0 +1,134 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "MGLStyleLayerTests.h" + +#import "MGLStyleLayer_Private.h" + +#include <mbgl/style/layers/background_layer.hpp> + +@interface MGLBackgroundLayerTests : MGLStyleLayerTests +@end + +@implementation MGLBackgroundLayerTests + ++ (NSString *)layerType { + return @"background"; +} + +- (void)testProperties { + MGLBackgroundStyleLayer *layer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"layerID"]; + XCTAssertNotEqual(layer.rawLayer, nullptr); + XCTAssertTrue(layer.rawLayer->is<mbgl::style::BackgroundLayer>()); + auto rawLayer = layer.rawLayer->as<mbgl::style::BackgroundLayer>(); + + // background-color + { + XCTAssertTrue(rawLayer->getBackgroundColor().isUndefined(), + @"background-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.backgroundColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.backgroundColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getBackgroundColor(), propertyValue, + @"Setting backgroundColor to a constant value should update background-color."); + XCTAssertEqualObjects(layer.backgroundColor, styleValue, + @"backgroundColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.backgroundColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getBackgroundColor(), propertyValue, + @"Setting backgroundColor to a function should update background-color."); + XCTAssertEqualObjects(layer.backgroundColor, styleValue, + @"backgroundColor should round-trip functions."); + + layer.backgroundColor = nil; + XCTAssertTrue(rawLayer->getBackgroundColor().isUndefined(), + @"Unsetting backgroundColor should return background-color to the default value."); + XCTAssertEqualObjects(layer.backgroundColor, defaultStyleValue, + @"backgroundColor should return the default value after being unset."); + } + + // background-opacity + { + XCTAssertTrue(rawLayer->getBackgroundOpacity().isUndefined(), + @"background-opacity should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.backgroundOpacity; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.backgroundOpacity = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getBackgroundOpacity(), propertyValue, + @"Setting backgroundOpacity to a constant value should update background-opacity."); + XCTAssertEqualObjects(layer.backgroundOpacity, styleValue, + @"backgroundOpacity should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.backgroundOpacity = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getBackgroundOpacity(), propertyValue, + @"Setting backgroundOpacity to a function should update background-opacity."); + XCTAssertEqualObjects(layer.backgroundOpacity, styleValue, + @"backgroundOpacity should round-trip functions."); + + layer.backgroundOpacity = nil; + XCTAssertTrue(rawLayer->getBackgroundOpacity().isUndefined(), + @"Unsetting backgroundOpacity should return background-opacity to the default value."); + XCTAssertEqualObjects(layer.backgroundOpacity, defaultStyleValue, + @"backgroundOpacity should return the default value after being unset."); + } + + // background-pattern + { + XCTAssertTrue(rawLayer->getBackgroundPattern().isUndefined(), + @"background-pattern should be unset initially."); + MGLStyleValue<NSString *> *defaultStyleValue = layer.backgroundPattern; + + MGLStyleValue<NSString *> *styleValue = [MGLStyleValue<NSString *> valueWithRawValue:@"Background Pattern"]; + layer.backgroundPattern = styleValue; + mbgl::style::PropertyValue<std::string> propertyValue = { "Background Pattern" }; + XCTAssertEqual(rawLayer->getBackgroundPattern(), propertyValue, + @"Setting backgroundPattern to a constant value should update background-pattern."); + XCTAssertEqualObjects(layer.backgroundPattern, styleValue, + @"backgroundPattern should round-trip constant values."); + + styleValue = [MGLStyleValue<NSString *> valueWithStops:@{ + @18: styleValue, + }]; + layer.backgroundPattern = styleValue; + propertyValue = { mbgl::style::Function<std::string> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getBackgroundPattern(), propertyValue, + @"Setting backgroundPattern to a function should update background-pattern."); + XCTAssertEqualObjects(layer.backgroundPattern, styleValue, + @"backgroundPattern should round-trip functions."); + + layer.backgroundPattern = nil; + XCTAssertTrue(rawLayer->getBackgroundPattern().isUndefined(), + @"Unsetting backgroundPattern should return background-pattern to the default value."); + XCTAssertEqualObjects(layer.backgroundPattern, defaultStyleValue, + @"backgroundPattern should return the default value after being unset."); + } +} + +- (void)testPropertyNames { + [self testPropertyName:@"background-color" isBoolean:NO]; + [self testPropertyName:@"background-opacity" isBoolean:NO]; + [self testPropertyName:@"background-pattern" isBoolean:NO]; +} + +@end diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.m b/platform/darwin/test/MGLCircleStyleLayerTests.m deleted file mode 100644 index 78898a49cb..0000000000 --- a/platform/darwin/test/MGLCircleStyleLayerTests.m +++ /dev/null @@ -1,70 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -#import "MGLStyleLayerTests.h" - -@interface MGLCircleLayerTests : MGLStyleLayerTests -@end - -@implementation MGLCircleLayerTests - -+ (NSString *)layerType { - return @"circle"; -} - -- (void)testCircleLayer { - NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; - NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; - [self.mapView.style addSource:source]; - MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; - [self.mapView.style addLayer:layer]; - - layer.circleBlur = [MGLRuntimeStylingHelper testNumber]; - layer.circleColor = [MGLRuntimeStylingHelper testColor]; - layer.circleOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.circleRadius = [MGLRuntimeStylingHelper testNumber]; - layer.circleScaleAlignment = [MGLRuntimeStylingHelper testEnum:MGLCircleScaleAlignmentViewport type:@encode(MGLCircleScaleAlignment)]; - layer.circleTranslation = [MGLRuntimeStylingHelper testOffset]; - layer.circleTranslationAnchor = [MGLRuntimeStylingHelper testEnum:MGLCircleTranslationAnchorViewport type:@encode(MGLCircleTranslationAnchor)]; - - MGLCircleStyleLayer *gLayer = (MGLCircleStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; - XCTAssertTrue([gLayer isKindOfClass:[MGLCircleStyleLayer class]]); - XCTAssertEqualObjects(gLayer.circleBlur, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.circleColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.circleOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.circleRadius, [MGLRuntimeStylingHelper testNumber]); - XCTAssert([gLayer.circleScaleAlignment isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.circleScaleAlignment, [MGLRuntimeStylingHelper testEnum:MGLCircleScaleAlignmentViewport type:@encode(MGLCircleScaleAlignment)]); - XCTAssertEqualObjects(gLayer.circleTranslation, [MGLRuntimeStylingHelper testOffset]); - XCTAssert([gLayer.circleTranslationAnchor isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.circleTranslationAnchor, [MGLRuntimeStylingHelper testEnum:MGLCircleTranslationAnchorViewport type:@encode(MGLCircleTranslationAnchor)]); - - layer.circleBlur = [MGLRuntimeStylingHelper testNumberFunction]; - layer.circleColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.circleOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.circleRadius = [MGLRuntimeStylingHelper testNumberFunction]; - layer.circleScaleAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLCircleScaleAlignmentViewport type:@encode(MGLCircleScaleAlignment)]; - layer.circleTranslation = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.circleTranslationAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLCircleTranslationAnchorViewport type:@encode(MGLCircleTranslationAnchor)]; - - XCTAssertEqualObjects(gLayer.circleBlur, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.circleColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.circleOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.circleRadius, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.circleScaleAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLCircleScaleAlignmentViewport type:@encode(MGLCircleScaleAlignment)]); - XCTAssertEqualObjects(gLayer.circleTranslation, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.circleTranslationAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLCircleTranslationAnchorViewport type:@encode(MGLCircleTranslationAnchor)]); -} - -- (void)testPropertyNames { - [self testPropertyName:@"circle-blur" isBoolean:NO]; - [self testPropertyName:@"circle-color" isBoolean:NO]; - [self testPropertyName:@"circle-opacity" isBoolean:NO]; - [self testPropertyName:@"circle-radius" isBoolean:NO]; - [self testPropertyName:@"circle-scale-alignment" isBoolean:NO]; - [self testPropertyName:@"circle-translation" isBoolean:NO]; - [self testPropertyName:@"circle-translation-anchor" isBoolean:NO]; -} - -@end diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.mm b/platform/darwin/test/MGLCircleStyleLayerTests.mm new file mode 100644 index 0000000000..1f4b82e32b --- /dev/null +++ b/platform/darwin/test/MGLCircleStyleLayerTests.mm @@ -0,0 +1,308 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "MGLStyleLayerTests.h" + +#import "MGLStyleLayer_Private.h" + +#include <mbgl/style/layers/circle_layer.hpp> + +@interface MGLCircleLayerTests : MGLStyleLayerTests +@end + +@implementation MGLCircleLayerTests + ++ (NSString *)layerType { + return @"circle"; +} + +- (void)testPredicates { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + + XCTAssertNil(layer.sourceLayerIdentifier); + layer.sourceLayerIdentifier = @"layerID"; + XCTAssertEqualObjects(layer.sourceLayerIdentifier, @"layerID"); + layer.sourceLayerIdentifier = nil; + XCTAssertNil(layer.sourceLayerIdentifier); + + XCTAssertNil(layer.predicate); + layer.predicate = [NSPredicate predicateWithValue:NO]; + XCTAssertEqualObjects(layer.predicate, [NSPredicate predicateWithValue:NO]); + layer.predicate = nil; + XCTAssertNil(layer.predicate); +} + +- (void)testProperties { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + + MGLCircleStyleLayer *layer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + XCTAssertNotEqual(layer.rawLayer, nullptr); + XCTAssertTrue(layer.rawLayer->is<mbgl::style::CircleLayer>()); + auto rawLayer = layer.rawLayer->as<mbgl::style::CircleLayer>(); + + // circle-blur + { + XCTAssertTrue(rawLayer->getCircleBlur().isUndefined(), + @"circle-blur should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.circleBlur; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.circleBlur = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, + @"Setting circleBlur to a constant value should update circle-blur."); + XCTAssertEqualObjects(layer.circleBlur, styleValue, + @"circleBlur should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.circleBlur = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getCircleBlur(), propertyValue, + @"Setting circleBlur to a function should update circle-blur."); + XCTAssertEqualObjects(layer.circleBlur, styleValue, + @"circleBlur should round-trip functions."); + + layer.circleBlur = nil; + XCTAssertTrue(rawLayer->getCircleBlur().isUndefined(), + @"Unsetting circleBlur should return circle-blur to the default value."); + XCTAssertEqualObjects(layer.circleBlur, defaultStyleValue, + @"circleBlur should return the default value after being unset."); + } + + // circle-color + { + XCTAssertTrue(rawLayer->getCircleColor().isUndefined(), + @"circle-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.circleColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.circleColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, + @"Setting circleColor to a constant value should update circle-color."); + XCTAssertEqualObjects(layer.circleColor, styleValue, + @"circleColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.circleColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getCircleColor(), propertyValue, + @"Setting circleColor to a function should update circle-color."); + XCTAssertEqualObjects(layer.circleColor, styleValue, + @"circleColor should round-trip functions."); + + layer.circleColor = nil; + XCTAssertTrue(rawLayer->getCircleColor().isUndefined(), + @"Unsetting circleColor should return circle-color to the default value."); + XCTAssertEqualObjects(layer.circleColor, defaultStyleValue, + @"circleColor should return the default value after being unset."); + } + + // circle-opacity + { + XCTAssertTrue(rawLayer->getCircleOpacity().isUndefined(), + @"circle-opacity should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.circleOpacity; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.circleOpacity = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, + @"Setting circleOpacity to a constant value should update circle-opacity."); + XCTAssertEqualObjects(layer.circleOpacity, styleValue, + @"circleOpacity should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.circleOpacity = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getCircleOpacity(), propertyValue, + @"Setting circleOpacity to a function should update circle-opacity."); + XCTAssertEqualObjects(layer.circleOpacity, styleValue, + @"circleOpacity should round-trip functions."); + + layer.circleOpacity = nil; + XCTAssertTrue(rawLayer->getCircleOpacity().isUndefined(), + @"Unsetting circleOpacity should return circle-opacity to the default value."); + XCTAssertEqualObjects(layer.circleOpacity, defaultStyleValue, + @"circleOpacity should return the default value after being unset."); + } + + // circle-radius + { + XCTAssertTrue(rawLayer->getCircleRadius().isUndefined(), + @"circle-radius should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.circleRadius; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.circleRadius = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, + @"Setting circleRadius to a constant value should update circle-radius."); + XCTAssertEqualObjects(layer.circleRadius, styleValue, + @"circleRadius should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.circleRadius = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getCircleRadius(), propertyValue, + @"Setting circleRadius to a function should update circle-radius."); + XCTAssertEqualObjects(layer.circleRadius, styleValue, + @"circleRadius should round-trip functions."); + + layer.circleRadius = nil; + XCTAssertTrue(rawLayer->getCircleRadius().isUndefined(), + @"Unsetting circleRadius should return circle-radius to the default value."); + XCTAssertEqualObjects(layer.circleRadius, defaultStyleValue, + @"circleRadius should return the default value after being unset."); + } + + // circle-pitch-scale + { + XCTAssertTrue(rawLayer->getCirclePitchScale().isUndefined(), + @"circle-pitch-scale should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.circleScaleAlignment; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLCircleScaleAlignment:MGLCircleScaleAlignmentViewport]]; + layer.circleScaleAlignment = styleValue; + mbgl::style::PropertyValue<mbgl::style::CirclePitchScaleType> propertyValue = { mbgl::style::CirclePitchScaleType::Viewport }; + XCTAssertEqual(rawLayer->getCirclePitchScale(), propertyValue, + @"Setting circleScaleAlignment to a constant value should update circle-pitch-scale."); + XCTAssertEqualObjects(layer.circleScaleAlignment, styleValue, + @"circleScaleAlignment should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.circleScaleAlignment = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::CirclePitchScaleType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getCirclePitchScale(), propertyValue, + @"Setting circleScaleAlignment to a function should update circle-pitch-scale."); + XCTAssertEqualObjects(layer.circleScaleAlignment, styleValue, + @"circleScaleAlignment should round-trip 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."); + } + + // circle-translate + { + XCTAssertTrue(rawLayer->getCircleTranslate().isUndefined(), + @"circle-translate should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.circleTranslation; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.circleTranslation = styleValue; + mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + XCTAssertEqual(rawLayer->getCircleTranslate(), propertyValue, + @"Setting circleTranslation to a constant value should update circle-translate."); + XCTAssertEqualObjects(layer.circleTranslation, styleValue, + @"circleTranslation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.circleTranslation = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 2>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getCircleTranslate(), propertyValue, + @"Setting circleTranslation to a function should update circle-translate."); + XCTAssertEqualObjects(layer.circleTranslation, styleValue, + @"circleTranslation should round-trip functions."); + + layer.circleTranslation = nil; + XCTAssertTrue(rawLayer->getCircleTranslate().isUndefined(), + @"Unsetting circleTranslation should return circle-translate to the default value."); + XCTAssertEqualObjects(layer.circleTranslation, defaultStyleValue, + @"circleTranslation should return the default value after being unset."); + } + + // circle-translate-anchor + { + XCTAssertTrue(rawLayer->getCircleTranslateAnchor().isUndefined(), + @"circle-translate-anchor should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.circleTranslationAnchor; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLCircleTranslationAnchor:MGLCircleTranslationAnchorViewport]]; + layer.circleTranslationAnchor = styleValue; + mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType> propertyValue = { mbgl::style::TranslateAnchorType::Viewport }; + XCTAssertEqual(rawLayer->getCircleTranslateAnchor(), propertyValue, + @"Setting circleTranslationAnchor to a constant value should update circle-translate-anchor."); + XCTAssertEqualObjects(layer.circleTranslationAnchor, styleValue, + @"circleTranslationAnchor should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.circleTranslationAnchor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TranslateAnchorType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getCircleTranslateAnchor(), propertyValue, + @"Setting circleTranslationAnchor to a function should update circle-translate-anchor."); + XCTAssertEqualObjects(layer.circleTranslationAnchor, styleValue, + @"circleTranslationAnchor should round-trip 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."); + } +} + +- (void)testPropertyNames { + [self testPropertyName:@"circle-blur" isBoolean:NO]; + [self testPropertyName:@"circle-color" isBoolean:NO]; + [self testPropertyName:@"circle-opacity" isBoolean:NO]; + [self testPropertyName:@"circle-radius" isBoolean:NO]; + [self testPropertyName:@"circle-scale-alignment" isBoolean:NO]; + [self testPropertyName:@"circle-translation" isBoolean:NO]; + [self testPropertyName:@"circle-translation-anchor" isBoolean:NO]; +} + +- (void)testValueAdditions { + XCTAssertEqual([NSValue valueWithMGLCircleScaleAlignment:MGLCircleScaleAlignmentMap].MGLCircleScaleAlignmentValue, MGLCircleScaleAlignmentMap); + XCTAssertEqual([NSValue valueWithMGLCircleScaleAlignment:MGLCircleScaleAlignmentViewport].MGLCircleScaleAlignmentValue, MGLCircleScaleAlignmentViewport); + XCTAssertEqual([NSValue valueWithMGLCircleTranslationAnchor:MGLCircleTranslationAnchorMap].MGLCircleTranslationAnchorValue, MGLCircleTranslationAnchorMap); + XCTAssertEqual([NSValue valueWithMGLCircleTranslationAnchor:MGLCircleTranslationAnchorViewport].MGLCircleTranslationAnchorValue, MGLCircleTranslationAnchorViewport); +} + +@end diff --git a/platform/darwin/test/MGLFillStyleLayerTests.m b/platform/darwin/test/MGLFillStyleLayerTests.m deleted file mode 100644 index 549a8cf4a8..0000000000 --- a/platform/darwin/test/MGLFillStyleLayerTests.m +++ /dev/null @@ -1,69 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -#import "MGLStyleLayerTests.h" - -@interface MGLFillLayerTests : MGLStyleLayerTests -@end - -@implementation MGLFillLayerTests - -+ (NSString *)layerType { - return @"fill"; -} - -- (void)testFillLayer { - NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; - NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; - [self.mapView.style addSource:source]; - MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; - [self.mapView.style addLayer:layer]; - - layer.fillAntialiased = [MGLRuntimeStylingHelper testBool]; - layer.fillColor = [MGLRuntimeStylingHelper testColor]; - layer.fillOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.fillOutlineColor = [MGLRuntimeStylingHelper testColor]; - layer.fillPattern = [MGLRuntimeStylingHelper testString]; - layer.fillTranslation = [MGLRuntimeStylingHelper testOffset]; - layer.fillTranslationAnchor = [MGLRuntimeStylingHelper testEnum:MGLFillTranslationAnchorViewport type:@encode(MGLFillTranslationAnchor)]; - - MGLFillStyleLayer *gLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; - XCTAssertTrue([gLayer isKindOfClass:[MGLFillStyleLayer class]]); - XCTAssertEqualObjects(gLayer.fillAntialiased, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.fillColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.fillOutlineColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testString]); - XCTAssertEqualObjects(gLayer.fillTranslation, [MGLRuntimeStylingHelper testOffset]); - XCTAssert([gLayer.fillTranslationAnchor isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.fillTranslationAnchor, [MGLRuntimeStylingHelper testEnum:MGLFillTranslationAnchorViewport type:@encode(MGLFillTranslationAnchor)]); - - layer.fillAntialiased = [MGLRuntimeStylingHelper testBoolFunction]; - layer.fillColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.fillOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.fillOutlineColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.fillPattern = [MGLRuntimeStylingHelper testStringFunction]; - layer.fillTranslation = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.fillTranslationAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLFillTranslationAnchorViewport type:@encode(MGLFillTranslationAnchor)]; - - XCTAssertEqualObjects(gLayer.fillAntialiased, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.fillColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.fillOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.fillOutlineColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.fillPattern, [MGLRuntimeStylingHelper testStringFunction]); - XCTAssertEqualObjects(gLayer.fillTranslation, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.fillTranslationAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLFillTranslationAnchorViewport type:@encode(MGLFillTranslationAnchor)]); -} - -- (void)testPropertyNames { - [self testPropertyName:@"is-fill-antialiased" isBoolean:YES]; - [self testPropertyName:@"fill-color" isBoolean:NO]; - [self testPropertyName:@"fill-opacity" isBoolean:NO]; - [self testPropertyName:@"fill-outline-color" isBoolean:NO]; - [self testPropertyName:@"fill-pattern" isBoolean:NO]; - [self testPropertyName:@"fill-translation" isBoolean:NO]; - [self testPropertyName:@"fill-translation-anchor" isBoolean:NO]; -} - -@end diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm new file mode 100644 index 0000000000..869ad4f9b5 --- /dev/null +++ b/platform/darwin/test/MGLFillStyleLayerTests.mm @@ -0,0 +1,306 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "MGLStyleLayerTests.h" + +#import "MGLStyleLayer_Private.h" + +#include <mbgl/style/layers/fill_layer.hpp> + +@interface MGLFillLayerTests : MGLStyleLayerTests +@end + +@implementation MGLFillLayerTests + ++ (NSString *)layerType { + return @"fill"; +} + +- (void)testPredicates { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + + XCTAssertNil(layer.sourceLayerIdentifier); + layer.sourceLayerIdentifier = @"layerID"; + XCTAssertEqualObjects(layer.sourceLayerIdentifier, @"layerID"); + layer.sourceLayerIdentifier = nil; + XCTAssertNil(layer.sourceLayerIdentifier); + + XCTAssertNil(layer.predicate); + layer.predicate = [NSPredicate predicateWithValue:NO]; + XCTAssertEqualObjects(layer.predicate, [NSPredicate predicateWithValue:NO]); + layer.predicate = nil; + XCTAssertNil(layer.predicate); +} + +- (void)testProperties { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + + MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + XCTAssertNotEqual(layer.rawLayer, nullptr); + XCTAssertTrue(layer.rawLayer->is<mbgl::style::FillLayer>()); + auto rawLayer = layer.rawLayer->as<mbgl::style::FillLayer>(); + + // fill-antialias + { + XCTAssertTrue(rawLayer->getFillAntialias().isUndefined(), + @"fill-antialias should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.fillAntialiased; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@NO]; + layer.fillAntialiased = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { false }; + XCTAssertEqual(rawLayer->getFillAntialias(), propertyValue, + @"Setting fillAntialiased to a constant value should update fill-antialias."); + XCTAssertEqualObjects(layer.fillAntialiased, styleValue, + @"fillAntialiased should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.fillAntialiased = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getFillAntialias(), propertyValue, + @"Setting fillAntialiased to a function should update fill-antialias."); + XCTAssertEqualObjects(layer.fillAntialiased, styleValue, + @"fillAntialiased should round-trip functions."); + + layer.fillAntialiased = nil; + XCTAssertTrue(rawLayer->getFillAntialias().isUndefined(), + @"Unsetting fillAntialiased should return fill-antialias to the default value."); + XCTAssertEqualObjects(layer.fillAntialiased, defaultStyleValue, + @"fillAntialiased should return the default value after being unset."); + } + + // fill-color + { + XCTAssertTrue(rawLayer->getFillColor().isUndefined(), + @"fill-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.fillColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.fillColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getFillColor(), propertyValue, + @"Setting fillColor to a constant value should update fill-color."); + XCTAssertEqualObjects(layer.fillColor, styleValue, + @"fillColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.fillColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getFillColor(), propertyValue, + @"Setting fillColor to a function should update fill-color."); + XCTAssertEqualObjects(layer.fillColor, styleValue, + @"fillColor should round-trip functions."); + + layer.fillColor = nil; + XCTAssertTrue(rawLayer->getFillColor().isUndefined(), + @"Unsetting fillColor should return fill-color to the default value."); + XCTAssertEqualObjects(layer.fillColor, defaultStyleValue, + @"fillColor should return the default value after being unset."); + } + + // fill-opacity + { + XCTAssertTrue(rawLayer->getFillOpacity().isUndefined(), + @"fill-opacity should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.fillOpacity; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.fillOpacity = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getFillOpacity(), propertyValue, + @"Setting fillOpacity to a constant value should update fill-opacity."); + XCTAssertEqualObjects(layer.fillOpacity, styleValue, + @"fillOpacity should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.fillOpacity = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getFillOpacity(), propertyValue, + @"Setting fillOpacity to a function should update fill-opacity."); + XCTAssertEqualObjects(layer.fillOpacity, styleValue, + @"fillOpacity should round-trip functions."); + + layer.fillOpacity = nil; + XCTAssertTrue(rawLayer->getFillOpacity().isUndefined(), + @"Unsetting fillOpacity should return fill-opacity to the default value."); + XCTAssertEqualObjects(layer.fillOpacity, defaultStyleValue, + @"fillOpacity should return the default value after being unset."); + } + + // fill-outline-color + { + XCTAssertTrue(rawLayer->getFillOutlineColor().isUndefined(), + @"fill-outline-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.fillOutlineColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.fillOutlineColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getFillOutlineColor(), propertyValue, + @"Setting fillOutlineColor to a constant value should update fill-outline-color."); + XCTAssertEqualObjects(layer.fillOutlineColor, styleValue, + @"fillOutlineColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.fillOutlineColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getFillOutlineColor(), propertyValue, + @"Setting fillOutlineColor to a function should update fill-outline-color."); + XCTAssertEqualObjects(layer.fillOutlineColor, styleValue, + @"fillOutlineColor should round-trip functions."); + + layer.fillOutlineColor = nil; + XCTAssertTrue(rawLayer->getFillOutlineColor().isUndefined(), + @"Unsetting fillOutlineColor should return fill-outline-color to the default value."); + XCTAssertEqualObjects(layer.fillOutlineColor, defaultStyleValue, + @"fillOutlineColor should return the default value after being unset."); + } + + // fill-pattern + { + XCTAssertTrue(rawLayer->getFillPattern().isUndefined(), + @"fill-pattern should be unset initially."); + MGLStyleValue<NSString *> *defaultStyleValue = layer.fillPattern; + + MGLStyleValue<NSString *> *styleValue = [MGLStyleValue<NSString *> valueWithRawValue:@"Fill Pattern"]; + layer.fillPattern = styleValue; + mbgl::style::PropertyValue<std::string> propertyValue = { "Fill Pattern" }; + XCTAssertEqual(rawLayer->getFillPattern(), propertyValue, + @"Setting fillPattern to a constant value should update fill-pattern."); + XCTAssertEqualObjects(layer.fillPattern, styleValue, + @"fillPattern should round-trip constant values."); + + styleValue = [MGLStyleValue<NSString *> valueWithStops:@{ + @18: styleValue, + }]; + layer.fillPattern = styleValue; + propertyValue = { mbgl::style::Function<std::string> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getFillPattern(), propertyValue, + @"Setting fillPattern to a function should update fill-pattern."); + XCTAssertEqualObjects(layer.fillPattern, styleValue, + @"fillPattern should round-trip functions."); + + layer.fillPattern = nil; + XCTAssertTrue(rawLayer->getFillPattern().isUndefined(), + @"Unsetting fillPattern should return fill-pattern to the default value."); + XCTAssertEqualObjects(layer.fillPattern, defaultStyleValue, + @"fillPattern should return the default value after being unset."); + } + + // fill-translate + { + XCTAssertTrue(rawLayer->getFillTranslate().isUndefined(), + @"fill-translate should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.fillTranslation; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.fillTranslation = styleValue; + mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + XCTAssertEqual(rawLayer->getFillTranslate(), propertyValue, + @"Setting fillTranslation to a constant value should update fill-translate."); + XCTAssertEqualObjects(layer.fillTranslation, styleValue, + @"fillTranslation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.fillTranslation = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 2>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getFillTranslate(), propertyValue, + @"Setting fillTranslation to a function should update fill-translate."); + XCTAssertEqualObjects(layer.fillTranslation, styleValue, + @"fillTranslation should round-trip functions."); + + layer.fillTranslation = nil; + XCTAssertTrue(rawLayer->getFillTranslate().isUndefined(), + @"Unsetting fillTranslation should return fill-translate to the default value."); + XCTAssertEqualObjects(layer.fillTranslation, defaultStyleValue, + @"fillTranslation should return the default value after being unset."); + } + + // fill-translate-anchor + { + XCTAssertTrue(rawLayer->getFillTranslateAnchor().isUndefined(), + @"fill-translate-anchor should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.fillTranslationAnchor; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLFillTranslationAnchor:MGLFillTranslationAnchorViewport]]; + layer.fillTranslationAnchor = styleValue; + mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType> propertyValue = { mbgl::style::TranslateAnchorType::Viewport }; + XCTAssertEqual(rawLayer->getFillTranslateAnchor(), propertyValue, + @"Setting fillTranslationAnchor to a constant value should update fill-translate-anchor."); + XCTAssertEqualObjects(layer.fillTranslationAnchor, styleValue, + @"fillTranslationAnchor should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.fillTranslationAnchor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TranslateAnchorType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getFillTranslateAnchor(), propertyValue, + @"Setting fillTranslationAnchor to a function should update fill-translate-anchor."); + XCTAssertEqualObjects(layer.fillTranslationAnchor, styleValue, + @"fillTranslationAnchor should round-trip functions."); + + layer.fillTranslationAnchor = nil; + XCTAssertTrue(rawLayer->getFillTranslateAnchor().isUndefined(), + @"Unsetting fillTranslationAnchor should return fill-translate-anchor to the default value."); + XCTAssertEqualObjects(layer.fillTranslationAnchor, defaultStyleValue, + @"fillTranslationAnchor should return the default value after being unset."); + } +} + +- (void)testPropertyNames { + [self testPropertyName:@"is-fill-antialiased" isBoolean:YES]; + [self testPropertyName:@"fill-color" isBoolean:NO]; + [self testPropertyName:@"fill-opacity" isBoolean:NO]; + [self testPropertyName:@"fill-outline-color" isBoolean:NO]; + [self testPropertyName:@"fill-pattern" isBoolean:NO]; + [self testPropertyName:@"fill-translation" isBoolean:NO]; + [self testPropertyName:@"fill-translation-anchor" isBoolean:NO]; +} + +- (void)testValueAdditions { + XCTAssertEqual([NSValue valueWithMGLFillTranslationAnchor:MGLFillTranslationAnchorMap].MGLFillTranslationAnchorValue, MGLFillTranslationAnchorMap); + XCTAssertEqual([NSValue valueWithMGLFillTranslationAnchor:MGLFillTranslationAnchorViewport].MGLFillTranslationAnchorValue, MGLFillTranslationAnchorViewport); +} + +@end diff --git a/platform/darwin/test/MGLLineStyleLayerTests.m b/platform/darwin/test/MGLLineStyleLayerTests.m deleted file mode 100644 index a9e9c7e6a3..0000000000 --- a/platform/darwin/test/MGLLineStyleLayerTests.m +++ /dev/null @@ -1,106 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -#import "MGLStyleLayerTests.h" - -@interface MGLLineLayerTests : MGLStyleLayerTests -@end - -@implementation MGLLineLayerTests - -+ (NSString *)layerType { - return @"line"; -} - -- (void)testLineLayer { - NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; - NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; - [self.mapView.style addSource:source]; - MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; - [self.mapView.style addLayer:layer]; - - layer.lineCap = [MGLRuntimeStylingHelper testEnum:MGLLineCapSquare type:@encode(MGLLineCap)]; - layer.lineJoin = [MGLRuntimeStylingHelper testEnum:MGLLineJoinMiter type:@encode(MGLLineJoin)]; - layer.lineMiterLimit = [MGLRuntimeStylingHelper testNumber]; - layer.lineRoundLimit = [MGLRuntimeStylingHelper testNumber]; - layer.lineBlur = [MGLRuntimeStylingHelper testNumber]; - layer.lineColor = [MGLRuntimeStylingHelper testColor]; - layer.lineDashPattern = [MGLRuntimeStylingHelper testDashArray]; - layer.lineGapWidth = [MGLRuntimeStylingHelper testNumber]; - layer.lineOffset = [MGLRuntimeStylingHelper testNumber]; - layer.lineOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.linePattern = [MGLRuntimeStylingHelper testString]; - layer.lineTranslation = [MGLRuntimeStylingHelper testOffset]; - layer.lineTranslationAnchor = [MGLRuntimeStylingHelper testEnum:MGLLineTranslationAnchorViewport type:@encode(MGLLineTranslationAnchor)]; - layer.lineWidth = [MGLRuntimeStylingHelper testNumber]; - - MGLLineStyleLayer *gLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; - XCTAssertTrue([gLayer isKindOfClass:[MGLLineStyleLayer class]]); - XCTAssert([gLayer.lineCap isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.lineCap, [MGLRuntimeStylingHelper testEnum:MGLLineCapSquare type:@encode(MGLLineCap)]); - XCTAssert([gLayer.lineJoin isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.lineJoin, [MGLRuntimeStylingHelper testEnum:MGLLineJoinMiter type:@encode(MGLLineJoin)]); - XCTAssertEqualObjects(gLayer.lineMiterLimit, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineRoundLimit, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineBlur, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.lineDashPattern, [MGLRuntimeStylingHelper testDashArray]); - XCTAssertEqualObjects(gLayer.lineGapWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineOffset, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.lineOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.linePattern, [MGLRuntimeStylingHelper testString]); - XCTAssertEqualObjects(gLayer.lineTranslation, [MGLRuntimeStylingHelper testOffset]); - XCTAssert([gLayer.lineTranslationAnchor isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.lineTranslationAnchor, [MGLRuntimeStylingHelper testEnum:MGLLineTranslationAnchorViewport type:@encode(MGLLineTranslationAnchor)]); - XCTAssertEqualObjects(gLayer.lineWidth, [MGLRuntimeStylingHelper testNumber]); - - layer.lineCap = [MGLRuntimeStylingHelper testEnumFunction:MGLLineCapSquare type:@encode(MGLLineCap)]; - layer.lineJoin = [MGLRuntimeStylingHelper testEnumFunction:MGLLineJoinMiter type:@encode(MGLLineJoin)]; - layer.lineMiterLimit = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineRoundLimit = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineBlur = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.lineDashPattern = [MGLRuntimeStylingHelper testDashArrayFunction]; - layer.lineGapWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineOffset = [MGLRuntimeStylingHelper testNumberFunction]; - layer.lineOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.linePattern = [MGLRuntimeStylingHelper testStringFunction]; - layer.lineTranslation = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.lineTranslationAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLLineTranslationAnchorViewport type:@encode(MGLLineTranslationAnchor)]; - layer.lineWidth = [MGLRuntimeStylingHelper testNumberFunction]; - - XCTAssertEqualObjects(gLayer.lineCap, [MGLRuntimeStylingHelper testEnumFunction:MGLLineCapSquare type:@encode(MGLLineCap)]); - XCTAssertEqualObjects(gLayer.lineJoin, [MGLRuntimeStylingHelper testEnumFunction:MGLLineJoinMiter type:@encode(MGLLineJoin)]); - XCTAssertEqualObjects(gLayer.lineMiterLimit, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineRoundLimit, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineBlur, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.lineDashPattern, [MGLRuntimeStylingHelper testDashArrayFunction]); - XCTAssertEqualObjects(gLayer.lineGapWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineOffset, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.lineOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.linePattern, [MGLRuntimeStylingHelper testStringFunction]); - XCTAssertEqualObjects(gLayer.lineTranslation, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.lineTranslationAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLLineTranslationAnchorViewport type:@encode(MGLLineTranslationAnchor)]); - XCTAssertEqualObjects(gLayer.lineWidth, [MGLRuntimeStylingHelper testNumberFunction]); -} - -- (void)testPropertyNames { - [self testPropertyName:@"line-cap" isBoolean:NO]; - [self testPropertyName:@"line-join" isBoolean:NO]; - [self testPropertyName:@"line-miter-limit" isBoolean:NO]; - [self testPropertyName:@"line-round-limit" isBoolean:NO]; - [self testPropertyName:@"line-blur" isBoolean:NO]; - [self testPropertyName:@"line-color" isBoolean:NO]; - [self testPropertyName:@"line-dash-pattern" isBoolean:NO]; - [self testPropertyName:@"line-gap-width" isBoolean:NO]; - [self testPropertyName:@"line-offset" isBoolean:NO]; - [self testPropertyName:@"line-opacity" isBoolean:NO]; - [self testPropertyName:@"line-pattern" isBoolean:NO]; - [self testPropertyName:@"line-translation" isBoolean:NO]; - [self testPropertyName:@"line-translation-anchor" isBoolean:NO]; - [self testPropertyName:@"line-width" isBoolean:NO]; -} - -@end diff --git a/platform/darwin/test/MGLLineStyleLayerTests.mm b/platform/darwin/test/MGLLineStyleLayerTests.mm new file mode 100644 index 0000000000..1abe1cf6c3 --- /dev/null +++ b/platform/darwin/test/MGLLineStyleLayerTests.mm @@ -0,0 +1,557 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "MGLStyleLayerTests.h" + +#import "MGLStyleLayer_Private.h" + +#include <mbgl/style/layers/line_layer.hpp> + +@interface MGLLineLayerTests : MGLStyleLayerTests +@end + +@implementation MGLLineLayerTests + ++ (NSString *)layerType { + return @"line"; +} + +- (void)testPredicates { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + + XCTAssertNil(layer.sourceLayerIdentifier); + layer.sourceLayerIdentifier = @"layerID"; + XCTAssertEqualObjects(layer.sourceLayerIdentifier, @"layerID"); + layer.sourceLayerIdentifier = nil; + XCTAssertNil(layer.sourceLayerIdentifier); + + XCTAssertNil(layer.predicate); + layer.predicate = [NSPredicate predicateWithValue:NO]; + XCTAssertEqualObjects(layer.predicate, [NSPredicate predicateWithValue:NO]); + layer.predicate = nil; + XCTAssertNil(layer.predicate); +} + +- (void)testProperties { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + + MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + XCTAssertNotEqual(layer.rawLayer, nullptr); + XCTAssertTrue(layer.rawLayer->is<mbgl::style::LineLayer>()); + auto rawLayer = layer.rawLayer->as<mbgl::style::LineLayer>(); + + // line-cap + { + XCTAssertTrue(rawLayer->getLineCap().isUndefined(), + @"line-cap should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.lineCap; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLLineCap:MGLLineCapSquare]]; + layer.lineCap = styleValue; + mbgl::style::PropertyValue<mbgl::style::LineCapType> propertyValue = { mbgl::style::LineCapType::Square }; + XCTAssertEqual(rawLayer->getLineCap(), propertyValue, + @"Setting lineCap to a constant value should update line-cap."); + XCTAssertEqualObjects(layer.lineCap, styleValue, + @"lineCap should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineCap = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::LineCapType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineCap(), propertyValue, + @"Setting lineCap to a function should update line-cap."); + XCTAssertEqualObjects(layer.lineCap, styleValue, + @"lineCap should round-trip functions."); + + layer.lineCap = nil; + XCTAssertTrue(rawLayer->getLineCap().isUndefined(), + @"Unsetting lineCap should return line-cap to the default value."); + XCTAssertEqualObjects(layer.lineCap, defaultStyleValue, + @"lineCap should return the default value after being unset."); + } + + // line-join + { + XCTAssertTrue(rawLayer->getLineJoin().isUndefined(), + @"line-join should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.lineJoin; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinMiter]]; + layer.lineJoin = styleValue; + mbgl::style::PropertyValue<mbgl::style::LineJoinType> propertyValue = { mbgl::style::LineJoinType::Miter }; + XCTAssertEqual(rawLayer->getLineJoin(), propertyValue, + @"Setting lineJoin to a constant value should update line-join."); + XCTAssertEqualObjects(layer.lineJoin, styleValue, + @"lineJoin should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineJoin = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::LineJoinType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineJoin(), propertyValue, + @"Setting lineJoin to a function should update line-join."); + XCTAssertEqualObjects(layer.lineJoin, styleValue, + @"lineJoin should round-trip functions."); + + layer.lineJoin = nil; + XCTAssertTrue(rawLayer->getLineJoin().isUndefined(), + @"Unsetting lineJoin should return line-join to the default value."); + XCTAssertEqualObjects(layer.lineJoin, defaultStyleValue, + @"lineJoin should return the default value after being unset."); + } + + // line-miter-limit + { + XCTAssertTrue(rawLayer->getLineMiterLimit().isUndefined(), + @"line-miter-limit should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.lineMiterLimit; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.lineMiterLimit = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getLineMiterLimit(), propertyValue, + @"Setting lineMiterLimit to a constant value should update line-miter-limit."); + XCTAssertEqualObjects(layer.lineMiterLimit, styleValue, + @"lineMiterLimit should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineMiterLimit = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineMiterLimit(), propertyValue, + @"Setting lineMiterLimit to a function should update line-miter-limit."); + XCTAssertEqualObjects(layer.lineMiterLimit, styleValue, + @"lineMiterLimit should round-trip functions."); + + layer.lineMiterLimit = nil; + XCTAssertTrue(rawLayer->getLineMiterLimit().isUndefined(), + @"Unsetting lineMiterLimit should return line-miter-limit to the default value."); + XCTAssertEqualObjects(layer.lineMiterLimit, defaultStyleValue, + @"lineMiterLimit should return the default value after being unset."); + } + + // line-round-limit + { + XCTAssertTrue(rawLayer->getLineRoundLimit().isUndefined(), + @"line-round-limit should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.lineRoundLimit; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.lineRoundLimit = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getLineRoundLimit(), propertyValue, + @"Setting lineRoundLimit to a constant value should update line-round-limit."); + XCTAssertEqualObjects(layer.lineRoundLimit, styleValue, + @"lineRoundLimit should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineRoundLimit = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineRoundLimit(), propertyValue, + @"Setting lineRoundLimit to a function should update line-round-limit."); + XCTAssertEqualObjects(layer.lineRoundLimit, styleValue, + @"lineRoundLimit should round-trip functions."); + + layer.lineRoundLimit = nil; + XCTAssertTrue(rawLayer->getLineRoundLimit().isUndefined(), + @"Unsetting lineRoundLimit should return line-round-limit to the default value."); + XCTAssertEqualObjects(layer.lineRoundLimit, defaultStyleValue, + @"lineRoundLimit should return the default value after being unset."); + } + + // line-blur + { + XCTAssertTrue(rawLayer->getLineBlur().isUndefined(), + @"line-blur should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.lineBlur; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.lineBlur = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getLineBlur(), propertyValue, + @"Setting lineBlur to a constant value should update line-blur."); + XCTAssertEqualObjects(layer.lineBlur, styleValue, + @"lineBlur should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineBlur = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineBlur(), propertyValue, + @"Setting lineBlur to a function should update line-blur."); + XCTAssertEqualObjects(layer.lineBlur, styleValue, + @"lineBlur should round-trip functions."); + + layer.lineBlur = nil; + XCTAssertTrue(rawLayer->getLineBlur().isUndefined(), + @"Unsetting lineBlur should return line-blur to the default value."); + XCTAssertEqualObjects(layer.lineBlur, defaultStyleValue, + @"lineBlur should return the default value after being unset."); + } + + // line-color + { + XCTAssertTrue(rawLayer->getLineColor().isUndefined(), + @"line-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.lineColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.lineColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getLineColor(), propertyValue, + @"Setting lineColor to a constant value should update line-color."); + XCTAssertEqualObjects(layer.lineColor, styleValue, + @"lineColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineColor(), propertyValue, + @"Setting lineColor to a function should update line-color."); + XCTAssertEqualObjects(layer.lineColor, styleValue, + @"lineColor should round-trip functions."); + + layer.lineColor = nil; + XCTAssertTrue(rawLayer->getLineColor().isUndefined(), + @"Unsetting lineColor should return line-color to the default value."); + XCTAssertEqualObjects(layer.lineColor, defaultStyleValue, + @"lineColor should return the default value after being unset."); + } + + // line-dasharray + { + XCTAssertTrue(rawLayer->getLineDasharray().isUndefined(), + @"line-dasharray should be unset initially."); + MGLStyleValue<NSArray<NSNumber *> *> *defaultStyleValue = layer.lineDashPattern; + + MGLStyleValue<NSArray<NSNumber *> *> *styleValue = [MGLStyleValue<NSArray<NSNumber *> *> valueWithRawValue:@[@1, @2]]; + layer.lineDashPattern = styleValue; + mbgl::style::PropertyValue<std::vector<float>> propertyValue = { {1, 2} }; + XCTAssertEqual(rawLayer->getLineDasharray(), propertyValue, + @"Setting lineDashPattern to a constant value should update line-dasharray."); + XCTAssertEqualObjects(layer.lineDashPattern, styleValue, + @"lineDashPattern should round-trip constant values."); + + styleValue = [MGLStyleValue<NSArray<NSNumber *> *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineDashPattern = styleValue; + propertyValue = { mbgl::style::Function<std::vector<float>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineDasharray(), propertyValue, + @"Setting lineDashPattern to a function should update line-dasharray."); + XCTAssertEqualObjects(layer.lineDashPattern, styleValue, + @"lineDashPattern should round-trip functions."); + + layer.lineDashPattern = nil; + XCTAssertTrue(rawLayer->getLineDasharray().isUndefined(), + @"Unsetting lineDashPattern should return line-dasharray to the default value."); + XCTAssertEqualObjects(layer.lineDashPattern, defaultStyleValue, + @"lineDashPattern should return the default value after being unset."); + } + + // line-gap-width + { + XCTAssertTrue(rawLayer->getLineGapWidth().isUndefined(), + @"line-gap-width should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.lineGapWidth; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.lineGapWidth = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getLineGapWidth(), propertyValue, + @"Setting lineGapWidth to a constant value should update line-gap-width."); + XCTAssertEqualObjects(layer.lineGapWidth, styleValue, + @"lineGapWidth should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineGapWidth = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineGapWidth(), propertyValue, + @"Setting lineGapWidth to a function should update line-gap-width."); + XCTAssertEqualObjects(layer.lineGapWidth, styleValue, + @"lineGapWidth should round-trip functions."); + + layer.lineGapWidth = nil; + XCTAssertTrue(rawLayer->getLineGapWidth().isUndefined(), + @"Unsetting lineGapWidth should return line-gap-width to the default value."); + XCTAssertEqualObjects(layer.lineGapWidth, defaultStyleValue, + @"lineGapWidth should return the default value after being unset."); + } + + // line-offset + { + XCTAssertTrue(rawLayer->getLineOffset().isUndefined(), + @"line-offset should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.lineOffset; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.lineOffset = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getLineOffset(), propertyValue, + @"Setting lineOffset to a constant value should update line-offset."); + XCTAssertEqualObjects(layer.lineOffset, styleValue, + @"lineOffset should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineOffset = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineOffset(), propertyValue, + @"Setting lineOffset to a function should update line-offset."); + XCTAssertEqualObjects(layer.lineOffset, styleValue, + @"lineOffset should round-trip functions."); + + layer.lineOffset = nil; + XCTAssertTrue(rawLayer->getLineOffset().isUndefined(), + @"Unsetting lineOffset should return line-offset to the default value."); + XCTAssertEqualObjects(layer.lineOffset, defaultStyleValue, + @"lineOffset should return the default value after being unset."); + } + + // line-opacity + { + XCTAssertTrue(rawLayer->getLineOpacity().isUndefined(), + @"line-opacity should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.lineOpacity; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.lineOpacity = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getLineOpacity(), propertyValue, + @"Setting lineOpacity to a constant value should update line-opacity."); + XCTAssertEqualObjects(layer.lineOpacity, styleValue, + @"lineOpacity should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineOpacity = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineOpacity(), propertyValue, + @"Setting lineOpacity to a function should update line-opacity."); + XCTAssertEqualObjects(layer.lineOpacity, styleValue, + @"lineOpacity should round-trip functions."); + + layer.lineOpacity = nil; + XCTAssertTrue(rawLayer->getLineOpacity().isUndefined(), + @"Unsetting lineOpacity should return line-opacity to the default value."); + XCTAssertEqualObjects(layer.lineOpacity, defaultStyleValue, + @"lineOpacity should return the default value after being unset."); + } + + // line-pattern + { + XCTAssertTrue(rawLayer->getLinePattern().isUndefined(), + @"line-pattern should be unset initially."); + MGLStyleValue<NSString *> *defaultStyleValue = layer.linePattern; + + MGLStyleValue<NSString *> *styleValue = [MGLStyleValue<NSString *> valueWithRawValue:@"Line Pattern"]; + layer.linePattern = styleValue; + mbgl::style::PropertyValue<std::string> propertyValue = { "Line Pattern" }; + XCTAssertEqual(rawLayer->getLinePattern(), propertyValue, + @"Setting linePattern to a constant value should update line-pattern."); + XCTAssertEqualObjects(layer.linePattern, styleValue, + @"linePattern should round-trip constant values."); + + styleValue = [MGLStyleValue<NSString *> valueWithStops:@{ + @18: styleValue, + }]; + layer.linePattern = styleValue; + propertyValue = { mbgl::style::Function<std::string> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLinePattern(), propertyValue, + @"Setting linePattern to a function should update line-pattern."); + XCTAssertEqualObjects(layer.linePattern, styleValue, + @"linePattern should round-trip functions."); + + layer.linePattern = nil; + XCTAssertTrue(rawLayer->getLinePattern().isUndefined(), + @"Unsetting linePattern should return line-pattern to the default value."); + XCTAssertEqualObjects(layer.linePattern, defaultStyleValue, + @"linePattern should return the default value after being unset."); + } + + // line-translate + { + XCTAssertTrue(rawLayer->getLineTranslate().isUndefined(), + @"line-translate should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.lineTranslation; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.lineTranslation = styleValue; + mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + XCTAssertEqual(rawLayer->getLineTranslate(), propertyValue, + @"Setting lineTranslation to a constant value should update line-translate."); + XCTAssertEqualObjects(layer.lineTranslation, styleValue, + @"lineTranslation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineTranslation = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 2>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineTranslate(), propertyValue, + @"Setting lineTranslation to a function should update line-translate."); + XCTAssertEqualObjects(layer.lineTranslation, styleValue, + @"lineTranslation should round-trip functions."); + + layer.lineTranslation = nil; + XCTAssertTrue(rawLayer->getLineTranslate().isUndefined(), + @"Unsetting lineTranslation should return line-translate to the default value."); + XCTAssertEqualObjects(layer.lineTranslation, defaultStyleValue, + @"lineTranslation should return the default value after being unset."); + } + + // line-translate-anchor + { + XCTAssertTrue(rawLayer->getLineTranslateAnchor().isUndefined(), + @"line-translate-anchor should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.lineTranslationAnchor; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLLineTranslationAnchor:MGLLineTranslationAnchorViewport]]; + layer.lineTranslationAnchor = styleValue; + mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType> propertyValue = { mbgl::style::TranslateAnchorType::Viewport }; + XCTAssertEqual(rawLayer->getLineTranslateAnchor(), propertyValue, + @"Setting lineTranslationAnchor to a constant value should update line-translate-anchor."); + XCTAssertEqualObjects(layer.lineTranslationAnchor, styleValue, + @"lineTranslationAnchor should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineTranslationAnchor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TranslateAnchorType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineTranslateAnchor(), propertyValue, + @"Setting lineTranslationAnchor to a function should update line-translate-anchor."); + XCTAssertEqualObjects(layer.lineTranslationAnchor, styleValue, + @"lineTranslationAnchor should round-trip functions."); + + layer.lineTranslationAnchor = nil; + XCTAssertTrue(rawLayer->getLineTranslateAnchor().isUndefined(), + @"Unsetting lineTranslationAnchor should return line-translate-anchor to the default value."); + XCTAssertEqualObjects(layer.lineTranslationAnchor, defaultStyleValue, + @"lineTranslationAnchor should return the default value after being unset."); + } + + // line-width + { + XCTAssertTrue(rawLayer->getLineWidth().isUndefined(), + @"line-width should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.lineWidth; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.lineWidth = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getLineWidth(), propertyValue, + @"Setting lineWidth to a constant value should update line-width."); + XCTAssertEqualObjects(layer.lineWidth, styleValue, + @"lineWidth should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.lineWidth = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getLineWidth(), propertyValue, + @"Setting lineWidth to a function should update line-width."); + XCTAssertEqualObjects(layer.lineWidth, styleValue, + @"lineWidth should round-trip functions."); + + layer.lineWidth = nil; + XCTAssertTrue(rawLayer->getLineWidth().isUndefined(), + @"Unsetting lineWidth should return line-width to the default value."); + XCTAssertEqualObjects(layer.lineWidth, defaultStyleValue, + @"lineWidth should return the default value after being unset."); + } +} + +- (void)testPropertyNames { + [self testPropertyName:@"line-cap" isBoolean:NO]; + [self testPropertyName:@"line-join" isBoolean:NO]; + [self testPropertyName:@"line-miter-limit" isBoolean:NO]; + [self testPropertyName:@"line-round-limit" isBoolean:NO]; + [self testPropertyName:@"line-blur" isBoolean:NO]; + [self testPropertyName:@"line-color" isBoolean:NO]; + [self testPropertyName:@"line-dash-pattern" isBoolean:NO]; + [self testPropertyName:@"line-gap-width" isBoolean:NO]; + [self testPropertyName:@"line-offset" isBoolean:NO]; + [self testPropertyName:@"line-opacity" isBoolean:NO]; + [self testPropertyName:@"line-pattern" isBoolean:NO]; + [self testPropertyName:@"line-translation" isBoolean:NO]; + [self testPropertyName:@"line-translation-anchor" isBoolean:NO]; + [self testPropertyName:@"line-width" isBoolean:NO]; +} + +- (void)testValueAdditions { + XCTAssertEqual([NSValue valueWithMGLLineCap:MGLLineCapButt].MGLLineCapValue, MGLLineCapButt); + XCTAssertEqual([NSValue valueWithMGLLineCap:MGLLineCapRound].MGLLineCapValue, MGLLineCapRound); + XCTAssertEqual([NSValue valueWithMGLLineCap:MGLLineCapSquare].MGLLineCapValue, MGLLineCapSquare); + XCTAssertEqual([NSValue valueWithMGLLineJoin:MGLLineJoinBevel].MGLLineJoinValue, MGLLineJoinBevel); + XCTAssertEqual([NSValue valueWithMGLLineJoin:MGLLineJoinRound].MGLLineJoinValue, MGLLineJoinRound); + XCTAssertEqual([NSValue valueWithMGLLineJoin:MGLLineJoinMiter].MGLLineJoinValue, MGLLineJoinMiter); + XCTAssertEqual([NSValue valueWithMGLLineTranslationAnchor:MGLLineTranslationAnchorMap].MGLLineTranslationAnchorValue, MGLLineTranslationAnchorMap); + XCTAssertEqual([NSValue valueWithMGLLineTranslationAnchor:MGLLineTranslationAnchorViewport].MGLLineTranslationAnchorValue, MGLLineTranslationAnchorViewport); +} + +@end diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.m b/platform/darwin/test/MGLRasterStyleLayerTests.m deleted file mode 100644 index f8de191da0..0000000000 --- a/platform/darwin/test/MGLRasterStyleLayerTests.m +++ /dev/null @@ -1,68 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -#import "MGLStyleLayerTests.h" - -@interface MGLRasterLayerTests : MGLStyleLayerTests -@end - -@implementation MGLRasterLayerTests - -+ (NSString *)layerType { - return @"raster"; -} - -- (void)testRasterLayer { - NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; - NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; - [self.mapView.style addSource:source]; - MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; - [self.mapView.style addLayer:layer]; - - layer.maximumRasterBrightness = [MGLRuntimeStylingHelper testNumber]; - layer.minimumRasterBrightness = [MGLRuntimeStylingHelper testNumber]; - layer.rasterContrast = [MGLRuntimeStylingHelper testNumber]; - layer.rasterFadeDuration = [MGLRuntimeStylingHelper testNumber]; - layer.rasterHueRotation = [MGLRuntimeStylingHelper testNumber]; - layer.rasterOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.rasterSaturation = [MGLRuntimeStylingHelper testNumber]; - - MGLRasterStyleLayer *gLayer = (MGLRasterStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; - XCTAssertTrue([gLayer isKindOfClass:[MGLRasterStyleLayer class]]); - XCTAssertEqualObjects(gLayer.maximumRasterBrightness, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.minimumRasterBrightness, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterContrast, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterFadeDuration, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterHueRotation, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumber]); - - layer.maximumRasterBrightness = [MGLRuntimeStylingHelper testNumberFunction]; - layer.minimumRasterBrightness = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterContrast = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterFadeDuration = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterHueRotation = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.rasterSaturation = [MGLRuntimeStylingHelper testNumberFunction]; - - XCTAssertEqualObjects(gLayer.maximumRasterBrightness, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.minimumRasterBrightness, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterContrast, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterFadeDuration, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterHueRotation, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumberFunction]); -} - -- (void)testPropertyNames { - [self testPropertyName:@"maximum-raster-brightness" isBoolean:NO]; - [self testPropertyName:@"minimum-raster-brightness" isBoolean:NO]; - [self testPropertyName:@"raster-contrast" isBoolean:NO]; - [self testPropertyName:@"raster-fade-duration" isBoolean:NO]; - [self testPropertyName:@"raster-hue-rotation" isBoolean:NO]; - [self testPropertyName:@"raster-opacity" isBoolean:NO]; - [self testPropertyName:@"raster-saturation" isBoolean:NO]; -} - -@end diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.mm b/platform/darwin/test/MGLRasterStyleLayerTests.mm new file mode 100644 index 0000000000..28a201961c --- /dev/null +++ b/platform/darwin/test/MGLRasterStyleLayerTests.mm @@ -0,0 +1,277 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "MGLStyleLayerTests.h" + +#import "MGLStyleLayer_Private.h" + +#include <mbgl/style/layers/raster_layer.hpp> + +@interface MGLRasterLayerTests : MGLStyleLayerTests +@end + +@implementation MGLRasterLayerTests + ++ (NSString *)layerType { + return @"raster"; +} + +- (void)testProperties { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + + MGLRasterStyleLayer *layer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + XCTAssertNotEqual(layer.rawLayer, nullptr); + XCTAssertTrue(layer.rawLayer->is<mbgl::style::RasterLayer>()); + auto rawLayer = layer.rawLayer->as<mbgl::style::RasterLayer>(); + + // raster-brightness-max + { + XCTAssertTrue(rawLayer->getRasterBrightnessMax().isUndefined(), + @"raster-brightness-max should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.maximumRasterBrightness; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.maximumRasterBrightness = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getRasterBrightnessMax(), propertyValue, + @"Setting maximumRasterBrightness to a constant value should update raster-brightness-max."); + XCTAssertEqualObjects(layer.maximumRasterBrightness, styleValue, + @"maximumRasterBrightness should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.maximumRasterBrightness = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getRasterBrightnessMax(), propertyValue, + @"Setting maximumRasterBrightness to a function should update raster-brightness-max."); + XCTAssertEqualObjects(layer.maximumRasterBrightness, styleValue, + @"maximumRasterBrightness should round-trip functions."); + + layer.maximumRasterBrightness = nil; + XCTAssertTrue(rawLayer->getRasterBrightnessMax().isUndefined(), + @"Unsetting maximumRasterBrightness should return raster-brightness-max to the default value."); + XCTAssertEqualObjects(layer.maximumRasterBrightness, defaultStyleValue, + @"maximumRasterBrightness should return the default value after being unset."); + } + + // raster-brightness-min + { + XCTAssertTrue(rawLayer->getRasterBrightnessMin().isUndefined(), + @"raster-brightness-min should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.minimumRasterBrightness; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.minimumRasterBrightness = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getRasterBrightnessMin(), propertyValue, + @"Setting minimumRasterBrightness to a constant value should update raster-brightness-min."); + XCTAssertEqualObjects(layer.minimumRasterBrightness, styleValue, + @"minimumRasterBrightness should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.minimumRasterBrightness = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getRasterBrightnessMin(), propertyValue, + @"Setting minimumRasterBrightness to a function should update raster-brightness-min."); + XCTAssertEqualObjects(layer.minimumRasterBrightness, styleValue, + @"minimumRasterBrightness should round-trip functions."); + + layer.minimumRasterBrightness = nil; + XCTAssertTrue(rawLayer->getRasterBrightnessMin().isUndefined(), + @"Unsetting minimumRasterBrightness should return raster-brightness-min to the default value."); + XCTAssertEqualObjects(layer.minimumRasterBrightness, defaultStyleValue, + @"minimumRasterBrightness should return the default value after being unset."); + } + + // raster-contrast + { + XCTAssertTrue(rawLayer->getRasterContrast().isUndefined(), + @"raster-contrast should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.rasterContrast; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.rasterContrast = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getRasterContrast(), propertyValue, + @"Setting rasterContrast to a constant value should update raster-contrast."); + XCTAssertEqualObjects(layer.rasterContrast, styleValue, + @"rasterContrast should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.rasterContrast = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getRasterContrast(), propertyValue, + @"Setting rasterContrast to a function should update raster-contrast."); + XCTAssertEqualObjects(layer.rasterContrast, styleValue, + @"rasterContrast should round-trip functions."); + + layer.rasterContrast = nil; + XCTAssertTrue(rawLayer->getRasterContrast().isUndefined(), + @"Unsetting rasterContrast should return raster-contrast to the default value."); + XCTAssertEqualObjects(layer.rasterContrast, defaultStyleValue, + @"rasterContrast should return the default value after being unset."); + } + + // raster-fade-duration + { + XCTAssertTrue(rawLayer->getRasterFadeDuration().isUndefined(), + @"raster-fade-duration should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.rasterFadeDuration; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.rasterFadeDuration = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getRasterFadeDuration(), propertyValue, + @"Setting rasterFadeDuration to a constant value should update raster-fade-duration."); + XCTAssertEqualObjects(layer.rasterFadeDuration, styleValue, + @"rasterFadeDuration should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.rasterFadeDuration = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getRasterFadeDuration(), propertyValue, + @"Setting rasterFadeDuration to a function should update raster-fade-duration."); + XCTAssertEqualObjects(layer.rasterFadeDuration, styleValue, + @"rasterFadeDuration should round-trip functions."); + + layer.rasterFadeDuration = nil; + XCTAssertTrue(rawLayer->getRasterFadeDuration().isUndefined(), + @"Unsetting rasterFadeDuration should return raster-fade-duration to the default value."); + XCTAssertEqualObjects(layer.rasterFadeDuration, defaultStyleValue, + @"rasterFadeDuration should return the default value after being unset."); + } + + // raster-hue-rotate + { + XCTAssertTrue(rawLayer->getRasterHueRotate().isUndefined(), + @"raster-hue-rotate should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.rasterHueRotation; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.rasterHueRotation = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getRasterHueRotate(), propertyValue, + @"Setting rasterHueRotation to a constant value should update raster-hue-rotate."); + XCTAssertEqualObjects(layer.rasterHueRotation, styleValue, + @"rasterHueRotation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.rasterHueRotation = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getRasterHueRotate(), propertyValue, + @"Setting rasterHueRotation to a function should update raster-hue-rotate."); + XCTAssertEqualObjects(layer.rasterHueRotation, styleValue, + @"rasterHueRotation should round-trip functions."); + + layer.rasterHueRotation = nil; + XCTAssertTrue(rawLayer->getRasterHueRotate().isUndefined(), + @"Unsetting rasterHueRotation should return raster-hue-rotate to the default value."); + XCTAssertEqualObjects(layer.rasterHueRotation, defaultStyleValue, + @"rasterHueRotation should return the default value after being unset."); + } + + // raster-opacity + { + XCTAssertTrue(rawLayer->getRasterOpacity().isUndefined(), + @"raster-opacity should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.rasterOpacity; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.rasterOpacity = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getRasterOpacity(), propertyValue, + @"Setting rasterOpacity to a constant value should update raster-opacity."); + XCTAssertEqualObjects(layer.rasterOpacity, styleValue, + @"rasterOpacity should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.rasterOpacity = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getRasterOpacity(), propertyValue, + @"Setting rasterOpacity to a function should update raster-opacity."); + XCTAssertEqualObjects(layer.rasterOpacity, styleValue, + @"rasterOpacity should round-trip functions."); + + layer.rasterOpacity = nil; + XCTAssertTrue(rawLayer->getRasterOpacity().isUndefined(), + @"Unsetting rasterOpacity should return raster-opacity to the default value."); + XCTAssertEqualObjects(layer.rasterOpacity, defaultStyleValue, + @"rasterOpacity should return the default value after being unset."); + } + + // raster-saturation + { + XCTAssertTrue(rawLayer->getRasterSaturation().isUndefined(), + @"raster-saturation should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.rasterSaturation; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.rasterSaturation = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getRasterSaturation(), propertyValue, + @"Setting rasterSaturation to a constant value should update raster-saturation."); + XCTAssertEqualObjects(layer.rasterSaturation, styleValue, + @"rasterSaturation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.rasterSaturation = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getRasterSaturation(), propertyValue, + @"Setting rasterSaturation to a function should update raster-saturation."); + XCTAssertEqualObjects(layer.rasterSaturation, styleValue, + @"rasterSaturation should round-trip functions."); + + layer.rasterSaturation = nil; + XCTAssertTrue(rawLayer->getRasterSaturation().isUndefined(), + @"Unsetting rasterSaturation should return raster-saturation to the default value."); + XCTAssertEqualObjects(layer.rasterSaturation, defaultStyleValue, + @"rasterSaturation should return the default value after being unset."); + } +} + +- (void)testPropertyNames { + [self testPropertyName:@"maximum-raster-brightness" isBoolean:NO]; + [self testPropertyName:@"minimum-raster-brightness" isBoolean:NO]; + [self testPropertyName:@"raster-contrast" isBoolean:NO]; + [self testPropertyName:@"raster-fade-duration" isBoolean:NO]; + [self testPropertyName:@"raster-hue-rotation" isBoolean:NO]; + [self testPropertyName:@"raster-opacity" isBoolean:NO]; + [self testPropertyName:@"raster-saturation" isBoolean:NO]; +} + +@end diff --git a/platform/darwin/test/MGLRuntimeStylingHelper.h b/platform/darwin/test/MGLRuntimeStylingHelper.h deleted file mode 100644 index 8857dba9c5..0000000000 --- a/platform/darwin/test/MGLRuntimeStylingHelper.h +++ /dev/null @@ -1,35 +0,0 @@ -#import <Foundation/Foundation.h> - -#import "MGLTypes.h" -#import "MGLStyleValue.h" - -@interface MGLRuntimeStylingHelper : NSObject - -+ (MGLStyleConstantValue<NSValue *> *)testPadding; -+ (MGLStyleFunction<NSValue *> *)testPaddingFunction; - -+ (MGLStyleConstantValue<NSValue *> *)testOffset; -+ (MGLStyleFunction<NSValue *> *)testOffsetFunction; - -+ (MGLStyleConstantValue<NSArray<NSString *> *> *)testFont; -+ (MGLStyleFunction<NSArray<NSString *> *> *)testFontFunction; - -+ (MGLStyleConstantValue<NSArray<NSNumber *> *> *)testDashArray; -+ (MGLStyleFunction<NSArray<NSNumber *> *> *)testDashArrayFunction; - -+ (MGLStyleConstantValue<NSNumber *> *)testNumber; -+ (MGLStyleFunction<NSNumber *> *)testNumberFunction; - -+ (MGLStyleConstantValue<NSNumber *> *)testBool; -+ (MGLStyleFunction<NSNumber *> *)testBoolFunction; - -+ (MGLStyleConstantValue<NSString *> *)testString; -+ (MGLStyleFunction<NSString *> *)testStringFunction; - -+ (MGLStyleConstantValue<MGLColor *> *)testColor; -+ (MGLStyleFunction<MGLColor *> *)testColorFunction; - -+ (MGLStyleConstantValue<NSValue *> *)testEnum:(NSUInteger)value type:(const char *)type; -+ (MGLStyleFunction<NSValue *> *)testEnumFunction:(NSUInteger)value type:(const char *)type; - -@end diff --git a/platform/darwin/test/MGLRuntimeStylingHelper.m b/platform/darwin/test/MGLRuntimeStylingHelper.m deleted file mode 100644 index 955c664f2c..0000000000 --- a/platform/darwin/test/MGLRuntimeStylingHelper.m +++ /dev/null @@ -1,122 +0,0 @@ -#import "MGLRuntimeStylingHelper.h" - -#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - #import <UIKit/UIKit.h> - #define MGLEdgeInsets UIEdgeInsets -#else - #import <Cocoa/Cocoa.h> - #define MGLEdgeInsets NSEdgeInsets -#endif - -@implementation MGLRuntimeStylingHelper - -+ (MGLStyleConstantValue<NSValue *> *)testPadding -{ - MGLEdgeInsets insets = { - .top = 1, - .left = 1, - .bottom = 1, - .right = 1, - }; - return [MGLStyleConstantValue<NSValue *> valueWithRawValue:[NSValue value:&insets withObjCType:@encode(MGLEdgeInsets)]]; -} - -+ (MGLStyleFunction<NSValue *> *)testPaddingFunction -{ - return [MGLStyleFunction<NSValue *> functionWithStops:@{@(18): self.testPadding}]; -} - -+ (MGLStyleConstantValue<NSValue *> *)testOffset -{ - CGVector vector = CGVectorMake(1, 1); - return [MGLStyleConstantValue<NSValue *> valueWithRawValue:[NSValue value:&vector withObjCType:@encode(CGVector)]]; -} - -+ (MGLStyleFunction<NSValue *> *)testOffsetFunction -{ - return [MGLStyleFunction<NSValue *> valueWithStops:@{ @(18): self.testOffset }]; -} - -+ (MGLStyleConstantValue<NSArray<NSString *> *> *)testFont -{ - return [MGLStyleConstantValue<NSArray<NSString *> *> valueWithRawValue:@[@"Open Sans Regular", @"Arial Unicode MS Regular"]]; -} - -+ (MGLStyleFunction<NSArray<NSString *> *> *)testFontFunction -{ - return [MGLStyleFunction<NSArray<NSString *> *> valueWithStops:@{ @18: self.testFont }]; -} - -+ (MGLStyleConstantValue<NSArray<NSNumber *> *> *)testDashArray -{ - return [MGLStyleConstantValue<NSArray<NSNumber *> *> valueWithRawValue:@[@1, @2]]; -} - -+ (MGLStyleFunction<NSArray<NSNumber *> *> *)testDashArrayFunction -{ - return [MGLStyleFunction<NSArray<NSNumber *> *> valueWithStops:@{ - @18: self.testDashArray, - }]; -} - -+ (MGLStyleConstantValue<NSNumber *> *)testNumber -{ - return [MGLStyleConstantValue<NSNumber *> valueWithRawValue:@1]; -} - -+ (MGLStyleFunction<NSNumber *> *)testNumberFunction -{ - return [MGLStyleFunction<NSNumber *> valueWithStops:@{ - @18: self.testNumber, - }]; -} - -+ (MGLStyleConstantValue<NSNumber *> *)testBool -{ - return [MGLStyleConstantValue<NSNumber *> valueWithRawValue:@YES]; -} - -+ (MGLStyleFunction<NSNumber *> *)testBoolFunction -{ - return [MGLStyleFunction<NSNumber *> valueWithStops:@{ - @18: self.testBool, - }]; -} - -+ (MGLStyleConstantValue<NSString *> *)testString -{ - return [MGLStyleConstantValue<NSString *> valueWithRawValue:@"test"]; -} - -+ (MGLStyleFunction<NSString *> *)testStringFunction -{ - return [MGLStyleFunction<NSString *> valueWithStops:@{ - @18: self.testString, - }]; -} - -+ (MGLStyleConstantValue<MGLColor *> *)testColor -{ - return [MGLStyleConstantValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; -} - -+ (MGLStyleFunction<MGLColor *> *)testColorFunction -{ - return [MGLStyleFunction<MGLColor *> valueWithStops:@{ - @18: self.testColor, - }]; -} - -+ (MGLStyleConstantValue<NSValue *> *)testEnum:(NSUInteger)value type:(const char *)type -{ - return [MGLStyleConstantValue<NSValue *> valueWithRawValue:[NSValue value:&value withObjCType:type]]; -} - -+ (MGLStyleFunction<NSValue *> *)testEnumFunction:(NSUInteger)value type:(const char *)type -{ - return [MGLStyleFunction<NSValue *> valueWithStops:@{ - @18: [self testEnum:value type:type], - }]; -} - -@end diff --git a/platform/darwin/test/MGLStyleLayerTests.h b/platform/darwin/test/MGLStyleLayerTests.h index 65322ff331..f0b889f022 100644 --- a/platform/darwin/test/MGLStyleLayerTests.h +++ b/platform/darwin/test/MGLStyleLayerTests.h @@ -1,10 +1,8 @@ #import <Mapbox/Mapbox.h> -#import "MGLRuntimeStylingHelper.h" #import <XCTest/XCTest.h> @interface MGLStyleLayerTests : XCTestCase <MGLMapViewDelegate> -@property (nonatomic) IBOutlet MGLMapView *mapView; @property (nonatomic, copy, readonly, class) NSString *layerType; - (void)testPropertyName:(NSString *)name isBoolean:(BOOL)isBoolean; @@ -17,3 +15,11 @@ @property (nonatomic, readonly, copy) NSString *lemma; @end + +@interface NSValue (MGLStyleLayerTestAdditions) + ++ (instancetype)valueWithMGLVector:(CGVector)vector; + +@property (readonly) CGVector MGLVectorValue; + +@end diff --git a/platform/darwin/test/MGLStyleLayerTests.m b/platform/darwin/test/MGLStyleLayerTests.m index 0bf5072391..1dba9f4305 100644 --- a/platform/darwin/test/MGLStyleLayerTests.m +++ b/platform/darwin/test/MGLStyleLayerTests.m @@ -4,37 +4,32 @@ #define TEST_STRICT_NAMING_CONVENTIONS 0 -@implementation MGLStyleLayerTests { - XCTestExpectation *_styleLoadingExpectation; -} +@implementation MGLStyleLayerTests @dynamic layerType; -- (void)setUp { - [super setUp]; - [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; - self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 256, 256) 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); - XCTAssertNil(style.name); +- (void)testProperties { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; - [_styleLoadingExpectation fulfill]; -} - -- (void)tearDown { - _styleLoadingExpectation = nil; - _mapView = nil; + MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + + XCTAssertEqualObjects(layer.identifier, @"layerID"); + XCTAssertEqualObjects(layer.sourceIdentifier, source.identifier); + + XCTAssertTrue(layer.visible); + layer.visible = NO; + XCTAssertFalse(layer.visible); + layer.visible = YES; + XCTAssertTrue(layer.visible); + + XCTAssertEqual(layer.minimumZoomLevel, -INFINITY); + layer.minimumZoomLevel = 22; + XCTAssertEqual(layer.minimumZoomLevel, 22); - [super tearDown]; + XCTAssertEqual(layer.maximumZoomLevel, INFINITY); + layer.maximumZoomLevel = 0; + XCTAssertEqual(layer.maximumZoomLevel, 0); } - (void)testPropertyName:(NSString *)name isBoolean:(BOOL)isBoolean { @@ -99,3 +94,25 @@ } @end + +@implementation NSValue (MGLStyleLayerTestAdditions) + ++ (instancetype)valueWithMGLVector:(CGVector)vector { +#if TARGET_OS_IPHONE + return [self valueWithCGVector:vector]; +#else + return [self value:&vector withObjCType:@encode(CGVector)]; +#endif +} + +- (CGVector)MGLVectorValue { +#if TARGET_OS_IPHONE + return self.CGVectorValue; +#else + CGVector vector; + [self getValue:&vector]; + return vector; +#endif +} + +@end diff --git a/platform/darwin/test/MGLStyleLayerTests.m.ejs b/platform/darwin/test/MGLStyleLayerTests.m.ejs deleted file mode 100644 index 6b7bfe2f1c..0000000000 --- a/platform/darwin/test/MGLStyleLayerTests.m.ejs +++ /dev/null @@ -1,72 +0,0 @@ -<% - const type = locals.type; - const layoutProperties = locals.layoutProperties; - const paintProperties = locals.paintProperties; --%> -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -#import "MGLStyleLayerTests.h" - -@interface MGL<%- camelize(type) %>LayerTests : MGLStyleLayerTests -@end - -@implementation MGL<%- camelize(type) %>LayerTests - -+ (NSString *)layerType { - return @"<%- type %>"; -} - -- (void)test<%- camelize(type) %>Layer { -<% if (type === 'background') { -%> - MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID"]; -<% } else { -%> - NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; - NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; - [self.mapView.style addSource:source]; - MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID" source:source]; -<% } -%> - [self.mapView.style addLayer:layer]; - -<% for (const property of layoutProperties) { -%> - <%- testImplementation(property, type) %> -<% } -%> -<% for (const property of paintProperties) { -%> - <%- testImplementation(property, type) %> -<% } -%> - - MGL<%- camelize(type) %>StyleLayer *gLayer = (MGL<%- camelize(type) %>StyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; - XCTAssertTrue([gLayer isKindOfClass:[MGL<%- camelize(type) %>StyleLayer class]]); -<% for (const property of layoutProperties) { -%> - <%- testGetterImplementation(property, type) %> -<% } -%> -<% for (const property of paintProperties) { -%> - <%- testGetterImplementation(property, type) %> -<% } -%> - -<% for (const property of layoutProperties) { -%> - <%- testImplementation(property, type, true) %> -<% } -%> -<% for (const property of paintProperties) { -%> - <%- testImplementation(property, type, true) %> -<% } -%> - -<% for (const property of layoutProperties) { -%> - <%- testGetterImplementation(property, type, true) %> -<% } -%> -<% for (const property of paintProperties) { -%> - <%- testGetterImplementation(property, type, true) %> -<% } -%> -} - -- (void)testPropertyNames { -<% for (const property of layoutProperties) { -%> - [self testPropertyName:@"<%- property.getter || property.name %>" isBoolean:<%- property.type === 'boolean' ? 'YES' : 'NO' %>]; -<% } -%> -<% for (const property of paintProperties) { -%> - [self testPropertyName:@"<%- property.getter || property.name %>" isBoolean:<%- property.type === 'boolean' ? 'YES' : 'NO' %>]; -<% } -%> -} - -@end diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs new file mode 100644 index 0000000000..00842a5b4e --- /dev/null +++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs @@ -0,0 +1,114 @@ +<% + const type = locals.type; + const properties = locals.properties; + const enumProperties = locals.enumProperties; +-%> +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "MGLStyleLayerTests.h" + +#import "MGLStyleLayer_Private.h" + +#include <mbgl/style/layers/<%- type %>_layer.hpp> + +@interface MGL<%- camelize(type) %>LayerTests : MGLStyleLayerTests +@end + +@implementation MGL<%- camelize(type) %>LayerTests + ++ (NSString *)layerType { + return @"<%- type %>"; +} + +<% if (type !== 'background' && type !== 'raster') { -%> +- (void)testPredicates { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + + XCTAssertNil(layer.sourceLayerIdentifier); + layer.sourceLayerIdentifier = @"layerID"; + XCTAssertEqualObjects(layer.sourceLayerIdentifier, @"layerID"); + layer.sourceLayerIdentifier = nil; + XCTAssertNil(layer.sourceLayerIdentifier); + + XCTAssertNil(layer.predicate); + layer.predicate = [NSPredicate predicateWithValue:NO]; + XCTAssertEqualObjects(layer.predicate, [NSPredicate predicateWithValue:NO]); + layer.predicate = nil; + XCTAssertNil(layer.predicate); +} + +<% } -%> +- (void)testProperties { +<% if (type === 'background') { -%> + MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID"]; +<% } else { -%> + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + + MGL<%- camelize(type) %>StyleLayer *layer = [[MGL<%- camelize(type) %>StyleLayer alloc] initWithIdentifier:@"layerID" source:source]; +<% } -%> + XCTAssertNotEqual(layer.rawLayer, nullptr); + XCTAssertTrue(layer.rawLayer->is<mbgl::style::<%- camelize(type) %>Layer>()); + auto rawLayer = layer.rawLayer->as<mbgl::style::<%- camelize(type) %>Layer>(); +<% for (const property of properties) { -%> + + // <%- originalPropertyName(property) %> + { + XCTAssertTrue(rawLayer->get<%- camelize(originalPropertyName(property)) %>().isUndefined(), + @"<%- originalPropertyName(property) %> should be unset initially."); + MGLStyleValue<<%- propertyType(property) %>> *defaultStyleValue = layer.<%- objCName(property) %>; + + MGLStyleValue<<%- propertyType(property) %>> *styleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:<%- objCTestValue(property, type, 3) %>]; + layer.<%- objCName(property) %> = styleValue; + mbgl::style::PropertyValue<<%- mbglType(property) %>> propertyValue = { <%- mbglTestValue(property, type) %> }; + XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue, + @"Setting <%- objCName(property) %> to a constant value should update <%- originalPropertyName(property) %>."); + XCTAssertEqualObjects(layer.<%- objCName(property) %>, styleValue, + @"<%- objCName(property) %> should round-trip constant values."); + + styleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithStops:@{ + @18: styleValue, + }]; + layer.<%- objCName(property) %> = styleValue; + propertyValue = { mbgl::style::Function<<%- mbglType(property) %>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue, + @"Setting <%- objCName(property) %> to a function should update <%- originalPropertyName(property) %>."); + XCTAssertEqualObjects(layer.<%- objCName(property) %>, styleValue, + @"<%- objCName(property) %> should round-trip functions."); +<% if (!property.required) { -%> + + layer.<%- objCName(property) %> = nil; + XCTAssertTrue(rawLayer->get<%- camelize(originalPropertyName(property)) %>().isUndefined(), + @"Unsetting <%- objCName(property) %> should return <%- originalPropertyName(property) %> to the default value."); + XCTAssertEqualObjects(layer.<%- objCName(property) %>, defaultStyleValue, + @"<%- objCName(property) %> should return the default value after being unset."); +<% } -%> + } +<% } -%> +} + +- (void)testPropertyNames { +<% for (const property of properties) { -%> + [self testPropertyName:@"<%- property.getter || property.name %>" isBoolean:<%- property.type === 'boolean' ? 'YES' : 'NO' %>]; +<% } -%> +} + +<% if (enumProperties) { -%> +- (void)testValueAdditions { +<% for (let property of enumProperties) { -%> +<% for (let value in property.values) { -%> +<% if (property.values.hasOwnProperty(value)) { -%> + XCTAssertEqual([NSValue valueWithMGL<%- camelize(property.name) %>:MGL<%- camelize(property.name) %><%- camelize(value) %>].MGL<%- camelize(property.name) %>Value, MGL<%- camelize(property.name) %><%- camelize(value) %>); +<% } -%> +<% } -%> +<% } -%> +} + +<% } -%> +@end diff --git a/platform/darwin/test/MGLStyleLayerTests.xib b/platform/darwin/test/MGLStyleLayerTests.xib deleted file mode 100644 index d21f5753fc..0000000000 --- a/platform/darwin/test/MGLStyleLayerTests.xib +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1212" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> - <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/> - <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> - </dependencies> - <objects> - <customObject id="-2" userLabel="File's Owner" customClass="MGLMapViewTests"/> - <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> - <customObject id="-3" userLabel="Application" customClass="NSObject"/> - <window title="MGLMapViewTests" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g"> - <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> - <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> - <rect key="contentRect" x="196" y="240" width="256" height="256"/> - <rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/> - <view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ"> - <rect key="frame" x="0.0" y="0.0" width="256" height="256"/> - <autoresizingMask key="autoresizingMask"/> - </view> - </window> - </objects> -</document> diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 82de27973b..176217619d 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -39,7 +39,6 @@ - (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style { XCTAssertNotNil(mapView.style); XCTAssertEqual(mapView.style, style); - XCTAssertNil(style.name); [_styleLoadingExpectation fulfill]; } @@ -135,6 +134,24 @@ }]; } +- (void)testName { + XCTAssertNil(self.style.name); +} + +- (void)testSources { + NSSet<MGLSource *> *initialSources = self.style.sources; + if ([initialSources.anyObject.identifier isEqualToString:@"com.mapbox.annotations"]) { + XCTAssertEqual(self.style.sources.count, 1); + } else { + XCTAssertEqual(self.style.sources.count, 0); + } + MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shapeSource" shape:nil options:nil]; + [self.style addSource:shapeSource]; + XCTAssertEqual(self.style.sources.count, initialSources.count + 1); + [self.style removeSource:shapeSource]; + XCTAssertEqual(self.style.sources.count, initialSources.count); +} + - (void)testAddingSourcesTwice { MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shapeSource" shape:nil options:nil]; [self.style addSource:shapeSource]; @@ -157,6 +174,22 @@ XCTAssertThrowsSpecificNamed([self.style addSource: source2], NSException, @"MGLRedundantSourceIdentifierException"); } +- (void)testLayers { + NSArray<MGLStyleLayer *> *initialLayers = self.style.layers; + if ([initialLayers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) { + XCTAssertEqual(self.style.layers.count, 1); + } else { + XCTAssertEqual(self.style.layers.count, 0); + } + MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shapeSource" shape:nil options:nil]; + [self.style addSource:shapeSource]; + MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:shapeSource]; + [self.style addLayer:fillLayer]; + XCTAssertEqual(self.style.layers.count, initialLayers.count + 1); + [self.style removeLayer:fillLayer]; + XCTAssertEqual(self.style.layers.count, initialLayers.count); +} + - (void)testAddingLayersTwice { MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"shapeSource" shape:nil options:nil]; @@ -212,6 +245,10 @@ return styleHeader; } +- (void)testClasses { + XCTAssertEqual(self.style.styleClasses.count, 0); +} + - (void)testImages { NSString *imageName = @"TrackingLocationMask"; #if TARGET_OS_IPHONE diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.m b/platform/darwin/test/MGLSymbolStyleLayerTests.m deleted file mode 100644 index ba9bc78d26..0000000000 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.m +++ /dev/null @@ -1,283 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -#import "MGLStyleLayerTests.h" - -@interface MGLSymbolLayerTests : MGLStyleLayerTests -@end - -@implementation MGLSymbolLayerTests - -+ (NSString *)layerType { - return @"symbol"; -} - -- (void)testSymbolLayer { - NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; - NSURL *url = [NSURL fileURLWithPath:filePath]; - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil]; - [self.mapView.style addSource:source]; - MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; - [self.mapView.style addLayer:layer]; - - layer.iconAllowsOverlap = [MGLRuntimeStylingHelper testBool]; - layer.iconIgnoresPlacement = [MGLRuntimeStylingHelper testBool]; - layer.iconImageName = [MGLRuntimeStylingHelper testString]; - layer.iconOffset = [MGLRuntimeStylingHelper testOffset]; - layer.iconOptional = [MGLRuntimeStylingHelper testBool]; - layer.iconPadding = [MGLRuntimeStylingHelper testNumber]; - layer.iconRotation = [MGLRuntimeStylingHelper testNumber]; - layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]; - layer.iconScale = [MGLRuntimeStylingHelper testNumber]; - layer.iconTextFit = [MGLRuntimeStylingHelper testEnum:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]; - layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPadding]; - layer.keepsIconUpright = [MGLRuntimeStylingHelper testBool]; - layer.keepsTextUpright = [MGLRuntimeStylingHelper testBool]; - layer.maximumTextAngle = [MGLRuntimeStylingHelper testNumber]; - layer.maximumTextWidth = [MGLRuntimeStylingHelper testNumber]; - layer.symbolAvoidsEdges = [MGLRuntimeStylingHelper testBool]; - layer.symbolPlacement = [MGLRuntimeStylingHelper testEnum:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]; - layer.symbolSpacing = [MGLRuntimeStylingHelper testNumber]; - layer.text = [MGLRuntimeStylingHelper testString]; - layer.textAllowsOverlap = [MGLRuntimeStylingHelper testBool]; - layer.textAnchor = [MGLRuntimeStylingHelper testEnum:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]; - layer.textFontNames = [MGLRuntimeStylingHelper testFont]; - layer.textFontSize = [MGLRuntimeStylingHelper testNumber]; - layer.textIgnoresPlacement = [MGLRuntimeStylingHelper testBool]; - layer.textJustification = [MGLRuntimeStylingHelper testEnum:MGLTextJustificationRight type:@encode(MGLTextJustification)]; - layer.textLetterSpacing = [MGLRuntimeStylingHelper testNumber]; - layer.textLineHeight = [MGLRuntimeStylingHelper testNumber]; - layer.textOffset = [MGLRuntimeStylingHelper testOffset]; - layer.textOptional = [MGLRuntimeStylingHelper testBool]; - layer.textPadding = [MGLRuntimeStylingHelper testNumber]; - layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnum:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]; - layer.textRotation = [MGLRuntimeStylingHelper testNumber]; - layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnum:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]; - layer.textTransform = [MGLRuntimeStylingHelper testEnum:MGLTextTransformLowercase type:@encode(MGLTextTransform)]; - layer.iconColor = [MGLRuntimeStylingHelper testColor]; - layer.iconHaloBlur = [MGLRuntimeStylingHelper testNumber]; - layer.iconHaloColor = [MGLRuntimeStylingHelper testColor]; - layer.iconHaloWidth = [MGLRuntimeStylingHelper testNumber]; - layer.iconOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.iconTranslation = [MGLRuntimeStylingHelper testOffset]; - layer.iconTranslationAnchor = [MGLRuntimeStylingHelper testEnum:MGLIconTranslationAnchorViewport type:@encode(MGLIconTranslationAnchor)]; - layer.textColor = [MGLRuntimeStylingHelper testColor]; - layer.textHaloBlur = [MGLRuntimeStylingHelper testNumber]; - layer.textHaloColor = [MGLRuntimeStylingHelper testColor]; - layer.textHaloWidth = [MGLRuntimeStylingHelper testNumber]; - layer.textOpacity = [MGLRuntimeStylingHelper testNumber]; - layer.textTranslation = [MGLRuntimeStylingHelper testOffset]; - layer.textTranslationAnchor = [MGLRuntimeStylingHelper testEnum:MGLTextTranslationAnchorViewport type:@encode(MGLTextTranslationAnchor)]; - - MGLSymbolStyleLayer *gLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"]; - XCTAssertTrue([gLayer isKindOfClass:[MGLSymbolStyleLayer class]]); - XCTAssertEqualObjects(gLayer.iconAllowsOverlap, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.iconIgnoresPlacement, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.iconImageName, [MGLRuntimeStylingHelper testString]); - XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffset]); - XCTAssertEqualObjects(gLayer.iconOptional, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.iconRotation, [MGLRuntimeStylingHelper testNumber]); - XCTAssert([gLayer.iconRotationAlignment isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]); - XCTAssertEqualObjects(gLayer.iconScale, [MGLRuntimeStylingHelper testNumber]); - XCTAssert([gLayer.iconTextFit isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnum:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]); - XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPadding]); - XCTAssertEqualObjects(gLayer.keepsIconUpright, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.keepsTextUpright, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.maximumTextAngle, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.maximumTextWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.symbolAvoidsEdges, [MGLRuntimeStylingHelper testBool]); - XCTAssert([gLayer.symbolPlacement isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.symbolPlacement, [MGLRuntimeStylingHelper testEnum:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]); - XCTAssertEqualObjects(gLayer.symbolSpacing, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.text, [MGLRuntimeStylingHelper testString]); - XCTAssertEqualObjects(gLayer.textAllowsOverlap, [MGLRuntimeStylingHelper testBool]); - XCTAssert([gLayer.textAnchor isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textAnchor, [MGLRuntimeStylingHelper testEnum:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]); - XCTAssertEqualObjects(gLayer.textFontNames, [MGLRuntimeStylingHelper testFont]); - XCTAssertEqualObjects(gLayer.textFontSize, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textIgnoresPlacement, [MGLRuntimeStylingHelper testBool]); - XCTAssert([gLayer.textJustification isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textJustification, [MGLRuntimeStylingHelper testEnum:MGLTextJustificationRight type:@encode(MGLTextJustification)]); - XCTAssertEqualObjects(gLayer.textLetterSpacing, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textLineHeight, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textOffset, [MGLRuntimeStylingHelper testOffset]); - XCTAssertEqualObjects(gLayer.textOptional, [MGLRuntimeStylingHelper testBool]); - XCTAssertEqualObjects(gLayer.textPadding, [MGLRuntimeStylingHelper testNumber]); - XCTAssert([gLayer.textPitchAlignment isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnum:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]); - XCTAssertEqualObjects(gLayer.textRotation, [MGLRuntimeStylingHelper testNumber]); - XCTAssert([gLayer.textRotationAlignment isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnum:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]); - XCTAssert([gLayer.textTransform isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textTransform, [MGLRuntimeStylingHelper testEnum:MGLTextTransformLowercase type:@encode(MGLTextTransform)]); - XCTAssertEqualObjects(gLayer.iconColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.iconHaloBlur, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.iconHaloColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.iconHaloWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.iconTranslation, [MGLRuntimeStylingHelper testOffset]); - XCTAssert([gLayer.iconTranslationAnchor isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.iconTranslationAnchor, [MGLRuntimeStylingHelper testEnum:MGLIconTranslationAnchorViewport type:@encode(MGLIconTranslationAnchor)]); - XCTAssertEqualObjects(gLayer.textColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.textHaloBlur, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textHaloColor, [MGLRuntimeStylingHelper testColor]); - XCTAssertEqualObjects(gLayer.textHaloWidth, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textOpacity, [MGLRuntimeStylingHelper testNumber]); - XCTAssertEqualObjects(gLayer.textTranslation, [MGLRuntimeStylingHelper testOffset]); - XCTAssert([gLayer.textTranslationAnchor isKindOfClass:[MGLStyleConstantValue class]]); - XCTAssertEqualObjects(gLayer.textTranslationAnchor, [MGLRuntimeStylingHelper testEnum:MGLTextTranslationAnchorViewport type:@encode(MGLTextTranslationAnchor)]); - - layer.iconAllowsOverlap = [MGLRuntimeStylingHelper testBoolFunction]; - layer.iconIgnoresPlacement = [MGLRuntimeStylingHelper testBoolFunction]; - layer.iconImageName = [MGLRuntimeStylingHelper testStringFunction]; - layer.iconOffset = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.iconOptional = [MGLRuntimeStylingHelper testBoolFunction]; - layer.iconPadding = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconRotation = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]; - layer.iconScale = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconTextFit = [MGLRuntimeStylingHelper testEnumFunction:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]; - layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPaddingFunction]; - layer.keepsIconUpright = [MGLRuntimeStylingHelper testBoolFunction]; - layer.keepsTextUpright = [MGLRuntimeStylingHelper testBoolFunction]; - layer.maximumTextAngle = [MGLRuntimeStylingHelper testNumberFunction]; - layer.maximumTextWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.symbolAvoidsEdges = [MGLRuntimeStylingHelper testBoolFunction]; - layer.symbolPlacement = [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]; - layer.symbolSpacing = [MGLRuntimeStylingHelper testNumberFunction]; - layer.text = [MGLRuntimeStylingHelper testStringFunction]; - layer.textAllowsOverlap = [MGLRuntimeStylingHelper testBoolFunction]; - layer.textAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]; - layer.textFontNames = [MGLRuntimeStylingHelper testFontFunction]; - layer.textFontSize = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textIgnoresPlacement = [MGLRuntimeStylingHelper testBoolFunction]; - layer.textJustification = [MGLRuntimeStylingHelper testEnumFunction:MGLTextJustificationRight type:@encode(MGLTextJustification)]; - layer.textLetterSpacing = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textLineHeight = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textOffset = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.textOptional = [MGLRuntimeStylingHelper testBoolFunction]; - layer.textPadding = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textPitchAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]; - layer.textRotation = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textRotationAlignment = [MGLRuntimeStylingHelper testEnumFunction:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]; - layer.textTransform = [MGLRuntimeStylingHelper testEnumFunction:MGLTextTransformLowercase type:@encode(MGLTextTransform)]; - layer.iconColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.iconHaloBlur = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconHaloColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.iconHaloWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.iconTranslation = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.iconTranslationAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLIconTranslationAnchorViewport type:@encode(MGLIconTranslationAnchor)]; - layer.textColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.textHaloBlur = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textHaloColor = [MGLRuntimeStylingHelper testColorFunction]; - layer.textHaloWidth = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textOpacity = [MGLRuntimeStylingHelper testNumberFunction]; - layer.textTranslation = [MGLRuntimeStylingHelper testOffsetFunction]; - layer.textTranslationAnchor = [MGLRuntimeStylingHelper testEnumFunction:MGLTextTranslationAnchorViewport type:@encode(MGLTextTranslationAnchor)]; - - XCTAssertEqualObjects(gLayer.iconAllowsOverlap, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.iconIgnoresPlacement, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.iconImageName, [MGLRuntimeStylingHelper testStringFunction]); - XCTAssertEqualObjects(gLayer.iconOffset, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.iconOptional, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconRotation, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLIconRotationAlignmentAuto type:@encode(MGLIconRotationAlignment)]); - XCTAssertEqualObjects(gLayer.iconScale, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnumFunction:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]); - XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPaddingFunction]); - XCTAssertEqualObjects(gLayer.keepsIconUpright, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.keepsTextUpright, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.maximumTextAngle, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.maximumTextWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.symbolAvoidsEdges, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.symbolPlacement, [MGLRuntimeStylingHelper testEnumFunction:MGLSymbolPlacementLine type:@encode(MGLSymbolPlacement)]); - XCTAssertEqualObjects(gLayer.symbolSpacing, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.text, [MGLRuntimeStylingHelper testStringFunction]); - XCTAssertEqualObjects(gLayer.textAllowsOverlap, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.textAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLTextAnchorBottomRight type:@encode(MGLTextAnchor)]); - XCTAssertEqualObjects(gLayer.textFontNames, [MGLRuntimeStylingHelper testFontFunction]); - XCTAssertEqualObjects(gLayer.textFontSize, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textIgnoresPlacement, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.textJustification, [MGLRuntimeStylingHelper testEnumFunction:MGLTextJustificationRight type:@encode(MGLTextJustification)]); - XCTAssertEqualObjects(gLayer.textLetterSpacing, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textLineHeight, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textOffset, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.textOptional, [MGLRuntimeStylingHelper testBoolFunction]); - XCTAssertEqualObjects(gLayer.textPadding, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textPitchAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLTextPitchAlignmentAuto type:@encode(MGLTextPitchAlignment)]); - XCTAssertEqualObjects(gLayer.textRotation, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textRotationAlignment, [MGLRuntimeStylingHelper testEnumFunction:MGLTextRotationAlignmentAuto type:@encode(MGLTextRotationAlignment)]); - XCTAssertEqualObjects(gLayer.textTransform, [MGLRuntimeStylingHelper testEnumFunction:MGLTextTransformLowercase type:@encode(MGLTextTransform)]); - XCTAssertEqualObjects(gLayer.iconColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.iconHaloBlur, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconHaloColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.iconHaloWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.iconTranslation, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.iconTranslationAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLIconTranslationAnchorViewport type:@encode(MGLIconTranslationAnchor)]); - XCTAssertEqualObjects(gLayer.textColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.textHaloBlur, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textHaloColor, [MGLRuntimeStylingHelper testColorFunction]); - XCTAssertEqualObjects(gLayer.textHaloWidth, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textOpacity, [MGLRuntimeStylingHelper testNumberFunction]); - XCTAssertEqualObjects(gLayer.textTranslation, [MGLRuntimeStylingHelper testOffsetFunction]); - XCTAssertEqualObjects(gLayer.textTranslationAnchor, [MGLRuntimeStylingHelper testEnumFunction:MGLTextTranslationAnchorViewport type:@encode(MGLTextTranslationAnchor)]); -} - -- (void)testPropertyNames { - [self testPropertyName:@"icon-allows-overlap" isBoolean:YES]; - [self testPropertyName:@"icon-ignores-placement" isBoolean:YES]; - [self testPropertyName:@"icon-image-name" isBoolean:NO]; - [self testPropertyName:@"icon-offset" isBoolean:NO]; - [self testPropertyName:@"is-icon-optional" isBoolean:YES]; - [self testPropertyName:@"icon-padding" isBoolean:NO]; - [self testPropertyName:@"icon-rotation" isBoolean:NO]; - [self testPropertyName:@"icon-rotation-alignment" isBoolean:NO]; - [self testPropertyName:@"icon-scale" isBoolean:NO]; - [self testPropertyName:@"icon-text-fit" isBoolean:NO]; - [self testPropertyName:@"icon-text-fit-padding" isBoolean:NO]; - [self testPropertyName:@"keeps-icon-upright" isBoolean:YES]; - [self testPropertyName:@"keeps-text-upright" isBoolean:YES]; - [self testPropertyName:@"maximum-text-angle" isBoolean:NO]; - [self testPropertyName:@"maximum-text-width" isBoolean:NO]; - [self testPropertyName:@"symbol-avoids-edges" isBoolean:YES]; - [self testPropertyName:@"symbol-placement" isBoolean:NO]; - [self testPropertyName:@"symbol-spacing" isBoolean:NO]; - [self testPropertyName:@"text" isBoolean:NO]; - [self testPropertyName:@"text-allows-overlap" isBoolean:YES]; - [self testPropertyName:@"text-anchor" isBoolean:NO]; - [self testPropertyName:@"text-font-names" isBoolean:NO]; - [self testPropertyName:@"text-font-size" isBoolean:NO]; - [self testPropertyName:@"text-ignores-placement" isBoolean:YES]; - [self testPropertyName:@"text-justification" isBoolean:NO]; - [self testPropertyName:@"text-letter-spacing" isBoolean:NO]; - [self testPropertyName:@"text-line-height" isBoolean:NO]; - [self testPropertyName:@"text-offset" isBoolean:NO]; - [self testPropertyName:@"is-text-optional" isBoolean:YES]; - [self testPropertyName:@"text-padding" isBoolean:NO]; - [self testPropertyName:@"text-pitch-alignment" isBoolean:NO]; - [self testPropertyName:@"text-rotation" isBoolean:NO]; - [self testPropertyName:@"text-rotation-alignment" isBoolean:NO]; - [self testPropertyName:@"text-transform" isBoolean:NO]; - [self testPropertyName:@"icon-color" isBoolean:NO]; - [self testPropertyName:@"icon-halo-blur" isBoolean:NO]; - [self testPropertyName:@"icon-halo-color" isBoolean:NO]; - [self testPropertyName:@"icon-halo-width" isBoolean:NO]; - [self testPropertyName:@"icon-opacity" isBoolean:NO]; - [self testPropertyName:@"icon-translation" isBoolean:NO]; - [self testPropertyName:@"icon-translation-anchor" isBoolean:NO]; - [self testPropertyName:@"text-color" isBoolean:NO]; - [self testPropertyName:@"text-halo-blur" isBoolean:NO]; - [self testPropertyName:@"text-halo-color" isBoolean:NO]; - [self testPropertyName:@"text-halo-width" isBoolean:NO]; - [self testPropertyName:@"text-opacity" isBoolean:NO]; - [self testPropertyName:@"text-translation" isBoolean:NO]; - [self testPropertyName:@"text-translation-anchor" isBoolean:NO]; -} - -@end diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm new file mode 100644 index 0000000000..c4dee559fc --- /dev/null +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -0,0 +1,1797 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. + +#import "MGLStyleLayerTests.h" + +#import "MGLStyleLayer_Private.h" + +#include <mbgl/style/layers/symbol_layer.hpp> + +@interface MGLSymbolLayerTests : MGLStyleLayerTests +@end + +@implementation MGLSymbolLayerTests + ++ (NSString *)layerType { + return @"symbol"; +} + +- (void)testPredicates { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + + XCTAssertNil(layer.sourceLayerIdentifier); + layer.sourceLayerIdentifier = @"layerID"; + XCTAssertEqualObjects(layer.sourceLayerIdentifier, @"layerID"); + layer.sourceLayerIdentifier = nil; + XCTAssertNil(layer.sourceLayerIdentifier); + + XCTAssertNil(layer.predicate); + layer.predicate = [NSPredicate predicateWithValue:NO]; + XCTAssertEqualObjects(layer.predicate, [NSPredicate predicateWithValue:NO]); + layer.predicate = nil; + XCTAssertNil(layer.predicate); +} + +- (void)testProperties { + MGLPointFeature *feature = [[MGLPointFeature alloc] init]; + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; + + MGLSymbolStyleLayer *layer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; + XCTAssertNotEqual(layer.rawLayer, nullptr); + XCTAssertTrue(layer.rawLayer->is<mbgl::style::SymbolLayer>()); + auto rawLayer = layer.rawLayer->as<mbgl::style::SymbolLayer>(); + + // icon-allow-overlap + { + XCTAssertTrue(rawLayer->getIconAllowOverlap().isUndefined(), + @"icon-allow-overlap should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconAllowsOverlap; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.iconAllowsOverlap = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getIconAllowOverlap(), propertyValue, + @"Setting iconAllowsOverlap to a constant value should update icon-allow-overlap."); + XCTAssertEqualObjects(layer.iconAllowsOverlap, styleValue, + @"iconAllowsOverlap should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconAllowsOverlap = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconAllowOverlap(), propertyValue, + @"Setting iconAllowsOverlap to a function should update icon-allow-overlap."); + XCTAssertEqualObjects(layer.iconAllowsOverlap, styleValue, + @"iconAllowsOverlap should round-trip functions."); + + layer.iconAllowsOverlap = nil; + XCTAssertTrue(rawLayer->getIconAllowOverlap().isUndefined(), + @"Unsetting iconAllowsOverlap should return icon-allow-overlap to the default value."); + XCTAssertEqualObjects(layer.iconAllowsOverlap, defaultStyleValue, + @"iconAllowsOverlap should return the default value after being unset."); + } + + // icon-ignore-placement + { + XCTAssertTrue(rawLayer->getIconIgnorePlacement().isUndefined(), + @"icon-ignore-placement should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconIgnoresPlacement; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.iconIgnoresPlacement = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getIconIgnorePlacement(), propertyValue, + @"Setting iconIgnoresPlacement to a constant value should update icon-ignore-placement."); + XCTAssertEqualObjects(layer.iconIgnoresPlacement, styleValue, + @"iconIgnoresPlacement should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconIgnoresPlacement = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconIgnorePlacement(), propertyValue, + @"Setting iconIgnoresPlacement to a function should update icon-ignore-placement."); + XCTAssertEqualObjects(layer.iconIgnoresPlacement, styleValue, + @"iconIgnoresPlacement should round-trip functions."); + + layer.iconIgnoresPlacement = nil; + XCTAssertTrue(rawLayer->getIconIgnorePlacement().isUndefined(), + @"Unsetting iconIgnoresPlacement should return icon-ignore-placement to the default value."); + XCTAssertEqualObjects(layer.iconIgnoresPlacement, defaultStyleValue, + @"iconIgnoresPlacement should return the default value after being unset."); + } + + // icon-image + { + XCTAssertTrue(rawLayer->getIconImage().isUndefined(), + @"icon-image should be unset initially."); + MGLStyleValue<NSString *> *defaultStyleValue = layer.iconImageName; + + MGLStyleValue<NSString *> *styleValue = [MGLStyleValue<NSString *> valueWithRawValue:@"Icon Image"]; + layer.iconImageName = styleValue; + mbgl::style::PropertyValue<std::string> propertyValue = { "Icon Image" }; + XCTAssertEqual(rawLayer->getIconImage(), propertyValue, + @"Setting iconImageName to a constant value should update icon-image."); + XCTAssertEqualObjects(layer.iconImageName, styleValue, + @"iconImageName should round-trip constant values."); + + styleValue = [MGLStyleValue<NSString *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconImageName = styleValue; + propertyValue = { mbgl::style::Function<std::string> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconImage(), propertyValue, + @"Setting iconImageName to a function should update icon-image."); + XCTAssertEqualObjects(layer.iconImageName, styleValue, + @"iconImageName should round-trip functions."); + + layer.iconImageName = nil; + XCTAssertTrue(rawLayer->getIconImage().isUndefined(), + @"Unsetting iconImageName should return icon-image to the default value."); + XCTAssertEqualObjects(layer.iconImageName, defaultStyleValue, + @"iconImageName should return the default value after being unset."); + } + + // icon-offset + { + XCTAssertTrue(rawLayer->getIconOffset().isUndefined(), + @"icon-offset should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.iconOffset; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.iconOffset = styleValue; + mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + XCTAssertEqual(rawLayer->getIconOffset(), propertyValue, + @"Setting iconOffset to a constant value should update icon-offset."); + XCTAssertEqualObjects(layer.iconOffset, styleValue, + @"iconOffset should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconOffset = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 2>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconOffset(), propertyValue, + @"Setting iconOffset to a function should update icon-offset."); + XCTAssertEqualObjects(layer.iconOffset, styleValue, + @"iconOffset should round-trip functions."); + + layer.iconOffset = nil; + XCTAssertTrue(rawLayer->getIconOffset().isUndefined(), + @"Unsetting iconOffset should return icon-offset to the default value."); + XCTAssertEqualObjects(layer.iconOffset, defaultStyleValue, + @"iconOffset should return the default value after being unset."); + } + + // icon-optional + { + XCTAssertTrue(rawLayer->getIconOptional().isUndefined(), + @"icon-optional should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconOptional; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.iconOptional = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getIconOptional(), propertyValue, + @"Setting iconOptional to a constant value should update icon-optional."); + XCTAssertEqualObjects(layer.iconOptional, styleValue, + @"iconOptional should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconOptional = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconOptional(), propertyValue, + @"Setting iconOptional to a function should update icon-optional."); + XCTAssertEqualObjects(layer.iconOptional, styleValue, + @"iconOptional should round-trip functions."); + + layer.iconOptional = nil; + XCTAssertTrue(rawLayer->getIconOptional().isUndefined(), + @"Unsetting iconOptional should return icon-optional to the default value."); + XCTAssertEqualObjects(layer.iconOptional, defaultStyleValue, + @"iconOptional should return the default value after being unset."); + } + + // icon-padding + { + XCTAssertTrue(rawLayer->getIconPadding().isUndefined(), + @"icon-padding should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconPadding; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.iconPadding = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getIconPadding(), propertyValue, + @"Setting iconPadding to a constant value should update icon-padding."); + XCTAssertEqualObjects(layer.iconPadding, styleValue, + @"iconPadding should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconPadding = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconPadding(), propertyValue, + @"Setting iconPadding to a function should update icon-padding."); + XCTAssertEqualObjects(layer.iconPadding, styleValue, + @"iconPadding should round-trip functions."); + + layer.iconPadding = nil; + XCTAssertTrue(rawLayer->getIconPadding().isUndefined(), + @"Unsetting iconPadding should return icon-padding to the default value."); + XCTAssertEqualObjects(layer.iconPadding, defaultStyleValue, + @"iconPadding should return the default value after being unset."); + } + + // icon-rotate + { + XCTAssertTrue(rawLayer->getIconRotate().isUndefined(), + @"icon-rotate should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconRotation; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.iconRotation = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getIconRotate(), propertyValue, + @"Setting iconRotation to a constant value should update icon-rotate."); + XCTAssertEqualObjects(layer.iconRotation, styleValue, + @"iconRotation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconRotation = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconRotate(), propertyValue, + @"Setting iconRotation to a function should update icon-rotate."); + XCTAssertEqualObjects(layer.iconRotation, styleValue, + @"iconRotation should round-trip functions."); + + layer.iconRotation = nil; + XCTAssertTrue(rawLayer->getIconRotate().isUndefined(), + @"Unsetting iconRotation should return icon-rotate to the default value."); + XCTAssertEqualObjects(layer.iconRotation, defaultStyleValue, + @"iconRotation should return the default value after being unset."); + } + + // icon-rotation-alignment + { + XCTAssertTrue(rawLayer->getIconRotationAlignment().isUndefined(), + @"icon-rotation-alignment should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.iconRotationAlignment; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLIconRotationAlignment:MGLIconRotationAlignmentAuto]]; + layer.iconRotationAlignment = styleValue; + mbgl::style::PropertyValue<mbgl::style::AlignmentType> propertyValue = { mbgl::style::AlignmentType::Auto }; + XCTAssertEqual(rawLayer->getIconRotationAlignment(), propertyValue, + @"Setting iconRotationAlignment to a constant value should update icon-rotation-alignment."); + XCTAssertEqualObjects(layer.iconRotationAlignment, styleValue, + @"iconRotationAlignment should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconRotationAlignment = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::AlignmentType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconRotationAlignment(), propertyValue, + @"Setting iconRotationAlignment to a function should update icon-rotation-alignment."); + XCTAssertEqualObjects(layer.iconRotationAlignment, styleValue, + @"iconRotationAlignment should round-trip functions."); + + layer.iconRotationAlignment = nil; + XCTAssertTrue(rawLayer->getIconRotationAlignment().isUndefined(), + @"Unsetting iconRotationAlignment should return icon-rotation-alignment to the default value."); + XCTAssertEqualObjects(layer.iconRotationAlignment, defaultStyleValue, + @"iconRotationAlignment should return the default value after being unset."); + } + + // icon-size + { + XCTAssertTrue(rawLayer->getIconSize().isUndefined(), + @"icon-size should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconScale; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.iconScale = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getIconSize(), propertyValue, + @"Setting iconScale to a constant value should update icon-size."); + XCTAssertEqualObjects(layer.iconScale, styleValue, + @"iconScale should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconScale = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconSize(), propertyValue, + @"Setting iconScale to a function should update icon-size."); + XCTAssertEqualObjects(layer.iconScale, styleValue, + @"iconScale should round-trip functions."); + + layer.iconScale = nil; + XCTAssertTrue(rawLayer->getIconSize().isUndefined(), + @"Unsetting iconScale should return icon-size to the default value."); + XCTAssertEqualObjects(layer.iconScale, defaultStyleValue, + @"iconScale should return the default value after being unset."); + } + + // icon-text-fit + { + XCTAssertTrue(rawLayer->getIconTextFit().isUndefined(), + @"icon-text-fit should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.iconTextFit; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLIconTextFit:MGLIconTextFitBoth]]; + layer.iconTextFit = styleValue; + mbgl::style::PropertyValue<mbgl::style::IconTextFitType> propertyValue = { mbgl::style::IconTextFitType::Both }; + XCTAssertEqual(rawLayer->getIconTextFit(), propertyValue, + @"Setting iconTextFit to a constant value should update icon-text-fit."); + XCTAssertEqualObjects(layer.iconTextFit, styleValue, + @"iconTextFit should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconTextFit = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::IconTextFitType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconTextFit(), propertyValue, + @"Setting iconTextFit to a function should update icon-text-fit."); + XCTAssertEqualObjects(layer.iconTextFit, styleValue, + @"iconTextFit should round-trip functions."); + + layer.iconTextFit = nil; + XCTAssertTrue(rawLayer->getIconTextFit().isUndefined(), + @"Unsetting iconTextFit should return icon-text-fit to the default value."); + XCTAssertEqualObjects(layer.iconTextFit, defaultStyleValue, + @"iconTextFit should return the default value after being unset."); + } + + // icon-text-fit-padding + { + XCTAssertTrue(rawLayer->getIconTextFitPadding().isUndefined(), + @"icon-text-fit-padding should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.iconTextFitPadding; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(1, 1, 1, 1)] +#else + [NSValue valueWithEdgeInsets:NSEdgeInsetsMake(1, 1, 1, 1)] +#endif + ]; + layer.iconTextFitPadding = styleValue; + mbgl::style::PropertyValue<std::array<float, 4>> propertyValue = { { 1, 1, 1, 1 } }; + XCTAssertEqual(rawLayer->getIconTextFitPadding(), propertyValue, + @"Setting iconTextFitPadding to a constant value should update icon-text-fit-padding."); + XCTAssertEqualObjects(layer.iconTextFitPadding, styleValue, + @"iconTextFitPadding should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconTextFitPadding = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 4>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconTextFitPadding(), propertyValue, + @"Setting iconTextFitPadding to a function should update icon-text-fit-padding."); + XCTAssertEqualObjects(layer.iconTextFitPadding, styleValue, + @"iconTextFitPadding should round-trip functions."); + + layer.iconTextFitPadding = nil; + XCTAssertTrue(rawLayer->getIconTextFitPadding().isUndefined(), + @"Unsetting iconTextFitPadding should return icon-text-fit-padding to the default value."); + XCTAssertEqualObjects(layer.iconTextFitPadding, defaultStyleValue, + @"iconTextFitPadding should return the default value after being unset."); + } + + // icon-keep-upright + { + XCTAssertTrue(rawLayer->getIconKeepUpright().isUndefined(), + @"icon-keep-upright should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.keepsIconUpright; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.keepsIconUpright = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getIconKeepUpright(), propertyValue, + @"Setting keepsIconUpright to a constant value should update icon-keep-upright."); + XCTAssertEqualObjects(layer.keepsIconUpright, styleValue, + @"keepsIconUpright should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.keepsIconUpright = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconKeepUpright(), propertyValue, + @"Setting keepsIconUpright to a function should update icon-keep-upright."); + XCTAssertEqualObjects(layer.keepsIconUpright, styleValue, + @"keepsIconUpright should round-trip functions."); + + layer.keepsIconUpright = nil; + XCTAssertTrue(rawLayer->getIconKeepUpright().isUndefined(), + @"Unsetting keepsIconUpright should return icon-keep-upright to the default value."); + XCTAssertEqualObjects(layer.keepsIconUpright, defaultStyleValue, + @"keepsIconUpright should return the default value after being unset."); + } + + // text-keep-upright + { + XCTAssertTrue(rawLayer->getTextKeepUpright().isUndefined(), + @"text-keep-upright should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.keepsTextUpright; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@NO]; + layer.keepsTextUpright = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { false }; + XCTAssertEqual(rawLayer->getTextKeepUpright(), propertyValue, + @"Setting keepsTextUpright to a constant value should update text-keep-upright."); + XCTAssertEqualObjects(layer.keepsTextUpright, styleValue, + @"keepsTextUpright should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.keepsTextUpright = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextKeepUpright(), propertyValue, + @"Setting keepsTextUpright to a function should update text-keep-upright."); + XCTAssertEqualObjects(layer.keepsTextUpright, styleValue, + @"keepsTextUpright should round-trip functions."); + + layer.keepsTextUpright = nil; + XCTAssertTrue(rawLayer->getTextKeepUpright().isUndefined(), + @"Unsetting keepsTextUpright should return text-keep-upright to the default value."); + XCTAssertEqualObjects(layer.keepsTextUpright, defaultStyleValue, + @"keepsTextUpright should return the default value after being unset."); + } + + // text-max-angle + { + XCTAssertTrue(rawLayer->getTextMaxAngle().isUndefined(), + @"text-max-angle should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.maximumTextAngle; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.maximumTextAngle = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextMaxAngle(), propertyValue, + @"Setting maximumTextAngle to a constant value should update text-max-angle."); + XCTAssertEqualObjects(layer.maximumTextAngle, styleValue, + @"maximumTextAngle should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.maximumTextAngle = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextMaxAngle(), propertyValue, + @"Setting maximumTextAngle to a function should update text-max-angle."); + XCTAssertEqualObjects(layer.maximumTextAngle, styleValue, + @"maximumTextAngle should round-trip functions."); + + layer.maximumTextAngle = nil; + XCTAssertTrue(rawLayer->getTextMaxAngle().isUndefined(), + @"Unsetting maximumTextAngle should return text-max-angle to the default value."); + XCTAssertEqualObjects(layer.maximumTextAngle, defaultStyleValue, + @"maximumTextAngle should return the default value after being unset."); + } + + // text-max-width + { + XCTAssertTrue(rawLayer->getTextMaxWidth().isUndefined(), + @"text-max-width should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.maximumTextWidth; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.maximumTextWidth = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextMaxWidth(), propertyValue, + @"Setting maximumTextWidth to a constant value should update text-max-width."); + XCTAssertEqualObjects(layer.maximumTextWidth, styleValue, + @"maximumTextWidth should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.maximumTextWidth = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextMaxWidth(), propertyValue, + @"Setting maximumTextWidth to a function should update text-max-width."); + XCTAssertEqualObjects(layer.maximumTextWidth, styleValue, + @"maximumTextWidth should round-trip functions."); + + layer.maximumTextWidth = nil; + XCTAssertTrue(rawLayer->getTextMaxWidth().isUndefined(), + @"Unsetting maximumTextWidth should return text-max-width to the default value."); + XCTAssertEqualObjects(layer.maximumTextWidth, defaultStyleValue, + @"maximumTextWidth should return the default value after being unset."); + } + + // symbol-avoid-edges + { + XCTAssertTrue(rawLayer->getSymbolAvoidEdges().isUndefined(), + @"symbol-avoid-edges should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.symbolAvoidsEdges; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.symbolAvoidsEdges = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getSymbolAvoidEdges(), propertyValue, + @"Setting symbolAvoidsEdges to a constant value should update symbol-avoid-edges."); + XCTAssertEqualObjects(layer.symbolAvoidsEdges, styleValue, + @"symbolAvoidsEdges should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.symbolAvoidsEdges = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getSymbolAvoidEdges(), propertyValue, + @"Setting symbolAvoidsEdges to a function should update symbol-avoid-edges."); + XCTAssertEqualObjects(layer.symbolAvoidsEdges, styleValue, + @"symbolAvoidsEdges should round-trip functions."); + + layer.symbolAvoidsEdges = nil; + XCTAssertTrue(rawLayer->getSymbolAvoidEdges().isUndefined(), + @"Unsetting symbolAvoidsEdges should return symbol-avoid-edges to the default value."); + XCTAssertEqualObjects(layer.symbolAvoidsEdges, defaultStyleValue, + @"symbolAvoidsEdges should return the default value after being unset."); + } + + // symbol-placement + { + XCTAssertTrue(rawLayer->getSymbolPlacement().isUndefined(), + @"symbol-placement should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.symbolPlacement; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLine]]; + layer.symbolPlacement = styleValue; + mbgl::style::PropertyValue<mbgl::style::SymbolPlacementType> propertyValue = { mbgl::style::SymbolPlacementType::Line }; + XCTAssertEqual(rawLayer->getSymbolPlacement(), propertyValue, + @"Setting symbolPlacement to a constant value should update symbol-placement."); + XCTAssertEqualObjects(layer.symbolPlacement, styleValue, + @"symbolPlacement should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.symbolPlacement = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::SymbolPlacementType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getSymbolPlacement(), propertyValue, + @"Setting symbolPlacement to a function should update symbol-placement."); + XCTAssertEqualObjects(layer.symbolPlacement, styleValue, + @"symbolPlacement should round-trip functions."); + + layer.symbolPlacement = nil; + XCTAssertTrue(rawLayer->getSymbolPlacement().isUndefined(), + @"Unsetting symbolPlacement should return symbol-placement to the default value."); + XCTAssertEqualObjects(layer.symbolPlacement, defaultStyleValue, + @"symbolPlacement should return the default value after being unset."); + } + + // symbol-spacing + { + XCTAssertTrue(rawLayer->getSymbolSpacing().isUndefined(), + @"symbol-spacing should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.symbolSpacing; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.symbolSpacing = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getSymbolSpacing(), propertyValue, + @"Setting symbolSpacing to a constant value should update symbol-spacing."); + XCTAssertEqualObjects(layer.symbolSpacing, styleValue, + @"symbolSpacing should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.symbolSpacing = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getSymbolSpacing(), propertyValue, + @"Setting symbolSpacing to a function should update symbol-spacing."); + XCTAssertEqualObjects(layer.symbolSpacing, styleValue, + @"symbolSpacing should round-trip functions."); + + layer.symbolSpacing = nil; + XCTAssertTrue(rawLayer->getSymbolSpacing().isUndefined(), + @"Unsetting symbolSpacing should return symbol-spacing to the default value."); + XCTAssertEqualObjects(layer.symbolSpacing, defaultStyleValue, + @"symbolSpacing should return the default value after being unset."); + } + + // text-field + { + XCTAssertTrue(rawLayer->getTextField().isUndefined(), + @"text-field should be unset initially."); + MGLStyleValue<NSString *> *defaultStyleValue = layer.text; + + MGLStyleValue<NSString *> *styleValue = [MGLStyleValue<NSString *> valueWithRawValue:@"Text Field"]; + layer.text = styleValue; + mbgl::style::PropertyValue<std::string> propertyValue = { "Text Field" }; + XCTAssertEqual(rawLayer->getTextField(), propertyValue, + @"Setting text to a constant value should update text-field."); + XCTAssertEqualObjects(layer.text, styleValue, + @"text should round-trip constant values."); + + styleValue = [MGLStyleValue<NSString *> valueWithStops:@{ + @18: styleValue, + }]; + layer.text = styleValue; + propertyValue = { mbgl::style::Function<std::string> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextField(), propertyValue, + @"Setting text to a function should update text-field."); + XCTAssertEqualObjects(layer.text, styleValue, + @"text should round-trip functions."); + + layer.text = nil; + XCTAssertTrue(rawLayer->getTextField().isUndefined(), + @"Unsetting text should return text-field to the default value."); + XCTAssertEqualObjects(layer.text, defaultStyleValue, + @"text should return the default value after being unset."); + } + + // text-allow-overlap + { + XCTAssertTrue(rawLayer->getTextAllowOverlap().isUndefined(), + @"text-allow-overlap should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textAllowsOverlap; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.textAllowsOverlap = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getTextAllowOverlap(), propertyValue, + @"Setting textAllowsOverlap to a constant value should update text-allow-overlap."); + XCTAssertEqualObjects(layer.textAllowsOverlap, styleValue, + @"textAllowsOverlap should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textAllowsOverlap = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextAllowOverlap(), propertyValue, + @"Setting textAllowsOverlap to a function should update text-allow-overlap."); + XCTAssertEqualObjects(layer.textAllowsOverlap, styleValue, + @"textAllowsOverlap should round-trip functions."); + + layer.textAllowsOverlap = nil; + XCTAssertTrue(rawLayer->getTextAllowOverlap().isUndefined(), + @"Unsetting textAllowsOverlap should return text-allow-overlap to the default value."); + XCTAssertEqualObjects(layer.textAllowsOverlap, defaultStyleValue, + @"textAllowsOverlap should return the default value after being unset."); + } + + // text-anchor + { + XCTAssertTrue(rawLayer->getTextAnchor().isUndefined(), + @"text-anchor should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textAnchor; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextAnchor:MGLTextAnchorBottomRight]]; + layer.textAnchor = styleValue; + mbgl::style::PropertyValue<mbgl::style::TextAnchorType> propertyValue = { mbgl::style::TextAnchorType::BottomRight }; + XCTAssertEqual(rawLayer->getTextAnchor(), propertyValue, + @"Setting textAnchor to a constant value should update text-anchor."); + XCTAssertEqualObjects(layer.textAnchor, styleValue, + @"textAnchor should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textAnchor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TextAnchorType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextAnchor(), propertyValue, + @"Setting textAnchor to a function should update text-anchor."); + XCTAssertEqualObjects(layer.textAnchor, styleValue, + @"textAnchor should round-trip functions."); + + layer.textAnchor = nil; + XCTAssertTrue(rawLayer->getTextAnchor().isUndefined(), + @"Unsetting textAnchor should return text-anchor to the default value."); + XCTAssertEqualObjects(layer.textAnchor, defaultStyleValue, + @"textAnchor should return the default value after being unset."); + } + + // text-font + { + XCTAssertTrue(rawLayer->getTextFont().isUndefined(), + @"text-font should be unset initially."); + MGLStyleValue<NSArray<NSString *> *> *defaultStyleValue = layer.textFontNames; + + MGLStyleValue<NSArray<NSString *> *> *styleValue = [MGLStyleValue<NSArray<NSString *> *> valueWithRawValue:@[@"Text Font", @"Tnof Txet"]]; + layer.textFontNames = styleValue; + mbgl::style::PropertyValue<std::vector<std::string>> propertyValue = { { "Text Font", "Tnof Txet" } }; + XCTAssertEqual(rawLayer->getTextFont(), propertyValue, + @"Setting textFontNames to a constant value should update text-font."); + XCTAssertEqualObjects(layer.textFontNames, styleValue, + @"textFontNames should round-trip constant values."); + + styleValue = [MGLStyleValue<NSArray<NSString *> *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textFontNames = styleValue; + propertyValue = { mbgl::style::Function<std::vector<std::string>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextFont(), propertyValue, + @"Setting textFontNames to a function should update text-font."); + XCTAssertEqualObjects(layer.textFontNames, styleValue, + @"textFontNames should round-trip functions."); + + layer.textFontNames = nil; + XCTAssertTrue(rawLayer->getTextFont().isUndefined(), + @"Unsetting textFontNames should return text-font to the default value."); + XCTAssertEqualObjects(layer.textFontNames, defaultStyleValue, + @"textFontNames should return the default value after being unset."); + } + + // text-size + { + XCTAssertTrue(rawLayer->getTextSize().isUndefined(), + @"text-size should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textFontSize; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textFontSize = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextSize(), propertyValue, + @"Setting textFontSize to a constant value should update text-size."); + XCTAssertEqualObjects(layer.textFontSize, styleValue, + @"textFontSize should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textFontSize = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextSize(), propertyValue, + @"Setting textFontSize to a function should update text-size."); + XCTAssertEqualObjects(layer.textFontSize, styleValue, + @"textFontSize should round-trip functions."); + + layer.textFontSize = nil; + XCTAssertTrue(rawLayer->getTextSize().isUndefined(), + @"Unsetting textFontSize should return text-size to the default value."); + XCTAssertEqualObjects(layer.textFontSize, defaultStyleValue, + @"textFontSize should return the default value after being unset."); + } + + // text-ignore-placement + { + XCTAssertTrue(rawLayer->getTextIgnorePlacement().isUndefined(), + @"text-ignore-placement should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textIgnoresPlacement; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.textIgnoresPlacement = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getTextIgnorePlacement(), propertyValue, + @"Setting textIgnoresPlacement to a constant value should update text-ignore-placement."); + XCTAssertEqualObjects(layer.textIgnoresPlacement, styleValue, + @"textIgnoresPlacement should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textIgnoresPlacement = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextIgnorePlacement(), propertyValue, + @"Setting textIgnoresPlacement to a function should update text-ignore-placement."); + XCTAssertEqualObjects(layer.textIgnoresPlacement, styleValue, + @"textIgnoresPlacement should round-trip functions."); + + layer.textIgnoresPlacement = nil; + XCTAssertTrue(rawLayer->getTextIgnorePlacement().isUndefined(), + @"Unsetting textIgnoresPlacement should return text-ignore-placement to the default value."); + XCTAssertEqualObjects(layer.textIgnoresPlacement, defaultStyleValue, + @"textIgnoresPlacement should return the default value after being unset."); + } + + // text-justify + { + XCTAssertTrue(rawLayer->getTextJustify().isUndefined(), + @"text-justify should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textJustification; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextJustification:MGLTextJustificationRight]]; + layer.textJustification = styleValue; + mbgl::style::PropertyValue<mbgl::style::TextJustifyType> propertyValue = { mbgl::style::TextJustifyType::Right }; + XCTAssertEqual(rawLayer->getTextJustify(), propertyValue, + @"Setting textJustification to a constant value should update text-justify."); + XCTAssertEqualObjects(layer.textJustification, styleValue, + @"textJustification should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textJustification = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TextJustifyType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextJustify(), propertyValue, + @"Setting textJustification to a function should update text-justify."); + XCTAssertEqualObjects(layer.textJustification, styleValue, + @"textJustification should round-trip functions."); + + layer.textJustification = nil; + XCTAssertTrue(rawLayer->getTextJustify().isUndefined(), + @"Unsetting textJustification should return text-justify to the default value."); + XCTAssertEqualObjects(layer.textJustification, defaultStyleValue, + @"textJustification should return the default value after being unset."); + } + + // text-letter-spacing + { + XCTAssertTrue(rawLayer->getTextLetterSpacing().isUndefined(), + @"text-letter-spacing should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textLetterSpacing; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textLetterSpacing = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextLetterSpacing(), propertyValue, + @"Setting textLetterSpacing to a constant value should update text-letter-spacing."); + XCTAssertEqualObjects(layer.textLetterSpacing, styleValue, + @"textLetterSpacing should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textLetterSpacing = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextLetterSpacing(), propertyValue, + @"Setting textLetterSpacing to a function should update text-letter-spacing."); + XCTAssertEqualObjects(layer.textLetterSpacing, styleValue, + @"textLetterSpacing should round-trip functions."); + + layer.textLetterSpacing = nil; + XCTAssertTrue(rawLayer->getTextLetterSpacing().isUndefined(), + @"Unsetting textLetterSpacing should return text-letter-spacing to the default value."); + XCTAssertEqualObjects(layer.textLetterSpacing, defaultStyleValue, + @"textLetterSpacing should return the default value after being unset."); + } + + // text-line-height + { + XCTAssertTrue(rawLayer->getTextLineHeight().isUndefined(), + @"text-line-height should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textLineHeight; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textLineHeight = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextLineHeight(), propertyValue, + @"Setting textLineHeight to a constant value should update text-line-height."); + XCTAssertEqualObjects(layer.textLineHeight, styleValue, + @"textLineHeight should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textLineHeight = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextLineHeight(), propertyValue, + @"Setting textLineHeight to a function should update text-line-height."); + XCTAssertEqualObjects(layer.textLineHeight, styleValue, + @"textLineHeight should round-trip functions."); + + layer.textLineHeight = nil; + XCTAssertTrue(rawLayer->getTextLineHeight().isUndefined(), + @"Unsetting textLineHeight should return text-line-height to the default value."); + XCTAssertEqualObjects(layer.textLineHeight, defaultStyleValue, + @"textLineHeight should return the default value after being unset."); + } + + // text-offset + { + XCTAssertTrue(rawLayer->getTextOffset().isUndefined(), + @"text-offset should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textOffset; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.textOffset = styleValue; + mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, + @"Setting textOffset to a constant value should update text-offset."); + XCTAssertEqualObjects(layer.textOffset, styleValue, + @"textOffset should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textOffset = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 2>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, + @"Setting textOffset to a function should update text-offset."); + XCTAssertEqualObjects(layer.textOffset, styleValue, + @"textOffset should round-trip functions."); + + layer.textOffset = nil; + XCTAssertTrue(rawLayer->getTextOffset().isUndefined(), + @"Unsetting textOffset should return text-offset to the default value."); + XCTAssertEqualObjects(layer.textOffset, defaultStyleValue, + @"textOffset should return the default value after being unset."); + } + + // text-optional + { + XCTAssertTrue(rawLayer->getTextOptional().isUndefined(), + @"text-optional should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textOptional; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]; + layer.textOptional = styleValue; + mbgl::style::PropertyValue<bool> propertyValue = { true }; + XCTAssertEqual(rawLayer->getTextOptional(), propertyValue, + @"Setting textOptional to a constant value should update text-optional."); + XCTAssertEqualObjects(layer.textOptional, styleValue, + @"textOptional should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textOptional = styleValue; + propertyValue = { mbgl::style::Function<bool> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextOptional(), propertyValue, + @"Setting textOptional to a function should update text-optional."); + XCTAssertEqualObjects(layer.textOptional, styleValue, + @"textOptional should round-trip functions."); + + layer.textOptional = nil; + XCTAssertTrue(rawLayer->getTextOptional().isUndefined(), + @"Unsetting textOptional should return text-optional to the default value."); + XCTAssertEqualObjects(layer.textOptional, defaultStyleValue, + @"textOptional should return the default value after being unset."); + } + + // text-padding + { + XCTAssertTrue(rawLayer->getTextPadding().isUndefined(), + @"text-padding should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textPadding; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textPadding = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextPadding(), propertyValue, + @"Setting textPadding to a constant value should update text-padding."); + XCTAssertEqualObjects(layer.textPadding, styleValue, + @"textPadding should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textPadding = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextPadding(), propertyValue, + @"Setting textPadding to a function should update text-padding."); + XCTAssertEqualObjects(layer.textPadding, styleValue, + @"textPadding should round-trip functions."); + + layer.textPadding = nil; + XCTAssertTrue(rawLayer->getTextPadding().isUndefined(), + @"Unsetting textPadding should return text-padding to the default value."); + XCTAssertEqualObjects(layer.textPadding, defaultStyleValue, + @"textPadding should return the default value after being unset."); + } + + // text-pitch-alignment + { + XCTAssertTrue(rawLayer->getTextPitchAlignment().isUndefined(), + @"text-pitch-alignment should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textPitchAlignment; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextPitchAlignment:MGLTextPitchAlignmentAuto]]; + layer.textPitchAlignment = styleValue; + mbgl::style::PropertyValue<mbgl::style::AlignmentType> propertyValue = { mbgl::style::AlignmentType::Auto }; + XCTAssertEqual(rawLayer->getTextPitchAlignment(), propertyValue, + @"Setting textPitchAlignment to a constant value should update text-pitch-alignment."); + XCTAssertEqualObjects(layer.textPitchAlignment, styleValue, + @"textPitchAlignment should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textPitchAlignment = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::AlignmentType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextPitchAlignment(), propertyValue, + @"Setting textPitchAlignment to a function should update text-pitch-alignment."); + XCTAssertEqualObjects(layer.textPitchAlignment, styleValue, + @"textPitchAlignment should round-trip functions."); + + layer.textPitchAlignment = nil; + XCTAssertTrue(rawLayer->getTextPitchAlignment().isUndefined(), + @"Unsetting textPitchAlignment should return text-pitch-alignment to the default value."); + XCTAssertEqualObjects(layer.textPitchAlignment, defaultStyleValue, + @"textPitchAlignment should return the default value after being unset."); + } + + // text-rotate + { + XCTAssertTrue(rawLayer->getTextRotate().isUndefined(), + @"text-rotate should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textRotation; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textRotation = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, + @"Setting textRotation to a constant value should update text-rotate."); + XCTAssertEqualObjects(layer.textRotation, styleValue, + @"textRotation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textRotation = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextRotate(), propertyValue, + @"Setting textRotation to a function should update text-rotate."); + XCTAssertEqualObjects(layer.textRotation, styleValue, + @"textRotation should round-trip functions."); + + layer.textRotation = nil; + XCTAssertTrue(rawLayer->getTextRotate().isUndefined(), + @"Unsetting textRotation should return text-rotate to the default value."); + XCTAssertEqualObjects(layer.textRotation, defaultStyleValue, + @"textRotation should return the default value after being unset."); + } + + // text-rotation-alignment + { + XCTAssertTrue(rawLayer->getTextRotationAlignment().isUndefined(), + @"text-rotation-alignment should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textRotationAlignment; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextRotationAlignment:MGLTextRotationAlignmentAuto]]; + layer.textRotationAlignment = styleValue; + mbgl::style::PropertyValue<mbgl::style::AlignmentType> propertyValue = { mbgl::style::AlignmentType::Auto }; + XCTAssertEqual(rawLayer->getTextRotationAlignment(), propertyValue, + @"Setting textRotationAlignment to a constant value should update text-rotation-alignment."); + XCTAssertEqualObjects(layer.textRotationAlignment, styleValue, + @"textRotationAlignment should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textRotationAlignment = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::AlignmentType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextRotationAlignment(), propertyValue, + @"Setting textRotationAlignment to a function should update text-rotation-alignment."); + XCTAssertEqualObjects(layer.textRotationAlignment, styleValue, + @"textRotationAlignment should round-trip functions."); + + layer.textRotationAlignment = nil; + XCTAssertTrue(rawLayer->getTextRotationAlignment().isUndefined(), + @"Unsetting textRotationAlignment should return text-rotation-alignment to the default value."); + XCTAssertEqualObjects(layer.textRotationAlignment, defaultStyleValue, + @"textRotationAlignment should return the default value after being unset."); + } + + // text-transform + { + XCTAssertTrue(rawLayer->getTextTransform().isUndefined(), + @"text-transform should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textTransform; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextTransform:MGLTextTransformLowercase]]; + layer.textTransform = styleValue; + mbgl::style::PropertyValue<mbgl::style::TextTransformType> propertyValue = { mbgl::style::TextTransformType::Lowercase }; + XCTAssertEqual(rawLayer->getTextTransform(), propertyValue, + @"Setting textTransform to a constant value should update text-transform."); + XCTAssertEqualObjects(layer.textTransform, styleValue, + @"textTransform should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textTransform = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TextTransformType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextTransform(), propertyValue, + @"Setting textTransform to a function should update text-transform."); + XCTAssertEqualObjects(layer.textTransform, styleValue, + @"textTransform should round-trip functions."); + + layer.textTransform = nil; + XCTAssertTrue(rawLayer->getTextTransform().isUndefined(), + @"Unsetting textTransform should return text-transform to the default value."); + XCTAssertEqualObjects(layer.textTransform, defaultStyleValue, + @"textTransform should return the default value after being unset."); + } + + // icon-color + { + XCTAssertTrue(rawLayer->getIconColor().isUndefined(), + @"icon-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.iconColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.iconColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getIconColor(), propertyValue, + @"Setting iconColor to a constant value should update icon-color."); + XCTAssertEqualObjects(layer.iconColor, styleValue, + @"iconColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconColor(), propertyValue, + @"Setting iconColor to a function should update icon-color."); + XCTAssertEqualObjects(layer.iconColor, styleValue, + @"iconColor should round-trip functions."); + + layer.iconColor = nil; + XCTAssertTrue(rawLayer->getIconColor().isUndefined(), + @"Unsetting iconColor should return icon-color to the default value."); + XCTAssertEqualObjects(layer.iconColor, defaultStyleValue, + @"iconColor should return the default value after being unset."); + } + + // icon-halo-blur + { + XCTAssertTrue(rawLayer->getIconHaloBlur().isUndefined(), + @"icon-halo-blur should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconHaloBlur; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.iconHaloBlur = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getIconHaloBlur(), propertyValue, + @"Setting iconHaloBlur to a constant value should update icon-halo-blur."); + XCTAssertEqualObjects(layer.iconHaloBlur, styleValue, + @"iconHaloBlur should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconHaloBlur = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconHaloBlur(), propertyValue, + @"Setting iconHaloBlur to a function should update icon-halo-blur."); + XCTAssertEqualObjects(layer.iconHaloBlur, styleValue, + @"iconHaloBlur should round-trip functions."); + + layer.iconHaloBlur = nil; + XCTAssertTrue(rawLayer->getIconHaloBlur().isUndefined(), + @"Unsetting iconHaloBlur should return icon-halo-blur to the default value."); + XCTAssertEqualObjects(layer.iconHaloBlur, defaultStyleValue, + @"iconHaloBlur should return the default value after being unset."); + } + + // icon-halo-color + { + XCTAssertTrue(rawLayer->getIconHaloColor().isUndefined(), + @"icon-halo-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.iconHaloColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.iconHaloColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getIconHaloColor(), propertyValue, + @"Setting iconHaloColor to a constant value should update icon-halo-color."); + XCTAssertEqualObjects(layer.iconHaloColor, styleValue, + @"iconHaloColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconHaloColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconHaloColor(), propertyValue, + @"Setting iconHaloColor to a function should update icon-halo-color."); + XCTAssertEqualObjects(layer.iconHaloColor, styleValue, + @"iconHaloColor should round-trip functions."); + + layer.iconHaloColor = nil; + XCTAssertTrue(rawLayer->getIconHaloColor().isUndefined(), + @"Unsetting iconHaloColor should return icon-halo-color to the default value."); + XCTAssertEqualObjects(layer.iconHaloColor, defaultStyleValue, + @"iconHaloColor should return the default value after being unset."); + } + + // icon-halo-width + { + XCTAssertTrue(rawLayer->getIconHaloWidth().isUndefined(), + @"icon-halo-width should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconHaloWidth; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.iconHaloWidth = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getIconHaloWidth(), propertyValue, + @"Setting iconHaloWidth to a constant value should update icon-halo-width."); + XCTAssertEqualObjects(layer.iconHaloWidth, styleValue, + @"iconHaloWidth should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconHaloWidth = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconHaloWidth(), propertyValue, + @"Setting iconHaloWidth to a function should update icon-halo-width."); + XCTAssertEqualObjects(layer.iconHaloWidth, styleValue, + @"iconHaloWidth should round-trip functions."); + + layer.iconHaloWidth = nil; + XCTAssertTrue(rawLayer->getIconHaloWidth().isUndefined(), + @"Unsetting iconHaloWidth should return icon-halo-width to the default value."); + XCTAssertEqualObjects(layer.iconHaloWidth, defaultStyleValue, + @"iconHaloWidth should return the default value after being unset."); + } + + // icon-opacity + { + XCTAssertTrue(rawLayer->getIconOpacity().isUndefined(), + @"icon-opacity should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.iconOpacity; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.iconOpacity = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getIconOpacity(), propertyValue, + @"Setting iconOpacity to a constant value should update icon-opacity."); + XCTAssertEqualObjects(layer.iconOpacity, styleValue, + @"iconOpacity should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconOpacity = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconOpacity(), propertyValue, + @"Setting iconOpacity to a function should update icon-opacity."); + XCTAssertEqualObjects(layer.iconOpacity, styleValue, + @"iconOpacity should round-trip functions."); + + layer.iconOpacity = nil; + XCTAssertTrue(rawLayer->getIconOpacity().isUndefined(), + @"Unsetting iconOpacity should return icon-opacity to the default value."); + XCTAssertEqualObjects(layer.iconOpacity, defaultStyleValue, + @"iconOpacity should return the default value after being unset."); + } + + // icon-translate + { + XCTAssertTrue(rawLayer->getIconTranslate().isUndefined(), + @"icon-translate should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.iconTranslation; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.iconTranslation = styleValue; + mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + XCTAssertEqual(rawLayer->getIconTranslate(), propertyValue, + @"Setting iconTranslation to a constant value should update icon-translate."); + XCTAssertEqualObjects(layer.iconTranslation, styleValue, + @"iconTranslation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconTranslation = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 2>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconTranslate(), propertyValue, + @"Setting iconTranslation to a function should update icon-translate."); + XCTAssertEqualObjects(layer.iconTranslation, styleValue, + @"iconTranslation should round-trip functions."); + + layer.iconTranslation = nil; + XCTAssertTrue(rawLayer->getIconTranslate().isUndefined(), + @"Unsetting iconTranslation should return icon-translate to the default value."); + XCTAssertEqualObjects(layer.iconTranslation, defaultStyleValue, + @"iconTranslation should return the default value after being unset."); + } + + // icon-translate-anchor + { + XCTAssertTrue(rawLayer->getIconTranslateAnchor().isUndefined(), + @"icon-translate-anchor should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.iconTranslationAnchor; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLIconTranslationAnchor:MGLIconTranslationAnchorViewport]]; + layer.iconTranslationAnchor = styleValue; + mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType> propertyValue = { mbgl::style::TranslateAnchorType::Viewport }; + XCTAssertEqual(rawLayer->getIconTranslateAnchor(), propertyValue, + @"Setting iconTranslationAnchor to a constant value should update icon-translate-anchor."); + XCTAssertEqualObjects(layer.iconTranslationAnchor, styleValue, + @"iconTranslationAnchor should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.iconTranslationAnchor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TranslateAnchorType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getIconTranslateAnchor(), propertyValue, + @"Setting iconTranslationAnchor to a function should update icon-translate-anchor."); + XCTAssertEqualObjects(layer.iconTranslationAnchor, styleValue, + @"iconTranslationAnchor should round-trip functions."); + + layer.iconTranslationAnchor = nil; + XCTAssertTrue(rawLayer->getIconTranslateAnchor().isUndefined(), + @"Unsetting iconTranslationAnchor should return icon-translate-anchor to the default value."); + XCTAssertEqualObjects(layer.iconTranslationAnchor, defaultStyleValue, + @"iconTranslationAnchor should return the default value after being unset."); + } + + // text-color + { + XCTAssertTrue(rawLayer->getTextColor().isUndefined(), + @"text-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.textColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.textColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getTextColor(), propertyValue, + @"Setting textColor to a constant value should update text-color."); + XCTAssertEqualObjects(layer.textColor, styleValue, + @"textColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextColor(), propertyValue, + @"Setting textColor to a function should update text-color."); + XCTAssertEqualObjects(layer.textColor, styleValue, + @"textColor should round-trip functions."); + + layer.textColor = nil; + XCTAssertTrue(rawLayer->getTextColor().isUndefined(), + @"Unsetting textColor should return text-color to the default value."); + XCTAssertEqualObjects(layer.textColor, defaultStyleValue, + @"textColor should return the default value after being unset."); + } + + // text-halo-blur + { + XCTAssertTrue(rawLayer->getTextHaloBlur().isUndefined(), + @"text-halo-blur should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textHaloBlur; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textHaloBlur = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextHaloBlur(), propertyValue, + @"Setting textHaloBlur to a constant value should update text-halo-blur."); + XCTAssertEqualObjects(layer.textHaloBlur, styleValue, + @"textHaloBlur should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textHaloBlur = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextHaloBlur(), propertyValue, + @"Setting textHaloBlur to a function should update text-halo-blur."); + XCTAssertEqualObjects(layer.textHaloBlur, styleValue, + @"textHaloBlur should round-trip functions."); + + layer.textHaloBlur = nil; + XCTAssertTrue(rawLayer->getTextHaloBlur().isUndefined(), + @"Unsetting textHaloBlur should return text-halo-blur to the default value."); + XCTAssertEqualObjects(layer.textHaloBlur, defaultStyleValue, + @"textHaloBlur should return the default value after being unset."); + } + + // text-halo-color + { + XCTAssertTrue(rawLayer->getTextHaloColor().isUndefined(), + @"text-halo-color should be unset initially."); + MGLStyleValue<MGLColor *> *defaultStyleValue = layer.textHaloColor; + + MGLStyleValue<MGLColor *> *styleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor redColor]]; + layer.textHaloColor = styleValue; + mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { .r = 1, .g = 0, .b = 0, .a = 1 } }; + XCTAssertEqual(rawLayer->getTextHaloColor(), propertyValue, + @"Setting textHaloColor to a constant value should update text-halo-color."); + XCTAssertEqualObjects(layer.textHaloColor, styleValue, + @"textHaloColor should round-trip constant values."); + + styleValue = [MGLStyleValue<MGLColor *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textHaloColor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::Color> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextHaloColor(), propertyValue, + @"Setting textHaloColor to a function should update text-halo-color."); + XCTAssertEqualObjects(layer.textHaloColor, styleValue, + @"textHaloColor should round-trip functions."); + + layer.textHaloColor = nil; + XCTAssertTrue(rawLayer->getTextHaloColor().isUndefined(), + @"Unsetting textHaloColor should return text-halo-color to the default value."); + XCTAssertEqualObjects(layer.textHaloColor, defaultStyleValue, + @"textHaloColor should return the default value after being unset."); + } + + // text-halo-width + { + XCTAssertTrue(rawLayer->getTextHaloWidth().isUndefined(), + @"text-halo-width should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textHaloWidth; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textHaloWidth = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextHaloWidth(), propertyValue, + @"Setting textHaloWidth to a constant value should update text-halo-width."); + XCTAssertEqualObjects(layer.textHaloWidth, styleValue, + @"textHaloWidth should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textHaloWidth = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextHaloWidth(), propertyValue, + @"Setting textHaloWidth to a function should update text-halo-width."); + XCTAssertEqualObjects(layer.textHaloWidth, styleValue, + @"textHaloWidth should round-trip functions."); + + layer.textHaloWidth = nil; + XCTAssertTrue(rawLayer->getTextHaloWidth().isUndefined(), + @"Unsetting textHaloWidth should return text-halo-width to the default value."); + XCTAssertEqualObjects(layer.textHaloWidth, defaultStyleValue, + @"textHaloWidth should return the default value after being unset."); + } + + // text-opacity + { + XCTAssertTrue(rawLayer->getTextOpacity().isUndefined(), + @"text-opacity should be unset initially."); + MGLStyleValue<NSNumber *> *defaultStyleValue = layer.textOpacity; + + MGLStyleValue<NSNumber *> *styleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:@0xff]; + layer.textOpacity = styleValue; + mbgl::style::PropertyValue<float> propertyValue = { 0xff }; + XCTAssertEqual(rawLayer->getTextOpacity(), propertyValue, + @"Setting textOpacity to a constant value should update text-opacity."); + XCTAssertEqualObjects(layer.textOpacity, styleValue, + @"textOpacity should round-trip constant values."); + + styleValue = [MGLStyleValue<NSNumber *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textOpacity = styleValue; + propertyValue = { mbgl::style::Function<float> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextOpacity(), propertyValue, + @"Setting textOpacity to a function should update text-opacity."); + XCTAssertEqualObjects(layer.textOpacity, styleValue, + @"textOpacity should round-trip functions."); + + layer.textOpacity = nil; + XCTAssertTrue(rawLayer->getTextOpacity().isUndefined(), + @"Unsetting textOpacity should return text-opacity to the default value."); + XCTAssertEqualObjects(layer.textOpacity, defaultStyleValue, + @"textOpacity should return the default value after being unset."); + } + + // text-translate + { + XCTAssertTrue(rawLayer->getTextTranslate().isUndefined(), + @"text-translate should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textTranslation; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.textTranslation = styleValue; + mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + XCTAssertEqual(rawLayer->getTextTranslate(), propertyValue, + @"Setting textTranslation to a constant value should update text-translate."); + XCTAssertEqualObjects(layer.textTranslation, styleValue, + @"textTranslation should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textTranslation = styleValue; + propertyValue = { mbgl::style::Function<std::array<float, 2>> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextTranslate(), propertyValue, + @"Setting textTranslation to a function should update text-translate."); + XCTAssertEqualObjects(layer.textTranslation, styleValue, + @"textTranslation should round-trip functions."); + + layer.textTranslation = nil; + XCTAssertTrue(rawLayer->getTextTranslate().isUndefined(), + @"Unsetting textTranslation should return text-translate to the default value."); + XCTAssertEqualObjects(layer.textTranslation, defaultStyleValue, + @"textTranslation should return the default value after being unset."); + } + + // text-translate-anchor + { + XCTAssertTrue(rawLayer->getTextTranslateAnchor().isUndefined(), + @"text-translate-anchor should be unset initially."); + MGLStyleValue<NSValue *> *defaultStyleValue = layer.textTranslationAnchor; + + MGLStyleValue<NSValue *> *styleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLTextTranslationAnchor:MGLTextTranslationAnchorViewport]]; + layer.textTranslationAnchor = styleValue; + mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType> propertyValue = { mbgl::style::TranslateAnchorType::Viewport }; + XCTAssertEqual(rawLayer->getTextTranslateAnchor(), propertyValue, + @"Setting textTranslationAnchor to a constant value should update text-translate-anchor."); + XCTAssertEqualObjects(layer.textTranslationAnchor, styleValue, + @"textTranslationAnchor should round-trip constant values."); + + styleValue = [MGLStyleValue<NSValue *> valueWithStops:@{ + @18: styleValue, + }]; + layer.textTranslationAnchor = styleValue; + propertyValue = { mbgl::style::Function<mbgl::style::TranslateAnchorType> { + {{ 18, propertyValue.asConstant() }}, + 1, + }}; + XCTAssertEqual(rawLayer->getTextTranslateAnchor(), propertyValue, + @"Setting textTranslationAnchor to a function should update text-translate-anchor."); + XCTAssertEqualObjects(layer.textTranslationAnchor, styleValue, + @"textTranslationAnchor should round-trip functions."); + + layer.textTranslationAnchor = nil; + XCTAssertTrue(rawLayer->getTextTranslateAnchor().isUndefined(), + @"Unsetting textTranslationAnchor should return text-translate-anchor to the default value."); + XCTAssertEqualObjects(layer.textTranslationAnchor, defaultStyleValue, + @"textTranslationAnchor should return the default value after being unset."); + } +} + +- (void)testPropertyNames { + [self testPropertyName:@"icon-allows-overlap" isBoolean:YES]; + [self testPropertyName:@"icon-ignores-placement" isBoolean:YES]; + [self testPropertyName:@"icon-image-name" isBoolean:NO]; + [self testPropertyName:@"icon-offset" isBoolean:NO]; + [self testPropertyName:@"is-icon-optional" isBoolean:YES]; + [self testPropertyName:@"icon-padding" isBoolean:NO]; + [self testPropertyName:@"icon-rotation" isBoolean:NO]; + [self testPropertyName:@"icon-rotation-alignment" isBoolean:NO]; + [self testPropertyName:@"icon-scale" isBoolean:NO]; + [self testPropertyName:@"icon-text-fit" isBoolean:NO]; + [self testPropertyName:@"icon-text-fit-padding" isBoolean:NO]; + [self testPropertyName:@"keeps-icon-upright" isBoolean:YES]; + [self testPropertyName:@"keeps-text-upright" isBoolean:YES]; + [self testPropertyName:@"maximum-text-angle" isBoolean:NO]; + [self testPropertyName:@"maximum-text-width" isBoolean:NO]; + [self testPropertyName:@"symbol-avoids-edges" isBoolean:YES]; + [self testPropertyName:@"symbol-placement" isBoolean:NO]; + [self testPropertyName:@"symbol-spacing" isBoolean:NO]; + [self testPropertyName:@"text" isBoolean:NO]; + [self testPropertyName:@"text-allows-overlap" isBoolean:YES]; + [self testPropertyName:@"text-anchor" isBoolean:NO]; + [self testPropertyName:@"text-font-names" isBoolean:NO]; + [self testPropertyName:@"text-font-size" isBoolean:NO]; + [self testPropertyName:@"text-ignores-placement" isBoolean:YES]; + [self testPropertyName:@"text-justification" isBoolean:NO]; + [self testPropertyName:@"text-letter-spacing" isBoolean:NO]; + [self testPropertyName:@"text-line-height" isBoolean:NO]; + [self testPropertyName:@"text-offset" isBoolean:NO]; + [self testPropertyName:@"is-text-optional" isBoolean:YES]; + [self testPropertyName:@"text-padding" isBoolean:NO]; + [self testPropertyName:@"text-pitch-alignment" isBoolean:NO]; + [self testPropertyName:@"text-rotation" isBoolean:NO]; + [self testPropertyName:@"text-rotation-alignment" isBoolean:NO]; + [self testPropertyName:@"text-transform" isBoolean:NO]; + [self testPropertyName:@"icon-color" isBoolean:NO]; + [self testPropertyName:@"icon-halo-blur" isBoolean:NO]; + [self testPropertyName:@"icon-halo-color" isBoolean:NO]; + [self testPropertyName:@"icon-halo-width" isBoolean:NO]; + [self testPropertyName:@"icon-opacity" isBoolean:NO]; + [self testPropertyName:@"icon-translation" isBoolean:NO]; + [self testPropertyName:@"icon-translation-anchor" isBoolean:NO]; + [self testPropertyName:@"text-color" isBoolean:NO]; + [self testPropertyName:@"text-halo-blur" isBoolean:NO]; + [self testPropertyName:@"text-halo-color" isBoolean:NO]; + [self testPropertyName:@"text-halo-width" isBoolean:NO]; + [self testPropertyName:@"text-opacity" isBoolean:NO]; + [self testPropertyName:@"text-translation" isBoolean:NO]; + [self testPropertyName:@"text-translation-anchor" isBoolean:NO]; +} + +- (void)testValueAdditions { + XCTAssertEqual([NSValue valueWithMGLIconRotationAlignment:MGLIconRotationAlignmentMap].MGLIconRotationAlignmentValue, MGLIconRotationAlignmentMap); + XCTAssertEqual([NSValue valueWithMGLIconRotationAlignment:MGLIconRotationAlignmentViewport].MGLIconRotationAlignmentValue, MGLIconRotationAlignmentViewport); + XCTAssertEqual([NSValue valueWithMGLIconRotationAlignment:MGLIconRotationAlignmentAuto].MGLIconRotationAlignmentValue, MGLIconRotationAlignmentAuto); + XCTAssertEqual([NSValue valueWithMGLIconTextFit:MGLIconTextFitNone].MGLIconTextFitValue, MGLIconTextFitNone); + XCTAssertEqual([NSValue valueWithMGLIconTextFit:MGLIconTextFitWidth].MGLIconTextFitValue, MGLIconTextFitWidth); + XCTAssertEqual([NSValue valueWithMGLIconTextFit:MGLIconTextFitHeight].MGLIconTextFitValue, MGLIconTextFitHeight); + XCTAssertEqual([NSValue valueWithMGLIconTextFit:MGLIconTextFitBoth].MGLIconTextFitValue, MGLIconTextFitBoth); + XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementPoint].MGLSymbolPlacementValue, MGLSymbolPlacementPoint); + XCTAssertEqual([NSValue valueWithMGLSymbolPlacement:MGLSymbolPlacementLine].MGLSymbolPlacementValue, MGLSymbolPlacementLine); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorCenter].MGLTextAnchorValue, MGLTextAnchorCenter); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorLeft].MGLTextAnchorValue, MGLTextAnchorLeft); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorRight].MGLTextAnchorValue, MGLTextAnchorRight); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorTop].MGLTextAnchorValue, MGLTextAnchorTop); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorBottom].MGLTextAnchorValue, MGLTextAnchorBottom); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorTopLeft].MGLTextAnchorValue, MGLTextAnchorTopLeft); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorTopRight].MGLTextAnchorValue, MGLTextAnchorTopRight); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorBottomLeft].MGLTextAnchorValue, MGLTextAnchorBottomLeft); + XCTAssertEqual([NSValue valueWithMGLTextAnchor:MGLTextAnchorBottomRight].MGLTextAnchorValue, MGLTextAnchorBottomRight); + XCTAssertEqual([NSValue valueWithMGLTextJustification:MGLTextJustificationLeft].MGLTextJustificationValue, MGLTextJustificationLeft); + XCTAssertEqual([NSValue valueWithMGLTextJustification:MGLTextJustificationCenter].MGLTextJustificationValue, MGLTextJustificationCenter); + XCTAssertEqual([NSValue valueWithMGLTextJustification:MGLTextJustificationRight].MGLTextJustificationValue, MGLTextJustificationRight); + XCTAssertEqual([NSValue valueWithMGLTextPitchAlignment:MGLTextPitchAlignmentMap].MGLTextPitchAlignmentValue, MGLTextPitchAlignmentMap); + XCTAssertEqual([NSValue valueWithMGLTextPitchAlignment:MGLTextPitchAlignmentViewport].MGLTextPitchAlignmentValue, MGLTextPitchAlignmentViewport); + XCTAssertEqual([NSValue valueWithMGLTextPitchAlignment:MGLTextPitchAlignmentAuto].MGLTextPitchAlignmentValue, MGLTextPitchAlignmentAuto); + XCTAssertEqual([NSValue valueWithMGLTextRotationAlignment:MGLTextRotationAlignmentMap].MGLTextRotationAlignmentValue, MGLTextRotationAlignmentMap); + XCTAssertEqual([NSValue valueWithMGLTextRotationAlignment:MGLTextRotationAlignmentViewport].MGLTextRotationAlignmentValue, MGLTextRotationAlignmentViewport); + XCTAssertEqual([NSValue valueWithMGLTextRotationAlignment:MGLTextRotationAlignmentAuto].MGLTextRotationAlignmentValue, MGLTextRotationAlignmentAuto); + XCTAssertEqual([NSValue valueWithMGLTextTransform:MGLTextTransformNone].MGLTextTransformValue, MGLTextTransformNone); + XCTAssertEqual([NSValue valueWithMGLTextTransform:MGLTextTransformUppercase].MGLTextTransformValue, MGLTextTransformUppercase); + XCTAssertEqual([NSValue valueWithMGLTextTransform:MGLTextTransformLowercase].MGLTextTransformValue, MGLTextTransformLowercase); + XCTAssertEqual([NSValue valueWithMGLIconTranslationAnchor:MGLIconTranslationAnchorMap].MGLIconTranslationAnchorValue, MGLIconTranslationAnchorMap); + XCTAssertEqual([NSValue valueWithMGLIconTranslationAnchor:MGLIconTranslationAnchorViewport].MGLIconTranslationAnchorValue, MGLIconTranslationAnchorViewport); + XCTAssertEqual([NSValue valueWithMGLTextTranslationAnchor:MGLTextTranslationAnchorMap].MGLTextTranslationAnchorValue, MGLTextTranslationAnchorMap); + XCTAssertEqual([NSValue valueWithMGLTextTranslationAnchor:MGLTextTranslationAnchorViewport].MGLTextTranslationAnchorValue, MGLTextTranslationAnchorViewport); +} + +@end |