summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2019-04-15 10:52:40 -0700
committerFabian Guerra <fabian.guerra@mapbox.com>2019-04-15 11:53:21 -0700
commita68aa781630f08e99dfcaff0c06d3589d9dba79b (patch)
tree3e3f502fa0edfa73322a00129f112dd0a9c02ec1
parentcb4dfd9521d8051bb4a364aa998abcadd2a87d32 (diff)
downloadqtlocation-mapboxgl-upstream/fabian-style-localization-test.tar.gz
[ios, macos] Add style's text localization tests.upstream/fabian-style-localization-test
-rw-r--r--platform/darwin/test/MGLStyleTests.mm51
-rw-r--r--platform/darwin/test/basic-style.json53
-rw-r--r--platform/darwin/test/one-liner.json2
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj6
-rw-r--r--platform/macos/macos.xcodeproj/project.pbxproj4
5 files changed, 103 insertions, 13 deletions
diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm
index 7aaf70a80a..3ba6d6f2b7 100644
--- a/platform/darwin/test/MGLStyleTests.mm
+++ b/platform/darwin/test/MGLStyleTests.mm
@@ -28,7 +28,7 @@
[super setUp];
[MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"];
- NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
+ NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"basic-style" withExtension:@"json"];
self.mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) styleURL:styleURL];
self.mapView.delegate = self;
if (!self.mapView.style) {
@@ -140,11 +140,8 @@
- (void)testSources {
NSSet<MGLSource *> *initialSources = self.style.sources;
- if ([initialSources.anyObject.identifier isEqualToString:@"com.mapbox.annotations"]) {
- XCTAssertEqual(self.style.sources.count, 1UL);
- } else {
- XCTAssertEqual(self.style.sources.count, 0UL);
- }
+ XCTAssertTrue(initialSources.count <= 2);
+
MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shapeSource" shape:nil options:nil];
[self.style addSource:shapeSource];
XCTAssertEqual(self.style.sources.count, initialSources.count + 1);
@@ -250,11 +247,9 @@
- (void)testLayers {
NSArray<MGLStyleLayer *> *initialLayers = self.style.layers;
- if ([initialLayers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) {
- XCTAssertEqual(self.style.layers.count, 1UL);
- } else {
- XCTAssertEqual(self.style.layers.count, 0UL);
- }
+
+ XCTAssertTrue(initialLayers.count <= 2);
+
MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shapeSource" shape:nil options:nil];
[self.style addSource:shapeSource];
MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fillLayer" source:shapeSource];
@@ -396,6 +391,8 @@
NSURL *url = [NSURL fileURLWithPath:filePath];
MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"sourceID" URL:url options:nil];
[self.style addSource:source];
+
+ NSUInteger startIndex = self.style.layers.count;
MGLCircleStyleLayer *layer1 = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"layer1" source:source];
[self.style addLayer:layer1];
@@ -413,7 +410,7 @@
[self.style insertLayer:layer0 belowLayer:layer1];
NSArray<MGLStyleLayer *> *layers = [self.style layers];
- NSUInteger startIndex = 0;
+
if ([layers.firstObject.identifier isEqualToString:@"com.mapbox.annotations.points"]) {
startIndex++;
}
@@ -427,6 +424,36 @@
#pragma mark Localization tests
+- (void)testLocalization {
+ MGLSymbolStyleLayer *countryLabel = (MGLSymbolStyleLayer *)[self.style layerWithIdentifier:@"country-label"];
+ {
+ NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"de_DE"];
+ [self.style localizeLabelsIntoLocale:locale];
+
+ NSArray * keypathArray = @[ [NSExpression expressionForKeyPath:@"name_de"],
+ [NSExpression expressionForKeyPath:@"name"]];
+ NSExpression *coalesceExpression = [NSExpression expressionWithFormat:@"mgl_coalesce:(%@)", @[ [NSExpression expressionWithFormat:@"mgl_coalesce:(%@)", keypathArray],
+ [NSExpression expressionWithFormat:@"mgl_coalesce:(%@)", keypathArray] ]];
+ MGLAttributedExpression *attributedExpression = [MGLAttributedExpression attributedExpression:coalesceExpression attributes:@{}];
+ NSExpression *localizedExpression = [NSExpression mgl_expressionForAttributedExpressions:@[ [NSExpression expressionForConstantValue:attributedExpression] ]];
+ XCTAssertEqualObjects(countryLabel.text, localizedExpression);
+ countryLabel.text = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
+ }
+ {
+ NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"es"];
+ [self.style localizeLabelsIntoLocale:locale];
+
+ NSArray * keypathArray = @[ [NSExpression expressionForKeyPath:@"name_es"],
+ [NSExpression expressionForKeyPath:@"name"]];
+ NSExpression *coalesceExpression = [NSExpression expressionWithFormat:@"mgl_coalesce:(%@)", @[ [NSExpression expressionWithFormat:@"mgl_coalesce:(%@)", keypathArray],
+ [NSExpression expressionWithFormat:@"mgl_coalesce:(%@)", keypathArray] ]];
+ MGLAttributedExpression *attributedExpression = [MGLAttributedExpression attributedExpression:coalesceExpression attributes:@{}];
+ NSExpression *localizedExpression = [NSExpression mgl_expressionForAttributedExpressions:@[ [NSExpression expressionForConstantValue:attributedExpression] ]];
+ XCTAssertEqualObjects(countryLabel.text, localizedExpression);
+ countryLabel.text = [NSExpression expressionWithFormat:@"mgl_coalesce({%K, %K})", @"name_en", @"name"];
+ }
+}
+
- (void)testLanguageMatching {
{
NSArray *preferences = @[@"en"];
diff --git a/platform/darwin/test/basic-style.json b/platform/darwin/test/basic-style.json
new file mode 100644
index 0000000000..a9b42ddf4a
--- /dev/null
+++ b/platform/darwin/test/basic-style.json
@@ -0,0 +1,53 @@
+{
+ "version": 8,
+ "sources": {
+ "composite": {
+ "url": "mapbox://mapbox.mapbox-streets-v8",
+ "type": "vector"
+ }
+ },
+ "layers": [
+ {
+ "id": "country-label",
+ "type": "symbol",
+ "source": "composite",
+ "source-layer": "place_label",
+ "minzoom": 3,
+ "maxzoom": 8,
+ "filter": ["==", ["get", "type"], "country"],
+ "layout": {
+ "text-field": ["coalesce", ["get", "name_en"], ["get", "name"]],
+ "text-max-width": [
+ "interpolate",
+ ["linear"],
+ ["zoom"],
+ 0,
+ 5,
+ 3,
+ 6
+ ],
+ "text-font": [
+ "step",
+ ["zoom"],
+ ["literal", ["Roboto Medium", "Arial Unicode MS Regular"]],
+ 4,
+ ["literal", ["Roboto Bold", "Arial Unicode MS Bold"]]
+ ],
+ "text-size": [
+ "interpolate",
+ ["linear"],
+ ["zoom"],
+ 1,
+ ["step", ["get", "symbolrank"], 12, 3, 10, 5, 9],
+ 9,
+ ["step", ["get", "symbolrank"], 35, 3, 27, 5, 22]
+ ]
+ },
+ "paint": {
+ "text-halo-width": 1.5,
+ "text-halo-color": "hsla(0, 0%, 100%, 0.95)",
+ "text-color": "hsl(0, 0%, 0%)"
+ }
+ }
+ ]
+}
diff --git a/platform/darwin/test/one-liner.json b/platform/darwin/test/one-liner.json
index 23c546181f..3986412580 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":[]}
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 42e30b1417..ae812c1a6f 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -69,6 +69,8 @@
1FF48588223710BE00F19727 /* MGLAttributedExpression.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FF48585223710BE00F19727 /* MGLAttributedExpression.h */; settings = {ATTRIBUTES = (Public, ); }; };
1FF48589223710BE00F19727 /* MGLAttributedExpression.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FF48586223710BE00F19727 /* MGLAttributedExpression.m */; };
1FF4858A223710BE00F19727 /* MGLAttributedExpression.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FF48586223710BE00F19727 /* MGLAttributedExpression.m */; };
+ 1FFAEDB822650A23009A1B2A /* basic-style.json in Resources */ = {isa = PBXBuildFile; fileRef = 1FFAEDB722650A23009A1B2A /* basic-style.json */; };
+ 1FFAEDB922650A23009A1B2A /* basic-style.json in Resources */ = {isa = PBXBuildFile; fileRef = 1FFAEDB722650A23009A1B2A /* basic-style.json */; };
30E578171DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; };
30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */; };
30E578191DAA855E0050F07E /* UIImage+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 30E578121DAA7D690050F07E /* UIImage+MGLAdditions.mm */; };
@@ -856,6 +858,7 @@
1FDB00CB21F8F15300D21389 /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = cs; path = cs.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
1FF48585223710BE00F19727 /* MGLAttributedExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLAttributedExpression.h; sourceTree = "<group>"; };
1FF48586223710BE00F19727 /* MGLAttributedExpression.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLAttributedExpression.m; sourceTree = "<group>"; };
+ 1FFAEDB722650A23009A1B2A /* basic-style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "basic-style.json"; path = "../../darwin/test/basic-style.json"; sourceTree = "<group>"; };
20DABE861DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Foundation.strings"; sourceTree = "<group>"; };
20DABE881DF78148007AC5FF /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
30E578111DAA7D690050F07E /* UIImage+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImage+MGLAdditions.h"; path = "src/UIImage+MGLAdditions.h"; sourceTree = SOURCE_ROOT; };
@@ -1925,6 +1928,7 @@
DA2E88551CC036F400F24E7B /* Info.plist */,
DA2784FB1DF02FF4001D5B8D /* Media.xcassets */,
DA35D0871E1A6309007DED41 /* one-liner.json */,
+ 1FFAEDB722650A23009A1B2A /* basic-style.json */,
1F8A59F62165326C004DFE75 /* sideload_sat.db */,
);
name = "SDK Tests";
@@ -2852,6 +2856,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 1FFAEDB922650A23009A1B2A /* basic-style.json in Resources */,
16376B471FFDB92B0000563E /* one-liner.json in Resources */,
1F8A59F821653275004DFE75 /* sideload_sat.db in Resources */,
);
@@ -2895,6 +2900,7 @@
1F8A59F72165326D004DFE75 /* sideload_sat.db in Resources */,
353BAEF71D646370009A8DA9 /* amsterdam.geojson in Resources */,
DA35D0881E1A6309007DED41 /* one-liner.json in Resources */,
+ 1FFAEDB822650A23009A1B2A /* basic-style.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj
index 91ed2f4cfa..fe15a414de 100644
--- a/platform/macos/macos.xcodeproj/project.pbxproj
+++ b/platform/macos/macos.xcodeproj/project.pbxproj
@@ -35,6 +35,7 @@
1FCCEC55222EF9FE00302E3B /* MGLSDKMetricsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FCCEC52222EF9FE00302E3B /* MGLSDKMetricsManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
1FF4858D2237235300F19727 /* MGLAttributedExpression.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FF4858B2237235200F19727 /* MGLAttributedExpression.m */; };
1FF4858E2237235300F19727 /* MGLAttributedExpression.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FF4858C2237235200F19727 /* MGLAttributedExpression.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 1FFAEDBB22650A7E009A1B2A /* basic-style.json in Resources */ = {isa = PBXBuildFile; fileRef = 1FFAEDBA22650A7D009A1B2A /* basic-style.json */; };
3508EC641D749D39009B0EE4 /* NSExpression+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
3508EC651D749D39009B0EE4 /* NSExpression+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */; };
3526EABD1DF9B19800006B43 /* MGLCodingTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3526EABC1DF9B19800006B43 /* MGLCodingTests.mm */; };
@@ -355,6 +356,7 @@
1FDB00CD21F8F1FF00D21389 /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/Localizable.strings; sourceTree = "<group>"; };
1FF4858B2237235200F19727 /* MGLAttributedExpression.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLAttributedExpression.m; sourceTree = "<group>"; };
1FF4858C2237235200F19727 /* MGLAttributedExpression.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributedExpression.h; sourceTree = "<group>"; };
+ 1FFAEDBA22650A7D009A1B2A /* basic-style.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "basic-style.json"; path = "../../darwin/test/basic-style.json"; sourceTree = "<group>"; };
3508EC621D749D39009B0EE4 /* NSExpression+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSExpression+MGLAdditions.h"; sourceTree = "<group>"; };
3508EC631D749D39009B0EE4 /* NSExpression+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSExpression+MGLAdditions.mm"; sourceTree = "<group>"; };
3526EABC1DF9B19800006B43 /* MGLCodingTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLCodingTests.mm; path = ../../darwin/test/MGLCodingTests.mm; sourceTree = "<group>"; };
@@ -1196,6 +1198,7 @@
DAE6C33A1CC30DB200DB3429 /* Info.plist */,
DA2784FD1DF03060001D5B8D /* Media.xcassets */,
DA35D0891E1A631B007DED41 /* one-liner.json */,
+ 1FFAEDBA22650A7D009A1B2A /* basic-style.json */,
1F8A59F921653483004DFE75 /* sideload_sat.db */,
);
name = "SDK Tests";
@@ -1603,6 +1606,7 @@
DA2784FE1DF03060001D5B8D /* Media.xcassets in Resources */,
DA35D08A1E1A631B007DED41 /* one-liner.json in Resources */,
1F8A59FA21653483004DFE75 /* sideload_sat.db in Resources */,
+ 1FFAEDBB22650A7E009A1B2A /* basic-style.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};