Skip to content

Commit c153164

Browse files
authored
Merge pull request #80 from isaacbrodsky/turkish-locale-test
Test for Turkish locale
2 parents 9673882 + 7676e1c commit c153164

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed

src/main/java/com/uber/h3core/H3CoreLoader.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.io.InputStream;
2222
import java.io.OutputStream;
23+
import java.util.Locale;
2324

2425
/**
2526
* Extracts the native H3 core library to the local filesystem and loads it.
@@ -29,6 +30,12 @@ private H3CoreLoader() {
2930
// Prevent instantiation
3031
}
3132

33+
/**
34+
* Locale used when handling system strings that need to be mapped to resource names.
35+
* English is used since that locale was used when building the library.
36+
*/
37+
static final Locale H3_CORE_LOCALE = Locale.ENGLISH;
38+
3239
// Supported H3 architectures
3340
static final String ARCH_X64 = "x64";
3441
static final String ARCH_X86 = "x86";
@@ -167,7 +174,7 @@ public String getSuffix() {
167174
* How this operating system's name is rendered when extracting the native library.
168175
*/
169176
public String getDirName() {
170-
return name().toLowerCase();
177+
return name().toLowerCase(H3_CORE_LOCALE);
171178
}
172179
}
173180

@@ -180,11 +187,11 @@ public String getDirName() {
180187
static final OperatingSystem detectOs(String javaVendor, String osName) {
181188
// Detecting Android using the properties from:
182189
// https://developer.android.com/reference/java/lang/System.html
183-
if (javaVendor.toLowerCase().contains("android")) {
190+
if (javaVendor.toLowerCase(H3_CORE_LOCALE).contains("android")) {
184191
return OperatingSystem.ANDROID;
185192
}
186193

187-
String javaOs = osName.toLowerCase();
194+
String javaOs = osName.toLowerCase(H3_CORE_LOCALE);
188195
if (javaOs.contains("mac")) {
189196
return OperatingSystem.DARWIN;
190197
} else if (javaOs.contains("win")) {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2017-2018 Uber Technologies, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.uber.h3core;
17+
18+
import org.junit.AfterClass;
19+
import org.junit.BeforeClass;
20+
import org.junit.Ignore;
21+
import org.junit.Test;
22+
23+
import javax.annotation.concurrent.NotThreadSafe;
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.util.Locale;
27+
28+
import static org.junit.Assert.assertEquals;
29+
30+
/**
31+
* H3CoreLoader is mostly tested by {@link TestH3Core}. This also tests OS detection under different locales.
32+
*/
33+
@NotThreadSafe
34+
public class TestH3CoreLoaderLocale {
35+
private static Locale systemLocale;
36+
37+
@BeforeClass
38+
public static void setup() {
39+
systemLocale = Locale.getDefault();
40+
// Turkish is used as the test locale as the Turkish lower case I
41+
// is dotless and this frequently triggers locale-dependent bugs.
42+
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
43+
}
44+
45+
@AfterClass
46+
public static void tearDown() {
47+
Locale.setDefault(systemLocale);
48+
}
49+
50+
@Test
51+
public void testDetectOs() {
52+
assertEquals(H3CoreLoader.OperatingSystem.ANDROID,
53+
H3CoreLoader.detectOs("ANDROID", "anything"));
54+
assertEquals(H3CoreLoader.OperatingSystem.WINDOWS,
55+
H3CoreLoader.detectOs("vendor", "WINDOWS"));
56+
assertEquals(H3CoreLoader.OperatingSystem.LINUX,
57+
H3CoreLoader.detectOs("vendor", "LINUX"));
58+
59+
assertEquals(H3CoreLoader.OperatingSystem.LINUX,
60+
H3CoreLoader.detectOs("vendor", "anything else"));
61+
}
62+
63+
@Test
64+
public void testDetectArch() {
65+
assertEquals("I386", H3CoreLoader.detectArch("I386"));
66+
}
67+
68+
@Test
69+
public void testOsDir() {
70+
assertEquals("Turkish lower case I (Darwin)", "darwin", H3CoreLoader.OperatingSystem.DARWIN.getDirName());
71+
assertEquals("Turkish lower case I (Linux)", "linux", H3CoreLoader.OperatingSystem.LINUX.getDirName());
72+
assertEquals("Turkish lower case I (Windows)", "windows", H3CoreLoader.OperatingSystem.WINDOWS.getDirName());
73+
assertEquals("Turkish lower case I (Android)", "android", H3CoreLoader.OperatingSystem.ANDROID.getDirName());
74+
}
75+
}

0 commit comments

Comments
 (0)