diff options
Diffstat (limited to 'platform/darwin/test/MGLStyleLayerTests.mm.ejs')
-rw-r--r-- | platform/darwin/test/MGLStyleLayerTests.mm.ejs | 79 |
1 files changed, 57 insertions, 22 deletions
diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs index 00842a5b4e..810d7fbd3b 100644 --- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs +++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs @@ -3,8 +3,8 @@ 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`. +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLStyleLayerTests.h" @@ -26,13 +26,13 @@ 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]); @@ -47,48 +47,83 @@ <% } 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; + + MGLStyleValue<<%- propertyType(property) %>> *constantStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithRawValue:<%- objCTestValue(property, type, 3) %>]; + layer.<%- objCName(property) %> = constantStyleValue; +<% if (property["property-function"]) { -%> + mbgl::style::DataDrivenPropertyValue<<%- mbglType(property) %>> propertyValue = { <%- mbglTestValue(property, type) %> }; +<% } else { -%> 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, + XCTAssertEqualObjects(layer.<%- objCName(property) %>, constantStyleValue, @"<%- objCName(property) %> should round-trip constant values."); + + MGLStyleValue<<%- propertyType(property) %>> * functionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithInterpolationMode:MGLInterpolationModeInterval cameraStops:@{@18: constantStyleValue} options:nil]; + layer.<%- objCName(property) %> = functionStyleValue; + + mbgl::style::IntervalStops<<%- mbglType(property) %>> intervalStops = { {{18, <%- mbglTestValue(property, type) %>}} }; + propertyValue = mbgl::style::CameraFunction<<%- mbglType(property) %>> { intervalStops }; - 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."); + @"Setting <%- objCName(property) %> to a camera function should update <%- originalPropertyName(property) %>."); + XCTAssertEqualObjects(layer.<%- objCName(property) %>, functionStyleValue, + @"<%- objCName(property) %> should round-trip camera functions."); + +<% if (property["property-function"] && isInterpolatable(property)) { -%> + functionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.<%- objCName(property) %> = functionStyleValue; + + mbgl::style::ExponentialStops<<%- mbglType(property) %>> exponentialStops = { {{18, <%- mbglTestValue(property, type) %>}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction<<%- mbglType(property) %>> { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue, + @"Setting <%- objCName(property) %> to a source function should update <%- originalPropertyName(property) %>."); + XCTAssertEqualObjects(layer.<%- objCName(property) %>, functionStyleValue, + @"<%- objCName(property) %> should round-trip source functions."); + + functionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.<%- objCName(property) %> = functionStyleValue; + + std::map<float, <%- mbglType(property) %>> innerStops { {18, <%- mbglTestValue(property, type) %>} }; + mbgl::style::CompositeExponentialStops<<%- mbglType(property) %>> compositeStops { { {10.0, innerStops} }, 1.0 }; + + propertyValue = mbgl::style::CompositeFunction<<%- mbglType(property) %>> { "keyName", compositeStops }; + + XCTAssertEqual(rawLayer->get<%- camelize(originalPropertyName(property)) %>(), propertyValue, + @"Setting <%- objCName(property) %> to a composite function should update <%- originalPropertyName(property) %>."); + XCTAssertEqualObjects(layer.<%- objCName(property) %>, functionStyleValue, + @"<%- objCName(property) %> should round-trip composite 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."); <% } -%> +<% if (!property["property-function"]) { -%> + + functionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; + XCTAssertThrowsSpecificNamed(layer.<%- objCName(property) %> = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); + functionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithInterpolationMode:MGLInterpolationModeInterval compositeStops:@{@18: constantStyleValue} attributeName:@"" options:nil]; + XCTAssertThrowsSpecificNamed(layer.<%- objCName(property) %> = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); +<% } -%> } <% } -%> } |