1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, Hardware 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include "gtest/gtest.h" 17f6603c60Sopenharmony_ci#include "drawing_font_mgr.h" 18f6603c60Sopenharmony_ci#include "drawing_text_typography.h" 19f6603c60Sopenharmony_ci#include "drawing_typeface.h" 20f6603c60Sopenharmony_ci 21f6603c60Sopenharmony_ciusing namespace testing; 22f6603c60Sopenharmony_ciusing namespace testing::ext; 23f6603c60Sopenharmony_ci 24f6603c60Sopenharmony_cinamespace OHOS { 25f6603c60Sopenharmony_cinamespace Rosen { 26f6603c60Sopenharmony_cinamespace Drawing { 27f6603c60Sopenharmony_ciclass OH_Drawing_FontMgrTest : public testing::Test { 28f6603c60Sopenharmony_ci}; 29f6603c60Sopenharmony_ci 30f6603c60Sopenharmony_ci/* 31f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest001 32f6603c60Sopenharmony_ci * @tc.desc: test for creating and destroying font manager. 33f6603c60Sopenharmony_ci * @tc.type: FUNC 34f6603c60Sopenharmony_ci */ 35f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest001, TestSize.Level1) 36f6603c60Sopenharmony_ci{ 37f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 38f6603c60Sopenharmony_ci EXPECT_NE(mgr, nullptr); 39f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 40f6603c60Sopenharmony_ci} 41f6603c60Sopenharmony_ci 42f6603c60Sopenharmony_ci/* 43f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest002 44f6603c60Sopenharmony_ci * @tc.desc: test for getting family name. 45f6603c60Sopenharmony_ci * @tc.type: FUNC 46f6603c60Sopenharmony_ci */ 47f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest002, TestSize.Level1) 48f6603c60Sopenharmony_ci{ 49f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 50f6603c60Sopenharmony_ci EXPECT_NE(mgr, nullptr); 51f6603c60Sopenharmony_ci int count = OH_Drawing_FontMgrGetFamilyCount(mgr); 52f6603c60Sopenharmony_ci EXPECT_TRUE(count > 0); 53f6603c60Sopenharmony_ci 54f6603c60Sopenharmony_ci char *familyName = OH_Drawing_FontMgrGetFamilyName(mgr, 0); 55f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFamilyName(familyName); 56f6603c60Sopenharmony_ci 57f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 58f6603c60Sopenharmony_ci} 59f6603c60Sopenharmony_ci 60f6603c60Sopenharmony_ci/* 61f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest003 62f6603c60Sopenharmony_ci * @tc.desc: test for creating and destroying font style set by font mannager. 63f6603c60Sopenharmony_ci * @tc.type: FUNC 64f6603c60Sopenharmony_ci */ 65f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest003, TestSize.Level1) 66f6603c60Sopenharmony_ci{ 67f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 68f6603c60Sopenharmony_ci EXPECT_NE(mgr, nullptr); 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ci OH_Drawing_FontStyleSet* fontStyleSet = OH_Drawing_FontMgrCreateFontStyleSet(mgr, 0); 71f6603c60Sopenharmony_ci EXPECT_NE(fontStyleSet, nullptr); 72f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFontStyleSet(fontStyleSet); 73f6603c60Sopenharmony_ci 74f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 75f6603c60Sopenharmony_ci} 76f6603c60Sopenharmony_ci 77f6603c60Sopenharmony_ci/* 78f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest004 79f6603c60Sopenharmony_ci * @tc.desc: test for matching font family by family name. 80f6603c60Sopenharmony_ci * @tc.type: FUNC 81f6603c60Sopenharmony_ci */ 82f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest004, TestSize.Level1) 83f6603c60Sopenharmony_ci{ 84f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 85f6603c60Sopenharmony_ci EXPECT_NE(mgr, nullptr); 86f6603c60Sopenharmony_ci const char* matchFamilyName = "HarmonyOS-Sans"; 87f6603c60Sopenharmony_ci OH_Drawing_FontStyleSet* fontStyleSet = OH_Drawing_FontMgrMatchFamily(mgr, matchFamilyName); 88f6603c60Sopenharmony_ci EXPECT_NE(fontStyleSet, nullptr); 89f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFontStyleSet(fontStyleSet); 90f6603c60Sopenharmony_ci 91f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 92f6603c60Sopenharmony_ci} 93f6603c60Sopenharmony_ci 94f6603c60Sopenharmony_ci 95f6603c60Sopenharmony_ci/* 96f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest005 97f6603c60Sopenharmony_ci * @tc.desc: test for matching font typeface by family name and font style. 98f6603c60Sopenharmony_ci * @tc.type: FUNC 99f6603c60Sopenharmony_ci */ 100f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest005, TestSize.Level1) 101f6603c60Sopenharmony_ci{ 102f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 103f6603c60Sopenharmony_ci EXPECT_NE(mgr, nullptr); 104f6603c60Sopenharmony_ci const char* matchFamilyName = "HarmonyOS-Sans"; 105f6603c60Sopenharmony_ci OH_Drawing_FontStyleStruct normalStyle; 106f6603c60Sopenharmony_ci normalStyle.weight = FONT_WEIGHT_400; 107f6603c60Sopenharmony_ci normalStyle.width = FONT_WIDTH_NORMAL; 108f6603c60Sopenharmony_ci normalStyle.slant = FONT_STYLE_NORMAL; 109f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface = OH_Drawing_FontMgrMatchFamilyStyle(mgr, matchFamilyName, normalStyle); 110f6603c60Sopenharmony_ci EXPECT_NE(typeface, nullptr); 111f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(typeface); 112f6603c60Sopenharmony_ci 113f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 114f6603c60Sopenharmony_ci} 115f6603c60Sopenharmony_ci 116f6603c60Sopenharmony_ci/* 117f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest006 118f6603c60Sopenharmony_ci * @tc.desc: test for matching font typeface by family name, font style and specific character. 119f6603c60Sopenharmony_ci * @tc.type: FUNC 120f6603c60Sopenharmony_ci */ 121f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest006, TestSize.Level1) 122f6603c60Sopenharmony_ci{ 123f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 124f6603c60Sopenharmony_ci EXPECT_NE(mgr, nullptr); 125f6603c60Sopenharmony_ci 126f6603c60Sopenharmony_ci const char* matchFamilyName = "HarmonyOS-Sans"; 127f6603c60Sopenharmony_ci OH_Drawing_FontStyleStruct normalStyle; 128f6603c60Sopenharmony_ci normalStyle.weight = FONT_WEIGHT_400; 129f6603c60Sopenharmony_ci normalStyle.width = FONT_WIDTH_NORMAL; 130f6603c60Sopenharmony_ci normalStyle.slant = FONT_STYLE_NORMAL; 131f6603c60Sopenharmony_ci 132f6603c60Sopenharmony_ci const char *bcp47[] = {"zh-Hans", "zh-CN"}; 133f6603c60Sopenharmony_ci OH_Drawing_Typeface *CharTypeface = OH_Drawing_FontMgrMatchFamilyStyleCharacter(mgr, matchFamilyName, 134f6603c60Sopenharmony_ci normalStyle, bcp47, 1, ' '); 135f6603c60Sopenharmony_ci EXPECT_NE(CharTypeface, nullptr); 136f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(CharTypeface); 137f6603c60Sopenharmony_ci 138f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 139f6603c60Sopenharmony_ci} 140f6603c60Sopenharmony_ci 141f6603c60Sopenharmony_ci/* 142f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest007 143f6603c60Sopenharmony_ci * @tc.desc: test for getting family name. 144f6603c60Sopenharmony_ci * @tc.type: FUNC 145f6603c60Sopenharmony_ci */ 146f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest007, TestSize.Level1) 147f6603c60Sopenharmony_ci{ 148f6603c60Sopenharmony_ci int count = OH_Drawing_FontMgrGetFamilyCount(nullptr); 149f6603c60Sopenharmony_ci EXPECT_TRUE(count == 0); 150f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 151f6603c60Sopenharmony_ci EXPECT_NE(mgr, nullptr); 152f6603c60Sopenharmony_ci char *familyName = OH_Drawing_FontMgrGetFamilyName(nullptr, 0); 153f6603c60Sopenharmony_ci EXPECT_TRUE(familyName == nullptr); 154f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFamilyName(familyName); 155f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 156f6603c60Sopenharmony_ci} 157f6603c60Sopenharmony_ci 158f6603c60Sopenharmony_ci/* 159f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest008 160f6603c60Sopenharmony_ci * @tc.desc: test for matching family style. 161f6603c60Sopenharmony_ci * @tc.type: FUNC 162f6603c60Sopenharmony_ci */ 163f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest008, TestSize.Level1) 164f6603c60Sopenharmony_ci{ 165f6603c60Sopenharmony_ci OH_Drawing_FontStyleSet* fontStyleSet = OH_Drawing_FontMgrCreateFontStyleSet(nullptr, 0); 166f6603c60Sopenharmony_ci EXPECT_TRUE(fontStyleSet == nullptr); 167f6603c60Sopenharmony_ci const char* matchFamilyName = "HarmonyOS-Sans"; 168f6603c60Sopenharmony_ci fontStyleSet = OH_Drawing_FontMgrMatchFamily(nullptr, matchFamilyName); 169f6603c60Sopenharmony_ci EXPECT_TRUE(fontStyleSet == nullptr); 170f6603c60Sopenharmony_ci 171f6603c60Sopenharmony_ci OH_Drawing_FontStyleStruct normalStyle; 172f6603c60Sopenharmony_ci normalStyle.weight = FONT_WEIGHT_400; 173f6603c60Sopenharmony_ci normalStyle.width = FONT_WIDTH_NORMAL; 174f6603c60Sopenharmony_ci normalStyle.slant = FONT_STYLE_NORMAL; 175f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface = OH_Drawing_FontMgrMatchFamilyStyle(nullptr, matchFamilyName, normalStyle); 176f6603c60Sopenharmony_ci EXPECT_TRUE(typeface == nullptr); 177f6603c60Sopenharmony_ci} 178f6603c60Sopenharmony_ci 179f6603c60Sopenharmony_ci/* 180f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest009 181f6603c60Sopenharmony_ci * @tc.desc: test for matching family style character. 182f6603c60Sopenharmony_ci * @tc.type: FUNC 183f6603c60Sopenharmony_ci */ 184f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest009, TestSize.Level1) 185f6603c60Sopenharmony_ci{ 186f6603c60Sopenharmony_ci const char* matchFamilyName = "HarmonyOS-Sans"; 187f6603c60Sopenharmony_ci OH_Drawing_FontStyleStruct normalStyle; 188f6603c60Sopenharmony_ci normalStyle.weight = FONT_WEIGHT_400; 189f6603c60Sopenharmony_ci normalStyle.width = FONT_WIDTH_NORMAL; 190f6603c60Sopenharmony_ci normalStyle.slant = FONT_STYLE_NORMAL; 191f6603c60Sopenharmony_ci 192f6603c60Sopenharmony_ci const char *bcp47[] = {"zh-Hans", "zh-CN"}; 193f6603c60Sopenharmony_ci OH_Drawing_Typeface *CharTypeface = OH_Drawing_FontMgrMatchFamilyStyleCharacter(nullptr, matchFamilyName, 194f6603c60Sopenharmony_ci normalStyle, bcp47, 1, ' '); 195f6603c60Sopenharmony_ci EXPECT_TRUE(CharTypeface == nullptr); 196f6603c60Sopenharmony_ci} 197f6603c60Sopenharmony_ci 198f6603c60Sopenharmony_ci/* 199f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest010 200f6603c60Sopenharmony_ci * @tc.desc: test for create a typeface for the given index. 201f6603c60Sopenharmony_ci * @tc.type: FUNC 202f6603c60Sopenharmony_ci */ 203f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest010, TestSize.Level1) 204f6603c60Sopenharmony_ci{ 205f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 206f6603c60Sopenharmony_ci OH_Drawing_FontStyleSet* fontStyleSet = OH_Drawing_FontMgrCreateFontStyleSet(mgr, 0); 207f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface = OH_Drawing_FontStyleSetCreateTypeface(fontStyleSet, 0); 208f6603c60Sopenharmony_ci EXPECT_NE(typeface, nullptr); 209f6603c60Sopenharmony_ci typeface = OH_Drawing_FontStyleSetCreateTypeface(nullptr, 0); 210f6603c60Sopenharmony_ci EXPECT_TRUE(typeface == nullptr); 211f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFontStyleSet(fontStyleSet); 212f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(typeface); 213f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 214f6603c60Sopenharmony_ci} 215f6603c60Sopenharmony_ci 216f6603c60Sopenharmony_ci/* 217f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest011 218f6603c60Sopenharmony_ci * @tc.desc: test for get font style struct. 219f6603c60Sopenharmony_ci * @tc.type: FUNC 220f6603c60Sopenharmony_ci */ 221f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest011, TestSize.Level1) 222f6603c60Sopenharmony_ci{ 223f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 224f6603c60Sopenharmony_ci OH_Drawing_FontStyleSet* fontStyleSet = OH_Drawing_FontMgrCreateFontStyleSet(mgr, 0); 225f6603c60Sopenharmony_ci OH_Drawing_FontStyleStruct normalStyle; 226f6603c60Sopenharmony_ci char** styleName = nullptr; 227f6603c60Sopenharmony_ci normalStyle = OH_Drawing_FontStyleSetGetStyle(fontStyleSet, 0, styleName); 228f6603c60Sopenharmony_ci EXPECT_TRUE(normalStyle.weight == FONT_WEIGHT_400); 229f6603c60Sopenharmony_ci OH_Drawing_FontStyleSetFreeStyleName(styleName); 230f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFontStyleSet(fontStyleSet); 231f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 232f6603c60Sopenharmony_ci} 233f6603c60Sopenharmony_ci 234f6603c60Sopenharmony_ci/* 235f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest012 236f6603c60Sopenharmony_ci * @tc.desc: test for get typeface by match style. 237f6603c60Sopenharmony_ci * @tc.type: FUNC 238f6603c60Sopenharmony_ci */ 239f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest012, TestSize.Level1) 240f6603c60Sopenharmony_ci{ 241f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 242f6603c60Sopenharmony_ci OH_Drawing_FontStyleSet* fontStyleSet = OH_Drawing_FontMgrCreateFontStyleSet(mgr, 0); 243f6603c60Sopenharmony_ci OH_Drawing_FontStyleStruct normalStyle; 244f6603c60Sopenharmony_ci normalStyle.weight = FONT_WEIGHT_400; 245f6603c60Sopenharmony_ci normalStyle.width = FONT_WIDTH_NORMAL; 246f6603c60Sopenharmony_ci normalStyle.slant = FONT_STYLE_NORMAL; 247f6603c60Sopenharmony_ci OH_Drawing_Typeface* typeface = OH_Drawing_FontStyleSetMatchStyle(fontStyleSet, normalStyle); 248f6603c60Sopenharmony_ci EXPECT_NE(typeface, nullptr); 249f6603c60Sopenharmony_ci 250f6603c60Sopenharmony_ci typeface = OH_Drawing_FontStyleSetMatchStyle(nullptr, normalStyle); 251f6603c60Sopenharmony_ci EXPECT_TRUE(typeface == nullptr); 252f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFontStyleSet(fontStyleSet); 253f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(typeface); 254f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 255f6603c60Sopenharmony_ci} 256f6603c60Sopenharmony_ci 257f6603c60Sopenharmony_ci/* 258f6603c60Sopenharmony_ci * @tc.name: OH_Drawing_FontMgrTest013 259f6603c60Sopenharmony_ci * @tc.desc: test for get font style set. 260f6603c60Sopenharmony_ci * @tc.type: FUNC 261f6603c60Sopenharmony_ci */ 262f6603c60Sopenharmony_ciHWTEST_F(OH_Drawing_FontMgrTest, OH_Drawing_FontMgrTest013, TestSize.Level1) 263f6603c60Sopenharmony_ci{ 264f6603c60Sopenharmony_ci OH_Drawing_FontMgr *mgr = OH_Drawing_FontMgrCreate(); 265f6603c60Sopenharmony_ci OH_Drawing_FontStyleSet* fontStyleSet = OH_Drawing_FontMgrCreateFontStyleSet(mgr, 0); 266f6603c60Sopenharmony_ci int count = OH_Drawing_FontStyleSetCount(fontStyleSet); 267f6603c60Sopenharmony_ci EXPECT_TRUE(count > 0); 268f6603c60Sopenharmony_ci 269f6603c60Sopenharmony_ci count = OH_Drawing_FontStyleSetCount(nullptr); 270f6603c60Sopenharmony_ci EXPECT_TRUE(count == 0); 271f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroyFontStyleSet(fontStyleSet); 272f6603c60Sopenharmony_ci OH_Drawing_FontMgrDestroy(mgr); 273f6603c60Sopenharmony_ci} 274f6603c60Sopenharmony_ci} // namespace Drawing 275f6603c60Sopenharmony_ci} // namespace Rosen 276f6603c60Sopenharmony_ci} // namespace OHOS