Home | History | Annotate | Download | only in lang
      1 /* Licensed to the Apache Software Foundation (ASF) under one or more
      2  * contributor license agreements.  See the NOTICE file distributed with
      3  * this work for additional information regarding copyright ownership.
      4  * The ASF licenses this file to You under the Apache License, Version 2.0
      5  * (the "License"); you may not use this file except in compliance with
      6  * the License.  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 
     17 package libcore.java.lang;
     18 
     19 import junit.framework.TestCase;
     20 
     21 public class OldCharacterTest extends TestCase {
     22 
     23     public void test_codePointCountLjava_lang_CharArrayII() {
     24 
     25       assertEquals(1, Character.codePointCount("\uD800\uDC00".toCharArray(),
     26                                                0, 2));
     27       assertEquals(3, Character.codePointCount("a\uD800\uDC00b".toCharArray(),
     28                                                0, 4));
     29       assertEquals(4, Character.codePointCount("a\uD800\uDC00b\uD800".toCharArray(),
     30                                                0, 5));
     31       assertEquals(4, Character.codePointCount("ab\uD800\uDC00b\uD800".toCharArray(),
     32                                                 1, 5));
     33 
     34       try {
     35           Character.codePointCount((char[]) null, 0, 1);
     36           fail("No NPE, null char sequence.");
     37       } catch (NullPointerException e) {
     38       }
     39 
     40       try {
     41           Character.codePointCount("abc".toCharArray(), -1, 1);
     42           fail("No IOOBE, negative start.");
     43       } catch (IndexOutOfBoundsException e) {
     44       }
     45 
     46       try {
     47           Character.codePointCount("abc".toCharArray(), 0, 4);
     48           fail("No IOOBE, end greater than length.");
     49       } catch (IndexOutOfBoundsException e) {
     50       }
     51 
     52       try {
     53           Character.codePointCount("abc".toCharArray(), 1, 3);
     54           fail("No IOOBE, end greater than start.");
     55       } catch (IndexOutOfBoundsException e) {
     56       }
     57     }
     58 
     59     public void test_getDirectionality() throws Exception {
     60 
     61         byte[] directionalities = {
     62                 // BEGIN android-changed
     63                 // Unicode 5.1 defines U+0370 to be Greek capital letter Heta.
     64                 Character.DIRECTIONALITY_LEFT_TO_RIGHT,
     65                 // END android-changed.
     66 
     67                 Character.DIRECTIONALITY_LEFT_TO_RIGHT,
     68                 Character.DIRECTIONALITY_RIGHT_TO_LEFT,
     69 
     70                 // BEGIN android-changed
     71                 // Unicode standard 5.1 changed category of unicode point 0x0600 from AL to AN
     72                 Character.DIRECTIONALITY_ARABIC_NUMBER,
     73                 // END android-changed.
     74 
     75                 Character.DIRECTIONALITY_EUROPEAN_NUMBER,
     76                 // Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR,
     77                 Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR,
     78                 Character.DIRECTIONALITY_ARABIC_NUMBER,
     79                 Character.DIRECTIONALITY_COMMON_NUMBER_SEPARATOR,
     80                 Character.DIRECTIONALITY_NONSPACING_MARK,
     81                 Character.DIRECTIONALITY_BOUNDARY_NEUTRAL,
     82                 Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR,
     83                 Character.DIRECTIONALITY_SEGMENT_SEPARATOR,
     84                 Character.DIRECTIONALITY_WHITESPACE,
     85                 Character.DIRECTIONALITY_OTHER_NEUTRALS,
     86                 Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING,
     87                 Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE,
     88                 Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING,
     89                 Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE,
     90                 Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
     91                 };
     92 
     93         char[] characters = {
     94                 // BEGIN android-changed
     95                 // Unicode 5.1 defines U+0370 to be Greek capital letter Heta.
     96                 '\u0370', // 1
     97                 // END android-changed
     98                 '\u00B5', // 0
     99                 '\u05BE', // 1
    100                 // BEGIN android-changed
    101                 '\u0600', // 6
    102                 // END android-changed
    103                 '\u00B2', // 3
    104                 // '', // No common char in this group on android and java.
    105                 '\u00B1', // 5
    106                 '\u0660', // 6
    107                 '\u00A0', // 7
    108                 '\u0300', // 8
    109                 '\u009F', // 9
    110                 '\u0085', // 10
    111                 '\u001F', // 11
    112                 '\u0020', // 12
    113                 '\u00AB', // 13
    114                 '\u202A', // 14
    115                 '\u202D', // 15
    116                 '\u202B', // 16
    117                 '\u202E', // 17
    118                 '\u202C' // 18
    119                 };
    120 
    121         for(int i = 0; i < directionalities.length; i++) {
    122             assertEquals(directionalities[i],
    123                     Character.getDirectionality(characters[i]));
    124         }
    125 
    126 
    127     }
    128 
    129     public void test_digitCI() {
    130         assertEquals(-1, Character.digit('\uFFFF', 1));
    131     }
    132 
    133     public void test_isUpperCaseC() {
    134         assertFalse("Incorrect case value", Character.isUpperCase('1'));
    135         assertFalse("Incorrect case value", Character.isUpperCase('?'));
    136     }
    137 
    138     public void test_toLowerCaseC() {
    139         assertEquals("Failed to change case", 't', Character.toLowerCase('t'));
    140         assertEquals("Failed to change case", '1', Character.toLowerCase('1'));
    141     }
    142 
    143     public void test_toString() {
    144         assertEquals("Incorrect String returned", "T", new Character('T').toString());
    145         assertEquals("Incorrect String returned", "1", new Character('1').toString());
    146         assertEquals("Incorrect String returned", "$", new Character('$').toString());
    147     }
    148 
    149     public void test_toString_char() {
    150         assertEquals("Incorrect String returned", "T", Character.toString('T'));
    151     }
    152 }
    153