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