Victor Chang | c1463ec | 2018-11-27 12:40:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 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,d |
| 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 android.text; |
| 18 | |
| 19 | import static org.junit.Assert.assertArrayEquals; |
| 20 | |
| 21 | import android.platform.test.annotations.Presubmit; |
| 22 | import android.support.test.filters.SmallTest; |
| 23 | |
| 24 | import org.junit.Test; |
| 25 | |
| 26 | @Presubmit |
| 27 | @SmallTest |
| 28 | public class AndroidCharacterTest { |
| 29 | |
| 30 | @Test |
| 31 | public void testGetDirectionalities_nonSupplementaryCharacters() { |
| 32 | int size = Character.MAX_VALUE + 1 |
| 33 | - (Character.MAX_SURROGATE - Character.MIN_SURROGATE + 1); |
| 34 | char[] chars = new char[size]; |
| 35 | byte[] java_lang_results = new byte[size]; |
| 36 | int index = 0; |
| 37 | for (int cp = 0; cp <= Character.MAX_VALUE; cp++) { |
Victor Chang | 749d184 | 2018-11-27 16:43:20 +0000 | [diff] [blame] | 38 | if (cp < Character.MIN_SURROGATE || cp > Character.MAX_SURROGATE) { |
| 39 | chars[index] = (char) cp; |
| 40 | java_lang_results[index] = Character.getDirectionality(cp); |
| 41 | index++; |
Victor Chang | c1463ec | 2018-11-27 12:40:23 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | byte[] android_text_results = new byte[size]; |
| 46 | AndroidCharacter.getDirectionalities(chars, android_text_results, index); |
| 47 | assertArrayEquals(java_lang_results, android_text_results); |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void testGetDirectionalities_supplementaryCharacters() { |
| 52 | int maxNumberOfChars = Character.MAX_CODE_POINT - Character.MIN_SUPPLEMENTARY_CODE_POINT |
| 53 | + 1; |
| 54 | int size = maxNumberOfChars * 2; |
| 55 | char[] chars = new char[size]; |
| 56 | byte[] java_lang_results = new byte[size]; |
| 57 | int index = 0; |
| 58 | for (int cp = Character.MIN_SUPPLEMENTARY_CODE_POINT; cp <= Character.MAX_CODE_POINT; |
| 59 | cp++) { |
Victor Chang | 749d184 | 2018-11-27 16:43:20 +0000 | [diff] [blame] | 60 | chars[index] = Character.highSurrogate(cp); |
| 61 | chars[index + 1] = Character.lowSurrogate(cp); |
| 62 | java_lang_results[index] = java_lang_results[index + 1] = Character |
| 63 | .getDirectionality(cp); |
| 64 | index += 2; |
Victor Chang | c1463ec | 2018-11-27 12:40:23 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | byte[] android_text_results = new byte[size]; |
| 68 | AndroidCharacter.getDirectionalities(chars, android_text_results, index); |
| 69 | assertArrayEquals(java_lang_results, android_text_results); |
| 70 | } |
| 71 | } |