1 /* 2 * Copyright 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, 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.assertEquals; 20 import static org.junit.Assert.assertTrue; 21 22 import android.icu.lang.UCharacterDirection; 23 import android.icu.text.Bidi; 24 import android.support.test.filters.SmallTest; 25 import android.support.test.runner.AndroidJUnit4; 26 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 30 /** 31 * Emoji and ICU drops does not happen at the same time. Therefore there are almost always cases 32 * where the existing ICU version is not aware of the latest emoji that Android supports. 33 * This test covers Emoji and ICU related functions where other components such as 34 * {@link AndroidBidi}, {@link BidiFormatter} depend on. The tests are collected into the same 35 * class since the changes effect all those classes. 36 */ 37 @SmallTest 38 @RunWith(AndroidJUnit4.class) 39 public class EmojiTest { 40 41 @Test 42 public void testIsNewEmoji_Emoji5() { 43 // each row in the data is the range of emoji 44 final int[][][] data = new int[][][]{ 45 { // EMOJI 5 46 // range of emoji: i.e from 0x1F6F7 to 0x1F6F8 inclusive 47 {0x1F6F7, 0x1F6F8}, 48 {0x1F91F, 0x1F91F}, 49 {0x1F928, 0x1F92F}, 50 {0x1F94C, 0x1F94C}, 51 {0x1F95F, 0x1F96B}, 52 {0x1F992, 0x1F997}, 53 {0x1F9D0, 0x1F9E6}, 54 }, 55 { // EMOJI 11 56 {0x265F, 0x265F}, 57 {0x267E, 0x267E}, 58 {0x1F6F9, 0x1F6F9}, 59 {0x1F94D, 0x1F94F}, 60 {0x1F96C, 0x1F970}, 61 {0x1F973, 0x1F976}, 62 {0x1F97A, 0x1F97A}, 63 {0x1F97C, 0x1F97F}, 64 {0x1F998, 0x1F9A2}, 65 {0x1F9B0, 0x1F9B9}, 66 {0x1F9C1, 0x1F9C2}, 67 {0x1F9E7, 0x1F9FF}, 68 } 69 }; 70 71 final Bidi icuBidi = new Bidi(0 /* maxLength */, 0 /* maxRunCount */); 72 icuBidi.setCustomClassifier(new AndroidBidi.EmojiBidiOverride()); 73 74 for (int version = 0; version < data.length; version++) { 75 for (int row = 0; row < data[version].length; row++) { 76 for (int c = data[version][row][0]; c < data[version][row][1]; c++) { 77 assertTrue(Integer.toHexString(c) + " should be emoji", Emoji.isEmoji(c)); 78 79 assertEquals(Integer.toHexString(c) + " should have neutral directionality", 80 Character.DIRECTIONALITY_OTHER_NEUTRALS, 81 BidiFormatter.DirectionalityEstimator.getDirectionality(c)); 82 83 assertEquals(Integer.toHexString(c) + " shoud be OTHER_NEUTRAL for ICU Bidi", 84 UCharacterDirection.OTHER_NEUTRAL, icuBidi.getCustomizedClass(c)); 85 } 86 } 87 } 88 } 89 90 @Test 91 public void testisEmojiModifierBase_LegacyCompat() { 92 assertTrue(Emoji.isEmojiModifierBase(0x1F91D)); 93 assertTrue(Emoji.isEmojiModifierBase(0x1F93C)); 94 } 95 96 @Test 97 public void testisEmojiModifierBase() { 98 // each row in the data is the range of emoji 99 final int[][][] data = new int[][][]{ 100 { // EMOJI 5 101 // range of emoji: i.e from 0x1F91F to 0x1F91F inclusive 102 {0x1F91F, 0x1F91F}, 103 {0x1F931, 0x1F932}, 104 {0x1F9D1, 0x1F9DD}, 105 }, 106 { // EMOJI 11 107 {0x1F9B5, 0x1F9B6}, 108 {0x1F9B8, 0x1F9B9} 109 } 110 }; 111 for (int version = 0; version < data.length; version++) { 112 for (int row = 0; row < data[version].length; row++) { 113 for (int c = data[version][row][0]; c < data[version][row][1]; c++) { 114 assertTrue(Integer.toHexString(c) + " should be emoji modifier base", 115 Emoji.isEmojiModifierBase(c)); 116 } 117 } 118 } 119 } 120 } 121