summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLStyleLayerTests.mm.ejs
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-01-16 11:38:35 -0800
committerMinh Nguyễn <mxn@1ec5.org>2017-01-16 11:38:35 -0800
commit7ef2843e6a62116667be6a2c12de085951fdd5ea (patch)
tree40eca249e044e2706efd1193d617e6eb8e59d708 /platform/darwin/test/MGLStyleLayerTests.mm.ejs
parent76301b252cbc4bc3ae1fc84322bcbcdbd26cae8a (diff)
parent13b97dd0cebffe36b187bdb74923910def6bd87b (diff)
downloadqtlocation-mapboxgl-7ef2843e6a62116667be6a2c12de085951fdd5ea.tar.gz
Merge branch 'release-ios-v3.4.0' into 1ec5-release-ios-v3.4.0-beta.7
Diffstat (limited to 'platform/darwin/test/MGLStyleLayerTests.mm.ejs')
-rw-r--r--platform/darwin/test/MGLStyleLayerTests.mm.ejs114
1 files changed, 114 insertions, 0 deletions
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