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