|
| 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