diff --git a/platform/darwin/test/MGLMapSnapshotterTests.m b/platform/darwin/test/MGLMapSnapshotterTests.m index ef5f35ea0f..8296940805 100644 --- a/platform/darwin/test/MGLMapSnapshotterTests.m +++ b/platform/darwin/test/MGLMapSnapshotterTests.m @@ -49,7 +49,7 @@ BOOL MGLEqualImages(MGLImage *leftImage, MGLImage *rightImage) { #endif } -@interface MGLMapSnapshotterTests : XCTestCase +@interface MGLMapSnapshotterTests : XCTestCase @property (nonatomic) XCTestExpectation *styleLoadingExpectation; @property (nonatomic, copy, nullable) void (^runtimeStylingActions)(MGLStyle *style); @@ -62,10 +62,13 @@ - (void)setUp { [super setUp]; [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"]; + + [MGLOfflineStorage sharedOfflineStorage].delegate = self; } - (void)tearDown { [MGLAccountManager setAccessToken:nil]; + [MGLOfflineStorage sharedOfflineStorage].delegate = nil; self.styleLoadingExpectation = nil; self.runtimeStylingActions = nil; [super tearDown]; @@ -138,20 +141,26 @@ - (void)testDelegate { } - (void)testRuntimeStyling { - [self testRuntimeStylingActions:^(MGLStyle *style) { + [self testStyleURL:nil applyingRuntimeStylingActions:^(MGLStyle *style) { MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"background"]; backgroundLayer.backgroundColor = [NSExpression expressionForConstantValue:[MGLColor orangeColor]]; [style addLayer:backgroundLayer]; } expectedImageName:@"Fixtures/MGLMapSnapshotterTests/background"]; } +- (void)testLocalGlyphRendering { + [[NSUserDefaults standardUserDefaults] setObject:@[@"PingFang TC"] forKey:@"MGLIdeographicFontFamilyName"]; + NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"mixed" withExtension:@"json"]; + [self testStyleURL:styleURL applyingRuntimeStylingActions:^(MGLStyle *style) {} expectedImageName:@"Fixtures/MGLMapSnapshotterTests/PingFang"]; +} + /** Tests that applying the given runtime styling actions on a blank style results in a snapshot image that matches the image with the given name in the asset catalog. @param actions Runtime styling actions to apply to the blank style. @param expectedImageName Name of the test fixture image in Media.xcassets. */ -- (void)testRuntimeStylingActions:(void (^)(MGLStyle *style))actions expectedImageName:(NSString *)expectedImageName { +- (void)testStyleURL:(nullable NSURL *)styleURL applyingRuntimeStylingActions:(void (^)(MGLStyle *style))actions expectedImageName:(NSString *)expectedImageName { self.styleLoadingExpectation = [self expectationWithDescription:@"Style should finish loading."]; XCTestExpectation *overlayExpectation = [self expectationWithDescription:@"Overlay handler should get called."]; XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion handler should get called."]; @@ -163,9 +172,15 @@ - (void)testRuntimeStylingActions:(void (^)(MGLStyle *style))actions expectedIma #endif XCTAssertNotNil(expectedImage, @"Image fixture “%@” missing from Media.xcassets.", expectedImageName); - NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; + if (!styleURL) { + styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; + } MGLMapCamera *camera = [MGLMapCamera camera]; - MGLMapSnapshotOptions *options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:styleURL camera:camera size:CGSizeMake(500, 500)]; + camera.centerCoordinate = kCLLocationCoordinate2DInvalid; + camera.heading = -1; + camera.pitch = -1; + MGLMapSnapshotOptions *options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:styleURL camera:camera size:expectedImage.size]; + options.zoomLevel = -1; MGLMapSnapshotter *snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options]; snapshotter.delegate = self; @@ -183,8 +198,8 @@ - (void)testRuntimeStylingActions:(void (^)(MGLStyle *style))actions expectedIma XCTAssertNil(error); XCTAssertNotNil(snapshot); if (snapshot) { - XCTAssertEqual(snapshot.image.size.width, 500); - XCTAssertEqual(snapshot.image.size.height, 500); + XCTAssertEqual(snapshot.image.size.width, expectedImage.size.width); + XCTAssertEqual(snapshot.image.size.height, expectedImage.size.height); } [completionExpectation fulfill]; }]; @@ -205,4 +220,13 @@ - (void)mapSnapshotter:(MGLMapSnapshotter *)snapshotter didFinishLoadingStyle:(M [self.styleLoadingExpectation fulfill]; } +#pragma mark MGLOfflineStorageDelegate methods + +- (NSURL *)offlineStorage:(MGLOfflineStorage *)storage URLForResourceOfKind:(MGLResourceKind)kind withURL:(NSURL *)url { + if (kind == MGLResourceKindGlyphs && [url.scheme isEqualToString:@"local"]) { + return [[NSBundle bundleForClass:[self class]] URLForResource:@"glyphs" withExtension:@"pbf"]; + } + return url; +} + @end diff --git a/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/Contents.json b/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/Contents.json new file mode 100644 index 0000000000..42d77b97c9 --- /dev/null +++ b/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "filename" : "expected.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "actualImage.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/actualImage.png b/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/actualImage.png new file mode 100644 index 0000000000..01dae8b103 Binary files /dev/null and b/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/actualImage.png differ diff --git a/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/expected.png b/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/expected.png new file mode 100644 index 0000000000..6e7e5c80b9 Binary files /dev/null and b/platform/darwin/test/Media.xcassets/Fixtures/MGLMapSnapshotterTests/PingFang.imageset/expected.png differ diff --git a/platform/darwin/test/one-liner.json b/platform/darwin/test/one-liner.json index 23c546181f..7888811e92 100644 --- a/platform/darwin/test/one-liner.json +++ b/platform/darwin/test/one-liner.json @@ -1 +1 @@ -{"version":8,"sources":{},"layers":[]} \ No newline at end of file +{"version":8,"sources":{},"layers":[],"center":[0,0],"zoom":0} diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 88ddfc43ae..ca1c7a8002 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -635,6 +635,8 @@ DAC25FCD200FD83F009BE98E /* NSExpression+MGLPrivateAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC25FCB200FD83E009BE98E /* NSExpression+MGLPrivateAdditions.h */; }; DAC49C5C1CD02BC9009E1AA3 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = DAC49C5F1CD02BC9009E1AA3 /* Localizable.stringsdict */; }; DAC49C5D1CD02BC9009E1AA3 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = DAC49C5F1CD02BC9009E1AA3 /* Localizable.stringsdict */; }; + DAC8A48024527EDC00C795BB /* glyphs.pbf in Resources */ = {isa = PBXBuildFile; fileRef = DAC8A47F24527EDB00C795BB /* glyphs.pbf */; }; + DAC8A4822452971B00C795BB /* mixed.json in Resources */ = {isa = PBXBuildFile; fileRef = DAC8A4812452971B00C795BB /* mixed.json */; }; DACA86262019218600E9693A /* MGLRasterDEMSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DACA86242019218500E9693A /* MGLRasterDEMSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; DACA86272019218600E9693A /* MGLRasterDEMSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DACA86242019218500E9693A /* MGLRasterDEMSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; DACA86282019218600E9693A /* MGLRasterDEMSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = DACA86252019218500E9693A /* MGLRasterDEMSource.mm */; }; @@ -1281,6 +1283,8 @@ DAC49C621CD07D74009E1AA3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = ""; }; DAC832642404AF9000A61BF8 /* darwin.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = darwin.xcconfig; path = ../darwin/darwin.xcconfig; sourceTree = ""; }; DAC832672404AFBB00A61BF8 /* ci.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = ci.xcconfig; path = ../darwin/ci.xcconfig; sourceTree = ""; }; + DAC8A47F24527EDB00C795BB /* glyphs.pbf */ = {isa = PBXFileReference; lastKnownFileType = file; name = glyphs.pbf; path = "../../../vendor/mapbox-gl-native/test/fixtures/resources/glyphs.pbf"; sourceTree = ""; }; + DAC8A4812452971B00C795BB /* mixed.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = mixed.json; path = "../../../vendor/mapbox-gl-native/test/fixtures/local_glyphs/mixed.json"; sourceTree = ""; }; DACA86242019218500E9693A /* MGLRasterDEMSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLRasterDEMSource.h; sourceTree = ""; }; DACA86252019218500E9693A /* MGLRasterDEMSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLRasterDEMSource.mm; sourceTree = ""; }; DACBC60B20118ABE00C4D7E2 /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = ""; }; @@ -1888,6 +1892,8 @@ DA2E88601CC0382C00F24E7B /* MGLStyleTests.mm */, 556660D71E1D085500E2C41B /* MGLVersionNumber.m */, DA35D0871E1A6309007DED41 /* one-liner.json */, + DAC8A4812452971B00C795BB /* mixed.json */, + DAC8A47F24527EDB00C795BB /* glyphs.pbf */, 357579811D502AD4000B822E /* Styling */, 409F43FB1E9E77D10048729D /* Swift Integration */, 4031ACFD1E9FD26900A3EA26 /* Test Helpers */, @@ -2858,6 +2864,8 @@ DA2784FC1DF02FF4001D5B8D /* Media.xcassets in Resources */, 353BAEF71D646370009A8DA9 /* amsterdam.geojson in Resources */, DA35D0881E1A6309007DED41 /* one-liner.json in Resources */, + DAC8A4822452971B00C795BB /* mixed.json in Resources */, + DAC8A48024527EDC00C795BB /* glyphs.pbf in Resources */, 1F7839A6235E137000D4D606 /* sideload_sat.db in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/CI.xcscheme b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/CI.xcscheme index dc80638800..a659022100 100644 --- a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/CI.xcscheme +++ b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/CI.xcscheme @@ -71,6 +71,11 @@ BlueprintName = "test" ReferencedContainer = "container:ios.xcodeproj"> + + + + diff --git a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic+static.xcscheme b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic+static.xcscheme index 7f3eea47cd..9446478be5 100644 --- a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic+static.xcscheme +++ b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic+static.xcscheme @@ -74,6 +74,11 @@ BlueprintName = "test" ReferencedContainer = "container:ios.xcodeproj"> + + + + diff --git a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme index 84f1427762..16b4bf1845 100644 --- a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme +++ b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme @@ -63,6 +63,11 @@ BlueprintName = "test" ReferencedContainer = "container:ios.xcodeproj"> + + + + diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 79d96223eb..6b301ca71c 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -210,6 +210,8 @@ DAC2ABC51CC6D343006D18C4 /* MGLAnnotationImage_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC2ABC41CC6D343006D18C4 /* MGLAnnotationImage_Private.h */; }; DAC8325F24049D8700A61BF8 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = DAE6C3C61CC3499100DB3429 /* libsqlite3.tbd */; }; DAC8326024049D9C00A61BF8 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D9B4B01D005D3900C1CCE2 /* libz.tbd */; }; + DAC8A47E24527EBB00C795BB /* glyphs.pbf in Resources */ = {isa = PBXBuildFile; fileRef = DAC8A47D24527EBB00C795BB /* glyphs.pbf */; }; + DAC8A4842452972F00C795BB /* mixed.json in Resources */ = {isa = PBXBuildFile; fileRef = DAC8A4832452972F00C795BB /* mixed.json */; }; DACA8622201920BE00E9693A /* MGLRasterDEMSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DACA8620201920BE00E9693A /* MGLRasterDEMSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; DACA8623201920BE00E9693A /* MGLRasterDEMSource.mm in Sources */ = {isa = PBXBuildFile; fileRef = DACA8621201920BE00E9693A /* MGLRasterDEMSource.mm */; }; DACB0C391E18DFFD005DDBEA /* MGLStyle+MBXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DACB0C381E18DFFD005DDBEA /* MGLStyle+MBXAdditions.m */; }; @@ -615,6 +617,8 @@ DAC832652404AF9E00A61BF8 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = ../../Makefile; sourceTree = ""; }; DAC832662404AFB400A61BF8 /* ci.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = ci.xcconfig; path = ../darwin/ci.xcconfig; sourceTree = ""; }; DAC832682404B26400A61BF8 /* jazzy.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = jazzy.yml; sourceTree = ""; }; + DAC8A47D24527EBB00C795BB /* glyphs.pbf */ = {isa = PBXFileReference; lastKnownFileType = file; name = glyphs.pbf; path = "../../../vendor/mapbox-gl-native/test/fixtures/resources/glyphs.pbf"; sourceTree = ""; }; + DAC8A4832452972F00C795BB /* mixed.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = mixed.json; path = "../../../vendor/mapbox-gl-native/test/fixtures/local_glyphs/mixed.json"; sourceTree = ""; }; DACA8620201920BE00E9693A /* MGLRasterDEMSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLRasterDEMSource.h; sourceTree = ""; }; DACA8621201920BE00E9693A /* MGLRasterDEMSource.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLRasterDEMSource.mm; sourceTree = ""; }; DACB0C371E18DFFD005DDBEA /* MGLStyle+MBXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLStyle+MBXAdditions.h"; sourceTree = ""; }; @@ -1221,6 +1225,8 @@ DAE6C3CC1CC34BD800DB3429 /* MGLStyleTests.mm */, 556660D51E1D07E400E2C41B /* MGLVersionNumber.m */, DA35D0891E1A631B007DED41 /* one-liner.json */, + DAC8A4832452972F00C795BB /* mixed.json */, + DAC8A47D24527EBB00C795BB /* glyphs.pbf */, 1F8A59F921653483004DFE75 /* sideload_sat.db */, DA8F257D1D51C5F40010E6B5 /* Styling */, 4031ACFA1E9EB39A00A3EA26 /* Swift Integration */, @@ -1643,6 +1649,8 @@ 35724FC41D630502002A4AB4 /* amsterdam.geojson in Resources */, DA2784FE1DF03060001D5B8D /* Media.xcassets in Resources */, DA35D08A1E1A631B007DED41 /* one-liner.json in Resources */, + DAC8A4842452972F00C795BB /* mixed.json in Resources */, + DAC8A47E24527EBB00C795BB /* glyphs.pbf in Resources */, 1F8A59FA21653483004DFE75 /* sideload_sat.db in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/CI.xcscheme b/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/CI.xcscheme index 5449adcb6d..601c152e85 100644 --- a/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/CI.xcscheme +++ b/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/CI.xcscheme @@ -62,6 +62,11 @@ BlueprintName = "test" ReferencedContainer = "container:macos.xcodeproj"> + + + + diff --git a/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme b/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme index 55a36344d5..5c8f95f9d1 100644 --- a/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme +++ b/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/dynamic.xcscheme @@ -62,6 +62,11 @@ BlueprintName = "test" ReferencedContainer = "container:macos.xcodeproj"> + + + + diff --git a/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/macosapp.xcscheme b/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/macosapp.xcscheme index 98e6c54a33..e94969afa9 100644 --- a/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/macosapp.xcscheme +++ b/platform/macos/macos.xcodeproj/xcshareddata/xcschemes/macosapp.xcscheme @@ -48,6 +48,11 @@ BlueprintName = "test" ReferencedContainer = "container:macos.xcodeproj"> + + + +