From 67c09b18e491e66e2ba058498b8f3b44e49d0105 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Fri, 16 Jun 2017 06:41:51 -0700 Subject: MGLLight autogenerate scripts (#9260) * [ios, macos] Add the MGLLight generation templates * [ios, macos] Add MGLLight generation script * [ios, macos] Add the auto-generation script for MGLLight.mm * [ios, macos] Add the auto-generation script for MGLLightTest.mm * [core] Add const to Position constructor. * [ios, macos] Simplify MGLLightTest.mm autogenerate script. --- platform/darwin/test/MGLLightTest.mm.ejs | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 platform/darwin/test/MGLLightTest.mm.ejs (limited to 'platform/darwin/test/MGLLightTest.mm.ejs') diff --git a/platform/darwin/test/MGLLightTest.mm.ejs b/platform/darwin/test/MGLLightTest.mm.ejs new file mode 100644 index 0000000000..c1904d5ab8 --- /dev/null +++ b/platform/darwin/test/MGLLightTest.mm.ejs @@ -0,0 +1,92 @@ +<% + const type = locals.type; + const properties = locals.properties; +-%> +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#import +#import + +#import "MGLLight_Private.h" + +#import "../../darwin/src/NSDate+MGLAdditions.h" + +#import +#import +#include + +@interface MGLLightTest : XCTestCase + +@end + +@implementation MGLLightTest + +- (void)testProperties { + + MGLTransition defaultTransition = MGLTransitionMake(0, 0); + MGLTransition transition = MGLTransitionMake(6, 3); + mbgl::style::TransitionOptions transitionOptions { { MGLDurationFromTimeInterval(6) }, { MGLDurationFromTimeInterval(3) } }; + +<% for (const property of properties) { -%> + // <%- property.name %> + { + mbgl::style::Light light; + MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + auto lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.getDefault<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>()); +<% if (property.transition) { -%> + auto <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition(); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay) == defaultTransition.delay); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration) == defaultTransition.duration); + +<% } -%> +<% if (property.type == "enum" && property.default) { -%> + XCTAssert([mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isn’t a MGLConstantStyleValue."); + NSValue *<%- camelizeWithLeadingLowercase(property.name) -%>Value = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue; + XCTAssertEqual(<%- camelizeWithLeadingLowercase(property.name) -%>Value.MGLLight<%- camelize(property.name) -%>Value, MGLLight<%- camelize(property.name) -%><%- camelize(property.default) -%>); + +<% } -%> +<% if (property.type == "array") { -%> + const std::array positionArray = { { 6, 180, 90 } }; + mbgl::style::Position position = { positionArray }; + mbgl::style::PropertyValue propertyValue = { position }; +<% } else { -%> + mbgl::style::PropertyValue<<%- mbglType(property) %>> propertyValue = { <%- mbglTestValue(property, type) %> }; +<% } -%> + light.set<%- camelize(property.name) -%>(propertyValue); +<% if (property.transition) { -%> + light.set<%- camelize(property.name) -%>Transition(transitionOptions); + +<% } -%> + mglLight = [[MGLLight alloc] initWithMBGLLight:&light]; + lightFromMGLlight = [mglLight mbglLight]; + + XCTAssertEqual(light.get<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>()); +<% if (property.transition) { -%> + <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition(); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay) == transition.delay); + XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration) == transition.duration); + +<% } -%> + } + +<% } -%> +} + +- (void)testValueAdditions { + MGLSphericalPosition position = MGLSphericalPositionMake(1.15, 210, 30); + + XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.radial, position.radial); + XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.azimuthal, position.azimuthal); + XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.polar, position.polar); +<% for (const property of properties) { -%> +<% if (property.type == "enum") { -%> +<% for (const value in property.values) { -%> + XCTAssertEqual([NSValue valueWithMGLLight<%- camelize(property.name) %>:MGLLight<%- camelize(property.name) %><%- camelize(value) %>].MGLLight<%- camelize(property.name) %>Value, MGLLight<%- camelize(property.name) %><%- camelize(value) %>); +<% } -%> +<% } -%> +<% } -%> +} + +@end -- cgit v1.2.1