1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include "gtest/gtest.h"
17f6603c60Sopenharmony_ci
18f6603c60Sopenharmony_ci#include "drawing_bitmap.h"
19f6603c60Sopenharmony_ci#include "drawing_brush.h"
20f6603c60Sopenharmony_ci#include "drawing_canvas.h"
21f6603c60Sopenharmony_ci#include "drawing_color.h"
22f6603c60Sopenharmony_ci#include "drawing_color_filter.h"
23f6603c60Sopenharmony_ci#include "drawing_filter.h"
24f6603c60Sopenharmony_ci#include "drawing_font.h"
25f6603c60Sopenharmony_ci#include "drawing_image.h"
26f6603c60Sopenharmony_ci#include "drawing_mask_filter.h"
27f6603c60Sopenharmony_ci#include "drawing_matrix.h"
28f6603c60Sopenharmony_ci#include "drawing_memory_stream.h"
29f6603c60Sopenharmony_ci#include "drawing_path.h"
30f6603c60Sopenharmony_ci#include "drawing_pen.h"
31f6603c60Sopenharmony_ci#include "drawing_point.h"
32f6603c60Sopenharmony_ci#include "drawing_rect.h"
33f6603c60Sopenharmony_ci#include "drawing_region.h"
34f6603c60Sopenharmony_ci#include "drawing_round_rect.h"
35f6603c60Sopenharmony_ci#include "drawing_sampling_options.h"
36f6603c60Sopenharmony_ci#include "drawing_shader_effect.h"
37f6603c60Sopenharmony_ci#include "drawing_text_blob.h"
38f6603c60Sopenharmony_ci#include "drawing_typeface.h"
39f6603c60Sopenharmony_ci
40f6603c60Sopenharmony_ciusing namespace testing;
41f6603c60Sopenharmony_ciusing namespace testing::ext;
42f6603c60Sopenharmony_ci
43f6603c60Sopenharmony_cinamespace OHOS {
44f6603c60Sopenharmony_cinamespace Rosen {
45f6603c60Sopenharmony_cinamespace Drawing {
46f6603c60Sopenharmony_ciclass DrawingNativeTextBlobTest : public testing::Test {};
47f6603c60Sopenharmony_ci
48f6603c60Sopenharmony_ci/*
49f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0100
50f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderCreateDestroyNormal
51f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderCreateDestroyNormal.
52f6603c60Sopenharmony_ci * @tc.size  : SmallTest
53f6603c60Sopenharmony_ci * @tc.type  : Function
54f6603c60Sopenharmony_ci * @tc.level : Level 0
55f6603c60Sopenharmony_ci */
56f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderCreateDestroyNormal, TestSize.Level0) {
57f6603c60Sopenharmony_ci    OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
58f6603c60Sopenharmony_ci    EXPECT_NE(nullptr, canvas);
59f6603c60Sopenharmony_ci    // 1. Use OH_Drawing_TextBlobBuilderCreate and OH_Drawing_CanvasDrawTextBlob together
60f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilder *builder = OH_Drawing_TextBlobBuilderCreate();
61f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobBuilderMake(builder);
62f6603c60Sopenharmony_ci    OH_Drawing_CanvasDrawTextBlob(canvas, textBlob, 0, 0);
63f6603c60Sopenharmony_ci    if (0) {
64f6603c60Sopenharmony_ci        // todo cpp crash
65f6603c60Sopenharmony_ci        // 2. OH_Drawing_TextBlobBuilderDestroy
66f6603c60Sopenharmony_ci        OH_Drawing_TextBlobBuilderDestroy(builder);
67f6603c60Sopenharmony_ci    }
68f6603c60Sopenharmony_ci    OH_Drawing_CanvasDestroy(canvas);
69f6603c60Sopenharmony_ci}
70f6603c60Sopenharmony_ci
71f6603c60Sopenharmony_ci/*
72f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0101
73f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderCreateDestroyNull
74f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderCreateDestroyNull.
75f6603c60Sopenharmony_ci * @tc.size  : SmallTest
76f6603c60Sopenharmony_ci * @tc.type  : Function
77f6603c60Sopenharmony_ci * @tc.level : Level 3
78f6603c60Sopenharmony_ci */
79f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderCreateDestroyNull, TestSize.Level3) {
80f6603c60Sopenharmony_ci    // 1. OH_Drawing_TextBlobBuilderDestroy with nullptr parameter
81f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilderDestroy(nullptr);
82f6603c60Sopenharmony_ci}
83f6603c60Sopenharmony_ci
84f6603c60Sopenharmony_ci/*
85f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0102
86f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderCreateDestroyMultipleCalls
87f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderCreateDestroyMultipleCalls.
88f6603c60Sopenharmony_ci * @tc.size  : SmallTest
89f6603c60Sopenharmony_ci * @tc.type  : Function
90f6603c60Sopenharmony_ci * @tc.level : Level 3
91f6603c60Sopenharmony_ci */
92f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderCreateDestroyMultipleCalls, TestSize.Level3) {
93f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilder *builders[10];
94f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobBuilderCreate 10 times
95f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
96f6603c60Sopenharmony_ci        builders[i] = OH_Drawing_TextBlobBuilderCreate();
97f6603c60Sopenharmony_ci        EXPECT_NE(nullptr, builders[i]);
98f6603c60Sopenharmony_ci    }
99f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobBuilderDestroy 10 times
100f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
101f6603c60Sopenharmony_ci        if (0) {
102f6603c60Sopenharmony_ci            // todo cpp crash
103f6603c60Sopenharmony_ci            OH_Drawing_TextBlobBuilderDestroy(builders[i]);
104f6603c60Sopenharmony_ci        }
105f6603c60Sopenharmony_ci    }
106f6603c60Sopenharmony_ci    // 3. Call OH_Drawing_TextBlobBuilderCreate and OH_Drawing_TextBlobBuilderDestroy alternately 10 times
107f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
108f6603c60Sopenharmony_ci        OH_Drawing_TextBlobBuilder *builder = OH_Drawing_TextBlobBuilderCreate();
109f6603c60Sopenharmony_ci        EXPECT_NE(nullptr, builder);
110f6603c60Sopenharmony_ci        if (0) {
111f6603c60Sopenharmony_ci            // todo cpp crash
112f6603c60Sopenharmony_ci            OH_Drawing_TextBlobBuilderDestroy(builder);
113f6603c60Sopenharmony_ci        }
114f6603c60Sopenharmony_ci    }
115f6603c60Sopenharmony_ci}
116f6603c60Sopenharmony_ci
117f6603c60Sopenharmony_ci/*
118f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0200
119f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromTextNormal
120f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromTextNormal.
121f6603c60Sopenharmony_ci * @tc.size  : SmallTest
122f6603c60Sopenharmony_ci * @tc.type  : Function
123f6603c60Sopenharmony_ci * @tc.level : Level 0
124f6603c60Sopenharmony_ci */
125f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromTextNormal, TestSize.Level0) {
126f6603c60Sopenharmony_ci    OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
127f6603c60Sopenharmony_ci    EXPECT_NE(nullptr, canvas);
128f6603c60Sopenharmony_ci    // 1. Traverse the enumeration values of OH_Drawing_TextEncoding and use OH_Drawing_CanvasDrawTextBlob in
129f6603c60Sopenharmony_ci    // combination
130f6603c60Sopenharmony_ci    const char *str = "123456";
131f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
132f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
133f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
134f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
135f6603c60Sopenharmony_ci    OH_Drawing_TextEncoding encodeArray[] = {
136f6603c60Sopenharmony_ci        TEXT_ENCODING_UTF8,
137f6603c60Sopenharmony_ci        TEXT_ENCODING_UTF16,
138f6603c60Sopenharmony_ci        TEXT_ENCODING_UTF32,
139f6603c60Sopenharmony_ci        TEXT_ENCODING_GLYPH_ID,
140f6603c60Sopenharmony_ci    };
141f6603c60Sopenharmony_ci    for (OH_Drawing_TextEncoding encode : encodeArray) {
142f6603c60Sopenharmony_ci        size_t byteLength = 0;
143f6603c60Sopenharmony_ci        if (encode == TEXT_ENCODING_UTF8) {
144f6603c60Sopenharmony_ci            byteLength = strlen(str);
145f6603c60Sopenharmony_ci        } else if (encode == TEXT_ENCODING_UTF16) {
146f6603c60Sopenharmony_ci            byteLength = strlen(str) * 2;
147f6603c60Sopenharmony_ci        } else if (encode == TEXT_ENCODING_UTF32) {
148f6603c60Sopenharmony_ci            byteLength = strlen(str) * 4;
149f6603c60Sopenharmony_ci        } else if (encode == TEXT_ENCODING_GLYPH_ID) {
150f6603c60Sopenharmony_ci            byteLength = strlen(str) * 16;
151f6603c60Sopenharmony_ci        }
152f6603c60Sopenharmony_ci        OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobCreateFromText(str, byteLength, font, encode);
153f6603c60Sopenharmony_ci        OH_Drawing_CanvasDrawTextBlob(canvas, textBlob, 0, 0);
154f6603c60Sopenharmony_ci    }
155f6603c60Sopenharmony_ci    // 2. free memory
156f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
157f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
158f6603c60Sopenharmony_ci    OH_Drawing_CanvasDestroy(canvas);
159f6603c60Sopenharmony_ci}
160f6603c60Sopenharmony_ci
161f6603c60Sopenharmony_ci/*
162f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0201
163f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromTextNull
164f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromTextNull.
165f6603c60Sopenharmony_ci * @tc.size  : SmallTest
166f6603c60Sopenharmony_ci * @tc.type  : Function
167f6603c60Sopenharmony_ci * @tc.level : Level 3
168f6603c60Sopenharmony_ci */
169f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromTextNull, TestSize.Level3) {
170f6603c60Sopenharmony_ci    const char *str = "123456";
171f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
172f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
173f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
174f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
175f6603c60Sopenharmony_ci    // 1. OH_Drawing_TextBlobCreateFromText with the first parameter being nullptr, check the error code with
176f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
177f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob1 = OH_Drawing_TextBlobCreateFromText(nullptr, strlen(str), font, TEXT_ENCODING_UTF8);
178f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
179f6603c60Sopenharmony_ci    // 2. OH_Drawing_TextBlobCreateFromText with the second parameter being empty, check the error code with
180f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
181f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob2 = OH_Drawing_TextBlobCreateFromText(str, 0, font, TEXT_ENCODING_UTF8);
182f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
183f6603c60Sopenharmony_ci    // 3. OH_Drawing_TextBlobCreateFromText with the third parameter being nullptr, check the error code with
184f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
185f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob3 = OH_Drawing_TextBlobCreateFromText(str, strlen(str), nullptr, TEXT_ENCODING_UTF8);
186f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
187f6603c60Sopenharmony_ci    // 4. OH_Drawing_TextBlobCreateFromText with the first parameter being a string
188f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob4 = OH_Drawing_TextBlobCreateFromText("123456", 6, font, TEXT_ENCODING_UTF8);
189f6603c60Sopenharmony_ci    // 5. Free memory
190f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
191f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
192f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob1);
193f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob2);
194f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob3);
195f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob4);
196f6603c60Sopenharmony_ci}
197f6603c60Sopenharmony_ci
198f6603c60Sopenharmony_ci/*
199f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0203
200f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromTextMultipleCalls
201f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromTextMultipleCalls.
202f6603c60Sopenharmony_ci * @tc.size  : SmallTest
203f6603c60Sopenharmony_ci * @tc.type  : Function
204f6603c60Sopenharmony_ci * @tc.level : Level 3
205f6603c60Sopenharmony_ci */
206f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromTextMultipleCalls, TestSize.Level3) {
207f6603c60Sopenharmony_ci    const char *strs[] = {
208f6603c60Sopenharmony_ci        "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文",
209f6603c60Sopenharmony_ci    };
210f6603c60Sopenharmony_ci    OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
211f6603c60Sopenharmony_ci    EXPECT_NE(nullptr, canvas);
212f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
213f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
214f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
215f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
216f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobCreateFromText 10 times (passing in different types of strings with different lengths,
217f6603c60Sopenharmony_ci    // such as Chinese, English, special characters, numbers, traditional Chinese characters, etc.) and use
218f6603c60Sopenharmony_ci    // OH_Drawing_CanvasDrawTextBlob in combination
219f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
220f6603c60Sopenharmony_ci        const char *str = strs[i % 6];
221f6603c60Sopenharmony_ci        OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobCreateFromText(str, strlen(str), font, TEXT_ENCODING_UTF8);
222f6603c60Sopenharmony_ci        OH_Drawing_CanvasDrawTextBlob(canvas, textBlob, 0, 0);
223f6603c60Sopenharmony_ci        OH_Drawing_TextBlobDestroy(textBlob);
224f6603c60Sopenharmony_ci    }
225f6603c60Sopenharmony_ci    // 2. Free memory
226f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
227f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
228f6603c60Sopenharmony_ci    OH_Drawing_CanvasDestroy(canvas);
229f6603c60Sopenharmony_ci}
230f6603c60Sopenharmony_ci
231f6603c60Sopenharmony_ci/*
232f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0204
233f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromTextAbnormal
234f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromTextAbnormal.
235f6603c60Sopenharmony_ci * @tc.size  : SmallTest
236f6603c60Sopenharmony_ci * @tc.type  : Function
237f6603c60Sopenharmony_ci * @tc.level : Level 3
238f6603c60Sopenharmony_ci */
239f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromTextAbnormal, TestSize.Level3) {
240f6603c60Sopenharmony_ci    const char *str = "123456";
241f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
242f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
243f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
244f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
245f6603c60Sopenharmony_ci    // 1. OH_Drawing_TextBlobCreateFromText interface with OH_Drawing_TextEncoding out of range, check the error code
246f6603c60Sopenharmony_ci    // with OH_Drawing_ErrorCodeGet
247f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob =
248f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromText(str, strlen(str), font, static_cast<OH_Drawing_TextEncoding>(-1));
249f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
250f6603c60Sopenharmony_ci    // 2. Free memory
251f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
252f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
253f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
254f6603c60Sopenharmony_ci}
255f6603c60Sopenharmony_ci
256f6603c60Sopenharmony_ci/*
257f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0300
258f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromPosTextNormal
259f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromPosTextNormal.
260f6603c60Sopenharmony_ci * @tc.size  : SmallTest
261f6603c60Sopenharmony_ci * @tc.type  : Function
262f6603c60Sopenharmony_ci * @tc.level : Level 0
263f6603c60Sopenharmony_ci */
264f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromPosTextNormal, TestSize.Level0) {
265f6603c60Sopenharmony_ci    const char *str = "123456";
266f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
267f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
268f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
269f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
270f6603c60Sopenharmony_ci    // 1. Traverse the enumeration values of OH_Drawing_TextEncoding and use OH_Drawing_CanvasDrawTextBlob in
271f6603c60Sopenharmony_ci    // combination
272f6603c60Sopenharmony_ci    size_t byteLength = strlen(str);
273f6603c60Sopenharmony_ci    int count = OH_Drawing_FontCountText(font, str, byteLength, TEXT_ENCODING_UTF8);
274f6603c60Sopenharmony_ci    OH_Drawing_Point2D pts[count];
275f6603c60Sopenharmony_ci    OH_Drawing_TextBlobCreateFromPosText(str, count, &pts[0], font, TEXT_ENCODING_UTF8);
276f6603c60Sopenharmony_ci    // 2. Free memory
277f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
278f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
279f6603c60Sopenharmony_ci}
280f6603c60Sopenharmony_ci
281f6603c60Sopenharmony_ci/*
282f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0301
283f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromPosTextNull
284f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromPosTextNull.
285f6603c60Sopenharmony_ci * @tc.size  : SmallTest
286f6603c60Sopenharmony_ci * @tc.type  : Function
287f6603c60Sopenharmony_ci * @tc.level : Level 3
288f6603c60Sopenharmony_ci */
289f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromPosTextNull, TestSize.Level3) {
290f6603c60Sopenharmony_ci    const char *str = "123456";
291f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
292f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
293f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
294f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
295f6603c60Sopenharmony_ci    int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8);
296f6603c60Sopenharmony_ci    OH_Drawing_Point2D pts[count];
297f6603c60Sopenharmony_ci    // 1. OH_Drawing_TextBlobCreateFromPosText with the first parameter being nullptr, check the error code with
298f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
299f6603c60Sopenharmony_ci    OH_Drawing_TextBlobCreateFromPosText(nullptr, strlen(str), &pts[0], font, TEXT_ENCODING_UTF8);
300f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
301f6603c60Sopenharmony_ci    // 2. OH_Drawing_TextBlobCreateFromPosText with the second parameter being empty, check the error code with
302f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
303f6603c60Sopenharmony_ci    OH_Drawing_TextBlobCreateFromPosText(str, 0, &pts[0], font, TEXT_ENCODING_UTF8);
304f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
305f6603c60Sopenharmony_ci    // 3. OH_Drawing_TextBlobCreateFromPosText with the third parameter being nullptr, check the error code with
306f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
307f6603c60Sopenharmony_ci    OH_Drawing_TextBlobCreateFromPosText(str, strlen(str), nullptr, font, TEXT_ENCODING_UTF8);
308f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
309f6603c60Sopenharmony_ci    // 4. OH_Drawing_TextBlobCreateFromPosText with the first parameter being a string
310f6603c60Sopenharmony_ci    OH_Drawing_TextBlobCreateFromPosText("123456", 6, &pts[0], font, TEXT_ENCODING_UTF8);
311f6603c60Sopenharmony_ci    // 5. OH_Drawing_TextBlobCreateFromPosText with the fourth parameter being nullptr, check the error code with
312f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
313f6603c60Sopenharmony_ci    OH_Drawing_TextBlobCreateFromPosText(str, strlen(str), &pts[0], nullptr, TEXT_ENCODING_UTF8);
314f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
315f6603c60Sopenharmony_ci    // 6. Free memory
316f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
317f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
318f6603c60Sopenharmony_ci}
319f6603c60Sopenharmony_ci
320f6603c60Sopenharmony_ci/*
321f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0302
322f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromPosTextMultipleCalls
323f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromPosTextMultipleCalls.
324f6603c60Sopenharmony_ci * @tc.size  : SmallTest
325f6603c60Sopenharmony_ci * @tc.type  : Function
326f6603c60Sopenharmony_ci * @tc.level : Level 3
327f6603c60Sopenharmony_ci */
328f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromPosTextMultipleCalls, TestSize.Level3) {
329f6603c60Sopenharmony_ci    const char *strs[] = {
330f6603c60Sopenharmony_ci        "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文",
331f6603c60Sopenharmony_ci    };
332f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
333f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
334f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
335f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
336f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobCreateFromPosText 10 times (passing in different types of strings with different
337f6603c60Sopenharmony_ci    // lengths, such as Chinese, English, special characters, numbers, traditional Chinese characters, etc.) and use
338f6603c60Sopenharmony_ci    // OH_Drawing_CanvasDrawTextBlob in combination
339f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
340f6603c60Sopenharmony_ci        const char *str = strs[i % 6];
341f6603c60Sopenharmony_ci        int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8);
342f6603c60Sopenharmony_ci        OH_Drawing_Point2D pts[count];
343f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromPosText(str, strlen(str), &pts[0], font, TEXT_ENCODING_UTF8);
344f6603c60Sopenharmony_ci    }
345f6603c60Sopenharmony_ci    // 2. Free memory
346f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
347f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
348f6603c60Sopenharmony_ci}
349f6603c60Sopenharmony_ci
350f6603c60Sopenharmony_ci/*
351f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0303
352f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromPosTextAbnormal
353f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromPosTextAbnormal.
354f6603c60Sopenharmony_ci * @tc.size  : SmallTest
355f6603c60Sopenharmony_ci * @tc.type  : Function
356f6603c60Sopenharmony_ci * @tc.level : Level 3
357f6603c60Sopenharmony_ci */
358f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromPosTextAbnormal, TestSize.Level3) {
359f6603c60Sopenharmony_ci    const char *str = "123456";
360f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
361f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
362f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
363f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
364f6603c60Sopenharmony_ci    int count = OH_Drawing_FontCountText(font, str, strlen(str), TEXT_ENCODING_UTF8);
365f6603c60Sopenharmony_ci    OH_Drawing_Point2D pts[count];
366f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobCreateFromPosText interface with OH_Drawing_TextEncoding out of range, check the error
367f6603c60Sopenharmony_ci    // code with OH_Drawing_ErrorCodeGet
368f6603c60Sopenharmony_ci    OH_Drawing_TextBlobCreateFromPosText(str, strlen(str), &pts[0], font, static_cast<OH_Drawing_TextEncoding>(-1));
369f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
370f6603c60Sopenharmony_ci    // 2. Free memory
371f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
372f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
373f6603c60Sopenharmony_ci}
374f6603c60Sopenharmony_ci
375f6603c60Sopenharmony_ci/*
376f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0400
377f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromStringNormal
378f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromStringNormal.
379f6603c60Sopenharmony_ci * @tc.size  : SmallTest
380f6603c60Sopenharmony_ci * @tc.type  : Function
381f6603c60Sopenharmony_ci * @tc.level : Level 0
382f6603c60Sopenharmony_ci */
383f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromStringNormal, TestSize.Level0) {
384f6603c60Sopenharmony_ci    const char *str = "123456";
385f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
386f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
387f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
388f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
389f6603c60Sopenharmony_ci    OH_Drawing_TextEncoding encodeArray[] = {
390f6603c60Sopenharmony_ci        TEXT_ENCODING_UTF8,
391f6603c60Sopenharmony_ci        TEXT_ENCODING_UTF16,
392f6603c60Sopenharmony_ci        TEXT_ENCODING_UTF32,
393f6603c60Sopenharmony_ci        TEXT_ENCODING_GLYPH_ID,
394f6603c60Sopenharmony_ci    };
395f6603c60Sopenharmony_ci    // 1. Traverse the enumeration values of OH_Drawing_TextEncoding and use OH_Drawing_CanvasDrawTextBlob in
396f6603c60Sopenharmony_ci    // combination
397f6603c60Sopenharmony_ci    for (OH_Drawing_TextEncoding encode : encodeArray) {
398f6603c60Sopenharmony_ci        OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobCreateFromString(str, font, encode);
399f6603c60Sopenharmony_ci        OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
400f6603c60Sopenharmony_ci        EXPECT_NE(nullptr, canvas);
401f6603c60Sopenharmony_ci        OH_Drawing_CanvasDrawTextBlob(canvas, textBlob, 0, 0);
402f6603c60Sopenharmony_ci        OH_Drawing_CanvasDestroy(canvas);
403f6603c60Sopenharmony_ci    }
404f6603c60Sopenharmony_ci    // 2. Free memory
405f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
406f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
407f6603c60Sopenharmony_ci}
408f6603c60Sopenharmony_ci
409f6603c60Sopenharmony_ci/*
410f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0401
411f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromStringNull
412f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromStringNull.
413f6603c60Sopenharmony_ci * @tc.size  : SmallTest
414f6603c60Sopenharmony_ci * @tc.type  : Function
415f6603c60Sopenharmony_ci * @tc.level : Level 3
416f6603c60Sopenharmony_ci */
417f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromStringNull, TestSize.Level3) {
418f6603c60Sopenharmony_ci    const char *str = "123456";
419f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
420f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
421f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
422f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
423f6603c60Sopenharmony_ci    // 1. OH_Drawing_TextBlobCreateFromString with the first parameter being nullptr, check the error code with
424f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
425f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob1 = OH_Drawing_TextBlobCreateFromString(nullptr, font, TEXT_ENCODING_UTF8);
426f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
427f6603c60Sopenharmony_ci    // 2. OH_Drawing_TextBlobCreateFromString with the second parameter being nullptr, check the error code with
428f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
429f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob2 = OH_Drawing_TextBlobCreateFromString(str, nullptr, TEXT_ENCODING_UTF8);
430f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
431f6603c60Sopenharmony_ci    // 3. OH_Drawing_TextBlobCreateFromPosText with the first parameter being a string
432f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob3 = OH_Drawing_TextBlobCreateFromString("123456", font, TEXT_ENCODING_UTF8);
433f6603c60Sopenharmony_ci    // 4. Free memory
434f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
435f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob1);
436f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob2);
437f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob3);
438f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
439f6603c60Sopenharmony_ci}
440f6603c60Sopenharmony_ci
441f6603c60Sopenharmony_ci/*
442f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0402
443f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromStringMultipleCalls
444f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromStringMultipleCalls.
445f6603c60Sopenharmony_ci * @tc.size  : SmallTest
446f6603c60Sopenharmony_ci * @tc.type  : Function
447f6603c60Sopenharmony_ci * @tc.level : Level 3
448f6603c60Sopenharmony_ci */
449f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromStringMultipleCalls, TestSize.Level3) {
450f6603c60Sopenharmony_ci    const char *strs[] = {
451f6603c60Sopenharmony_ci        "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文",
452f6603c60Sopenharmony_ci    };
453f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
454f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
455f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
456f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
457f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobCreateFromString 10 times (passing in strings of different lengths and types, such as
458f6603c60Sopenharmony_ci    // Chinese, English, special characters, numbers, traditional Chinese characters, etc.) and use
459f6603c60Sopenharmony_ci    // OH_Drawing_CanvasDrawTextBlob in combination
460f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
461f6603c60Sopenharmony_ci        const char *str = strs[i % 6];
462f6603c60Sopenharmony_ci        OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobCreateFromString(str, font, TEXT_ENCODING_UTF8);
463f6603c60Sopenharmony_ci        OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
464f6603c60Sopenharmony_ci        EXPECT_NE(nullptr, canvas);
465f6603c60Sopenharmony_ci        OH_Drawing_CanvasDrawTextBlob(canvas, textBlob, 0, 0);
466f6603c60Sopenharmony_ci        OH_Drawing_CanvasDestroy(canvas);
467f6603c60Sopenharmony_ci    }
468f6603c60Sopenharmony_ci    // 2. Free memory
469f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
470f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
471f6603c60Sopenharmony_ci}
472f6603c60Sopenharmony_ci
473f6603c60Sopenharmony_ci/*
474f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0403
475f6603c60Sopenharmony_ci * @tc.name: testTextBlobCreateFromStringAbnormal
476f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobCreateFromStringAbnormal.
477f6603c60Sopenharmony_ci * @tc.size  : SmallTest
478f6603c60Sopenharmony_ci * @tc.type  : Function
479f6603c60Sopenharmony_ci * @tc.level : Level 3
480f6603c60Sopenharmony_ci */
481f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobCreateFromStringAbnormal, TestSize.Level3) {
482f6603c60Sopenharmony_ci    const char *str = "123456";
483f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
484f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
485f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
486f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
487f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobCreateFromString interface with OH_Drawing_TextEncoding out of range, check the error
488f6603c60Sopenharmony_ci    // code with OH_Drawing_ErrorCodeGet
489f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob =
490f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromString(str, font, static_cast<OH_Drawing_TextEncoding>(-1));
491f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
492f6603c60Sopenharmony_ci    // 2. Free memory
493f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
494f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
495f6603c60Sopenharmony_ci    OH_Drawing_TypefaceDestroy(typeSurface);
496f6603c60Sopenharmony_ci}
497f6603c60Sopenharmony_ci
498f6603c60Sopenharmony_ci/*
499f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0500
500f6603c60Sopenharmony_ci * @tc.name: testTextBlobGetBoundsNormal
501f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobGetBoundsNormal.
502f6603c60Sopenharmony_ci * @tc.size  : SmallTest
503f6603c60Sopenharmony_ci * @tc.type  : Function
504f6603c60Sopenharmony_ci * @tc.level : Level 0
505f6603c60Sopenharmony_ci */
506f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobGetBoundsNormal, TestSize.Level0) {
507f6603c60Sopenharmony_ci    // 1、创建OH_Drawing_TextBlob、OH_Drawing_Rect
508f6603c60Sopenharmony_ci    OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 0, 0);
509f6603c60Sopenharmony_ci    EXPECT_NE(rect, nullptr);
510f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
511f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
512f6603c60Sopenharmony_ci    const char *str = "123456";
513f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob =
514f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromString(str, font, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8);
515f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobGetBounds
516f6603c60Sopenharmony_ci    OH_Drawing_TextBlobGetBounds(textBlob, rect);
517f6603c60Sopenharmony_ci    float left = OH_Drawing_RectGetLeft(rect);
518f6603c60Sopenharmony_ci    float right = OH_Drawing_RectGetRight(rect);
519f6603c60Sopenharmony_ci    EXPECT_EQ(right - left > 0, true);
520f6603c60Sopenharmony_ci    // 3. Free memory
521f6603c60Sopenharmony_ci    OH_Drawing_RectDestroy(rect);
522f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
523f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
524f6603c60Sopenharmony_ci}
525f6603c60Sopenharmony_ci
526f6603c60Sopenharmony_ci/*
527f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0501
528f6603c60Sopenharmony_ci * @tc.name: testTextBlobGetBoundsNull
529f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobGetBoundsNull.
530f6603c60Sopenharmony_ci * @tc.size  : SmallTest
531f6603c60Sopenharmony_ci * @tc.type  : Function
532f6603c60Sopenharmony_ci * @tc.level : Level 3
533f6603c60Sopenharmony_ci */
534f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobGetBoundsNull, TestSize.Level3) {
535f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlob and OH_Drawing_Rect
536f6603c60Sopenharmony_ci    OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 0, 0);
537f6603c60Sopenharmony_ci    EXPECT_NE(rect, nullptr);
538f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
539f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
540f6603c60Sopenharmony_ci    const char *str = "123456";
541f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob =
542f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromString(str, font, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8);
543f6603c60Sopenharmony_ci    // 2. Pass nullptr as the first parameter to OH_Drawing_TextBlobGetBounds and check the error code with
544f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
545f6603c60Sopenharmony_ci    OH_Drawing_TextBlobGetBounds(nullptr, rect);
546f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
547f6603c60Sopenharmony_ci    // 3. Pass nullptr as the second parameter to OH_Drawing_TextBlobGetBounds and check the error code with
548f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
549f6603c60Sopenharmony_ci    OH_Drawing_TextBlobGetBounds(textBlob, nullptr);
550f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
551f6603c60Sopenharmony_ci    // 4. Free memory
552f6603c60Sopenharmony_ci    OH_Drawing_RectDestroy(rect);
553f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
554f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
555f6603c60Sopenharmony_ci}
556f6603c60Sopenharmony_ci
557f6603c60Sopenharmony_ci/*
558f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0502
559f6603c60Sopenharmony_ci * @tc.name: testTextBlobGetBoundsMultipleCalls
560f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobGetBoundsMultipleCalls.
561f6603c60Sopenharmony_ci * @tc.size  : SmallTest
562f6603c60Sopenharmony_ci * @tc.type  : Function
563f6603c60Sopenharmony_ci * @tc.level : Level 3
564f6603c60Sopenharmony_ci */
565f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobGetBoundsMultipleCalls, TestSize.Level3) {
566f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlob and OH_Drawing_Rect
567f6603c60Sopenharmony_ci    OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 0, 0);
568f6603c60Sopenharmony_ci    EXPECT_NE(rect, nullptr);
569f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
570f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
571f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobGetBounds 10 times (passing in strings of different lengths and types, such as
572f6603c60Sopenharmony_ci    // Chinese, English, special characters, numbers, traditional Chinese characters, etc.)
573f6603c60Sopenharmony_ci    const char *strs[] = {
574f6603c60Sopenharmony_ci        "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文",
575f6603c60Sopenharmony_ci    };
576f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
577f6603c60Sopenharmony_ci        const char *str = strs[i % 6];
578f6603c60Sopenharmony_ci        OH_Drawing_TextBlob *textBlob =
579f6603c60Sopenharmony_ci            OH_Drawing_TextBlobCreateFromString(str, font, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8);
580f6603c60Sopenharmony_ci        OH_Drawing_TextBlobGetBounds(textBlob, rect);
581f6603c60Sopenharmony_ci        float left = OH_Drawing_RectGetLeft(rect);
582f6603c60Sopenharmony_ci        float right = OH_Drawing_RectGetRight(rect);
583f6603c60Sopenharmony_ci        EXPECT_EQ(right - left > 0, true);
584f6603c60Sopenharmony_ci        OH_Drawing_TextBlobDestroy(textBlob);
585f6603c60Sopenharmony_ci    }
586f6603c60Sopenharmony_ci    // 3. Free memory
587f6603c60Sopenharmony_ci    OH_Drawing_RectDestroy(rect);
588f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
589f6603c60Sopenharmony_ci}
590f6603c60Sopenharmony_ci
591f6603c60Sopenharmony_ci/*
592f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0503
593f6603c60Sopenharmony_ci * @tc.name: testTextBlobGetBoundsAbnormal
594f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobGetBoundsAbnormal.
595f6603c60Sopenharmony_ci * @tc.size  : SmallTest
596f6603c60Sopenharmony_ci * @tc.type  : Function
597f6603c60Sopenharmony_ci * @tc.level : Level 3
598f6603c60Sopenharmony_ci */
599f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobGetBoundsAbnormal, TestSize.Level3) {
600f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlob and OH_Drawing_Rect
601f6603c60Sopenharmony_ci    OH_Drawing_Rect *rect = OH_Drawing_RectCreate(-1, -1, -1, -1);
602f6603c60Sopenharmony_ci    EXPECT_NE(rect, nullptr);
603f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
604f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
605f6603c60Sopenharmony_ci    const char *str = "123456";
606f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob =
607f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromString(str, font, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8);
608f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobGetBounds with rect initialized with negative values
609f6603c60Sopenharmony_ci    OH_Drawing_TextBlobGetBounds(textBlob, rect);
610f6603c60Sopenharmony_ci    float left = OH_Drawing_RectGetLeft(rect);
611f6603c60Sopenharmony_ci    float right = OH_Drawing_RectGetRight(rect);
612f6603c60Sopenharmony_ci    EXPECT_EQ(right - left > 0, true);
613f6603c60Sopenharmony_ci    // 3. Free memory
614f6603c60Sopenharmony_ci    OH_Drawing_RectDestroy(rect);
615f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
616f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
617f6603c60Sopenharmony_ci}
618f6603c60Sopenharmony_ci
619f6603c60Sopenharmony_ci/*
620f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0600
621f6603c60Sopenharmony_ci * @tc.name: testTextBlobUniqueIDNormal
622f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobUniqueIDNormal.
623f6603c60Sopenharmony_ci * @tc.size  : SmallTest
624f6603c60Sopenharmony_ci * @tc.type  : Function
625f6603c60Sopenharmony_ci * @tc.level : Level 0
626f6603c60Sopenharmony_ci */
627f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobUniqueIDNormal, TestSize.Level0) {
628f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlob
629f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
630f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
631f6603c60Sopenharmony_ci    const char *str = "123456";
632f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob =
633f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromString(str, font, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8);
634f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobUniqueID
635f6603c60Sopenharmony_ci    uint32_t ret = OH_Drawing_TextBlobUniqueID(textBlob);
636f6603c60Sopenharmony_ci    EXPECT_EQ(ret > 0, true);
637f6603c60Sopenharmony_ci    // 3. Free memory
638f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
639f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
640f6603c60Sopenharmony_ci}
641f6603c60Sopenharmony_ci
642f6603c60Sopenharmony_ci/*
643f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0601
644f6603c60Sopenharmony_ci * @tc.name: testTextBlobUniqueIDNull
645f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobUniqueIDNull.
646f6603c60Sopenharmony_ci * @tc.size  : SmallTest
647f6603c60Sopenharmony_ci * @tc.type  : Function
648f6603c60Sopenharmony_ci * @tc.level : Level 3
649f6603c60Sopenharmony_ci */
650f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobUniqueIDNull, TestSize.Level3) {
651f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlob
652f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
653f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
654f6603c60Sopenharmony_ci    const char *str = "123456";
655f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob =
656f6603c60Sopenharmony_ci        OH_Drawing_TextBlobCreateFromString(str, font, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8);
657f6603c60Sopenharmony_ci    // 2. Pass nullptr as the parameter to OH_Drawing_TextBlobUniqueID and check the error code with
658f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
659f6603c60Sopenharmony_ci    OH_Drawing_TextBlobUniqueID(nullptr);
660f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
661f6603c60Sopenharmony_ci    // 3. Free memory
662f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
663f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
664f6603c60Sopenharmony_ci}
665f6603c60Sopenharmony_ci
666f6603c60Sopenharmony_ci/*
667f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0602
668f6603c60Sopenharmony_ci * @tc.name: testTextBlobUniqueIDMultipleCalls
669f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobUniqueIDMultipleCalls.
670f6603c60Sopenharmony_ci * @tc.size  : SmallTest
671f6603c60Sopenharmony_ci * @tc.type  : Function
672f6603c60Sopenharmony_ci * @tc.level : Level 3
673f6603c60Sopenharmony_ci */
674f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobUniqueIDMultipleCalls, TestSize.Level3) {
675f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlob
676f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
677f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
678f6603c60Sopenharmony_ci    const char *strs[] = {
679f6603c60Sopenharmony_ci        "Hello World", "你好世界", "Hello 世界", "Hello 世界123", "Hello $#@!", "繁體中文",
680f6603c60Sopenharmony_ci    };
681f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobUniqueID 10 times (passing in strings of different lengths and types, such as Chinese,
682f6603c60Sopenharmony_ci    // English, special characters, numbers, traditional Chinese characters, etc.)
683f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
684f6603c60Sopenharmony_ci        const char *str = strs[i % 6];
685f6603c60Sopenharmony_ci        OH_Drawing_TextBlob *textBlob =
686f6603c60Sopenharmony_ci            OH_Drawing_TextBlobCreateFromString(str, font, OH_Drawing_TextEncoding::TEXT_ENCODING_UTF8);
687f6603c60Sopenharmony_ci        uint32_t ret = OH_Drawing_TextBlobUniqueID(textBlob);
688f6603c60Sopenharmony_ci        EXPECT_EQ(ret > 0, true);
689f6603c60Sopenharmony_ci        OH_Drawing_TextBlobDestroy(textBlob);
690f6603c60Sopenharmony_ci    }
691f6603c60Sopenharmony_ci    // 3. Free memory
692f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
693f6603c60Sopenharmony_ci}
694f6603c60Sopenharmony_ci
695f6603c60Sopenharmony_ci/*
696f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0700
697f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderAllocRunPosNormal
698f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderAllocRunPosNormal.
699f6603c60Sopenharmony_ci * @tc.size  : SmallTest
700f6603c60Sopenharmony_ci * @tc.type  : Function
701f6603c60Sopenharmony_ci * @tc.level : Level 0
702f6603c60Sopenharmony_ci */
703f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderAllocRunPosNormal, TestSize.Level0) {
704f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlobBuilder, OH_Drawing_Font, OH_Drawing_Rect
705f6603c60Sopenharmony_ci    OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 0, 0);
706f6603c60Sopenharmony_ci    EXPECT_NE(rect, nullptr);
707f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
708f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
709f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilder *builder = OH_Drawing_TextBlobBuilderCreate();
710f6603c60Sopenharmony_ci    // 2. OH_Drawing_TextBlobBuilderAllocRunPos
711f6603c60Sopenharmony_ci    const OH_Drawing_RunBuffer *runBuffer = OH_Drawing_TextBlobBuilderAllocRunPos(builder, font, 9, rect);
712f6603c60Sopenharmony_ci    EXPECT_NE(runBuffer, nullptr);
713f6603c60Sopenharmony_ci    // 3. Free memory
714f6603c60Sopenharmony_ci    OH_Drawing_RectDestroy(rect);
715f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
716f6603c60Sopenharmony_ci    if (0) {
717f6603c60Sopenharmony_ci        // todo cpp crash
718f6603c60Sopenharmony_ci        OH_Drawing_TextBlobBuilderDestroy(builder);
719f6603c60Sopenharmony_ci    }
720f6603c60Sopenharmony_ci}
721f6603c60Sopenharmony_ci
722f6603c60Sopenharmony_ci/*
723f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0701
724f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderAllocRunPosNull
725f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderAllocRunPosNull.
726f6603c60Sopenharmony_ci * @tc.size  : SmallTest
727f6603c60Sopenharmony_ci * @tc.type  : Function
728f6603c60Sopenharmony_ci * @tc.level : Level 3
729f6603c60Sopenharmony_ci */
730f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderAllocRunPosNull, TestSize.Level3) {
731f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlobBuilder, OH_Drawing_Font, OH_Drawing_Rect
732f6603c60Sopenharmony_ci    OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 0, 0);
733f6603c60Sopenharmony_ci    EXPECT_NE(rect, nullptr);
734f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
735f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
736f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilder *builder = OH_Drawing_TextBlobBuilderCreate();
737f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobBuilderAllocRunPos with the first parameter as nullptr and check the error code with
738f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
739f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilderAllocRunPos(nullptr, font, 9, rect);
740f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
741f6603c60Sopenharmony_ci    // 3. Call OH_Drawing_TextBlobBuilderAllocRunPos with the second parameter as nullptr and check the error code with
742f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
743f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilderAllocRunPos(builder, nullptr, 9, rect);
744f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
745f6603c60Sopenharmony_ci    // 4. Call OH_Drawing_TextBlobBuilderAllocRunPos with the third parameter as nullptr and check the error code with
746f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
747f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilderAllocRunPos(builder, font, 0, rect);
748f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
749f6603c60Sopenharmony_ci    // 5. Call OH_Drawing_TextBlobBuilderAllocRunPos with the fourth parameter as nullptr and check the error code with
750f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
751f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilderAllocRunPos(builder, font, 9, nullptr);
752f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
753f6603c60Sopenharmony_ci    // 6. Free memory
754f6603c60Sopenharmony_ci    OH_Drawing_RectDestroy(rect);
755f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
756f6603c60Sopenharmony_ci    if (0) {
757f6603c60Sopenharmony_ci        // todo cpp crash
758f6603c60Sopenharmony_ci        OH_Drawing_TextBlobBuilderDestroy(builder);
759f6603c60Sopenharmony_ci    }
760f6603c60Sopenharmony_ci}
761f6603c60Sopenharmony_ci
762f6603c60Sopenharmony_ci/*
763f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0702
764f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderAllocRunPosMultipleCalls
765f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderAllocRunPosMultipleCalls.
766f6603c60Sopenharmony_ci * @tc.size  : SmallTest
767f6603c60Sopenharmony_ci * @tc.type  : Function
768f6603c60Sopenharmony_ci * @tc.level : Level 3
769f6603c60Sopenharmony_ci */
770f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderAllocRunPosMultipleCalls, TestSize.Level3) {
771f6603c60Sopenharmony_ci    OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 0, 0);
772f6603c60Sopenharmony_ci    EXPECT_NE(rect, nullptr);
773f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
774f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
775f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilder *builder = OH_Drawing_TextBlobBuilderCreate();
776f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobBuilderAllocRunPos 10 times
777f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
778f6603c60Sopenharmony_ci        const OH_Drawing_RunBuffer *runBuffer = OH_Drawing_TextBlobBuilderAllocRunPos(builder, font, 9, rect);
779f6603c60Sopenharmony_ci        EXPECT_NE(runBuffer, nullptr);
780f6603c60Sopenharmony_ci    }
781f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobBuilderMake and then call OH_Drawing_TextBlobBuilderAllocRunPos again
782f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilderMake(builder);
783f6603c60Sopenharmony_ci    const OH_Drawing_RunBuffer *runBuffer = OH_Drawing_TextBlobBuilderAllocRunPos(builder, font, 9, rect);
784f6603c60Sopenharmony_ci    EXPECT_NE(runBuffer, nullptr);
785f6603c60Sopenharmony_ci    // 3. Free memory
786f6603c60Sopenharmony_ci    OH_Drawing_RectDestroy(rect);
787f6603c60Sopenharmony_ci    OH_Drawing_FontDestroy(font);
788f6603c60Sopenharmony_ci    if (0) {
789f6603c60Sopenharmony_ci        // todo cpp crash
790f6603c60Sopenharmony_ci        OH_Drawing_TextBlobBuilderDestroy(builder);
791f6603c60Sopenharmony_ci    }
792f6603c60Sopenharmony_ci}
793f6603c60Sopenharmony_ci
794f6603c60Sopenharmony_ci/*
795f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0800
796f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderMakeNormal
797f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderMakeNormal.
798f6603c60Sopenharmony_ci * @tc.size  : SmallTest
799f6603c60Sopenharmony_ci * @tc.type  : Function
800f6603c60Sopenharmony_ci * @tc.level : Level 0
801f6603c60Sopenharmony_ci */
802f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderMakeNormal, TestSize.Level0) {
803f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlobBuilder
804f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilder *builder = OH_Drawing_TextBlobBuilderCreate();
805f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobBuilderMake
806f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobBuilderMake(builder);
807f6603c60Sopenharmony_ci    // 3. Free memory
808f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
809f6603c60Sopenharmony_ci    if (0) {
810f6603c60Sopenharmony_ci        // todo cpp crash
811f6603c60Sopenharmony_ci        OH_Drawing_TextBlobBuilderDestroy(builder);
812f6603c60Sopenharmony_ci    }
813f6603c60Sopenharmony_ci}
814f6603c60Sopenharmony_ci
815f6603c60Sopenharmony_ci/*
816f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0801
817f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderMakeNull
818f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderMakeNull.
819f6603c60Sopenharmony_ci * @tc.size  : SmallTest
820f6603c60Sopenharmony_ci * @tc.type  : Function
821f6603c60Sopenharmony_ci * @tc.level : Level 3
822f6603c60Sopenharmony_ci */
823f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderMakeNull, TestSize.Level3) {
824f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_TextBlobBuilderMake with nullptr as the parameter and check the error code with
825f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
826f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilderMake(nullptr);
827f6603c60Sopenharmony_ci    // 1. No crash, error code returns OH_DRAWING_ERROR_INVALID_PARAMETER
828f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
829f6603c60Sopenharmony_ci}
830f6603c60Sopenharmony_ci
831f6603c60Sopenharmony_ci/*
832f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0802
833f6603c60Sopenharmony_ci * @tc.name: testTextBlobBuilderMakeMultipleCalls
834f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobBuilderMakeMultipleCalls.
835f6603c60Sopenharmony_ci * @tc.size  : SmallTest
836f6603c60Sopenharmony_ci * @tc.type  : Function
837f6603c60Sopenharmony_ci * @tc.level : Level 3
838f6603c60Sopenharmony_ci */
839f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobBuilderMakeMultipleCalls, TestSize.Level3) {
840f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlobBuilder
841f6603c60Sopenharmony_ci    OH_Drawing_TextBlobBuilder *builder = OH_Drawing_TextBlobBuilderCreate();
842f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_TextBlobBuilderMake 10 times
843f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
844f6603c60Sopenharmony_ci        OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobBuilderMake(builder);
845f6603c60Sopenharmony_ci        OH_Drawing_TextBlobDestroy(textBlob);
846f6603c60Sopenharmony_ci    }
847f6603c60Sopenharmony_ci    // 3. Free memory
848f6603c60Sopenharmony_ci    if (0) {
849f6603c60Sopenharmony_ci        // todo cpp crash
850f6603c60Sopenharmony_ci        OH_Drawing_TextBlobBuilderDestroy(builder);
851f6603c60Sopenharmony_ci    }
852f6603c60Sopenharmony_ci}
853f6603c60Sopenharmony_ci
854f6603c60Sopenharmony_ci/*
855f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0800
856f6603c60Sopenharmony_ci * @tc.name: testTextBlobDestroyNormal
857f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobDestroyNormal.
858f6603c60Sopenharmony_ci * @tc.size  : SmallTest
859f6603c60Sopenharmony_ci * @tc.type  : Function
860f6603c60Sopenharmony_ci * @tc.level : Level 0
861f6603c60Sopenharmony_ci */
862f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobDestroyNormal, TestSize.Level0) {
863f6603c60Sopenharmony_ci    const char *str = "123456";
864f6603c60Sopenharmony_ci    OH_Drawing_Font *font = OH_Drawing_FontCreate();
865f6603c60Sopenharmony_ci    EXPECT_NE(font, nullptr);
866f6603c60Sopenharmony_ci    OH_Drawing_Typeface *typeSurface = OH_Drawing_TypefaceCreateDefault();
867f6603c60Sopenharmony_ci    OH_Drawing_FontSetTypeface(font, typeSurface);
868f6603c60Sopenharmony_ci    // 1. Create OH_Drawing_TextBlob
869f6603c60Sopenharmony_ci    OH_Drawing_TextBlob *textBlob = OH_Drawing_TextBlobCreateFromString(str, font, TEXT_ENCODING_UTF8);
870f6603c60Sopenharmony_ci    // 2. OH_Drawing_TextBlobDestroy
871f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(textBlob);
872f6603c60Sopenharmony_ci}
873f6603c60Sopenharmony_ci
874f6603c60Sopenharmony_ci/*
875f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_TEXTBLOB_0801
876f6603c60Sopenharmony_ci * @tc.name: testTextBlobDestroyNull
877f6603c60Sopenharmony_ci * @tc.desc: test for testTextBlobDestroyNull.
878f6603c60Sopenharmony_ci * @tc.size  : SmallTest
879f6603c60Sopenharmony_ci * @tc.type  : Function
880f6603c60Sopenharmony_ci * @tc.level : Level 3
881f6603c60Sopenharmony_ci */
882f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeTextBlobTest, testTextBlobDestroyNull, TestSize.Level3) {
883f6603c60Sopenharmony_ci    // 1. OH_Drawing_TextBlobDestroy with null parameter
884f6603c60Sopenharmony_ci    OH_Drawing_TextBlobDestroy(nullptr);
885f6603c60Sopenharmony_ci}
886f6603c60Sopenharmony_ci
887f6603c60Sopenharmony_ci} // namespace Drawing
888f6603c60Sopenharmony_ci} // namespace Rosen
889f6603c60Sopenharmony_ci} // namespace OHOS