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