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     EXPECT_FALSE(isEmoji(0x0000));   // <control>
36     EXPECT_FALSE(isEmoji(0x0061));   // LATIN SMALL LETTER A
37     EXPECT_FALSE(isEmoji(0x1F93B));  // MODERN PENTATHLON
38     EXPECT_FALSE(isEmoji(0x1F946));  // RIFLE
39     EXPECT_FALSE(isEmoji(0x29E3D));  // A han character.
40 }
41 
TEST(EmojiTest,isEmojiModifierTest)42 TEST(EmojiTest, isEmojiModifierTest) {
43     EXPECT_TRUE(isEmojiModifier(0x1F3FB));  // EMOJI MODIFIER FITZPATRICK TYPE-1-2
44     EXPECT_TRUE(isEmojiModifier(0x1F3FC));  // EMOJI MODIFIER FITZPATRICK TYPE-3
45     EXPECT_TRUE(isEmojiModifier(0x1F3FD));  // EMOJI MODIFIER FITZPATRICK TYPE-4
46     EXPECT_TRUE(isEmojiModifier(0x1F3FE));  // EMOJI MODIFIER FITZPATRICK TYPE-5
47     EXPECT_TRUE(isEmojiModifier(0x1F3FF));  // EMOJI MODIFIER FITZPATRICK TYPE-6
48 
49     EXPECT_FALSE(isEmojiModifier(0x0000));   // <control>
50     EXPECT_FALSE(isEmojiModifier(0x1F3FA));  // AMPHORA
51     EXPECT_FALSE(isEmojiModifier(0x1F400));  // RAT
52     EXPECT_FALSE(isEmojiModifier(0x29E3D));  // A han character.
53 }
54 
TEST(EmojiTest,isEmojiBaseTest)55 TEST(EmojiTest, isEmojiBaseTest) {
56     EXPECT_TRUE(isEmojiBase(0x261D));   // WHITE UP POINTING INDEX
57     EXPECT_TRUE(isEmojiBase(0x270D));   // WRITING HAND
58     EXPECT_TRUE(isEmojiBase(0x1F385));  // FATHER CHRISTMAS
59     EXPECT_TRUE(isEmojiBase(0x1F3C2));  // SNOWBOARDER
60     EXPECT_TRUE(isEmojiBase(0x1F3C7));  // HORSE RACING
61     EXPECT_TRUE(isEmojiBase(0x1F3CC));  // GOLFER
62     EXPECT_TRUE(isEmojiBase(0x1F574));  // MAN IN BUSINESS SUIT LEVITATING
63     EXPECT_TRUE(isEmojiBase(0x1F6CC));  // SLEEPING ACCOMMODATION
64     EXPECT_TRUE(isEmojiBase(0x1F91D));  // HANDSHAKE (removed from Emoji 4.0, but we need it)
65     EXPECT_TRUE(isEmojiBase(0x1F91F));  // I LOVE YOU HAND SIGN
66     EXPECT_TRUE(isEmojiBase(0x1F931));  // BREAST-FEEDING
67     EXPECT_TRUE(isEmojiBase(0x1F932));  // PALMS UP TOGETHER
68     EXPECT_TRUE(isEmojiBase(0x1F93C));  // WRESTLERS (removed from Emoji 4.0, but we need it)
69     EXPECT_TRUE(isEmojiBase(0x1F9D1));  // ADULT
70     EXPECT_TRUE(isEmojiBase(0x1F9DD));  // ELF
71 
72     EXPECT_FALSE(isEmojiBase(0x0000));   // <control>
73     EXPECT_FALSE(isEmojiBase(0x261C));   // WHITE LEFT POINTING INDEX
74     EXPECT_FALSE(isEmojiBase(0x1F384));  // CHRISTMAS TREE
75     EXPECT_FALSE(isEmojiBase(0x1F9DE));  // GENIE
76     EXPECT_FALSE(isEmojiBase(0x29E3D));  // A han character.
77 }
78 
TEST(EmojiTest,emojiBidiOverrideTest)79 TEST(EmojiTest, emojiBidiOverrideTest) {
80     EXPECT_EQ(U_RIGHT_TO_LEFT, emojiBidiOverride(nullptr, 0x05D0));  // HEBREW LETTER ALEF
81     EXPECT_EQ(U_LEFT_TO_RIGHT,
82               emojiBidiOverride(nullptr, 0x1F170));  // NEGATIVE SQUARED LATIN CAPITAL LETTER A
83     EXPECT_EQ(U_OTHER_NEUTRAL, emojiBidiOverride(nullptr, 0x1F6F7));  // SLED
84     EXPECT_EQ(U_OTHER_NEUTRAL, emojiBidiOverride(nullptr, 0x1F9E6));  // SOCKS
85 }
86 
87 }  // namespace minikin
88