1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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, software 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 "drawing_bitmap.h" 17f6603c60Sopenharmony_ci#include "drawing_brush.h" 18f6603c60Sopenharmony_ci#include "drawing_canvas.h" 19f6603c60Sopenharmony_ci#include "drawing_color.h" 20f6603c60Sopenharmony_ci#include "drawing_color_filter.h" 21f6603c60Sopenharmony_ci#include "drawing_filter.h" 22f6603c60Sopenharmony_ci#include "drawing_font.h" 23f6603c60Sopenharmony_ci#include "drawing_image.h" 24f6603c60Sopenharmony_ci#include "drawing_mask_filter.h" 25f6603c60Sopenharmony_ci#include "drawing_matrix.h" 26f6603c60Sopenharmony_ci#include "drawing_memory_stream.h" 27f6603c60Sopenharmony_ci#include "drawing_path.h" 28f6603c60Sopenharmony_ci#include "drawing_pen.h" 29f6603c60Sopenharmony_ci#include "drawing_point.h" 30f6603c60Sopenharmony_ci#include "drawing_rect.h" 31f6603c60Sopenharmony_ci#include "drawing_region.h" 32f6603c60Sopenharmony_ci#include "drawing_round_rect.h" 33f6603c60Sopenharmony_ci#include "drawing_sampling_options.h" 34f6603c60Sopenharmony_ci#include "drawing_shader_effect.h" 35f6603c60Sopenharmony_ci#include "drawing_text_blob.h" 36f6603c60Sopenharmony_ci#include "drawing_typeface.h" 37f6603c60Sopenharmony_ci#include "utils/scalar.h" 38f6603c60Sopenharmony_ci#include "gtest/gtest.h" 39f6603c60Sopenharmony_ci#include <random> 40f6603c60Sopenharmony_ci 41f6603c60Sopenharmony_ciusing namespace testing; 42f6603c60Sopenharmony_ciusing namespace testing::ext; 43f6603c60Sopenharmony_ci 44f6603c60Sopenharmony_cinamespace OHOS { 45f6603c60Sopenharmony_cinamespace Rosen { 46f6603c60Sopenharmony_cinamespace Drawing { 47f6603c60Sopenharmony_ciclass DrawingNativeFontTest : public testing::Test {}; 48f6603c60Sopenharmony_ci 49f6603c60Sopenharmony_ci/* 50f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0100 51f6603c60Sopenharmony_ci * @tc.name: testFontCreateDestroyNormal 52f6603c60Sopenharmony_ci * @tc.desc: Test for creating and destroying a font object with normal parameters. 53f6603c60Sopenharmony_ci * @tc.size : SmallTest 54f6603c60Sopenharmony_ci * @tc.type : Function 55f6603c60Sopenharmony_ci * @tc.level : Level 0 56f6603c60Sopenharmony_ci */ 57f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontCreateDestroyNormal, TestSize.Level0) { 58f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 59f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 60f6603c60Sopenharmony_ci // 2. OH_Drawing_FontDestroy 61f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 62f6603c60Sopenharmony_ci} 63f6603c60Sopenharmony_ci 64f6603c60Sopenharmony_ci/* 65f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0101 66f6603c60Sopenharmony_ci * @tc.name: testFontCreateDestroyNULL 67f6603c60Sopenharmony_ci * @tc.desc: test for testFontCreateDestroyNULL. 68f6603c60Sopenharmony_ci * @tc.size : SmallTest 69f6603c60Sopenharmony_ci * @tc.type : Function 70f6603c60Sopenharmony_ci * @tc.level : Level 3 71f6603c60Sopenharmony_ci */ 72f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontCreateDestroyNULL, TestSize.Level3) { 73f6603c60Sopenharmony_ci // 1. OH_Drawing_FontDestroy with nullptr as parameter 74f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(nullptr); 75f6603c60Sopenharmony_ci} 76f6603c60Sopenharmony_ci 77f6603c60Sopenharmony_ci/* 78f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0102 79f6603c60Sopenharmony_ci * @tc.name: testFontCreateDestroyMultipleCalls 80f6603c60Sopenharmony_ci * @tc.desc: test for testFontCreateDestroyMultipleCalls. 81f6603c60Sopenharmony_ci * @tc.size : SmallTest 82f6603c60Sopenharmony_ci * @tc.type : Function 83f6603c60Sopenharmony_ci * @tc.level : Level 3 84f6603c60Sopenharmony_ci */ 85f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontCreateDestroyMultipleCalls, TestSize.Level3) { 86f6603c60Sopenharmony_ci OH_Drawing_Font *fonts[10]; 87f6603c60Sopenharmony_ci // 1. Call OH_Drawing_FontCreate 10 times 88f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 89f6603c60Sopenharmony_ci fonts[i] = OH_Drawing_FontCreate(); 90f6603c60Sopenharmony_ci EXPECT_NE(fonts[i], nullptr); 91f6603c60Sopenharmony_ci } 92f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontDestroy 10 times 93f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 94f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(fonts[i]); 95f6603c60Sopenharmony_ci } 96f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontCreate and OH_Drawing_FontDestroy alternately 10 times 97f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 98f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 99f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 100f6603c60Sopenharmony_ci } 101f6603c60Sopenharmony_ci} 102f6603c60Sopenharmony_ci 103f6603c60Sopenharmony_ci/* 104f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0200 105f6603c60Sopenharmony_ci * @tc.name: testFontSetBaselineSnapNormal 106f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetBaselineSnapNormal. 107f6603c60Sopenharmony_ci * @tc.size : SmallTest 108f6603c60Sopenharmony_ci * @tc.type : Function 109f6603c60Sopenharmony_ci * @tc.level : Level 0 110f6603c60Sopenharmony_ci */ 111f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetBaselineSnapNormal, TestSize.Level0) { 112f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 113f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 114f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetBaselineSnap with isForce parameter set to false, 115f6603c60Sopenharmony_ci // verify by calling OH_Drawing_FontIsBaselineSnap to check if the font baseline is aligned with pixels 116f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(font, false); 117f6603c60Sopenharmony_ci bool isBaselineSnap = OH_Drawing_FontIsBaselineSnap(font); 118f6603c60Sopenharmony_ci EXPECT_FALSE(isBaselineSnap); 119f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetBaselineSnap with isForce parameter set to true, 120f6603c60Sopenharmony_ci // verify by calling OH_Drawing_FontIsBaselineSnap to check if the font baseline is aligned with pixels 121f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(font, true); 122f6603c60Sopenharmony_ci isBaselineSnap = OH_Drawing_FontIsBaselineSnap(font); 123f6603c60Sopenharmony_ci EXPECT_TRUE(isBaselineSnap); 124f6603c60Sopenharmony_ci // 4. Release memory 125f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 126f6603c60Sopenharmony_ci} 127f6603c60Sopenharmony_ci 128f6603c60Sopenharmony_ci/* 129f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0201 130f6603c60Sopenharmony_ci * @tc.name: testFontSetBaselineSnapNULL 131f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetBaselineSnapNULL. 132f6603c60Sopenharmony_ci * @tc.size : SmallTest 133f6603c60Sopenharmony_ci * @tc.type : Function 134f6603c60Sopenharmony_ci * @tc.level : Level 3 135f6603c60Sopenharmony_ci */ 136f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetBaselineSnapNULL, TestSize.Level3) { 137f6603c60Sopenharmony_ci // 1. Call OH_Drawing_FontSetBaselineSnap with nullptr as the first parameter, check the error code using 138f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 139f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(nullptr, false); 140f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 141f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsBaselineSnap with nullptr as the parameter, check the error code using 142f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 143f6603c60Sopenharmony_ci OH_Drawing_FontIsBaselineSnap(nullptr); 144f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 145f6603c60Sopenharmony_ci} 146f6603c60Sopenharmony_ci 147f6603c60Sopenharmony_ci/* 148f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0202 149f6603c60Sopenharmony_ci * @tc.name: testFontSetBaselineSnapMultipleCalls 150f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetBaselineSnapMultipleCalls. 151f6603c60Sopenharmony_ci * @tc.size : SmallTest 152f6603c60Sopenharmony_ci * @tc.type : Function 153f6603c60Sopenharmony_ci * @tc.level : Level 3 154f6603c60Sopenharmony_ci */ 155f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetBaselineSnapMultipleCalls, TestSize.Level3) { 156f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 157f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 158f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetBaselineSnap 10 times, and call OH_Drawing_FontIsBaselineSnap each time to check if the 159f6603c60Sopenharmony_ci // font baseline is aligned with pixels 160f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 161f6603c60Sopenharmony_ci OH_Drawing_FontSetBaselineSnap(font, i % 2 == 0); 162f6603c60Sopenharmony_ci bool isBaselineSnap = OH_Drawing_FontIsBaselineSnap(font); 163f6603c60Sopenharmony_ci EXPECT_EQ(isBaselineSnap, i % 2 == 0); 164f6603c60Sopenharmony_ci } 165f6603c60Sopenharmony_ci // 3. Release memory 166f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 167f6603c60Sopenharmony_ci} 168f6603c60Sopenharmony_ci 169f6603c60Sopenharmony_ci/* 170f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0203 171f6603c60Sopenharmony_ci * @tc.name: testFontIsBaselineSnapWhenNoSet 172f6603c60Sopenharmony_ci * @tc.desc: test for testFontIsBaselineSnapWhenNoSet. 173f6603c60Sopenharmony_ci * @tc.size : SmallTest 174f6603c60Sopenharmony_ci * @tc.type : Function 175f6603c60Sopenharmony_ci * @tc.level : Level 2 176f6603c60Sopenharmony_ci */ 177f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontIsBaselineSnapWhenNoSet, TestSize.Level2) { 178f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 179f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 180f6603c60Sopenharmony_ci // 2. OH_Drawing_FontIsBaselineSnap 181f6603c60Sopenharmony_ci bool isBaselineSnap = OH_Drawing_FontIsBaselineSnap(font); 182f6603c60Sopenharmony_ci EXPECT_TRUE(isBaselineSnap); 183f6603c60Sopenharmony_ci} 184f6603c60Sopenharmony_ci 185f6603c60Sopenharmony_ci/* 186f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0300 187f6603c60Sopenharmony_ci * @tc.name: testFontSetSubpixelNormal 188f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetSubpixelNormal. 189f6603c60Sopenharmony_ci * @tc.size : SmallTest 190f6603c60Sopenharmony_ci * @tc.type : Function 191f6603c60Sopenharmony_ci * @tc.level : Level 0 192f6603c60Sopenharmony_ci */ 193f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetSubpixelNormal, TestSize.Level0) { 194f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 195f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 196f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetSubpixel with isSubpixel parameter set to false, 197f6603c60Sopenharmony_ci // verify by calling OH_Drawing_FontIsSubpixel to check if the glyph is rendered using subpixels 198f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(font, false); 199f6603c60Sopenharmony_ci bool isSubpixel = OH_Drawing_FontIsSubpixel(font); 200f6603c60Sopenharmony_ci EXPECT_FALSE(isSubpixel); 201f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetSubpixel with isSubpixel parameter set to true, 202f6603c60Sopenharmony_ci // verify by calling OH_Drawing_FontIsSubpixel to check if the glyph is rendered using subpixels 203f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(font, true); 204f6603c60Sopenharmony_ci isSubpixel = OH_Drawing_FontIsSubpixel(font); 205f6603c60Sopenharmony_ci EXPECT_TRUE(isSubpixel); 206f6603c60Sopenharmony_ci // 4. Release memory 207f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 208f6603c60Sopenharmony_ci} 209f6603c60Sopenharmony_ci 210f6603c60Sopenharmony_ci/* 211f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0301 212f6603c60Sopenharmony_ci * @tc.name: testFontSetSubpixelNULL 213f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetSubpixelNULL. 214f6603c60Sopenharmony_ci * @tc.size : SmallTest 215f6603c60Sopenharmony_ci * @tc.type : Function 216f6603c60Sopenharmony_ci * @tc.level : Level 3 217f6603c60Sopenharmony_ci */ 218f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetSubpixelNULL, TestSize.Level3) { 219f6603c60Sopenharmony_ci // 1. Call OH_Drawing_FontSetSubpixel with nullptr as the first parameter, check the error code using 220f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 221f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(nullptr, false); 222f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 223f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsSubpixel with nullptr as the parameter, check the error code using 224f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 225f6603c60Sopenharmony_ci OH_Drawing_FontIsSubpixel(nullptr); 226f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 227f6603c60Sopenharmony_ci} 228f6603c60Sopenharmony_ci 229f6603c60Sopenharmony_ci/* 230f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0302 231f6603c60Sopenharmony_ci * @tc.name: testFontSetSubpixelMultipleCalls 232f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetSubpixelMultipleCalls. 233f6603c60Sopenharmony_ci * @tc.size : SmallTest 234f6603c60Sopenharmony_ci * @tc.type : Function 235f6603c60Sopenharmony_ci * @tc.level : Level 3 236f6603c60Sopenharmony_ci */ 237f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetSubpixelMultipleCalls, TestSize.Level3) { 238f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 239f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 240f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsSubpixel 10 times, and call OH_Drawing_FontIsSubpixel each time to check if the glyph is 241f6603c60Sopenharmony_ci // rendered using subpixels 242f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 243f6603c60Sopenharmony_ci OH_Drawing_FontSetSubpixel(font, i % 2 == 0); 244f6603c60Sopenharmony_ci bool isSubpixel = OH_Drawing_FontIsSubpixel(font); 245f6603c60Sopenharmony_ci EXPECT_EQ(isSubpixel, i % 2 == 0); 246f6603c60Sopenharmony_ci } 247f6603c60Sopenharmony_ci // 3. Release memory 248f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 249f6603c60Sopenharmony_ci} 250f6603c60Sopenharmony_ci 251f6603c60Sopenharmony_ci/* 252f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0303 253f6603c60Sopenharmony_ci * @tc.name: testFontIsSubpixelWhenNoSet 254f6603c60Sopenharmony_ci * @tc.desc: test for testFontIsSubpixelWhenNoSet. 255f6603c60Sopenharmony_ci * @tc.size : SmallTest 256f6603c60Sopenharmony_ci * @tc.type : Function 257f6603c60Sopenharmony_ci * @tc.level : Level 2 258f6603c60Sopenharmony_ci */ 259f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontIsSubpixelWhenNoSet, TestSize.Level2) { 260f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 261f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 262f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsSubpixel 263f6603c60Sopenharmony_ci bool isSubpixel = OH_Drawing_FontIsSubpixel(font); 264f6603c60Sopenharmony_ci EXPECT_FALSE(isSubpixel); 265f6603c60Sopenharmony_ci // 3. Release memory 266f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 267f6603c60Sopenharmony_ci} 268f6603c60Sopenharmony_ci 269f6603c60Sopenharmony_ci/* 270f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0400 271f6603c60Sopenharmony_ci * @tc.name: testFontSetForceAutoHintingNormal 272f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetForceAutoHintingNormal. 273f6603c60Sopenharmony_ci * @tc.size : SmallTest 274f6603c60Sopenharmony_ci * @tc.type : Function 275f6603c60Sopenharmony_ci * @tc.level : Level 0 276f6603c60Sopenharmony_ci */ 277f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetForceAutoHintingNormal, TestSize.Level0) { 278f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 279f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 280f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetForceAutoHinting with isForceAutoHinting parameter set to false, 281f6603c60Sopenharmony_ci // verify by calling OH_Drawing_FontIsForceAutoHinting to check if the glyph outlines are automatically adjusted 282f6603c60Sopenharmony_ci OH_Drawing_FontSetForceAutoHinting(font, false); 283f6603c60Sopenharmony_ci bool isForceAutoHinting = OH_Drawing_FontIsForceAutoHinting(font); 284f6603c60Sopenharmony_ci EXPECT_FALSE(isForceAutoHinting); 285f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetForceAutoHinting with isForceAutoHinting parameter set to true, 286f6603c60Sopenharmony_ci // verify by calling OH_Drawing_FontIsForceAutoHinting to check if the glyph outlines are automatically adjusted 287f6603c60Sopenharmony_ci OH_Drawing_FontSetForceAutoHinting(font, true); 288f6603c60Sopenharmony_ci isForceAutoHinting = OH_Drawing_FontIsForceAutoHinting(font); 289f6603c60Sopenharmony_ci EXPECT_TRUE(isForceAutoHinting); 290f6603c60Sopenharmony_ci // 4. Release memory 291f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 292f6603c60Sopenharmony_ci} 293f6603c60Sopenharmony_ci 294f6603c60Sopenharmony_ci/* 295f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0401 296f6603c60Sopenharmony_ci * @tc.name: testFontSetForceAutoHintingNULL 297f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetForceAutoHintingNULL. 298f6603c60Sopenharmony_ci * @tc.size : SmallTest 299f6603c60Sopenharmony_ci * @tc.type : Function 300f6603c60Sopenharmony_ci * @tc.level : Level 3 301f6603c60Sopenharmony_ci */ 302f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetForceAutoHintingNULL, TestSize.Level3) { 303f6603c60Sopenharmony_ci // 1. Call OH_Drawing_FontSetForceAutoHinting with nullptr as the first parameter, check the error code using 304f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 305f6603c60Sopenharmony_ci OH_Drawing_FontSetForceAutoHinting(nullptr, false); 306f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 307f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsForceAutoHinting with nullptr as the parameter, check the error code using 308f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 309f6603c60Sopenharmony_ci OH_Drawing_FontIsForceAutoHinting(nullptr); 310f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 311f6603c60Sopenharmony_ci} 312f6603c60Sopenharmony_ci 313f6603c60Sopenharmony_ci/* 314f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0402 315f6603c60Sopenharmony_ci * @tc.name: testFontSetForceAutoHintingMultipleCalls 316f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetForceAutoHintingMultipleCalls. 317f6603c60Sopenharmony_ci * @tc.size : SmallTest 318f6603c60Sopenharmony_ci * @tc.type : Function 319f6603c60Sopenharmony_ci * @tc.level : Level 3 320f6603c60Sopenharmony_ci */ 321f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetForceAutoHintingMultipleCalls, TestSize.Level3) { 322f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 323f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 324f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetForceAutoHinting 10 times, and call OH_Drawing_FontIsForceAutoHinting each time to 325f6603c60Sopenharmony_ci // check if the glyph outlines are automatically adjusted 326f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 327f6603c60Sopenharmony_ci OH_Drawing_FontSetForceAutoHinting(font, i % 2 == 0); 328f6603c60Sopenharmony_ci bool isForceAutoHinting = OH_Drawing_FontIsForceAutoHinting(font); 329f6603c60Sopenharmony_ci EXPECT_EQ(isForceAutoHinting, i % 2 == 0); 330f6603c60Sopenharmony_ci } 331f6603c60Sopenharmony_ci // 3. Release memory 332f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 333f6603c60Sopenharmony_ci} 334f6603c60Sopenharmony_ci 335f6603c60Sopenharmony_ci/* 336f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0403 337f6603c60Sopenharmony_ci * @tc.name: testFontIsForceAutoHintingWhenNoSet 338f6603c60Sopenharmony_ci * @tc.desc: test for testFontIsForceAutoHintingWhenNoSet. 339f6603c60Sopenharmony_ci * @tc.size : SmallTest 340f6603c60Sopenharmony_ci * @tc.type : Function 341f6603c60Sopenharmony_ci * @tc.level : Level 3 342f6603c60Sopenharmony_ci */ 343f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontIsForceAutoHintingWhenNoSet, TestSize.Level3) { 344f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 345f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 346f6603c60Sopenharmony_ci // 2. OH_Drawing_FontIsForceAutoHinting 347f6603c60Sopenharmony_ci bool isForceAutoHinting = OH_Drawing_FontIsForceAutoHinting(font); 348f6603c60Sopenharmony_ci EXPECT_FALSE(isForceAutoHinting); 349f6603c60Sopenharmony_ci // 3. Release memory 350f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 351f6603c60Sopenharmony_ci} 352f6603c60Sopenharmony_ci 353f6603c60Sopenharmony_ci/* 354f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0500 355f6603c60Sopenharmony_ci * @tc.name: testFontSetTypefaceNormal 356f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTypefaceNormal. 357f6603c60Sopenharmony_ci * @tc.size : SmallTest 358f6603c60Sopenharmony_ci * @tc.type : Function 359f6603c60Sopenharmony_ci * @tc.level : Level 0 360f6603c60Sopenharmony_ci */ 361f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTypefaceNormal, TestSize.Level0) { 362f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 363f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 364f6603c60Sopenharmony_ci // 2. OH_Drawing_TypefaceCreateDefault 365f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface1 = OH_Drawing_TypefaceCreateDefault(); 366f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetTypeface, and call OH_Drawing_FontGetTypeface to get the glyph object 367f6603c60Sopenharmony_ci OH_Drawing_FontSetTypeface(font, typeface1); 368f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface2 = OH_Drawing_FontGetTypeface(font); 369f6603c60Sopenharmony_ci // 4. Release memory 370f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 371f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(typeface1); 372f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(typeface2); 373f6603c60Sopenharmony_ci} 374f6603c60Sopenharmony_ci 375f6603c60Sopenharmony_ci/* 376f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0501 377f6603c60Sopenharmony_ci * @tc.name: testFontSetTypefaceNULL 378f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTypefaceNULL. 379f6603c60Sopenharmony_ci * @tc.size : SmallTest 380f6603c60Sopenharmony_ci * @tc.type : Function 381f6603c60Sopenharmony_ci * @tc.level : Level 3 382f6603c60Sopenharmony_ci */ 383f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTypefaceNULL, TestSize.Level3) { 384f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 385f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 386f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTypeface with nullptr as the first parameter, check the error code using 387f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 388f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface = OH_Drawing_TypefaceCreateDefault(); 389f6603c60Sopenharmony_ci OH_Drawing_FontSetTypeface(nullptr, typeface); 390f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 391f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetTypeface with nullptr as the second parameter, call OH_Drawing_FontGetTypeface to get 392f6603c60Sopenharmony_ci // the default value 393f6603c60Sopenharmony_ci OH_Drawing_FontSetTypeface(font, nullptr); 394f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface2 = OH_Drawing_FontGetTypeface(font); 395f6603c60Sopenharmony_ci EXPECT_NE(typeface2, nullptr); 396f6603c60Sopenharmony_ci // 4. Call OH_Drawing_FontGetTypeface with nullptr as the parameter, check the error code using 397f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 398f6603c60Sopenharmony_ci OH_Drawing_FontGetTypeface(nullptr); 399f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 400f6603c60Sopenharmony_ci // 5. Release memory 401f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 402f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(typeface); 403f6603c60Sopenharmony_ci} 404f6603c60Sopenharmony_ci 405f6603c60Sopenharmony_ci/* 406f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0502 407f6603c60Sopenharmony_ci * @tc.name: testFontSetTypefaceMultipleCalls 408f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTypefaceMultipleCalls. 409f6603c60Sopenharmony_ci * @tc.size : SmallTest 410f6603c60Sopenharmony_ci * @tc.type : Function 411f6603c60Sopenharmony_ci * @tc.level : Level 3 412f6603c60Sopenharmony_ci */ 413f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTypefaceMultipleCalls, TestSize.Level3) { 414f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 415f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 416f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTypeface 10 times (with different typefaces), and call OH_Drawing_FontGetTypeface each 417f6603c60Sopenharmony_ci // time to get the glyph object 418f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 419f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface = OH_Drawing_TypefaceCreateDefault(); 420f6603c60Sopenharmony_ci OH_Drawing_FontSetTypeface(font, typeface); 421f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface2 = OH_Drawing_FontGetTypeface(font); 422f6603c60Sopenharmony_ci EXPECT_EQ(typeface, typeface2); 423f6603c60Sopenharmony_ci OH_Drawing_TypefaceDestroy(typeface); 424f6603c60Sopenharmony_ci } 425f6603c60Sopenharmony_ci // 3. Release memory 426f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 427f6603c60Sopenharmony_ci} 428f6603c60Sopenharmony_ci 429f6603c60Sopenharmony_ci/* 430f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0503 431f6603c60Sopenharmony_ci * @tc.name: testFontGetTypefaceWhenNoSet 432f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetTypefaceWhenNoSet. 433f6603c60Sopenharmony_ci * @tc.size : SmallTest 434f6603c60Sopenharmony_ci * @tc.type : Function 435f6603c60Sopenharmony_ci * @tc.level : Level 3 436f6603c60Sopenharmony_ci */ 437f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetTypefaceWhenNoSet, TestSize.Level3) { 438f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 439f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 440f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetTypeface to get the glyph object 441f6603c60Sopenharmony_ci OH_Drawing_Typeface *typeface = OH_Drawing_FontGetTypeface(font); 442f6603c60Sopenharmony_ci EXPECT_NE(typeface, nullptr); 443f6603c60Sopenharmony_ci // 3. Release memory 444f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 445f6603c60Sopenharmony_ci} 446f6603c60Sopenharmony_ci 447f6603c60Sopenharmony_ci/* 448f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0600 449f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSizeNormal 450f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSizeNormal. 451f6603c60Sopenharmony_ci * @tc.size : SmallTest 452f6603c60Sopenharmony_ci * @tc.type : Function 453f6603c60Sopenharmony_ci * @tc.level : Level 0 454f6603c60Sopenharmony_ci */ 455f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSizeNormal, TestSize.Level0) { 456f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 457f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 458f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSize with textSize parameter set to 100, and call OH_Drawing_FontGetTextSize to get 459f6603c60Sopenharmony_ci // the text size 460f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, 100); 461f6603c60Sopenharmony_ci float textSize = OH_Drawing_FontGetTextSize(font); 462f6603c60Sopenharmony_ci EXPECT_EQ(textSize, 100); 463f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetTextSize with textSize parameter set to 50.255, and call OH_Drawing_FontGetTextSize to 464f6603c60Sopenharmony_ci // get the text size 465f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, 50.255); 466f6603c60Sopenharmony_ci textSize = OH_Drawing_FontGetTextSize(font); 467f6603c60Sopenharmony_ci EXPECT_EQ(IsScalarAlmostEqual(textSize, 50.255), true); 468f6603c60Sopenharmony_ci // 4. Release memory 469f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 470f6603c60Sopenharmony_ci} 471f6603c60Sopenharmony_ci 472f6603c60Sopenharmony_ci/* 473f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0601 474f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSizeNULL 475f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSizeNULL. 476f6603c60Sopenharmony_ci * @tc.size : SmallTest 477f6603c60Sopenharmony_ci * @tc.type : Function 478f6603c60Sopenharmony_ci * @tc.level : Level 3 479f6603c60Sopenharmony_ci */ 480f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSizeNULL, TestSize.Level3) { 481f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 482f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 483f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSize with nullptr as the first parameter, check the error code using 484f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 485f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(nullptr, 100); 486f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 487f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetTextSize with 0 as the second parameter 488f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, 0); 489f6603c60Sopenharmony_ci float textSize = OH_Drawing_FontGetTextSize(font); 490f6603c60Sopenharmony_ci EXPECT_EQ(textSize, 0); 491f6603c60Sopenharmony_ci // 4. Call OH_Drawing_FontGetTextSize with nullptr as the parameter, check the error code using 492f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 493f6603c60Sopenharmony_ci OH_Drawing_FontGetTextSize(nullptr); 494f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 495f6603c60Sopenharmony_ci // 5. Release memory 496f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 497f6603c60Sopenharmony_ci} 498f6603c60Sopenharmony_ci 499f6603c60Sopenharmony_ci/* 500f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0602 501f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSizeMultipleCalls 502f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSizeMultipleCalls. 503f6603c60Sopenharmony_ci * @tc.size : SmallTest 504f6603c60Sopenharmony_ci * @tc.type : Function 505f6603c60Sopenharmony_ci * @tc.level : Level 3 506f6603c60Sopenharmony_ci */ 507f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSizeMultipleCalls, TestSize.Level3) { 508f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 509f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 510f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSize 10 times (with random textSize parameter), and call OH_Drawing_FontGetTextSize 511f6603c60Sopenharmony_ci // each time to get the text size 512f6603c60Sopenharmony_ci std::random_device rd; 513f6603c60Sopenharmony_ci std::mt19937 gen(rd()); 514f6603c60Sopenharmony_ci std::uniform_real_distribution<float> dis(0.0, 100.0); 515f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 516f6603c60Sopenharmony_ci float size = dis(gen); 517f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, size); 518f6603c60Sopenharmony_ci float textSize = OH_Drawing_FontGetTextSize(font); 519f6603c60Sopenharmony_ci EXPECT_EQ(textSize, size); 520f6603c60Sopenharmony_ci } 521f6603c60Sopenharmony_ci // 3. Release memory 522f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 523f6603c60Sopenharmony_ci} 524f6603c60Sopenharmony_ci 525f6603c60Sopenharmony_ci/* 526f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0603 527f6603c60Sopenharmony_ci * @tc.name: testFontGetTextSizeWhenNoSet 528f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetTextSizeWhenNoSet. 529f6603c60Sopenharmony_ci * @tc.size : SmallTest 530f6603c60Sopenharmony_ci * @tc.type : Function 531f6603c60Sopenharmony_ci * @tc.level : Level 3 532f6603c60Sopenharmony_ci */ 533f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetTextSizeWhenNoSet, TestSize.Level3) { 534f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 535f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 536f6603c60Sopenharmony_ci // 2. OH_Drawing_FontGetTextSize to get the text size 537f6603c60Sopenharmony_ci float textSize = OH_Drawing_FontGetTextSize(font); 538f6603c60Sopenharmony_ci EXPECT_EQ(textSize, 12); 539f6603c60Sopenharmony_ci // 3. Release memory 540f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 541f6603c60Sopenharmony_ci} 542f6603c60Sopenharmony_ci 543f6603c60Sopenharmony_ci/* 544f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0604 545f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSizeAbnormal 546f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSizeAbnormal. 547f6603c60Sopenharmony_ci * @tc.size : SmallTest 548f6603c60Sopenharmony_ci * @tc.type : Function 549f6603c60Sopenharmony_ci * @tc.level : Level 3 550f6603c60Sopenharmony_ci */ 551f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSizeAbnormal, TestSize.Level3) { 552f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 553f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 554f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSize with textSize parameter set to -100, and call OH_Drawing_FontGetTextSize to 555f6603c60Sopenharmony_ci // get the text size 556f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, -100); 557f6603c60Sopenharmony_ci float textSize = OH_Drawing_FontGetTextSize(font); 558f6603c60Sopenharmony_ci EXPECT_EQ(textSize, 0); 559f6603c60Sopenharmony_ci // 3. Release memory 560f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 561f6603c60Sopenharmony_ci} 562f6603c60Sopenharmony_ci 563f6603c60Sopenharmony_ci/* 564f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0700 565f6603c60Sopenharmony_ci * @tc.name: testFontCountTextNormal 566f6603c60Sopenharmony_ci * @tc.desc: test for testFontCountTextNormal. 567f6603c60Sopenharmony_ci * @tc.size : SmallTest 568f6603c60Sopenharmony_ci * @tc.type : Function 569f6603c60Sopenharmony_ci * @tc.level : Level 0 570f6603c60Sopenharmony_ci */ 571f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontCountTextNormal, TestSize.Level0) { 572f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 573f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 574f6603c60Sopenharmony_ci // 2. Enumerate through the encoding values in OH_Drawing_FontCountText 575f6603c60Sopenharmony_ci const char *str = "Hello World"; 576f6603c60Sopenharmony_ci OH_Drawing_TextEncoding encodes[] = { 577f6603c60Sopenharmony_ci TEXT_ENCODING_UTF8, 578f6603c60Sopenharmony_ci TEXT_ENCODING_UTF16, 579f6603c60Sopenharmony_ci TEXT_ENCODING_UTF32, 580f6603c60Sopenharmony_ci TEXT_ENCODING_GLYPH_ID, 581f6603c60Sopenharmony_ci }; 582f6603c60Sopenharmony_ci for (OH_Drawing_TextEncoding encode : encodes) { 583f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), encode); 584f6603c60Sopenharmony_ci switch (encode) { 585f6603c60Sopenharmony_ci case TEXT_ENCODING_UTF8: 586f6603c60Sopenharmony_ci EXPECT_EQ(count, 11); 587f6603c60Sopenharmony_ci break; 588f6603c60Sopenharmony_ci case TEXT_ENCODING_UTF16: 589f6603c60Sopenharmony_ci EXPECT_EQ(count, 11); 590f6603c60Sopenharmony_ci break; 591f6603c60Sopenharmony_ci case TEXT_ENCODING_UTF32: 592f6603c60Sopenharmony_ci EXPECT_EQ(count, 11); 593f6603c60Sopenharmony_ci break; 594f6603c60Sopenharmony_ci case TEXT_ENCODING_GLYPH_ID: 595f6603c60Sopenharmony_ci EXPECT_EQ(count, 11); 596f6603c60Sopenharmony_ci break; 597f6603c60Sopenharmony_ci default: 598f6603c60Sopenharmony_ci break; 599f6603c60Sopenharmony_ci } 600f6603c60Sopenharmony_ci } 601f6603c60Sopenharmony_ci // 3. Release memory 602f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 603f6603c60Sopenharmony_ci} 604f6603c60Sopenharmony_ci 605f6603c60Sopenharmony_ci/* 606f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0701 607f6603c60Sopenharmony_ci * @tc.name: testFontCountTextNULL 608f6603c60Sopenharmony_ci * @tc.desc: test for testFontCountTextNULL. 609f6603c60Sopenharmony_ci * @tc.size : SmallTest 610f6603c60Sopenharmony_ci * @tc.type : Function 611f6603c60Sopenharmony_ci * @tc.level : Level 3 612f6603c60Sopenharmony_ci */ 613f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontCountTextNULL, TestSize.Level3) { 614f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 615f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 616f6603c60Sopenharmony_ci const char *str = "Hello World"; 617f6603c60Sopenharmony_ci // 2. Pass nullptr as the first parameter to OH_Drawing_FontCountText and check the error code using 618f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 619f6603c60Sopenharmony_ci OH_Drawing_FontCountText(nullptr, str, strlen(str), TEXT_ENCODING_UTF8); 620f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 621f6603c60Sopenharmony_ci // 3. Pass nullptr as the second parameter to OH_Drawing_FontCountText and check the error code using 622f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 623f6603c60Sopenharmony_ci OH_Drawing_FontCountText(font, nullptr, strlen(str), TEXT_ENCODING_UTF8); 624f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 625f6603c60Sopenharmony_ci // 4. Pass an empty string as the second parameter and NULL as the third parameter to OH_Drawing_FontCountText 626f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, "", 0, TEXT_ENCODING_UTF8); 627f6603c60Sopenharmony_ci EXPECT_EQ(count, 0); 628f6603c60Sopenharmony_ci // 5. Release memory 629f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 630f6603c60Sopenharmony_ci} 631f6603c60Sopenharmony_ci 632f6603c60Sopenharmony_ci/* 633f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0702 634f6603c60Sopenharmony_ci * @tc.name: testFontCountTextMultipleCalls 635f6603c60Sopenharmony_ci * @tc.desc: test for testFontCountTextMultipleCalls. 636f6603c60Sopenharmony_ci * @tc.size : SmallTest 637f6603c60Sopenharmony_ci * @tc.type : Function 638f6603c60Sopenharmony_ci * @tc.level : Level 3 639f6603c60Sopenharmony_ci */ 640f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontCountTextMultipleCalls, TestSize.Level3) { 641f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 642f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 643f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontCountText 10 times (with different lengths and types of strings, such as Chinese, English, 644f6603c60Sopenharmony_ci // traditional characters, special characters, numbers, etc.) 645f6603c60Sopenharmony_ci const char *strs[] = { 646f6603c60Sopenharmony_ci "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文", 647f6603c60Sopenharmony_ci }; 648f6603c60Sopenharmony_ci for (const char *str : strs) { 649f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 650f6603c60Sopenharmony_ci if (strcmp(str, "Hello World") == 0) { // Use strcmp for string comparison 651f6603c60Sopenharmony_ci EXPECT_EQ(count, 11); 652f6603c60Sopenharmony_ci } else if (strcmp(str, "你好世界") == 0) { 653f6603c60Sopenharmony_ci EXPECT_EQ(count, 4); 654f6603c60Sopenharmony_ci } else if (strcmp(str, "Hello 世界") == 0) { 655f6603c60Sopenharmony_ci EXPECT_EQ(count, 8); 656f6603c60Sopenharmony_ci } else if (strcmp(str, "Hello 世界123") == 0) { 657f6603c60Sopenharmony_ci EXPECT_EQ(count, 11); 658f6603c60Sopenharmony_ci } else if (strcmp(str, "Hello $#@!") == 0) { 659f6603c60Sopenharmony_ci EXPECT_EQ(count, 10); 660f6603c60Sopenharmony_ci } else if (strcmp(str, "繁體中文") == 0) { 661f6603c60Sopenharmony_ci EXPECT_EQ(count, 4); 662f6603c60Sopenharmony_ci } 663f6603c60Sopenharmony_ci } 664f6603c60Sopenharmony_ci // 3. Release memory 665f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 666f6603c60Sopenharmony_ci} 667f6603c60Sopenharmony_ci 668f6603c60Sopenharmony_ci/* 669f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0703 670f6603c60Sopenharmony_ci * @tc.name: testFontCountTextAbnormal 671f6603c60Sopenharmony_ci * @tc.desc: test for testFontCountTextAbnormal. 672f6603c60Sopenharmony_ci * @tc.size : SmallTest 673f6603c60Sopenharmony_ci * @tc.type : Function 674f6603c60Sopenharmony_ci * @tc.level : Level 3 675f6603c60Sopenharmony_ci */ 676f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontCountTextAbnormal, TestSize.Level3) { 677f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 678f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 679f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSize with textSize parameter set to -1 680f6603c60Sopenharmony_ci const char *str = "Hello World"; 681f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, -1, TEXT_ENCODING_UTF8); 682f6603c60Sopenharmony_ci EXPECT_EQ(count, 0); 683f6603c60Sopenharmony_ci // 3. Release memory 684f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 685f6603c60Sopenharmony_ci} 686f6603c60Sopenharmony_ci 687f6603c60Sopenharmony_ci/* 688f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0800 689f6603c60Sopenharmony_ci * @tc.name: testFontTextToGlyphsNormal 690f6603c60Sopenharmony_ci * @tc.desc: test for testFontTextToGlyphsNormal. 691f6603c60Sopenharmony_ci * @tc.size : SmallTest 692f6603c60Sopenharmony_ci * @tc.type : Function 693f6603c60Sopenharmony_ci * @tc.level : Level 0 694f6603c60Sopenharmony_ci */ 695f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontTextToGlyphsNormal, TestSize.Level0) { 696f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 697f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 698f6603c60Sopenharmony_ci // 2. Enumerate through the encoding values in OH_Drawing_FontTextToGlyphs 699f6603c60Sopenharmony_ci const char *str = "Hello World"; 700f6603c60Sopenharmony_ci OH_Drawing_TextEncoding encodes[] = { 701f6603c60Sopenharmony_ci TEXT_ENCODING_UTF8, 702f6603c60Sopenharmony_ci TEXT_ENCODING_UTF16, 703f6603c60Sopenharmony_ci TEXT_ENCODING_UTF32, 704f6603c60Sopenharmony_ci TEXT_ENCODING_GLYPH_ID, 705f6603c60Sopenharmony_ci }; 706f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 707f6603c60Sopenharmony_ci for (OH_Drawing_TextEncoding encode : encodes) { 708f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), encode); 709f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, strlen(str), encode, glyphs, count); 710f6603c60Sopenharmony_ci } 711f6603c60Sopenharmony_ci // 3. Pass floating-point values for maxGlyphCount and byteLength parameters in OH_Drawing_FontTextToGlyphs 712f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, 11.0f, TEXT_ENCODING_UTF8, glyphs, 11.0f); 713f6603c60Sopenharmony_ci // 4. Release memory 714f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 715f6603c60Sopenharmony_ci} 716f6603c60Sopenharmony_ci 717f6603c60Sopenharmony_ci/* 718f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0801 719f6603c60Sopenharmony_ci * @tc.name: testFontTextToGlyphsNULL 720f6603c60Sopenharmony_ci * @tc.desc: test for testFontTextToGlyphsNULL. 721f6603c60Sopenharmony_ci * @tc.size : SmallTest 722f6603c60Sopenharmony_ci * @tc.type : Function 723f6603c60Sopenharmony_ci * @tc.level : Level 3 724f6603c60Sopenharmony_ci */ 725f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontTextToGlyphsNULL, TestSize.Level3) { 726f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 727f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 728f6603c60Sopenharmony_ci const char *str = "Hello World"; 729f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 730f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 731f6603c60Sopenharmony_ci // 2. Pass nullptr as the first parameter to OH_Drawing_FontTextToGlyphs and check the error code using 732f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 733f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(nullptr, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 734f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 735f6603c60Sopenharmony_ci // 3. Pass nullptr as the second parameter to OH_Drawing_FontTextToGlyphs and check the error code using 736f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 737f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, nullptr, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 738f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 739f6603c60Sopenharmony_ci // 4. Pass an empty string as the third parameter to OH_Drawing_FontTextToGlyphs and check the error code using 740f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 741f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, 0, TEXT_ENCODING_UTF8, glyphs, count); 742f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 743f6603c60Sopenharmony_ci // 5. Pass nullptr as the fifth parameter to OH_Drawing_FontTextToGlyphs and check the error code using 744f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 745f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, nullptr, count); 746f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 747f6603c60Sopenharmony_ci // 6. Pass 0 as the sixth parameter to OH_Drawing_FontTextToGlyphs and check the error code using 748f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 749f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, 0); 750f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 751f6603c60Sopenharmony_ci // 7. Pass an empty string as the second parameter to OH_Drawing_FontTextToGlyphs 752f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, "", 0, TEXT_ENCODING_UTF8, glyphs, count); 753f6603c60Sopenharmony_ci // 8. Release memory 754f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 755f6603c60Sopenharmony_ci} 756f6603c60Sopenharmony_ci 757f6603c60Sopenharmony_ci/* 758f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0802 759f6603c60Sopenharmony_ci * @tc.name: testFontTextToGlyphsMultipleCalls 760f6603c60Sopenharmony_ci * @tc.desc: test for testFontTextToGlyphsMultipleCalls. 761f6603c60Sopenharmony_ci * @tc.size : SmallTest 762f6603c60Sopenharmony_ci * @tc.type : Function 763f6603c60Sopenharmony_ci * @tc.level : Level 3 764f6603c60Sopenharmony_ci */ 765f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontTextToGlyphsMultipleCalls, TestSize.Level3) { 766f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 767f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 768f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontTextToGlyphs 10 times (with different lengths and types of strings, such as Chinese, 769f6603c60Sopenharmony_ci // English, traditional characters, special characters, numbers, etc.) 770f6603c60Sopenharmony_ci const char *strs[] = { 771f6603c60Sopenharmony_ci "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文", 772f6603c60Sopenharmony_ci }; 773f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 774f6603c60Sopenharmony_ci for (const char *str : strs) { 775f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 776f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 777f6603c60Sopenharmony_ci } 778f6603c60Sopenharmony_ci // 3. Release memory 779f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 780f6603c60Sopenharmony_ci} 781f6603c60Sopenharmony_ci 782f6603c60Sopenharmony_ci/* 783f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0803 784f6603c60Sopenharmony_ci * @tc.name: testFontTextToGlyphsAbnormal 785f6603c60Sopenharmony_ci * @tc.desc: test for testFontTextToGlyphsAbnormal. 786f6603c60Sopenharmony_ci * @tc.size : SmallTest 787f6603c60Sopenharmony_ci * @tc.type : Function 788f6603c60Sopenharmony_ci * @tc.level : Level 3 789f6603c60Sopenharmony_ci */ 790f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontTextToGlyphsAbnormal, TestSize.Level3) { 791f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 792f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 793f6603c60Sopenharmony_ci const char *str = "Hello World"; 794f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 795f6603c60Sopenharmony_ci // 2. Set byteLength parameter to -1 for OH_Drawing_FontTextToGlyphs interface 796f6603c60Sopenharmony_ci // Ignore, no need to test the case with byteLength parameter set to -1 797f6603c60Sopenharmony_ci // 3. Set maxGlyphCount parameter to -1 for OH_Drawing_FontTextToGlyphs interface and check the error code using 798f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 799f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, -1); 800f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 801f6603c60Sopenharmony_ci // 4. Release memory 802f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 803f6603c60Sopenharmony_ci} 804f6603c60Sopenharmony_ci 805f6603c60Sopenharmony_ci/* 806f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0804 807f6603c60Sopenharmony_ci * @tc.name: testFontTextToGlyphsMaximum 808f6603c60Sopenharmony_ci * @tc.desc: test for testFontTextToGlyphsMaximum. 809f6603c60Sopenharmony_ci * @tc.size : SmallTest 810f6603c60Sopenharmony_ci * @tc.type : Function 811f6603c60Sopenharmony_ci * @tc.level : Level 3 812f6603c60Sopenharmony_ci */ 813f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontTextToGlyphsMaximum, TestSize.Level3) { 814f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 815f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 816f6603c60Sopenharmony_ci const char *str = "Hello World"; 817f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 818f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 819f6603c60Sopenharmony_ci // 2. Set byteLength parameter to maximum value for OH_Drawing_FontTextToGlyphs interface 820f6603c60Sopenharmony_ci // Ignore, no need to test the case with maximum byteLength parameter 821f6603c60Sopenharmony_ci // 3. Set maxGlyphCount parameter to maximum value for OH_Drawing_FontTextToGlyphs interface 822f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, INT32_MAX); 823f6603c60Sopenharmony_ci // 4. Set glyphs parameter to maximum value for OH_Drawing_FontTextToGlyphs interface 824f6603c60Sopenharmony_ci uint16_t glyphs2[50] = {UINT16_MAX}; 825f6603c60Sopenharmony_ci OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs2, count); 826f6603c60Sopenharmony_ci // 5. Release memory 827f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 828f6603c60Sopenharmony_ci} 829f6603c60Sopenharmony_ci 830f6603c60Sopenharmony_ci/* 831f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0900 832f6603c60Sopenharmony_ci * @tc.name: testFontGetWidthsNormal 833f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetWidthsNormal. 834f6603c60Sopenharmony_ci * @tc.size : SmallTest 835f6603c60Sopenharmony_ci * @tc.type : Function 836f6603c60Sopenharmony_ci * @tc.level : Level 0 837f6603c60Sopenharmony_ci */ 838f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetWidthsNormal, TestSize.Level0) { 839f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 840f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 841f6603c60Sopenharmony_ci // 2. OH_Drawing_FontGetWidths 842f6603c60Sopenharmony_ci const char *str = "Hello World"; 843f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 844f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 845f6603c60Sopenharmony_ci int glyphsCount = OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 846f6603c60Sopenharmony_ci float widths[50] = {0.f}; 847f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, glyphsCount, widths); 848f6603c60Sopenharmony_ci EXPECT_GT(widths[0], 0.f); 849f6603c60Sopenharmony_ci // 3. Release memory 850f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 851f6603c60Sopenharmony_ci} 852f6603c60Sopenharmony_ci 853f6603c60Sopenharmony_ci/* 854f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0901 855f6603c60Sopenharmony_ci * @tc.name: testFontGetWidthsNULL 856f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetWidthsNULL. 857f6603c60Sopenharmony_ci * @tc.size : SmallTest 858f6603c60Sopenharmony_ci * @tc.type : Function 859f6603c60Sopenharmony_ci * @tc.level : Level 3 860f6603c60Sopenharmony_ci */ 861f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetWidthsNULL, TestSize.Level3) { 862f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 863f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 864f6603c60Sopenharmony_ci const char *str = "Hello World"; 865f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 866f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 867f6603c60Sopenharmony_ci int glyphsCount = OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 868f6603c60Sopenharmony_ci float widths[50] = {0.f}; 869f6603c60Sopenharmony_ci // 2. Pass nullptr as the first parameter to OH_Drawing_FontGetWidths and check the error code using 870f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 871f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(nullptr, glyphs, glyphsCount, widths); 872f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 873f6603c60Sopenharmony_ci // 3. Pass nullptr as the second parameter to OH_Drawing_FontGetWidths and check the error code using 874f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 875f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, nullptr, glyphsCount, widths); 876f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 877f6603c60Sopenharmony_ci // 4. Pass 0 as the third parameter to OH_Drawing_FontGetWidths and check the error code using 878f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 879f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, 0, widths); 880f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 881f6603c60Sopenharmony_ci // 5. Pass nullptr as the fourth parameter to OH_Drawing_FontGetWidths and check the error code using 882f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 883f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, glyphsCount, nullptr); 884f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 885f6603c60Sopenharmony_ci // 6. Release memory 886f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 887f6603c60Sopenharmony_ci} 888f6603c60Sopenharmony_ci 889f6603c60Sopenharmony_ci/* 890f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0902 891f6603c60Sopenharmony_ci * @tc.name: testFontGetWidthsMultipleCalls 892f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetWidthsMultipleCalls. 893f6603c60Sopenharmony_ci * @tc.size : SmallTest 894f6603c60Sopenharmony_ci * @tc.type : Function 895f6603c60Sopenharmony_ci * @tc.level : Level 3 896f6603c60Sopenharmony_ci */ 897f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetWidthsMultipleCalls, TestSize.Level3) { 898f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 899f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 900f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetWidths 10 times (with different lengths and types of strings, such as Chinese, English, 901f6603c60Sopenharmony_ci // traditional characters, special characters, numbers, etc.) 902f6603c60Sopenharmony_ci const char *strs[] = { 903f6603c60Sopenharmony_ci "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文", 904f6603c60Sopenharmony_ci }; 905f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 906f6603c60Sopenharmony_ci float widths[50] = {0.f}; 907f6603c60Sopenharmony_ci for (const char *str : strs) { 908f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 909f6603c60Sopenharmony_ci int glyphsCount = OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 910f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, glyphsCount, widths); 911f6603c60Sopenharmony_ci EXPECT_GT(widths[0], 0.f); 912f6603c60Sopenharmony_ci } 913f6603c60Sopenharmony_ci // 3. Release memory 914f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 915f6603c60Sopenharmony_ci} 916f6603c60Sopenharmony_ci 917f6603c60Sopenharmony_ci/* 918f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0903 919f6603c60Sopenharmony_ci * @tc.name: testFontGetWidthsAbnormal 920f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetWidthsAbnormal. 921f6603c60Sopenharmony_ci * @tc.size : SmallTest 922f6603c60Sopenharmony_ci * @tc.type : Function 923f6603c60Sopenharmony_ci * @tc.level : Level 3 924f6603c60Sopenharmony_ci */ 925f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetWidthsAbnormal, TestSize.Level3) { 926f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 927f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 928f6603c60Sopenharmony_ci const char *str = "Hello World"; 929f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 930f6603c60Sopenharmony_ci float widths[50] = {0.f}; 931f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 932f6603c60Sopenharmony_ci int glyphsCount = OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 933f6603c60Sopenharmony_ci // 2. Set byteLength parameter to -1 for OH_Drawing_FontGetWidths interface 934f6603c60Sopenharmony_ci // There is no byteLength parameter 935f6603c60Sopenharmony_ci // 3. Set count parameter to -1 for OH_Drawing_FontGetWidths interface and check the error code using 936f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 937f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, -1, widths); 938f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 939f6603c60Sopenharmony_ci // 4. Set widths parameter to -1 for OH_Drawing_FontGetWidths interface 940f6603c60Sopenharmony_ci float widths2[50] = {-1}; 941f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, glyphsCount, widths2); 942f6603c60Sopenharmony_ci // 5. Set count parameter to a floating-point value greater than 0 for OH_Drawing_FontGetWidths interface 943f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, 2.0f, widths); 944f6603c60Sopenharmony_ci // 6. Release memory 945f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 946f6603c60Sopenharmony_ci} 947f6603c60Sopenharmony_ci 948f6603c60Sopenharmony_ci/* 949f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_0904 950f6603c60Sopenharmony_ci * @tc.name: testFontGetWidthsMaximum 951f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetWidthsMaximum. 952f6603c60Sopenharmony_ci * @tc.size : SmallTest 953f6603c60Sopenharmony_ci * @tc.type : Function 954f6603c60Sopenharmony_ci * @tc.level : Level 3 955f6603c60Sopenharmony_ci */ 956f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetWidthsMaximum, TestSize.Level3) { 957f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 958f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 959f6603c60Sopenharmony_ci const char *str = "Hello World"; 960f6603c60Sopenharmony_ci uint16_t glyphs[50] = {0}; // 50 means glyphs array number 961f6603c60Sopenharmony_ci float widths[50] = {0.f}; 962f6603c60Sopenharmony_ci int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8); 963f6603c60Sopenharmony_ci int glyphsCount = OH_Drawing_FontTextToGlyphs(font, str, strlen(str), TEXT_ENCODING_UTF8, glyphs, count); 964f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetWidths interface with maximum value for glyphs parameter 965f6603c60Sopenharmony_ci uint16_t glyphs2[50] = {UINT16_MAX}; 966f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs2, glyphsCount, widths); 967f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontGetWidths interface with maximum value for count parameter 968f6603c60Sopenharmony_ci // Ignore, no need to test the case with maximum count parameter 969f6603c60Sopenharmony_ci // 4. Call OH_Drawing_FontGetWidths interface with maximum value for widths parameter 970f6603c60Sopenharmony_ci float widths2[50] = {FLT_MAX}; 971f6603c60Sopenharmony_ci OH_Drawing_FontGetWidths(font, glyphs, glyphsCount, widths2); 972f6603c60Sopenharmony_ci // 5. Release memory 973f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 974f6603c60Sopenharmony_ci} 975f6603c60Sopenharmony_ci 976f6603c60Sopenharmony_ci/* 977f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1000 978f6603c60Sopenharmony_ci * @tc.name: testFontSetLinearTextNormal 979f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetLinearTextNormal. 980f6603c60Sopenharmony_ci * @tc.size : SmallTest 981f6603c60Sopenharmony_ci * @tc.type : Function 982f6603c60Sopenharmony_ci * @tc.level : Level 0 983f6603c60Sopenharmony_ci */ 984f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetLinearTextNormal, TestSize.Level0) { 985f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 986f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 987f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetLinearText with isLinearText parameter set to false, and then call 988f6603c60Sopenharmony_ci // OH_Drawing_FontIsLinearText to check if the glyphs are scaled linearly 989f6603c60Sopenharmony_ci OH_Drawing_FontSetLinearText(font, false); 990f6603c60Sopenharmony_ci bool isLinearText = OH_Drawing_FontIsLinearText(font); 991f6603c60Sopenharmony_ci EXPECT_EQ(isLinearText, false); 992f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetLinearText with isLinearText parameter set to true, and then call 993f6603c60Sopenharmony_ci // OH_Drawing_FontIsLinearText to check if the glyphs are scaled linearly 994f6603c60Sopenharmony_ci OH_Drawing_FontSetLinearText(font, true); 995f6603c60Sopenharmony_ci isLinearText = OH_Drawing_FontIsLinearText(font); 996f6603c60Sopenharmony_ci EXPECT_EQ(isLinearText, true); 997f6603c60Sopenharmony_ci // 4. Release memory 998f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 999f6603c60Sopenharmony_ci} 1000f6603c60Sopenharmony_ci 1001f6603c60Sopenharmony_ci/* 1002f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1001 1003f6603c60Sopenharmony_ci * @tc.name: testFontSetLinearTextNULL 1004f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetLinearTextNULL. 1005f6603c60Sopenharmony_ci * @tc.size : SmallTest 1006f6603c60Sopenharmony_ci * @tc.type : Function 1007f6603c60Sopenharmony_ci * @tc.level : Level 3 1008f6603c60Sopenharmony_ci */ 1009f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetLinearTextNULL, TestSize.Level3) { 1010f6603c60Sopenharmony_ci // 1. Pass nullptr as the first parameter to OH_Drawing_FontSetLinearText and check the error code using 1011f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1012f6603c60Sopenharmony_ci OH_Drawing_FontSetLinearText(nullptr, false); 1013f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1014f6603c60Sopenharmony_ci // 2. Pass nullptr as the parameter to OH_Drawing_FontIsLinearText and check the error code using 1015f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1016f6603c60Sopenharmony_ci OH_Drawing_FontIsLinearText(nullptr); 1017f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1018f6603c60Sopenharmony_ci} 1019f6603c60Sopenharmony_ci 1020f6603c60Sopenharmony_ci/* 1021f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1002 1022f6603c60Sopenharmony_ci * @tc.name: testFontSetLinearTextMultipleCalls 1023f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetLinearTextMultipleCalls. 1024f6603c60Sopenharmony_ci * @tc.size : SmallTest 1025f6603c60Sopenharmony_ci * @tc.type : Function 1026f6603c60Sopenharmony_ci * @tc.level : Level 3 1027f6603c60Sopenharmony_ci */ 1028f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetLinearTextMultipleCalls, TestSize.Level3) { 1029f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1030f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1031f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetLinearText 10 times, and call OH_Drawing_FontIsLinearText to check if the glyphs are 1032f6603c60Sopenharmony_ci // scaled linearly 1033f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1034f6603c60Sopenharmony_ci OH_Drawing_FontSetLinearText(font, i % 2 == 0); 1035f6603c60Sopenharmony_ci bool isLinearText = OH_Drawing_FontIsLinearText(font); 1036f6603c60Sopenharmony_ci EXPECT_EQ(isLinearText, i % 2 == 0); 1037f6603c60Sopenharmony_ci } 1038f6603c60Sopenharmony_ci // 3. Release memory 1039f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1040f6603c60Sopenharmony_ci} 1041f6603c60Sopenharmony_ci 1042f6603c60Sopenharmony_ci/* 1043f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1003 1044f6603c60Sopenharmony_ci * @tc.name: testFontIsLinearTextWhenNoSet 1045f6603c60Sopenharmony_ci * @tc.desc: test for testFontIsLinearTextWhenNoSet. 1046f6603c60Sopenharmony_ci * @tc.size : SmallTest 1047f6603c60Sopenharmony_ci * @tc.type : Function 1048f6603c60Sopenharmony_ci * @tc.level : Level 3 1049f6603c60Sopenharmony_ci */ 1050f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontIsLinearTextWhenNoSet, TestSize.Level3) { 1051f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1052f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1053f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsLinearText 1054f6603c60Sopenharmony_ci bool isLinearText = OH_Drawing_FontIsLinearText(font); 1055f6603c60Sopenharmony_ci EXPECT_EQ(isLinearText, false); 1056f6603c60Sopenharmony_ci // 3. Release memory 1057f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1058f6603c60Sopenharmony_ci} 1059f6603c60Sopenharmony_ci 1060f6603c60Sopenharmony_ci/* 1061f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1100 1062f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSkewXNormal 1063f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSkewXNormal. 1064f6603c60Sopenharmony_ci * @tc.size : SmallTest 1065f6603c60Sopenharmony_ci * @tc.type : Function 1066f6603c60Sopenharmony_ci * @tc.level : Level 0 1067f6603c60Sopenharmony_ci */ 1068f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSkewXNormal, TestSize.Level0) { 1069f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1070f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1071f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSkewX interface with skewX parameter set to 10, and then call 1072f6603c60Sopenharmony_ci // OH_Drawing_FontGetTextSkewX to get the text skew on the x-axis 1073f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(font, 10); 1074f6603c60Sopenharmony_ci float skewX = OH_Drawing_FontGetTextSkewX(font); 1075f6603c60Sopenharmony_ci EXPECT_EQ(skewX, 10); 1076f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetTextSkewX interface with skewX parameter set to 0.55, and then call 1077f6603c60Sopenharmony_ci // OH_Drawing_FontGetTextSkewX to get the text skew on the x-axis 1078f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(font, 0.55); 1079f6603c60Sopenharmony_ci skewX = OH_Drawing_FontGetTextSkewX(font); 1080f6603c60Sopenharmony_ci EXPECT_EQ(IsScalarAlmostEqual(skewX, 0.55), true); 1081f6603c60Sopenharmony_ci // 4. Release memory 1082f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1083f6603c60Sopenharmony_ci} 1084f6603c60Sopenharmony_ci 1085f6603c60Sopenharmony_ci/* 1086f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1101 1087f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSkewXNULL 1088f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSkewXNULL. 1089f6603c60Sopenharmony_ci * @tc.size : SmallTest 1090f6603c60Sopenharmony_ci * @tc.type : Function 1091f6603c60Sopenharmony_ci * @tc.level : Level 3 1092f6603c60Sopenharmony_ci */ 1093f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSkewXNULL, TestSize.Level3) { 1094f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1095f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1096f6603c60Sopenharmony_ci // 2. Pass nullptr as the first parameter to OH_Drawing_FontSetTextSkewX and check the error code using 1097f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1098f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(nullptr, 10); 1099f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1100f6603c60Sopenharmony_ci // 3. Pass 0 as the second parameter to OH_Drawing_FontSetTextSkewX 1101f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(font, 0); 1102f6603c60Sopenharmony_ci // 4. Pass nullptr as the parameter to OH_Drawing_FontGetTextSkewX and check the error code using 1103f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1104f6603c60Sopenharmony_ci OH_Drawing_FontGetTextSkewX(nullptr); 1105f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1106f6603c60Sopenharmony_ci // 5. Release memory 1107f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1108f6603c60Sopenharmony_ci} 1109f6603c60Sopenharmony_ci 1110f6603c60Sopenharmony_ci/* 1111f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1102 1112f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSkewXMultipleCalls 1113f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSkewXMultipleCalls. 1114f6603c60Sopenharmony_ci * @tc.size : SmallTest 1115f6603c60Sopenharmony_ci * @tc.type : Function 1116f6603c60Sopenharmony_ci * @tc.level : Level 3 1117f6603c60Sopenharmony_ci */ 1118f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSkewXMultipleCalls, TestSize.Level3) { 1119f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1120f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1121f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSkewX 10 times (with random skewX values), and call OH_Drawing_FontGetTextSkewX to 1122f6603c60Sopenharmony_ci // get the text skew on the x-axis each time 1123f6603c60Sopenharmony_ci std::random_device rd; 1124f6603c60Sopenharmony_ci std::mt19937 gen(rd()); 1125f6603c60Sopenharmony_ci std::uniform_real_distribution<float> dis(0, 30); 1126f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1127f6603c60Sopenharmony_ci float val = dis(gen); 1128f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(font, val); 1129f6603c60Sopenharmony_ci float skewX = OH_Drawing_FontGetTextSkewX(font); 1130f6603c60Sopenharmony_ci EXPECT_EQ(skewX, val); 1131f6603c60Sopenharmony_ci } 1132f6603c60Sopenharmony_ci // 3. Release memory 1133f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1134f6603c60Sopenharmony_ci} 1135f6603c60Sopenharmony_ci 1136f6603c60Sopenharmony_ci/* 1137f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1103 1138f6603c60Sopenharmony_ci * @tc.name: testFontGetTextSkewXWhenNoSet 1139f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetTextSkewXWhenNoSet. 1140f6603c60Sopenharmony_ci * @tc.size : SmallTest 1141f6603c60Sopenharmony_ci * @tc.type : Function 1142f6603c60Sopenharmony_ci * @tc.level : Level 3 1143f6603c60Sopenharmony_ci */ 1144f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetTextSkewXWhenNoSet, TestSize.Level3) { 1145f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1146f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1147f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetTextSkewX to get the text skew on the x-axis 1148f6603c60Sopenharmony_ci float skewX = OH_Drawing_FontGetTextSkewX(font); 1149f6603c60Sopenharmony_ci EXPECT_EQ(skewX, 0); 1150f6603c60Sopenharmony_ci // 3. Release memory 1151f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1152f6603c60Sopenharmony_ci} 1153f6603c60Sopenharmony_ci 1154f6603c60Sopenharmony_ci/* 1155f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1104 1156f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSkewXAbnormal 1157f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSkewXAbnormal. 1158f6603c60Sopenharmony_ci * @tc.size : SmallTest 1159f6603c60Sopenharmony_ci * @tc.type : Function 1160f6603c60Sopenharmony_ci * @tc.level : Level 3 1161f6603c60Sopenharmony_ci */ 1162f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSkewXAbnormal, TestSize.Level3) { 1163f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1164f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1165f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSkewX interface with skewX parameter set to -1, and then call 1166f6603c60Sopenharmony_ci // OH_Drawing_FontGetTextSkewX to get the text skew on the x-axis 1167f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(font, -1); 1168f6603c60Sopenharmony_ci float skewX = OH_Drawing_FontGetTextSkewX(font); 1169f6603c60Sopenharmony_ci EXPECT_EQ(skewX, -1); 1170f6603c60Sopenharmony_ci // 3. Release memory 1171f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1172f6603c60Sopenharmony_ci} 1173f6603c60Sopenharmony_ci 1174f6603c60Sopenharmony_ci/* 1175f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1105 1176f6603c60Sopenharmony_ci * @tc.name: testFontSetTextSkewXMaximum 1177f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetTextSkewXMaximum. 1178f6603c60Sopenharmony_ci * @tc.size : SmallTest 1179f6603c60Sopenharmony_ci * @tc.type : Function 1180f6603c60Sopenharmony_ci * @tc.level : Level 3 1181f6603c60Sopenharmony_ci */ 1182f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetTextSkewXMaximum, TestSize.Level3) { 1183f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1184f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1185f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetTextSkewX interface with skewX parameter set to FLT_MAX 1186f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSkewX(font, FLT_MAX); 1187f6603c60Sopenharmony_ci // 3. Release memory 1188f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1189f6603c60Sopenharmony_ci} 1190f6603c60Sopenharmony_ci 1191f6603c60Sopenharmony_ci/* 1192f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1200 1193f6603c60Sopenharmony_ci * @tc.name: testFontSetFakeBoldTextNormal 1194f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetFakeBoldTextNormal. 1195f6603c60Sopenharmony_ci * @tc.size : SmallTest 1196f6603c60Sopenharmony_ci * @tc.type : Function 1197f6603c60Sopenharmony_ci * @tc.level : Level 0 1198f6603c60Sopenharmony_ci */ 1199f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetFakeBoldTextNormal, TestSize.Level0) { 1200f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1201f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1202f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetFakeBoldText interface with isFakeBoldText parameter set to false, and then call 1203f6603c60Sopenharmony_ci // OH_Drawing_FontIsFakeBoldText to check if the stroke width is increased to approximate bold text 1204f6603c60Sopenharmony_ci OH_Drawing_FontSetFakeBoldText(font, false); 1205f6603c60Sopenharmony_ci bool isFakeBoldText = OH_Drawing_FontIsFakeBoldText(font); 1206f6603c60Sopenharmony_ci EXPECT_EQ(isFakeBoldText, false); 1207f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetFakeBoldText interface with isFakeBoldText parameter set to true, and then call 1208f6603c60Sopenharmony_ci // OH_Drawing_FontIsFakeBoldText to check if the stroke width is increased to approximate bold text 1209f6603c60Sopenharmony_ci OH_Drawing_FontSetFakeBoldText(font, true); 1210f6603c60Sopenharmony_ci isFakeBoldText = OH_Drawing_FontIsFakeBoldText(font); 1211f6603c60Sopenharmony_ci EXPECT_EQ(isFakeBoldText, true); 1212f6603c60Sopenharmony_ci // 4. Release memory 1213f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1214f6603c60Sopenharmony_ci} 1215f6603c60Sopenharmony_ci 1216f6603c60Sopenharmony_ci/* 1217f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1201 1218f6603c60Sopenharmony_ci * @tc.name: testFontSetFakeBoldTextNULL 1219f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetFakeBoldTextNULL. 1220f6603c60Sopenharmony_ci * @tc.size : SmallTest 1221f6603c60Sopenharmony_ci * @tc.type : Function 1222f6603c60Sopenharmony_ci * @tc.level : Level 3 1223f6603c60Sopenharmony_ci */ 1224f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetFakeBoldTextNULL, TestSize.Level3) { 1225f6603c60Sopenharmony_ci // 1. Pass nullptr as the first parameter to OH_Drawing_FontSetFakeBoldText and check the error code using 1226f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1227f6603c60Sopenharmony_ci OH_Drawing_FontSetFakeBoldText(nullptr, false); 1228f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1229f6603c60Sopenharmony_ci // 2. Pass nullptr as the parameter to OH_Drawing_FontIsFakeBoldText and check the error code using 1230f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1231f6603c60Sopenharmony_ci OH_Drawing_FontIsFakeBoldText(nullptr); 1232f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1233f6603c60Sopenharmony_ci} 1234f6603c60Sopenharmony_ci 1235f6603c60Sopenharmony_ci/* 1236f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1202 1237f6603c60Sopenharmony_ci * @tc.name: testFontSetFakeBoldTextMultipleCalls 1238f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetFakeBoldTextMultipleCalls. 1239f6603c60Sopenharmony_ci * @tc.size : SmallTest 1240f6603c60Sopenharmony_ci * @tc.type : Function 1241f6603c60Sopenharmony_ci * @tc.level : Level 3 1242f6603c60Sopenharmony_ci */ 1243f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetFakeBoldTextMultipleCalls, TestSize.Level3) { 1244f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1245f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1246f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetFakeBoldText 10 times, and call OH_Drawing_FontIsFakeBoldText each time to check if the 1247f6603c60Sopenharmony_ci // stroke width is increased to approximate bold text 1248f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1249f6603c60Sopenharmony_ci OH_Drawing_FontSetFakeBoldText(font, i % 2 == 0); 1250f6603c60Sopenharmony_ci bool isFakeBoldText = OH_Drawing_FontIsFakeBoldText(font); 1251f6603c60Sopenharmony_ci EXPECT_EQ(isFakeBoldText, i % 2 == 0); 1252f6603c60Sopenharmony_ci } 1253f6603c60Sopenharmony_ci // 3. Release memory 1254f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1255f6603c60Sopenharmony_ci} 1256f6603c60Sopenharmony_ci 1257f6603c60Sopenharmony_ci/* 1258f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1203 1259f6603c60Sopenharmony_ci * @tc.name: testFontIsFakeBoldTextWhenNoSet 1260f6603c60Sopenharmony_ci * @tc.desc: test for testFontIsFakeBoldTextWhenNoSet. 1261f6603c60Sopenharmony_ci * @tc.size : SmallTest 1262f6603c60Sopenharmony_ci * @tc.type : Function 1263f6603c60Sopenharmony_ci * @tc.level : Level 3 1264f6603c60Sopenharmony_ci */ 1265f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontIsFakeBoldTextWhenNoSet, TestSize.Level3) { 1266f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1267f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1268f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsFakeBoldText 1269f6603c60Sopenharmony_ci bool isFakeBoldText = OH_Drawing_FontIsFakeBoldText(font); 1270f6603c60Sopenharmony_ci EXPECT_EQ(isFakeBoldText, false); 1271f6603c60Sopenharmony_ci // 3. Release memory 1272f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1273f6603c60Sopenharmony_ci} 1274f6603c60Sopenharmony_ci 1275f6603c60Sopenharmony_ci/* 1276f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1300 1277f6603c60Sopenharmony_ci * @tc.name: testFontSetScaleXNormal 1278f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetScaleXNormal. 1279f6603c60Sopenharmony_ci * @tc.size : SmallTest 1280f6603c60Sopenharmony_ci * @tc.type : Function 1281f6603c60Sopenharmony_ci * @tc.level : Level 0 1282f6603c60Sopenharmony_ci */ 1283f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetScaleXNormal, TestSize.Level0) { 1284f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1285f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1286f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetScaleX interface with scaleX parameter set to 10, and then call 1287f6603c60Sopenharmony_ci // OH_Drawing_FontGetScaleX to get the text scale on the x-axis 1288f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(font, 10); 1289f6603c60Sopenharmony_ci float scaleX = OH_Drawing_FontGetScaleX(font); 1290f6603c60Sopenharmony_ci EXPECT_EQ(scaleX, 10); 1291f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetScaleX interface with scaleX parameter set to 0.55, and then call 1292f6603c60Sopenharmony_ci // OH_Drawing_FontGetScaleX to get the text scale on the x-axis 1293f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(font, 0.55); 1294f6603c60Sopenharmony_ci scaleX = OH_Drawing_FontGetScaleX(font); 1295f6603c60Sopenharmony_ci EXPECT_EQ(IsScalarAlmostEqual(scaleX, 0.55), true); 1296f6603c60Sopenharmony_ci // 4. Release memory 1297f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1298f6603c60Sopenharmony_ci} 1299f6603c60Sopenharmony_ci 1300f6603c60Sopenharmony_ci/* 1301f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1301 1302f6603c60Sopenharmony_ci * @tc.name: testFontSetScaleXNULL 1303f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetScaleXNULL. 1304f6603c60Sopenharmony_ci * @tc.size : SmallTest 1305f6603c60Sopenharmony_ci * @tc.type : Function 1306f6603c60Sopenharmony_ci * @tc.level : Level 3 1307f6603c60Sopenharmony_ci */ 1308f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetScaleXNULL, TestSize.Level3) { 1309f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1310f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1311f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetScaleX with nullptr as the first parameter and check the error code using 1312f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1313f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(nullptr, 10); 1314f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1315f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetScaleX with 0 as the second parameter 1316f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(font, 0); 1317f6603c60Sopenharmony_ci // 4. Call OH_Drawing_FontGetScaleX with nullptr as the parameter and check the error code using 1318f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1319f6603c60Sopenharmony_ci OH_Drawing_FontGetScaleX(nullptr); 1320f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1321f6603c60Sopenharmony_ci // 5. Release memory 1322f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1323f6603c60Sopenharmony_ci} 1324f6603c60Sopenharmony_ci 1325f6603c60Sopenharmony_ci/* 1326f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1302 1327f6603c60Sopenharmony_ci * @tc.name: testFontSetScaleXMultipleCalls 1328f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetScaleXMultipleCalls. 1329f6603c60Sopenharmony_ci * @tc.size : SmallTest 1330f6603c60Sopenharmony_ci * @tc.type : Function 1331f6603c60Sopenharmony_ci * @tc.level : Level 3 1332f6603c60Sopenharmony_ci */ 1333f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetScaleXMultipleCalls, TestSize.Level3) { 1334f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1335f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1336f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetScaleX 10 times (with random values for scaleX parameter), and call 1337f6603c60Sopenharmony_ci // OH_Drawing_FontGetScaleX each time to get the text scale on the x-axis 1338f6603c60Sopenharmony_ci std::random_device rd; 1339f6603c60Sopenharmony_ci std::mt19937 gen(rd()); 1340f6603c60Sopenharmony_ci std::uniform_real_distribution<float> dis(0, 30); 1341f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1342f6603c60Sopenharmony_ci float val = dis(gen); 1343f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(font, val); 1344f6603c60Sopenharmony_ci float scaleX = OH_Drawing_FontGetScaleX(font); 1345f6603c60Sopenharmony_ci EXPECT_EQ(scaleX, val); 1346f6603c60Sopenharmony_ci } 1347f6603c60Sopenharmony_ci // 3. Release memory 1348f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1349f6603c60Sopenharmony_ci} 1350f6603c60Sopenharmony_ci 1351f6603c60Sopenharmony_ci/* 1352f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1303 1353f6603c60Sopenharmony_ci * @tc.name: testFontGetScaleXWhenNoSet 1354f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetScaleXWhenNoSet. 1355f6603c60Sopenharmony_ci * @tc.size : SmallTest 1356f6603c60Sopenharmony_ci * @tc.type : Function 1357f6603c60Sopenharmony_ci * @tc.level : Level 3 1358f6603c60Sopenharmony_ci */ 1359f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetScaleXWhenNoSet, TestSize.Level3) { 1360f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1361f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1362f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetScaleX to get the text scale on the x-axis 1363f6603c60Sopenharmony_ci float scaleX = OH_Drawing_FontGetScaleX(font); 1364f6603c60Sopenharmony_ci EXPECT_EQ(scaleX, 1); 1365f6603c60Sopenharmony_ci // 3. Release memory 1366f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1367f6603c60Sopenharmony_ci} 1368f6603c60Sopenharmony_ci 1369f6603c60Sopenharmony_ci/* 1370f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1304 1371f6603c60Sopenharmony_ci * @tc.name: testFontSetScaleXAbnormal 1372f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetScaleXAbnormal. 1373f6603c60Sopenharmony_ci * @tc.size : SmallTest 1374f6603c60Sopenharmony_ci * @tc.type : Function 1375f6603c60Sopenharmony_ci * @tc.level : Level 3 1376f6603c60Sopenharmony_ci */ 1377f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetScaleXAbnormal, TestSize.Level3) { 1378f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1379f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1380f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetScaleX interface with scaleX parameter set to -1, and then call 1381f6603c60Sopenharmony_ci // OH_Drawing_FontGetScaleX to get the text scale on the x-axis 1382f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(font, -1); 1383f6603c60Sopenharmony_ci float scaleX = OH_Drawing_FontGetScaleX(font); 1384f6603c60Sopenharmony_ci EXPECT_EQ(scaleX, -1); 1385f6603c60Sopenharmony_ci // 3. Release memory 1386f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1387f6603c60Sopenharmony_ci} 1388f6603c60Sopenharmony_ci 1389f6603c60Sopenharmony_ci/* 1390f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1305 1391f6603c60Sopenharmony_ci * @tc.name: testFontSetScaleXMaximum 1392f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetScaleXMaximum. 1393f6603c60Sopenharmony_ci * @tc.size : SmallTest 1394f6603c60Sopenharmony_ci * @tc.type : Function 1395f6603c60Sopenharmony_ci * @tc.level : Level 3 1396f6603c60Sopenharmony_ci */ 1397f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetScaleXMaximum, TestSize.Level3) { 1398f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1399f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1400f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetScaleX interface with scaleX parameter set to FLT_MAX, and then call 1401f6603c60Sopenharmony_ci // OH_Drawing_FontGetScaleX to get the text scale on the x-axis 1402f6603c60Sopenharmony_ci OH_Drawing_FontSetScaleX(font, FLT_MAX); 1403f6603c60Sopenharmony_ci // 3. Release memory 1404f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1405f6603c60Sopenharmony_ci} 1406f6603c60Sopenharmony_ci 1407f6603c60Sopenharmony_ci/* 1408f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1400 1409f6603c60Sopenharmony_ci * @tc.name: testFontSetHintingNormal 1410f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetHintingNormal. 1411f6603c60Sopenharmony_ci * @tc.size : SmallTest 1412f6603c60Sopenharmony_ci * @tc.type : Function 1413f6603c60Sopenharmony_ci * @tc.level : Level 0 1414f6603c60Sopenharmony_ci */ 1415f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetHintingNormal, TestSize.Level0) { 1416f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1417f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1418f6603c60Sopenharmony_ci // 2. OH_Drawing_FontSetHinting enum value OH_Drawing_FontHinting coverage verification, call 1419f6603c60Sopenharmony_ci // OH_Drawing_FontGetHinting to get the font outline effect enum type 1420f6603c60Sopenharmony_ci OH_Drawing_FontHinting hinting[] = { 1421f6603c60Sopenharmony_ci FONT_HINTING_NONE, 1422f6603c60Sopenharmony_ci FONT_HINTING_SLIGHT, 1423f6603c60Sopenharmony_ci FONT_HINTING_NORMAL, 1424f6603c60Sopenharmony_ci FONT_HINTING_FULL, 1425f6603c60Sopenharmony_ci }; 1426f6603c60Sopenharmony_ci for (OH_Drawing_FontHinting h : hinting) { 1427f6603c60Sopenharmony_ci OH_Drawing_FontSetHinting(font, h); 1428f6603c60Sopenharmony_ci OH_Drawing_FontHinting hinting2 = OH_Drawing_FontGetHinting(font); 1429f6603c60Sopenharmony_ci EXPECT_EQ(hinting2, h); 1430f6603c60Sopenharmony_ci } 1431f6603c60Sopenharmony_ci // 3. Release memory 1432f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1433f6603c60Sopenharmony_ci} 1434f6603c60Sopenharmony_ci 1435f6603c60Sopenharmony_ci/* 1436f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1401 1437f6603c60Sopenharmony_ci * @tc.name: testFontSetHintingNULL 1438f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetHintingNULL. 1439f6603c60Sopenharmony_ci * @tc.size : SmallTest 1440f6603c60Sopenharmony_ci * @tc.type : Function 1441f6603c60Sopenharmony_ci * @tc.level : Level 3 1442f6603c60Sopenharmony_ci */ 1443f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetHintingNULL, TestSize.Level3) { 1444f6603c60Sopenharmony_ci // 1. Call OH_Drawing_FontSetHinting with nullptr as the first parameter and check the error code using 1445f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1446f6603c60Sopenharmony_ci OH_Drawing_FontSetHinting(nullptr, FONT_HINTING_NONE); 1447f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1448f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetHinting with nullptr as the parameter and check the error code using 1449f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1450f6603c60Sopenharmony_ci OH_Drawing_FontGetHinting(nullptr); 1451f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1452f6603c60Sopenharmony_ci} 1453f6603c60Sopenharmony_ci 1454f6603c60Sopenharmony_ci/* 1455f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1402 1456f6603c60Sopenharmony_ci * @tc.name: testFontSetHintingMultipleCalls 1457f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetHintingMultipleCalls. 1458f6603c60Sopenharmony_ci * @tc.size : SmallTest 1459f6603c60Sopenharmony_ci * @tc.type : Function 1460f6603c60Sopenharmony_ci * @tc.level : Level 3 1461f6603c60Sopenharmony_ci */ 1462f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetHintingMultipleCalls, TestSize.Level3) { 1463f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1464f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1465f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetHinting 10 times (with random enum values), and call OH_Drawing_FontGetHinting each 1466f6603c60Sopenharmony_ci // time to get the font outline effect enum type 1467f6603c60Sopenharmony_ci std::random_device rd; 1468f6603c60Sopenharmony_ci std::mt19937 gen(rd()); 1469f6603c60Sopenharmony_ci std::uniform_int_distribution<int> dis(0, 3); 1470f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1471f6603c60Sopenharmony_ci OH_Drawing_FontHinting hinting = static_cast<OH_Drawing_FontHinting>(dis(gen)); 1472f6603c60Sopenharmony_ci OH_Drawing_FontSetHinting(font, hinting); 1473f6603c60Sopenharmony_ci OH_Drawing_FontHinting hinting2 = OH_Drawing_FontGetHinting(font); 1474f6603c60Sopenharmony_ci EXPECT_EQ(hinting2, hinting); 1475f6603c60Sopenharmony_ci } 1476f6603c60Sopenharmony_ci // 3. Release memory 1477f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1478f6603c60Sopenharmony_ci} 1479f6603c60Sopenharmony_ci 1480f6603c60Sopenharmony_ci/* 1481f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1403 1482f6603c60Sopenharmony_ci * @tc.name: testFontGetHintingWhenNoSet 1483f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetHintingWhenNoSet. 1484f6603c60Sopenharmony_ci * @tc.size : SmallTest 1485f6603c60Sopenharmony_ci * @tc.type : Function 1486f6603c60Sopenharmony_ci * @tc.level : Level 3 1487f6603c60Sopenharmony_ci */ 1488f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetHintingWhenNoSet, TestSize.Level3) { 1489f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1490f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1491f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetHinting 1492f6603c60Sopenharmony_ci OH_Drawing_FontHinting hinting = OH_Drawing_FontGetHinting(font); 1493f6603c60Sopenharmony_ci EXPECT_EQ(hinting, FONT_HINTING_NORMAL); 1494f6603c60Sopenharmony_ci // 3. Release memory 1495f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1496f6603c60Sopenharmony_ci} 1497f6603c60Sopenharmony_ci 1498f6603c60Sopenharmony_ci/* 1499f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1500 1500f6603c60Sopenharmony_ci * @tc.name: testFontSetEmbeddedBitmapsNormal 1501f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetEmbeddedBitmapsNormal. 1502f6603c60Sopenharmony_ci * @tc.size : SmallTest 1503f6603c60Sopenharmony_ci * @tc.type : Function 1504f6603c60Sopenharmony_ci * @tc.level : Level 0 1505f6603c60Sopenharmony_ci */ 1506f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetEmbeddedBitmapsNormal, TestSize.Level0) { 1507f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1508f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1509f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetEmbeddedBitmaps with false as the isEmbeddedBitmaps parameter, and call 1510f6603c60Sopenharmony_ci // OH_Drawing_FontIsEmbeddedBitmaps to check if the glyph is converted to a bitmap 1511f6603c60Sopenharmony_ci OH_Drawing_FontSetEmbeddedBitmaps(font, false); 1512f6603c60Sopenharmony_ci bool isEmbeddedBitmaps = OH_Drawing_FontIsEmbeddedBitmaps(font); 1513f6603c60Sopenharmony_ci EXPECT_EQ(isEmbeddedBitmaps, false); 1514f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontSetEmbeddedBitmaps with true as the isEmbeddedBitmaps parameter, and call 1515f6603c60Sopenharmony_ci // OH_Drawing_FontIsEmbeddedBitmaps to check if the glyph is converted to a bitmap 1516f6603c60Sopenharmony_ci OH_Drawing_FontSetEmbeddedBitmaps(font, true); 1517f6603c60Sopenharmony_ci isEmbeddedBitmaps = OH_Drawing_FontIsEmbeddedBitmaps(font); 1518f6603c60Sopenharmony_ci EXPECT_EQ(isEmbeddedBitmaps, true); 1519f6603c60Sopenharmony_ci // 4. Release memory 1520f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1521f6603c60Sopenharmony_ci} 1522f6603c60Sopenharmony_ci 1523f6603c60Sopenharmony_ci/* 1524f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1501 1525f6603c60Sopenharmony_ci * @tc.name: testFontSetEmbeddedBitmapsNULL 1526f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetEmbeddedBitmapsNULL. 1527f6603c60Sopenharmony_ci * @tc.size : SmallTest 1528f6603c60Sopenharmony_ci * @tc.type : Function 1529f6603c60Sopenharmony_ci * @tc.level : Level 3 1530f6603c60Sopenharmony_ci */ 1531f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetEmbeddedBitmapsNULL, TestSize.Level3) { 1532f6603c60Sopenharmony_ci // 1. Call OH_Drawing_FontSetEmbeddedBitmaps with nullptr as the first parameter and check the error code using 1533f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1534f6603c60Sopenharmony_ci OH_Drawing_FontSetEmbeddedBitmaps(nullptr, false); 1535f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1536f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsEmbeddedBitmaps with nullptr as the parameter and check the error code using 1537f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1538f6603c60Sopenharmony_ci OH_Drawing_FontIsEmbeddedBitmaps(nullptr); 1539f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1540f6603c60Sopenharmony_ci} 1541f6603c60Sopenharmony_ci 1542f6603c60Sopenharmony_ci/* 1543f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1502 1544f6603c60Sopenharmony_ci * @tc.name: testFontSetEmbeddedBitmapsMultipleCalls 1545f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetEmbeddedBitmapsMultipleCalls. 1546f6603c60Sopenharmony_ci * @tc.size : SmallTest 1547f6603c60Sopenharmony_ci * @tc.type : Function 1548f6603c60Sopenharmony_ci * @tc.level : Level 3 1549f6603c60Sopenharmony_ci */ 1550f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetEmbeddedBitmapsMultipleCalls, TestSize.Level3) { 1551f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1552f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1553f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetEmbeddedBitmaps 10 times, and call OH_Drawing_FontIsEmbeddedBitmaps each time to check 1554f6603c60Sopenharmony_ci // if the glyph is converted to a bitmap 1555f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1556f6603c60Sopenharmony_ci OH_Drawing_FontSetEmbeddedBitmaps(font, i % 2 == 0); 1557f6603c60Sopenharmony_ci bool isEmbeddedBitmaps = OH_Drawing_FontIsEmbeddedBitmaps(font); 1558f6603c60Sopenharmony_ci EXPECT_EQ(isEmbeddedBitmaps, i % 2 == 0); 1559f6603c60Sopenharmony_ci } 1560f6603c60Sopenharmony_ci // 3. Release memory 1561f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1562f6603c60Sopenharmony_ci} 1563f6603c60Sopenharmony_ci 1564f6603c60Sopenharmony_ci/* 1565f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1503 1566f6603c60Sopenharmony_ci * @tc.name: testFontIsEmbeddedBitmapsWhenNoSet 1567f6603c60Sopenharmony_ci * @tc.desc: test for testFontIsEmbeddedBitmapsWhenNoSet. 1568f6603c60Sopenharmony_ci * @tc.size : SmallTest 1569f6603c60Sopenharmony_ci * @tc.type : Function 1570f6603c60Sopenharmony_ci * @tc.level : Level 3 1571f6603c60Sopenharmony_ci */ 1572f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontIsEmbeddedBitmapsWhenNoSet, TestSize.Level3) { 1573f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1574f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1575f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontIsEmbeddedBitmaps 1576f6603c60Sopenharmony_ci bool isEmbeddedBitmaps = OH_Drawing_FontIsEmbeddedBitmaps(font); 1577f6603c60Sopenharmony_ci EXPECT_EQ(isEmbeddedBitmaps, false); 1578f6603c60Sopenharmony_ci // 3. Release memory 1579f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1580f6603c60Sopenharmony_ci} 1581f6603c60Sopenharmony_ci 1582f6603c60Sopenharmony_ci/* 1583f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1600 1584f6603c60Sopenharmony_ci * @tc.name: testFontSetEdgingNormal 1585f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetEdgingNormal. 1586f6603c60Sopenharmony_ci * @tc.size : SmallTest 1587f6603c60Sopenharmony_ci * @tc.type : Function 1588f6603c60Sopenharmony_ci * @tc.level : Level 0 1589f6603c60Sopenharmony_ci */ 1590f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetEdgingNormal, TestSize.Level0) { 1591f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1592f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1593f6603c60Sopenharmony_ci // 2. OH_Drawing_FontSetEdging enum value OH_Drawing_FontEdging coverage verification, call OH_Drawing_FontGetEdging 1594f6603c60Sopenharmony_ci // to get the font edge effect enum type 1595f6603c60Sopenharmony_ci OH_Drawing_FontEdging edging[] = { 1596f6603c60Sopenharmony_ci FONT_EDGING_ALIAS, 1597f6603c60Sopenharmony_ci FONT_EDGING_ANTI_ALIAS, 1598f6603c60Sopenharmony_ci FONT_EDGING_SUBPIXEL_ANTI_ALIAS, 1599f6603c60Sopenharmony_ci }; 1600f6603c60Sopenharmony_ci for (OH_Drawing_FontEdging e : edging) { 1601f6603c60Sopenharmony_ci OH_Drawing_FontSetEdging(font, e); 1602f6603c60Sopenharmony_ci OH_Drawing_FontEdging e2 = OH_Drawing_FontGetEdging(font); 1603f6603c60Sopenharmony_ci EXPECT_EQ(e2, e); 1604f6603c60Sopenharmony_ci } 1605f6603c60Sopenharmony_ci // 3. Release memory 1606f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1607f6603c60Sopenharmony_ci} 1608f6603c60Sopenharmony_ci 1609f6603c60Sopenharmony_ci/* 1610f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1601 1611f6603c60Sopenharmony_ci * @tc.name: testFontSetEdgingNULL 1612f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetEdgingNULL. 1613f6603c60Sopenharmony_ci * @tc.size : SmallTest 1614f6603c60Sopenharmony_ci * @tc.type : Function 1615f6603c60Sopenharmony_ci * @tc.level : Level 3 1616f6603c60Sopenharmony_ci */ 1617f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetEdgingNULL, TestSize.Level3) { 1618f6603c60Sopenharmony_ci // 1. Call OH_Drawing_FontSetEdging with nullptr as the first parameter and check the error code using 1619f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1620f6603c60Sopenharmony_ci OH_Drawing_FontSetEdging(nullptr, FONT_EDGING_ALIAS); 1621f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1622f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetEdging with nullptr as the parameter and check the error code using 1623f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1624f6603c60Sopenharmony_ci OH_Drawing_FontGetEdging(nullptr); 1625f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1626f6603c60Sopenharmony_ci} 1627f6603c60Sopenharmony_ci 1628f6603c60Sopenharmony_ci/* 1629f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1602 1630f6603c60Sopenharmony_ci * @tc.name: testFontSetEdgingMultipleCalls 1631f6603c60Sopenharmony_ci * @tc.desc: test for testFontSetEdgingMultipleCalls. 1632f6603c60Sopenharmony_ci * @tc.size : SmallTest 1633f6603c60Sopenharmony_ci * @tc.type : Function 1634f6603c60Sopenharmony_ci * @tc.level : Level 3 1635f6603c60Sopenharmony_ci */ 1636f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontSetEdgingMultipleCalls, TestSize.Level3) { 1637f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1638f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1639f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontSetEdging 10 times (with random enum values), and call OH_Drawing_FontGetEdging each time 1640f6603c60Sopenharmony_ci // to get the font edge effect enum type 1641f6603c60Sopenharmony_ci std::random_device rd; 1642f6603c60Sopenharmony_ci std::mt19937 gen(rd()); 1643f6603c60Sopenharmony_ci std::uniform_int_distribution<int> dis(0, 2); 1644f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1645f6603c60Sopenharmony_ci OH_Drawing_FontEdging edging = static_cast<OH_Drawing_FontEdging>(dis(gen)); 1646f6603c60Sopenharmony_ci OH_Drawing_FontSetEdging(font, edging); 1647f6603c60Sopenharmony_ci OH_Drawing_FontEdging edging2 = OH_Drawing_FontGetEdging(font); 1648f6603c60Sopenharmony_ci EXPECT_EQ(edging2, edging); 1649f6603c60Sopenharmony_ci } 1650f6603c60Sopenharmony_ci // 3. Release memory 1651f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1652f6603c60Sopenharmony_ci} 1653f6603c60Sopenharmony_ci 1654f6603c60Sopenharmony_ci/* 1655f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1603 1656f6603c60Sopenharmony_ci * @tc.name: testFontGetEdgingWhenNoSet 1657f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetEdgingWhenNoSet. 1658f6603c60Sopenharmony_ci * @tc.size : SmallTest 1659f6603c60Sopenharmony_ci * @tc.type : Function 1660f6603c60Sopenharmony_ci * @tc.level : Level 3 1661f6603c60Sopenharmony_ci */ 1662f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetEdgingWhenNoSet, TestSize.Level3) { 1663f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1664f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1665f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetEdging 1666f6603c60Sopenharmony_ci OH_Drawing_FontEdging edging = OH_Drawing_FontGetEdging(font); 1667f6603c60Sopenharmony_ci EXPECT_EQ(edging, FONT_EDGING_ANTI_ALIAS); 1668f6603c60Sopenharmony_ci // 3. Release memory 1669f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1670f6603c60Sopenharmony_ci} 1671f6603c60Sopenharmony_ci 1672f6603c60Sopenharmony_ci/* 1673f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1700 1674f6603c60Sopenharmony_ci * @tc.name: testFontGetMetricsNormal 1675f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetMetricsNormal. 1676f6603c60Sopenharmony_ci * @tc.size : SmallTest 1677f6603c60Sopenharmony_ci * @tc.type : Function 1678f6603c60Sopenharmony_ci * @tc.level : Level 0 1679f6603c60Sopenharmony_ci */ 1680f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetMetricsNormal, TestSize.Level0) { 1681f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1682f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1683f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetMetrics 1684f6603c60Sopenharmony_ci OH_Drawing_Font_Metrics cFontMetrics; 1685f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetMetrics(font, &cFontMetrics) >= 0); 1686f6603c60Sopenharmony_ci // 3. Release memory 1687f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1688f6603c60Sopenharmony_ci} 1689f6603c60Sopenharmony_ci 1690f6603c60Sopenharmony_ci/* 1691f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1701 1692f6603c60Sopenharmony_ci * @tc.name: testFontGetMetricsNULL 1693f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetMetricsNULL. 1694f6603c60Sopenharmony_ci * @tc.size : SmallTest 1695f6603c60Sopenharmony_ci * @tc.type : Function 1696f6603c60Sopenharmony_ci * @tc.level : Level 3 1697f6603c60Sopenharmony_ci */ 1698f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetMetricsNULL, TestSize.Level3) { 1699f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1700f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1701f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetMetrics with nullptr as the first parameter and check the error code using 1702f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1703f6603c60Sopenharmony_ci OH_Drawing_Font_Metrics cFontMetrics; 1704f6603c60Sopenharmony_ci OH_Drawing_FontGetMetrics(nullptr, &cFontMetrics); 1705f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1706f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontGetMetrics with nullptr as the second parameter and check the error code using 1707f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1708f6603c60Sopenharmony_ci OH_Drawing_FontGetMetrics(font, nullptr); 1709f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1710f6603c60Sopenharmony_ci // 4. Release memory 1711f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1712f6603c60Sopenharmony_ci} 1713f6603c60Sopenharmony_ci 1714f6603c60Sopenharmony_ci/* 1715f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1702 1716f6603c60Sopenharmony_ci * @tc.name: testFontGetMetricsMultipleCalls 1717f6603c60Sopenharmony_ci * @tc.desc: test for testFontGetMetricsMultipleCalls. 1718f6603c60Sopenharmony_ci * @tc.size : SmallTest 1719f6603c60Sopenharmony_ci * @tc.type : Function 1720f6603c60Sopenharmony_ci * @tc.level : Level 3 1721f6603c60Sopenharmony_ci */ 1722f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontGetMetricsMultipleCalls, TestSize.Level3) { 1723f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 1724f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1725f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontGetMetrics 10 times 1726f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1727f6603c60Sopenharmony_ci OH_Drawing_Font_Metrics cFontMetrics; 1728f6603c60Sopenharmony_ci EXPECT_TRUE(OH_Drawing_FontGetMetrics(font, &cFontMetrics) >= 0); 1729f6603c60Sopenharmony_ci } 1730f6603c60Sopenharmony_ci // 3. Release memory 1731f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1732f6603c60Sopenharmony_ci} 1733f6603c60Sopenharmony_ci 1734f6603c60Sopenharmony_ci/* 1735f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1800 1736f6603c60Sopenharmony_ci * @tc.name: testFontMeasureSingleCharacterNormal 1737f6603c60Sopenharmony_ci * @tc.desc: test for testFontMeasureSingleCharacterNormal. 1738f6603c60Sopenharmony_ci * @tc.size : SmallTest 1739f6603c60Sopenharmony_ci * @tc.type : Function 1740f6603c60Sopenharmony_ci * @tc.level : Level 0 1741f6603c60Sopenharmony_ci */ 1742f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontMeasureSingleCharacterNormal, TestSize.Level0) 1743f6603c60Sopenharmony_ci{ 1744f6603c60Sopenharmony_ci //1. OH_Drawing_FontCreate 1745f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1746f6603c60Sopenharmony_ci //2. All OH_Drawing_FontMeasureSingleCharacter parameters are entered normally, including str single character, 1747f6603c60Sopenharmony_ci // UTF8 encoded Chinese/English characters 1748f6603c60Sopenharmony_ci float textWidth = 0.f; 1749f6603c60Sopenharmony_ci const char* strOne = "a"; 1750f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(font, strOne, &textWidth); 1751f6603c60Sopenharmony_ci strOne = "我"; 1752f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(font, strOne, &textWidth); 1753f6603c60Sopenharmony_ci //3. All OH_Drawing_FontMeasureSingleCharacter parameters are entered normally, including str multi-character, 1754f6603c60Sopenharmony_ci // UTF8 encoded Chinese/English characters 1755f6603c60Sopenharmony_ci const char* strTwo = "你好"; 1756f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(font, strTwo, &textWidth); 1757f6603c60Sopenharmony_ci strTwo = "baby"; 1758f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(font, strTwo, &textWidth); 1759f6603c60Sopenharmony_ci //4. free memory 1760f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1761f6603c60Sopenharmony_ci} 1762f6603c60Sopenharmony_ci 1763f6603c60Sopenharmony_ci/* 1764f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1801 1765f6603c60Sopenharmony_ci * @tc.name: testFontMeasureSingleCharacterNull 1766f6603c60Sopenharmony_ci * @tc.desc: test for testFontMeasureSingleCharacterNull. 1767f6603c60Sopenharmony_ci * @tc.size : SmallTest 1768f6603c60Sopenharmony_ci * @tc.type : Function 1769f6603c60Sopenharmony_ci * @tc.level : Level 3 1770f6603c60Sopenharmony_ci */ 1771f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontMeasureSingleCharacterNull, TestSize.Level3) 1772f6603c60Sopenharmony_ci{ 1773f6603c60Sopenharmony_ci //1. OH_Drawing_FontCreate 1774f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1775f6603c60Sopenharmony_ci //2. OH_Drawing_FontMeasureSingleCharacter with the parameter font as null 1776f6603c60Sopenharmony_ci float textWidth = 0.f; 1777f6603c60Sopenharmony_ci const char *strOne = "a"; 1778f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(nullptr, strOne, &textWidth); 1779f6603c60Sopenharmony_ci //3. OH_Drawing_FontMeasureSingleCharacter with the parameter str as null 1780f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(font, nullptr, &textWidth); 1781f6603c60Sopenharmony_ci //4. OH_Drawing_FontMeasureSingleCharacter with the parameter textWidth as null 1782f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(font, strOne, nullptr); 1783f6603c60Sopenharmony_ci //5. free memory 1784f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1785f6603c60Sopenharmony_ci} 1786f6603c60Sopenharmony_ci 1787f6603c60Sopenharmony_ci/* 1788f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1802 1789f6603c60Sopenharmony_ci * @tc.name: testFontMeasureSingleCharacterMultipleCalls 1790f6603c60Sopenharmony_ci * @tc.desc: test for testFontMeasureSingleCharacterMultipleCalls. 1791f6603c60Sopenharmony_ci * @tc.size : SmallTest 1792f6603c60Sopenharmony_ci * @tc.type : Function 1793f6603c60Sopenharmony_ci * @tc.level : Level 3 1794f6603c60Sopenharmony_ci */ 1795f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontMeasureSingleCharacterMultipleCalls, TestSize.Level3) 1796f6603c60Sopenharmony_ci{ 1797f6603c60Sopenharmony_ci //1. OH_Drawing_FontCreate 1798f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1799f6603c60Sopenharmony_ci //2. OH_Drawing_FontMeasureSingleCharacter API is called 10 times as a normal input parameter 1800f6603c60Sopenharmony_ci const char *str[] = { 1801f6603c60Sopenharmony_ci "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" 1802f6603c60Sopenharmony_ci }; 1803f6603c60Sopenharmony_ci float textWidth = 0.f; 1804f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1805f6603c60Sopenharmony_ci OH_Drawing_FontMeasureSingleCharacter(font, str[i], &textWidth); 1806f6603c60Sopenharmony_ci } 1807f6603c60Sopenharmony_ci //3. free memory 1808f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1809f6603c60Sopenharmony_ci} 1810f6603c60Sopenharmony_ci 1811f6603c60Sopenharmony_ci 1812f6603c60Sopenharmony_ci/* 1813f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1900 1814f6603c60Sopenharmony_ci * @tc.name: testFontMeasuretextNormal 1815f6603c60Sopenharmony_ci * @tc.desc: test for testFontMeasuretextNormal. 1816f6603c60Sopenharmony_ci * @tc.size : SmallTest 1817f6603c60Sopenharmony_ci * @tc.type : Function 1818f6603c60Sopenharmony_ci * @tc.level : Level 0 1819f6603c60Sopenharmony_ci */ 1820f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontMeasuretextNormal, TestSize.Level0) 1821f6603c60Sopenharmony_ci{ 1822f6603c60Sopenharmony_ci //1. OH_Drawing_FontCreate 1823f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1824f6603c60Sopenharmony_ci OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100); 1825f6603c60Sopenharmony_ci OH_Drawing_Rect *bounds = OH_Drawing_RectCreate(0, 0, 100, 100); 1826f6603c60Sopenharmony_ci //2. OH_Drawing_FontMeasureText enumeration traversal 1827f6603c60Sopenharmony_ci const void *text = "abc"; 1828f6603c60Sopenharmony_ci const size_t byteLength = 3; 1829f6603c60Sopenharmony_ci float textWidth = 0.f; 1830f6603c60Sopenharmony_ci OH_Drawing_TextEncoding encodes[] = { 1831f6603c60Sopenharmony_ci TEXT_ENCODING_UTF8, 1832f6603c60Sopenharmony_ci TEXT_ENCODING_UTF16, 1833f6603c60Sopenharmony_ci TEXT_ENCODING_UTF32, 1834f6603c60Sopenharmony_ci TEXT_ENCODING_GLYPH_ID, 1835f6603c60Sopenharmony_ci }; 1836f6603c60Sopenharmony_ci for (int i = 0; i < 4; i++) { 1837f6603c60Sopenharmony_ci OH_Drawing_FontMeasureText(font, text, byteLength, encodes[i], bounds, &textWidth); 1838f6603c60Sopenharmony_ci } 1839f6603c60Sopenharmony_ci //3. OH_Drawing_FontMeasureText with the fifth parameter as null(normally) 1840f6603c60Sopenharmony_ci OH_Drawing_FontMeasureText(font, text, byteLength, TEXT_ENCODING_UTF8, bounds, &textWidth); 1841f6603c60Sopenharmony_ci //4. free memory 1842f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1843f6603c60Sopenharmony_ci OH_Drawing_RectDestroy(rect); 1844f6603c60Sopenharmony_ci OH_Drawing_RectDestroy(bounds); 1845f6603c60Sopenharmony_ci} 1846f6603c60Sopenharmony_ci 1847f6603c60Sopenharmony_ci/* 1848f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1901 1849f6603c60Sopenharmony_ci * @tc.name: testFontMeasuretextNull 1850f6603c60Sopenharmony_ci * @tc.desc: test for testFontMeasuretextNull. 1851f6603c60Sopenharmony_ci * @tc.size : SmallTest 1852f6603c60Sopenharmony_ci * @tc.type : Function 1853f6603c60Sopenharmony_ci * @tc.level : Level 3 1854f6603c60Sopenharmony_ci */ 1855f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontMeasuretextNull, TestSize.Level3) 1856f6603c60Sopenharmony_ci{ 1857f6603c60Sopenharmony_ci //1. OH_Drawing_FontCreate 1858f6603c60Sopenharmony_ci OH_Drawing_Font *font = OH_Drawing_FontCreate(); 1859f6603c60Sopenharmony_ci OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100); 1860f6603c60Sopenharmony_ci OH_Drawing_Rect *bounds = OH_Drawing_RectCreate(0, 0, 100, 100); 1861f6603c60Sopenharmony_ci // 2. Call OH_Drawing_FontMeasureText with nullptr as the first parameter, check the error code using 1862f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1863f6603c60Sopenharmony_ci const void *text = "abc"; 1864f6603c60Sopenharmony_ci const size_t byteLength = 3; 1865f6603c60Sopenharmony_ci float textWidth = 0.f; 1866f6603c60Sopenharmony_ci OH_Drawing_FontMeasureText(nullptr, text, byteLength, TEXT_ENCODING_UTF8, bounds, &textWidth); 1867f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1868f6603c60Sopenharmony_ci // 3. Call OH_Drawing_FontMeasureText with nullptr as the second parameter, check the error code using 1869f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1870f6603c60Sopenharmony_ci OH_Drawing_FontMeasureText(font, nullptr, byteLength, TEXT_ENCODING_UTF8, bounds, &textWidth); 1871f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1872f6603c60Sopenharmony_ci // 4. Call OH_Drawing_FontMeasureText with nullptr or 0 as the third parameter, check the error code using 1873f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1874f6603c60Sopenharmony_ci OH_Drawing_FontMeasureText(font, text, 0, TEXT_ENCODING_UTF8, bounds, &textWidth); 1875f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1876f6603c60Sopenharmony_ci // 5. Call OH_Drawing_FontMeasureText with nullptr as the sixth parameter, check the error code using 1877f6603c60Sopenharmony_ci // OH_Drawing_ErrorCodeGet 1878f6603c60Sopenharmony_ci OH_Drawing_FontMeasureText(font, text, byteLength, TEXT_ENCODING_UTF8, bounds, nullptr); 1879f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER); 1880f6603c60Sopenharmony_ci // 6. free memory 1881f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1882f6603c60Sopenharmony_ci OH_Drawing_RectDestroy(rect); 1883f6603c60Sopenharmony_ci OH_Drawing_RectDestroy(bounds); 1884f6603c60Sopenharmony_ci} 1885f6603c60Sopenharmony_ci 1886f6603c60Sopenharmony_ci 1887f6603c60Sopenharmony_ci/* 1888f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1902 1889f6603c60Sopenharmony_ci * @tc.name: testFontMeasuretextMultipleCalls 1890f6603c60Sopenharmony_ci * @tc.desc: test for testFontMeasuretextMultipleCalls. 1891f6603c60Sopenharmony_ci * @tc.size : SmallTest 1892f6603c60Sopenharmony_ci * @tc.type : Function 1893f6603c60Sopenharmony_ci * @tc.level : Level 3 1894f6603c60Sopenharmony_ci */ 1895f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontMeasuretextMultipleCalls, TestSize.Level3) 1896f6603c60Sopenharmony_ci{ 1897f6603c60Sopenharmony_ci //1. OH_Drawing_FontCreate 1898f6603c60Sopenharmony_ci OH_Drawing_Font *fonts[10]; 1899f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1900f6603c60Sopenharmony_ci fonts[i] = OH_Drawing_FontCreate(); 1901f6603c60Sopenharmony_ci } 1902f6603c60Sopenharmony_ci OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100); 1903f6603c60Sopenharmony_ci OH_Drawing_Rect *bounds = OH_Drawing_RectCreate(0, 0, 100, 100); 1904f6603c60Sopenharmony_ci //2. Call OH_Drawing_FontMeasureText 10 times 1905f6603c60Sopenharmony_ci const void *text = "abc"; 1906f6603c60Sopenharmony_ci const size_t byteLength = 3; 1907f6603c60Sopenharmony_ci float textWidth = 0.f; 1908f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1909f6603c60Sopenharmony_ci OH_Drawing_FontMeasureText(fonts[i], text, byteLength, TEXT_ENCODING_UTF8, bounds, &textWidth); 1910f6603c60Sopenharmony_ci } 1911f6603c60Sopenharmony_ci //3. free memory 1912f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 1913f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(fonts[i]); 1914f6603c60Sopenharmony_ci } 1915f6603c60Sopenharmony_ci OH_Drawing_RectDestroy(rect); 1916f6603c60Sopenharmony_ci OH_Drawing_RectDestroy(bounds); 1917f6603c60Sopenharmony_ci} 1918f6603c60Sopenharmony_ci 1919f6603c60Sopenharmony_ci 1920f6603c60Sopenharmony_ci/* 1921f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_1703 1922f6603c60Sopenharmony_ci * @tc.name: testFontMeasureSingleCharacter 1923f6603c60Sopenharmony_ci * @tc.desc: test for testFontMeasureSingleCharacter. 1924f6603c60Sopenharmony_ci * @tc.size : SmallTest 1925f6603c60Sopenharmony_ci * @tc.type : Function 1926f6603c60Sopenharmony_ci * @tc.level : Level 1 1927f6603c60Sopenharmony_ci */ 1928f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontMeasureSingleCharacter, TestSize.Level1) 1929f6603c60Sopenharmony_ci{ 1930f6603c60Sopenharmony_ci OH_Drawing_Font* font = OH_Drawing_FontCreate(); 1931f6603c60Sopenharmony_ci EXPECT_NE(font, nullptr); 1932f6603c60Sopenharmony_ci OH_Drawing_FontSetTextSize(font, 50); // 50 means font text size 1933f6603c60Sopenharmony_ci const char* strOne = "a"; 1934f6603c60Sopenharmony_ci const char* strTwo = "你好"; 1935f6603c60Sopenharmony_ci float textWidth = 0.f; 1936f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_SUCCESS; 1937f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureSingleCharacter(nullptr, strOne, &textWidth); 1938f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 1939f6603c60Sopenharmony_ci EXPECT_EQ(textWidth, 0.f); 1940f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureSingleCharacter(font, nullptr, &textWidth); 1941f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 1942f6603c60Sopenharmony_ci EXPECT_EQ(textWidth, 0.f); 1943f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureSingleCharacter(font, strOne, nullptr); 1944f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 1945f6603c60Sopenharmony_ci EXPECT_EQ(textWidth, 0.f); 1946f6603c60Sopenharmony_ci const char* strThree = ""; 1947f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureSingleCharacter(font, strThree, &textWidth); 1948f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 1949f6603c60Sopenharmony_ci EXPECT_EQ(textWidth, 0.f); 1950f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureSingleCharacter(font, strOne, &textWidth); 1951f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 1952f6603c60Sopenharmony_ci EXPECT_TRUE(textWidth > 0); 1953f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontMeasureSingleCharacter(font, strTwo, &textWidth); 1954f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 1955f6603c60Sopenharmony_ci EXPECT_TRUE(textWidth > 0); 1956f6603c60Sopenharmony_ci OH_Drawing_FontDestroy(font); 1957f6603c60Sopenharmony_ci} 1958f6603c60Sopenharmony_ci} // namespace Drawing 1959f6603c60Sopenharmony_ci} // namespace Rosen 1960f6603c60Sopenharmony_ci} // namespace OHOS