This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Specialize codegen for heatmap-color property #11074
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7c4ac24
Specialize codegen for heatmap-color property
d2d6877
Add MGLHeatmapColorTests.mm
1bceeee
Add style-spec doc override for `heatmap-color`
a8d31c6
Add heatmap tests to iOS project
0406566
Fix build target for heatmap test files in ios project
ed970d1
Fix incorrect NSExpressions in MGLHeatmapColorTests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#import <Mapbox/Mapbox.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
#import "MGLStyleLayer_Private.h" | ||
|
||
#include <mbgl/style/layers/heatmap_layer.hpp> | ||
|
||
@interface MGLHeatmapColorTests : XCTestCase <MGLMapViewDelegate> | ||
@end | ||
|
||
@implementation MGLHeatmapColorTests | ||
|
||
- (void)testProperties { | ||
MGLPointFeature *feature = [[MGLPointFeature alloc] init]; | ||
MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" shape:feature options:nil]; | ||
MGLHeatmapStyleLayer *layer = [[MGLHeatmapStyleLayer alloc] initWithIdentifier:@"layerID" source:source]; | ||
|
||
auto rawLayer = layer.rawLayer->as<mbgl::style::HeatmapLayer>(); | ||
|
||
XCTAssertTrue(rawLayer->getHeatmapColor().isUndefined(), | ||
@"heatmap-color should be unset initially."); | ||
NSExpression *defaultExpression = layer.heatmapColor; | ||
|
||
NSExpression *constantExpression = [NSExpression expressionWithFormat:@"%@", [MGLColor redColor]]; | ||
layer.heatmapColor = constantExpression; | ||
|
||
|
||
mbgl::style::PropertyValue<float> propertyValue = { 0xff }; | ||
XCTAssertEqual(rawLayer->getHeatmapColor().evaluate(0.0), mbgl::Color::red(), | ||
@"Setting heatmapColor to a constant value expression should update heatmap-color."); | ||
XCTAssertEqualObjects(layer.heatmapColor, constantExpression, | ||
@"heatmapColor should round-trip constant value expressions."); | ||
|
||
constantExpression = [NSExpression expressionWithFormat:@"%@", [MGLColor redColor]]; | ||
NSExpression *constantExpression2 = [NSExpression expressionWithFormat:@"%@", [MGLColor blueColor]]; | ||
NSExpression *functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($heatmapDensity, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@12: constantExpression2}]; | ||
layer.heatmapColor = functionExpression; | ||
|
||
XCTAssertEqual(rawLayer->getHeatmapColor().evaluate(11.0), mbgl::Color::red(), | ||
@"Setting heatmapColor to an expression depending on $heatmapDensity should update heatmap-color."); | ||
XCTAssertEqual(rawLayer->getHeatmapColor().evaluate(12.0), mbgl::Color::blue(), | ||
@"Setting heatmapColor to an expression depending on $heatmapDensity should update heatmap-color."); | ||
XCTAssertEqualObjects(layer.heatmapColor, functionExpression, | ||
@"heatmapColor should round-trip expressions depending on $heatmapDensity."); | ||
|
||
layer.heatmapColor = nil; | ||
XCTAssertTrue(rawLayer->getHeatmapColor().isUndefined(), | ||
@"Unsetting heatmapColor should return heatmap-color to the default value."); | ||
XCTAssertEqualObjects(layer.heatmapColor, defaultExpression, | ||
@"heatmapColor should return the default value after being unset."); | ||
|
||
functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; | ||
XCTAssertThrowsSpecificNamed(layer.heatmapColor = functionExpression, NSException, NSInvalidArgumentException, @"MGLHeatmapLayer should raise an exception if a camera expression is applied to heatmapColor."); | ||
functionExpression = [NSExpression expressionForKeyPath:@"bogus"]; | ||
XCTAssertThrowsSpecificNamed(layer.heatmapColor = functionExpression, NSException, NSInvalidArgumentException, @"MGLHeatmapLayer should raise an exception if a data expression is applied to heatmapColor."); | ||
functionExpression = [NSExpression expressionWithFormat:@"FUNCTION(bogus, 'mgl_stepWithMinimum:stops:', %@, %@)", constantExpression, @{@18: constantExpression}]; | ||
functionExpression = [NSExpression expressionWithFormat:@"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)", @{@10: functionExpression}]; | ||
XCTAssertThrowsSpecificNamed(layer.heatmapColor = functionExpression, NSException, NSInvalidArgumentException, @"MGLHeatmapLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes."); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
07D9474D1F67441B00E37934 /* MGLAbstractShapeSource_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 07D947471F6741F500E37934 /* MGLAbstractShapeSource_Private.h */; }; | ||
07F8E2F71F674C8800F794BB /* MGLComputedShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 07F8E2F41F674C8000F794BB /* MGLComputedShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; | ||
07F8E2F81F674C9000F794BB /* MGLComputedShapeSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07F8E2F51F674C8000F794BB /* MGLComputedShapeSource.mm */; }; | ||
170A82BF201BDD1B00943087 /* MGLHeatmapStyleLayerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 170A82BE201BDD1B00943087 /* MGLHeatmapStyleLayerTests.mm */; }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add this file to the test target in ios.xcodeproj also. |
||
170A82C4201FB6EC00943087 /* MGLHeatmapColorTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 170A82C2201FAFF800943087 /* MGLHeatmapColorTests.mm */; }; | ||
1753ED401E53CE6100A9FD90 /* MGLConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1753ED3F1E53CE5200A9FD90 /* MGLConversion.h */; }; | ||
1F7454A31ECFB00300021D39 /* MGLLight_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F7454A01ECFB00300021D39 /* MGLLight_Private.h */; }; | ||
1F7454A41ECFB00300021D39 /* MGLLight.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F7454A11ECFB00300021D39 /* MGLLight.h */; settings = {ATTRIBUTES = (Public, ); }; }; | ||
|
@@ -301,6 +303,8 @@ | |
07D947491F6741F500E37934 /* MGLAbstractShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAbstractShapeSource.mm; sourceTree = "<group>"; }; | ||
07F8E2F41F674C8000F794BB /* MGLComputedShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLComputedShapeSource.h; sourceTree = "<group>"; }; | ||
07F8E2F51F674C8000F794BB /* MGLComputedShapeSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLComputedShapeSource.mm; sourceTree = "<group>"; }; | ||
170A82BE201BDD1B00943087 /* MGLHeatmapStyleLayerTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLHeatmapStyleLayerTests.mm; sourceTree = "<group>"; }; | ||
170A82C2201FAFF800943087 /* MGLHeatmapColorTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLHeatmapColorTests.mm; sourceTree = "<group>"; }; | ||
1753ED3F1E53CE5200A9FD90 /* MGLConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLConversion.h; sourceTree = "<group>"; }; | ||
1F7454A01ECFB00300021D39 /* MGLLight_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLLight_Private.h; sourceTree = "<group>"; }; | ||
1F7454A11ECFB00300021D39 /* MGLLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLLight.h; sourceTree = "<group>"; }; | ||
|
@@ -884,6 +888,8 @@ | |
DA8F257C1D51C5F40010E6B5 /* Layers */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
170A82C2201FAFF800943087 /* MGLHeatmapColorTests.mm */, | ||
170A82BE201BDD1B00943087 /* MGLHeatmapStyleLayerTests.mm */, | ||
40E1601A1DF216E6005EA6D9 /* MGLStyleLayerTests.h */, | ||
40E1601B1DF216E6005EA6D9 /* MGLStyleLayerTests.m */, | ||
DA2207BA1DC076930002F84D /* test-Bridging-Header.h */, | ||
|
@@ -1577,11 +1583,13 @@ | |
DAE6C3D21CC34C9900DB3429 /* MGLGeometryTests.mm in Sources */, | ||
DA87A9A41DCACC5000810D09 /* MGLSymbolStyleLayerTests.mm in Sources */, | ||
40E1601D1DF217D6005EA6D9 /* MGLStyleLayerTests.m in Sources */, | ||
170A82BF201BDD1B00943087 /* MGLHeatmapStyleLayerTests.mm in Sources */, | ||
1F95931B1E6DE2B600D5B294 /* MGLNSDateAdditionsTests.mm in Sources */, | ||
DAF25721201902C100367EF5 /* MGLHillshadeStyleLayerTests.mm in Sources */, | ||
DA87A9A61DCACC5000810D09 /* MGLCircleStyleLayerTests.mm in Sources */, | ||
DA87A99E1DC9DC2100810D09 /* MGLPredicateTests.mm in Sources */, | ||
DD58A4C91D822C6700E1F038 /* MGLExpressionTests.mm in Sources */, | ||
170A82C4201FB6EC00943087 /* MGLHeatmapColorTests.mm in Sources */, | ||
4031ACFC1E9EB3C100A3EA26 /* MGLMapViewDelegateIntegrationTests.swift in Sources */, | ||
4031AD031E9FD6AA00A3EA26 /* MGLSDKTestHelpers.swift in Sources */, | ||
DA87A9A71DCACC5000810D09 /* MGLBackgroundStyleLayerTests.mm in Sources */, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I just bailed out of generating tests here. I'm thinking it makes sense to just manually create an analogous unit test for
heatmapColor
-- @1ec5 does that sound right to you? If so, where/how's the best way to do that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that’s a fine idea: create a separate file alongside MGLHeatmapStyleLayerTests.mm – like MGLHeatmapColorTests.mm – and add it to the test target of ios.xcodeproj and macos.xcodeproj. Then import the XCTest umbrella header and implement a subclass of XCTestCase.