1 /*
2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /**
25  * @test
26  * @bug 8147531
27  * @summary  Check j.l.Character.getName and codePointOf
28  */
29 
30 package test.java.lang.Character;
31 
32 import android.platform.test.annotations.LargeTest;
33 
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.junit.runners.JUnit4;
37 
38 import java.util.Locale;
39 
40 // Android-changed: Shard the test.
41 @LargeTest
42 @RunWith(JUnit4.class)
43 public class CharacterName {
44 
45     // Android-changed: Shard the test.
46     // public static void main(String[] args) {
47     //    for (int cp = 0; cp < Character.MAX_CODE_POINT; cp++) {
testCodePointRange(int start)48     private static void testCodePointRange(int start) {
49         int end = start + 0x8000;
50         for (int cp = start; cp < end; cp++) {
51             if (!Character.isValidCodePoint(cp)) {
52                 try {
53                     Character.getName(cp);
54                 } catch (IllegalArgumentException x) {
55                     continue;
56                 }
57                 throw new RuntimeException("Invalid failed: " + cp);
58             } else if (Character.getType(cp) == Character.UNASSIGNED) {
59                 if (Character.getName(cp) != null)
60                     throw new RuntimeException("Unsigned failed: " + cp);
61             } else {
62                 String name = Character.getName(cp);
63                 if (cp != Character.codePointOf(name) ||
64                     cp != Character.codePointOf(name.toLowerCase(Locale.ENGLISH)))
65                 throw new RuntimeException("Roundtrip failed: " + cp);
66             }
67         }
68     }
69 
70     // BEGIN Android-added: Shard the test.
71     @Test
testGetName_shard1()72     public void testGetName_shard1() {
73         testCodePointRange(0);
74     }
75     @Test
testGetName_shard2()76     public void testGetName_shard2() {
77         testCodePointRange(0x8000);
78     }
79     @Test
testGetName_shard3()80     public void testGetName_shard3() {
81         testCodePointRange(0x10000);
82     }
83     @Test
testGetName_shard4()84     public void testGetName_shard4() {
85         testCodePointRange(0x18000);
86     }
87     @Test
testGetName_shard5()88     public void testGetName_shard5() {
89         testCodePointRange(0x100000);
90     }
91     @Test
testGetName_shard6()92     public void testGetName_shard6() {
93         testCodePointRange(0x108000);
94     }
95     // END Android-added: Shard the test.
96 }
97