From 4d5036616f85ff87ffe9042739872b1a080015b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 12 Jan 2017 16:48:17 -0800 Subject: [ios, macos] Rewrote style layer tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced the style layer integration tests with unit tests. Test conversion of style values to property values and vice versa, not just round-tripping. Test the initial state and null-resetting of each null-resettable property. Test NSValue additions for style attribute enumerations. Test properties common to all style layer classes. Test MGLStyle’s source and layer collections. Eviscerated implementations of unavailable style layer properties corresponding to style specification properties that were renamed. Implemented corresponding getters to prevent ivars from being autosynthesized for these unavailable properties. Added a missing bridging header to the iOS test project. --- platform/darwin/test/MGLFillStyleLayerTests.mm | 306 +++++++++++++++++++++++++ 1 file changed, 306 insertions(+) create mode 100644 platform/darwin/test/MGLFillStyleLayerTests.mm (limited to 'platform/darwin/test/MGLFillStyleLayerTests.mm') 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 + +@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()); + auto rawLayer = layer.rawLayer->as(); + + // fill-antialias + { + XCTAssertTrue(rawLayer->getFillAntialias().isUndefined(), + @"fill-antialias should be unset initially."); + MGLStyleValue *defaultStyleValue = layer.fillAntialiased; + + MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@NO]; + layer.fillAntialiased = styleValue; + mbgl::style::PropertyValue 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 valueWithStops:@{ + @18: styleValue, + }]; + layer.fillAntialiased = styleValue; + propertyValue = { mbgl::style::Function { + {{ 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 *defaultStyleValue = layer.fillColor; + + MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:[MGLColor redColor]]; + layer.fillColor = styleValue; + mbgl::style::PropertyValue 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 valueWithStops:@{ + @18: styleValue, + }]; + layer.fillColor = styleValue; + propertyValue = { mbgl::style::Function { + {{ 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 *defaultStyleValue = layer.fillOpacity; + + MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@0xff]; + layer.fillOpacity = styleValue; + mbgl::style::PropertyValue 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 valueWithStops:@{ + @18: styleValue, + }]; + layer.fillOpacity = styleValue; + propertyValue = { mbgl::style::Function { + {{ 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 *defaultStyleValue = layer.fillOutlineColor; + + MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:[MGLColor redColor]]; + layer.fillOutlineColor = styleValue; + mbgl::style::PropertyValue 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 valueWithStops:@{ + @18: styleValue, + }]; + layer.fillOutlineColor = styleValue; + propertyValue = { mbgl::style::Function { + {{ 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 *defaultStyleValue = layer.fillPattern; + + MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:@"Fill Pattern"]; + layer.fillPattern = styleValue; + mbgl::style::PropertyValue 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 valueWithStops:@{ + @18: styleValue, + }]; + layer.fillPattern = styleValue; + propertyValue = { mbgl::style::Function { + {{ 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 *defaultStyleValue = layer.fillTranslation; + + MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue: +#if TARGET_OS_IPHONE + [NSValue valueWithCGVector:CGVectorMake(1, 1)] +#else + [NSValue valueWithMGLVector:CGVectorMake(1, -1)] +#endif + ]; + layer.fillTranslation = styleValue; + mbgl::style::PropertyValue> 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 valueWithStops:@{ + @18: styleValue, + }]; + layer.fillTranslation = styleValue; + propertyValue = { mbgl::style::Function> { + {{ 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 *defaultStyleValue = layer.fillTranslationAnchor; + + MGLStyleValue *styleValue = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLFillTranslationAnchor:MGLFillTranslationAnchorViewport]]; + layer.fillTranslationAnchor = styleValue; + mbgl::style::PropertyValue 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 valueWithStops:@{ + @18: styleValue, + }]; + layer.fillTranslationAnchor = styleValue; + propertyValue = { mbgl::style::Function { + {{ 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 -- cgit v1.2.1