1 /*
2  * Copyright (C) 2016 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 #include "minikin/Emoji.h"
18 
19 #include <gtest/gtest.h>
20 #include <unicode/uchar.h>
21 
22 namespace minikin {
23 
TEST(EmojiTest,isEmojiTest)24 TEST(EmojiTest, isEmojiTest) {
25     EXPECT_TRUE(isEmoji(0x0023));   // NUMBER SIGN
26     EXPECT_TRUE(isEmoji(0x0035));   // DIGIT FIVE
27     EXPECT_TRUE(isEmoji(0x2640));   // FEMALE SIGN
28     EXPECT_TRUE(isEmoji(0x2642));   // MALE SIGN
29     EXPECT_TRUE(isEmoji(0x2695));   // STAFF OF AESCULAPIUS
30     EXPECT_TRUE(isEmoji(0x1F0CF));  // PLAYING CARD BLACK JOKER
31     EXPECT_TRUE(isEmoji(0x1F1E9));  // REGIONAL INDICATOR SYMBOL LETTER D
32     EXPECT_TRUE(isEmoji(0x1F6F7));  // SLED
33     EXPECT_TRUE(isEmoji(0x1F9E6));  // SOCKS
34 
35     // Unicode 12.0
36     EXPECT_TRUE(isEmoji(0x1F6D5));  // HINDU TEMPLE
37     EXPECT_TRUE(isEmoji(0x1F7E7));  // ORANGE SQUARE
38     EXPECT_TRUE(isEmoji(0x1F9CF));  // DEAF PERSON
39     EXPECT_TRUE(isEmoji(0x1F9CE));  // PERSON KNEELING
40     EXPECT_TRUE(isEmoji(0x1F9A6));  // OTTER
41     EXPECT_TRUE(isEmoji(0x1F9A9));  // FLAMINGO
42     EXPECT_TRUE(isEmoji(0x1F9C6));  // FALAFEL
43     EXPECT_TRUE(isEmoji(0x1F9AA));  // OYSTER
44     EXPECT_TRUE(isEmoji(0x1FA82));  // PARACHUTE
45     EXPECT_TRUE(isEmoji(0x1FA80));  // YO-YO
46     EXPECT_TRUE(isEmoji(0x1FA70));  // BALLET SHOES
47     EXPECT_TRUE(isEmoji(0x1FA79));  // ADHESIVE BANDAGE
48 
49     // Unicode 13.0
50     EXPECT_TRUE(isEmoji(0x1F6D6));  // HUT
51     EXPECT_TRUE(isEmoji(0x1F977));  // NINJA
52     EXPECT_TRUE(isEmoji(0x1F9A3));  // MAMMOTH
53     EXPECT_TRUE(isEmoji(0x1FA74));  // THONG SANDAL
54     EXPECT_TRUE(isEmoji(0x1FAC2));  // PEOPLE HUGGING
55     EXPECT_TRUE(isEmoji(0x1FAD6));  // TEAPOT
56 
57     EXPECT_FALSE(isEmoji(0x0000));   // <control>
58     EXPECT_FALSE(isEmoji(0x0061));   // LATIN SMALL LETTER A
59     EXPECT_FALSE(isEmoji(0x1F93B));  // MODERN PENTATHLON
60     EXPECT_FALSE(isEmoji(0x1F946));  // RIFLE
61     EXPECT_FALSE(isEmoji(0x29E3D));  // A han character.
62 }
63 
TEST(EmojiTest,isEmojiModifierTest)64 TEST(EmojiTest, isEmojiModifierTest) {
65     EXPECT_TRUE(isEmojiModifier(0x1F3FB));  // EMOJI MODIFIER FITZPATRICK TYPE-1-2
66     EXPECT_TRUE(isEmojiModifier(0x1F3FC));  // EMOJI MODIFIER FITZPATRICK TYPE-3
67     EXPECT_TRUE(isEmojiModifier(0x1F3FD));  // EMOJI MODIFIER FITZPATRICK TYPE-4
68     EXPECT_TRUE(isEmojiModifier(0x1F3FE));  // EMOJI MODIFIER FITZPATRICK TYPE-5
69     EXPECT_TRUE(isEmojiModifier(0x1F3FF));  // EMOJI MODIFIER FITZPATRICK TYPE-6
70 
71     EXPECT_FALSE(isEmojiModifier(0x0000));   // <control>
72     EXPECT_FALSE(isEmojiModifier(0x1F3FA));  // AMPHORA
73     EXPECT_FALSE(isEmojiModifier(0x1F400));  // RAT
74     EXPECT_FALSE(isEmojiModifier(0x29E3D));  // A han character.
75 }
76 
TEST(EmojiTest,isEmojiBaseTest)77 TEST(EmojiTest, isEmojiBaseTest) {
78     EXPECT_TRUE(isEmojiBase(0x261D));   // WHITE UP POINTING INDEX
79     EXPECT_TRUE(isEmojiBase(0x270D));   // WRITING HAND
80     EXPECT_TRUE(isEmojiBase(0x1F385));  // FATHER CHRISTMAS
81     EXPECT_TRUE(isEmojiBase(0x1F3C2));  // SNOWBOARDER
82     EXPECT_TRUE(isEmojiBase(0x1F3C7));  // HORSE RACING
83     EXPECT_TRUE(isEmojiBase(0x1F3CC));  // GOLFER
84     EXPECT_TRUE(isEmojiBase(0x1F574));  // MAN IN BUSINESS SUIT LEVITATING
85     EXPECT_TRUE(isEmojiBase(0x1F6CC));  // SLEEPING ACCOMMODATION
86     EXPECT_TRUE(isEmojiBase(0x1F91D));  // HANDSHAKE (removed from Emoji 4.0, but we need it)
87     EXPECT_TRUE(isEmojiBase(0x1F91F));  // I LOVE YOU HAND SIGN
88     EXPECT_TRUE(isEmojiBase(0x1F931));  // BREAST-FEEDING
89     EXPECT_TRUE(isEmojiBase(0x1F932));  // PALMS UP TOGETHER
90     EXPECT_TRUE(isEmojiBase(0x1F93C));  // WRESTLERS (removed from Emoji 4.0, but we need it)
91     EXPECT_TRUE(isEmojiBase(0x1F9D1));  // ADULT
92     EXPECT_TRUE(isEmojiBase(0x1F9DD));  // ELF
93 
94     EXPECT_TRUE(isEmojiBase(0x1F9B5));  // LEG
95     EXPECT_TRUE(isEmojiBase(0x1F9B6));  // FOOT
96     EXPECT_TRUE(isEmojiBase(0x1F9B8));  // SUPERHERO
97     EXPECT_TRUE(isEmojiBase(0x1F9B9));  // SUPERVILLAIN
98 
99     // Unicode 12
100     EXPECT_TRUE(isEmojiBase(0x1F90F));  // PINCHING HAND
101     EXPECT_TRUE(isEmojiBase(0x1F9BB));  // EAR WITH HEARING AID
102     EXPECT_TRUE(isEmojiBase(0x1F9CD));  // PERSON STANDING
103     EXPECT_TRUE(isEmojiBase(0x1F9CF));  // DEAF PERSON
104 
105     // Unicode 13
106     EXPECT_TRUE(isEmojiBase(0x1F90C));  // PINCHED FINGERS
107     EXPECT_TRUE(isEmojiBase(0x1F977));  // NINJA
108 
109     EXPECT_FALSE(isEmojiBase(0x0000));   // <control>
110     EXPECT_FALSE(isEmojiBase(0x261C));   // WHITE LEFT POINTING INDEX
111     EXPECT_FALSE(isEmojiBase(0x1F384));  // CHRISTMAS TREE
112     EXPECT_FALSE(isEmojiBase(0x1F9DE));  // GENIE
113     EXPECT_FALSE(isEmojiBase(0x29E3D));  // A han character.
114 }
115 
TEST(EmojiTest,emojiBidiOverrideTest)116 TEST(EmojiTest, emojiBidiOverrideTest) {
117     EXPECT_EQ(U_RIGHT_TO_LEFT, emojiBidiOverride(nullptr, 0x05D0));  // HEBREW LETTER ALEF
118     EXPECT_EQ(U_LEFT_TO_RIGHT,
119               emojiBidiOverride(nullptr, 0x1F170));  // NEGATIVE SQUARED LATIN CAPITAL LETTER A
120     EXPECT_EQ(U_OTHER_NEUTRAL, emojiBidiOverride(nullptr, 0x1F6F7));  // SLED
121     EXPECT_EQ(U_OTHER_NEUTRAL, emojiBidiOverride(nullptr, 0x1F9E6));  // SOCKS
122 }
123 
124 }  // namespace minikin
125