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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core, ios, osx] Version default style URL APIs; deprecated Emerald
Updated default styles from v8 to v9. Deprecated the MGLMapView class methods in favor of new methods that take a version parameter. Deprecated Emerald outright in favor of Outdoors. Replaced usage of the unversioned MGLStyle methods with the corresponding versioned methods and MGLStyleCurrentVersion to ensure consistency. Expanded MGLStyle unit tests to also assert that MGLStyle has the right number of style URL methods and that they’re all public. Linked the OS X SDK unit test bundle to libmbgl-core.a. Removed an unnecessary dependency on osxapp. Replaced Emerald with Outdoors in iosapp and osxapp. Fixes the iOS and OS X side of #4577 and #4702.
- Loading branch information
Showing
17 changed files
with
224 additions
and
92 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,81 @@ | ||
#import "MGLStyle.h" | ||
|
||
#import "NSBundle+MGLAdditions.h" | ||
|
||
#import <mbgl/util/default_styles.hpp> | ||
|
||
#import <XCTest/XCTest.h> | ||
#import <objc/runtime.h> | ||
|
||
@interface MGLStyleTests : XCTestCase | ||
@end | ||
|
||
@implementation MGLStyleTests | ||
|
||
- (void)testStyleURLs { | ||
// Test that all the default styles have publicly-declared MGLStyle class | ||
// methods and that the URLs are all well-formed. | ||
- (void)testUnversionedStyleURLs { | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
XCTAssertEqualObjects([MGLStyle streetsStyleURL].absoluteString, @(mbgl::util::default_styles::streets.url)); | ||
XCTAssertEqualObjects([MGLStyle emeraldStyleURL].absoluteString, @(mbgl::util::default_styles::emerald.url)); | ||
XCTAssertEqualObjects([MGLStyle emeraldStyleURL].absoluteString, @"mapbox://styles/mapbox/emerald-v8"); | ||
XCTAssertEqualObjects([MGLStyle lightStyleURL].absoluteString, @(mbgl::util::default_styles::light.url)); | ||
XCTAssertEqualObjects([MGLStyle darkStyleURL].absoluteString, @(mbgl::util::default_styles::dark.url)); | ||
XCTAssertEqualObjects([MGLStyle satelliteStyleURL].absoluteString, @(mbgl::util::default_styles::satellite.url)); | ||
XCTAssertEqualObjects([MGLStyle hybridStyleURL].absoluteString, @(mbgl::util::default_styles::hybrid.url)); | ||
#pragma clang diagnostic pop | ||
} | ||
|
||
- (void)testVersionedStyleURLs { | ||
// Test that all the default styles have publicly-declared MGLStyle class | ||
// methods and that the URLs all have the right values. | ||
XCTAssertEqualObjects([MGLStyle streetsStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::streets.url)); | ||
XCTAssertEqualObjects([MGLStyle outdoorsStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::outdoors.url)); | ||
XCTAssertEqualObjects([MGLStyle lightStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::light.url)); | ||
XCTAssertEqualObjects([MGLStyle darkStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::dark.url)); | ||
XCTAssertEqualObjects([MGLStyle satelliteStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::satellite.url)); | ||
XCTAssertEqualObjects([MGLStyle hybridStyleURLWithVersion:MGLStyleCurrentVersion].absoluteString, @(mbgl::util::default_styles::hybrid.url)); | ||
|
||
static_assert(6 == mbgl::util::default_styles::numOrderedStyles, | ||
"MGLStyleTests isn’t testing all the styles in mbgl::util::default_styles."); | ||
} | ||
|
||
- (void)testStyleURLComprehensiveness { | ||
// Make sure this test is comprehensive. | ||
const unsigned numImplicitArgs = 2 /* _cmd, self */; | ||
unsigned numMethods = 0; | ||
Method *methods = class_copyMethodList(object_getClass([MGLStyle class]), &numMethods); | ||
unsigned numVersionedMethods = 0; | ||
for (NSUInteger i = 0; i < numMethods; i++) { | ||
Method method = methods[i]; | ||
SEL selector = method_getName(method); | ||
NSString *name = @(sel_getName(selector)); | ||
unsigned numArgs = method_getNumberOfArguments(method); | ||
if ([name hasSuffix:@"StyleURL"]) { | ||
XCTAssertEqual(numArgs, numImplicitArgs, @"Unversioned style URL method should have no parameters, but it has %u.", numArgs - numImplicitArgs); | ||
} else if ([name hasSuffix:@"StyleURLWithVersion:"]) { | ||
XCTAssertEqual(numArgs, numImplicitArgs + 1, @"Versioned style URL method should have one parameter, but it has %u.", numArgs - numImplicitArgs); | ||
numVersionedMethods++; | ||
} else { | ||
XCTAssertEqual([name rangeOfString:@"URL"].location, NSNotFound, @"MGLStyle style URL method %@ is malformed.", name); | ||
} | ||
} | ||
XCTAssertEqual(mbgl::util::default_styles::numOrderedStyles, numVersionedMethods, | ||
@"There are %lu default styles but MGLStyleTests only provides versioned style URL methods for %u of them.", | ||
mbgl::util::default_styles::numOrderedStyles, numVersionedMethods); | ||
|
||
// Test that all the versioned style methods are in the public header. | ||
NSURL *styleHeaderURL = [[[NSBundle mgl_frameworkBundle].bundleURL | ||
URLByAppendingPathComponent:@"Headers" isDirectory:YES] | ||
URLByAppendingPathComponent:@"MGLStyle.h"]; | ||
NSError *styleHeaderError; | ||
NSString *styleHeader = [NSString stringWithContentsOfURL:styleHeaderURL usedEncoding:nil error:&styleHeaderError]; | ||
XCTAssertNil(styleHeaderError, @"Error getting contents of MGLStyle.h."); | ||
|
||
NSError *versionedMethodError; | ||
NSString *versionedMethodExpressionString = @(R"RE(^\+\s*\(NSURL\s*\*\s*\)\s*\w+StyleURLWithVersion\s*:\s*\(\s*NSInteger\s*\)\s*version\s*;)RE"); | ||
NSRegularExpression *versionedMethodExpression = [NSRegularExpression regularExpressionWithPattern:versionedMethodExpressionString options:NSRegularExpressionAnchorsMatchLines error:&versionedMethodError]; | ||
XCTAssertNil(versionedMethodError, @"Error compiling regular expression to search for versioned methods."); | ||
NSUInteger numVersionedMethodDeclarations = [versionedMethodExpression numberOfMatchesInString:styleHeader options:0 range:NSMakeRange(0, styleHeader.length)]; | ||
XCTAssertEqual(numVersionedMethodDeclarations, numVersionedMethods); | ||
} | ||
|
||
@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
Oops, something went wrong.