Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Prevent stopless functions - #7309

Merged
frederoni merged 2 commits into
release-ios-v3.4.0from
7249-enforce-stops
Dec 7, 2016
Merged

frederoni merged 2 commits into
release-ios-v3.4.0from
7249-enforce-stops

Conversation

@frederoni

@frederoni frederoni commented Dec 6, 2016 •

Copy link
Copy Markdown
Contributor

Fixes #7249
Raises an exception if an MGLStyleFunction is initialized with no stops.

@frederoni frederoni added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling ✓ ready for review labels Dec 6, 2016
@frederoni frederoni added this to the ios-v3.4.0 milestone Dec 6, 2016
@mention-bot

Copy link
Copy Markdown

@frederoni, thanks for your PR! By analyzing this pull request, we identified @1ec5, @boundsj and @incanus to be potential reviewers.

@frederoni frederoni self-assigned this Dec 6, 2016
Comment thread platform/darwin/src/MGLStyleValue.mm Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stops.count would be more efficient.

Comment thread platform/darwin/src/MGLStyleValue.mm Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[self class] resolves to MGLConstantStyleValue or MGLStyleFunction, but I think self would be more informative since it calls -description.

Comment thread platform/darwin/src/MGLStyleValue.mm Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For internal errors, use NSAssert(). For developer errors, raise an NSException and give it a name like NSInvalidArgumentException that the developer can identify the exception by.

Comment thread platform/darwin/test/MGLFunctionTests.m Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you give the exception a name, you can use XCTAssertThrowsSpecificNamed() here.

Comment thread platform/darwin/test/MGLFunctionTests.m Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s call this MGLStyleValueTests for consistency with the file that contains the implementation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MGLStyleValueTests is taken by a Swift class with the same name but I can't use that class to catch a specific exception name if the method itself doesn't throw the exception. Renamed it to MGLStyleValueObjCTests for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Alternatively, maybe we can call this class MGLStyleValueTests and turn the Swift class into an extension on MGLStyleValueTests. Not sure if XCTest will be happy with that or not.

Comment thread platform/darwin/src/MGLStyleValue.mm Outdated
if (self = [super init]) {
if (!stops.count)
{
[NSException raise:@"NSInvalidArgumentException" format:@"%@ requires at least one stop.", self];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the constant, NSInvalidArgumentException.

@implementation MGLStyleValueObjCTests

- (void)testStoplessFunction {
XCTAssertThrowsSpecificNamed([MGLStyleValue<NSNumber *> valueWithStops:@{}], NSException, @"NSInvalidArgumentException", @"Stopless function should raise an exception");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant NSInvalidArgumentException works here too.

@frederoni
frederoni merged commit 508f020 into release-ios-v3.4.0 Dec 7, 2016
@frederoni
frederoni deleted the 7249-enforce-stops branch December 7, 2016 16:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS runtime styling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants