summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java/libcore/icu/ICUTest.java
blob: a7e732c0fcb6b246ea508c98f7878defe00aa982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package libcore.icu;

import java.util.Locale;

public class ICUTest extends junit.framework.TestCase {
    public void test_getISOLanguages() throws Exception {
        // Check that corrupting our array doesn't affect other callers.
        assertNotNull(ICU.getISOLanguages()[0]);
        ICU.getISOLanguages()[0] = null;
        assertNotNull(ICU.getISOLanguages()[0]);
    }

    public void test_getISOCountries() throws Exception {
        // Check that corrupting our array doesn't affect other callers.
        assertNotNull(ICU.getISOCountries()[0]);
        ICU.getISOCountries()[0] = null;
        assertNotNull(ICU.getISOCountries()[0]);
    }

    public void test_getAvailableLocales() throws Exception {
        // Check that corrupting our array doesn't affect other callers.
        assertNotNull(ICU.getAvailableLocales()[0]);
        ICU.getAvailableLocales()[0] = null;
        assertNotNull(ICU.getAvailableLocales()[0]);
    }

    public void test_localeFromString() throws Exception {
        // localeFromString is pretty lenient. Some of these can't be round-tripped
        // through Locale.toString.
        assertEquals(Locale.ENGLISH, ICU.localeFromString("en"));
        assertEquals(Locale.ENGLISH, ICU.localeFromString("en_"));
        assertEquals(Locale.ENGLISH, ICU.localeFromString("en__"));
        assertEquals(Locale.US, ICU.localeFromString("en_US"));
        assertEquals(Locale.US, ICU.localeFromString("en_US_"));
        assertEquals(new Locale("", "US", ""), ICU.localeFromString("_US"));
        assertEquals(new Locale("", "US", ""), ICU.localeFromString("_US_"));
        assertEquals(new Locale("", "", "POSIX"), ICU.localeFromString("__POSIX"));
        assertEquals(new Locale("aa", "BB", "CC"), ICU.localeFromString("aa_BB_CC"));
    }

    public void test_getScript_addLikelySubtags() throws Exception {
        assertEquals("Latn", ICU.getScript(ICU.addLikelySubtags("en_US")));
        assertEquals("Hebr", ICU.getScript(ICU.addLikelySubtags("he")));
        assertEquals("Hebr", ICU.getScript(ICU.addLikelySubtags("he_IL")));
        assertEquals("Hebr", ICU.getScript(ICU.addLikelySubtags("iw")));
        assertEquals("Hebr", ICU.getScript(ICU.addLikelySubtags("iw_IL")));
    }
}