• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device 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_font_collection.h"
17 #include "drawing_point.h"
18 #include "drawing_rect.h"
19 #include "drawing_text_line.h"
20 #include "drawing_text_run.h"
21 #include "drawing_types.h"
22 #include "drawing_text_typography.h"
23 #include "gtest/gtest.h"
24 #include "string"
25 
26 #ifdef RS_ENABLE_VK
27 #include "platform/ohos/backend/rs_vulkan_context.h"
28 #endif
29 
30 using namespace testing;
31 using namespace testing::ext;
32 
33 namespace OHOS {
34 namespace {
35     constexpr static float FLOAT_DATA_EPSILON = 1e-6f;
36 }
37 
38 class NativeTextRunTest : public testing::Test {
39 public:
SetUpTestCase()40     static void SetUpTestCase()
41     {
42 #ifdef RS_ENABLE_VK
43         Rosen::RsVulkanContext::SetRecyclable(false);
44 #endif
45     }
TearDownTestCase()46     static void TearDownTestCase() {}
SetUp()47     void SetUp() override {};
48     void TearDown() override;
49     void PrepareCreateTextLine();
50     void PrepareCreateTextLineForGlyphDrawing();
51 
52     OH_Drawing_TypographyStyle* typeStyle_ = nullptr;
53     OH_Drawing_TextStyle* txtStyle_ = nullptr;
54     OH_Drawing_FontCollection* fontCollection_ = nullptr;
55     OH_Drawing_TypographyCreate* handler_ = nullptr;
56     OH_Drawing_Typography* typography_ = nullptr;
57     OH_Drawing_Array* runs_ = nullptr;
58     OH_Drawing_Array* textLines_ = nullptr;
59     std::string text_;
60 };
61 
PrepareCreateTextLine()62 void NativeTextRunTest::PrepareCreateTextLine()
63 {
64     double maxWidth = 500.0;
65     typeStyle_ = OH_Drawing_CreateTypographyStyle();
66     EXPECT_TRUE(typeStyle_ != nullptr);
67     txtStyle_ = OH_Drawing_CreateTextStyle();
68     EXPECT_TRUE(txtStyle_ != nullptr);
69     fontCollection_ = OH_Drawing_CreateFontCollection();
70     EXPECT_TRUE(fontCollection_ != nullptr);
71     handler_ = OH_Drawing_CreateTypographyHandler(typeStyle_, fontCollection_);
72     EXPECT_TRUE(handler_ != nullptr);
73     OH_Drawing_SetTextStyleColor(txtStyle_, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
74     double fontSize = 30;
75     OH_Drawing_SetTextStyleFontSize(txtStyle_, fontSize);
76     OH_Drawing_SetTextStyleFontWeight(txtStyle_, FONT_WEIGHT_400);
77     bool halfLeading = true;
78     OH_Drawing_SetTextStyleHalfLeading(txtStyle_, halfLeading);
79     const char* fontFamilies[] = { "Roboto" };
80     OH_Drawing_SetTextStyleFontFamilies(txtStyle_, 1, fontFamilies);
81     OH_Drawing_TypographyHandlerPushTextStyle(handler_, txtStyle_);
82     OH_Drawing_TypographyHandlerAddText(handler_, text_.c_str());
83     OH_Drawing_TypographyHandlerPopTextStyle(handler_);
84     typography_ = OH_Drawing_CreateTypography(handler_);
85     EXPECT_TRUE(typography_ != nullptr);
86     OH_Drawing_TypographyLayout(typography_, maxWidth);
87 }
88 
PrepareCreateTextLineForGlyphDrawing()89 void NativeTextRunTest::PrepareCreateTextLineForGlyphDrawing()
90 {
91     double maxWidth = 1200.0;
92     typeStyle_ = OH_Drawing_CreateTypographyStyle();
93     EXPECT_NE(typeStyle_, nullptr);
94     txtStyle_ = OH_Drawing_CreateTextStyle();
95     EXPECT_NE(txtStyle_, nullptr);
96     fontCollection_ = OH_Drawing_CreateFontCollection();
97     EXPECT_NE(fontCollection_, nullptr);
98     handler_ = OH_Drawing_CreateTypographyHandler(typeStyle_, fontCollection_);
99     EXPECT_NE(handler_, nullptr);
100     double fontSize = 100;
101     OH_Drawing_SetTextStyleFontSize(txtStyle_, fontSize);
102     OH_Drawing_TypographyHandlerPushTextStyle(handler_, txtStyle_);
103     OH_Drawing_TypographyHandlerAddText(handler_, text_.c_str());
104     typography_ = OH_Drawing_CreateTypography(handler_);
105     EXPECT_NE(typography_, nullptr);
106     OH_Drawing_TypographyLayout(typography_, maxWidth);
107     textLines_ = OH_Drawing_TypographyGetTextLines(typography_);
108     EXPECT_NE(textLines_, nullptr);
109     size_t size = OH_Drawing_GetDrawingArraySize(textLines_);
110     EXPECT_TRUE(size != 0);
111     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines_, 0);
112     EXPECT_NE(textLine, nullptr);
113     runs_ = OH_Drawing_TextLineGetGlyphRuns(textLine);
114     EXPECT_NE(runs_, nullptr);
115     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs_);
116     EXPECT_TRUE(runsSize != 0);
117 }
118 
TearDown()119 void NativeTextRunTest::TearDown()
120 {
121     OH_Drawing_DestroyTypography(typography_);
122     typography_ = nullptr;
123     OH_Drawing_DestroyTypographyHandler(handler_);
124     handler_ = nullptr;
125     OH_Drawing_DestroyFontCollection(fontCollection_);
126     fontCollection_ = nullptr;
127     OH_Drawing_DestroyTextStyle(txtStyle_);
128     txtStyle_ = nullptr;
129     OH_Drawing_DestroyTypographyStyle(typeStyle_);
130     typeStyle_ = nullptr;
131     text_ = "";
132     if (textLines_ != nullptr) {
133         OH_Drawing_DestroyTextLines(textLines_);
134         textLines_ = nullptr;
135     }
136     if (runs_ != nullptr) {
137         OH_Drawing_DestroyRuns(runs_);
138         runs_ = nullptr;
139     }
140 }
141 
142 /*
143  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_001
144  * @tc.name  : RunTest001
145  * @tc.desc  : Test for get run by index
146  * @tc.size  : MediumTest
147  * @tc.type  : Function
148  * @tc.level : Level 0
149  */
150 HWTEST_F(NativeTextRunTest, RunTest001, Function | MediumTest | Level0)
151 {
152     text_ = "Hello 你好 World";
153     PrepareCreateTextLine();
154     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
155     EXPECT_TRUE(textLines != nullptr);
156     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
157     ASSERT_GT(size, 0);
158     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
159 
160     OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
161     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
162     ASSERT_GT(runsSize, 0);
163 
164     OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(nullptr, 0);
165     EXPECT_EQ(run, nullptr);
166     run = OH_Drawing_GetRunByIndex(runs, -1);
167     EXPECT_EQ(run, nullptr);
168     run = OH_Drawing_GetRunByIndex(runs, runsSize);
169     EXPECT_EQ(run, nullptr);
170     run = OH_Drawing_GetRunByIndex(runs, 0);
171     uint32_t countData = 6;
172     uint32_t count = OH_Drawing_GetRunGlyphCount(run);
173     EXPECT_EQ(count, countData);
174 
175     // branchCoverage
176     auto nullCount = OH_Drawing_GetDrawingArraySize(nullptr);
177     EXPECT_EQ(nullCount, 0);
178     OH_Drawing_DestroyRuns(nullptr);
179     OH_Drawing_DestroyRuns(runs);
180     OH_Drawing_DestroyTextLines(textLines);
181 }
182 
183 /*
184  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_002
185  * @tc.name  : RunTest002
186  * @tc.desc  : Test for get run glyph count
187  * @tc.size  : MediumTest
188  * @tc.type  : Function
189  * @tc.level : Level 0
190  */
191 HWTEST_F(NativeTextRunTest, RunTest002, Function | MediumTest | Level0)
192 {
193     text_ = "Hello 你好 World⌚����‍����‍��‍��‍����مرحبا中国 测文本\n 123";
194     PrepareCreateTextLine();
195     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
196     EXPECT_TRUE(textLines != nullptr);
197     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
198     ASSERT_GT(size, 0);
199     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
200 
201     OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
202     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
203     ASSERT_GT(runsSize, 0);
204     std::vector<int32_t> countArr = {6, 2, 1, 5, 5, 5};
205     for (int i = 0; i < runsSize; i++) {
206         OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(runs, i);
207         uint32_t count = OH_Drawing_GetRunGlyphCount(run);
208         EXPECT_EQ(count, countArr[i]);
209     }
210 
211     // branchCoverage
212     OH_Drawing_GetRunGlyphCount(nullptr);
213     OH_Drawing_DestroyRuns(runs);
214     OH_Drawing_DestroyTextLines(textLines);
215 }
216 
217 /*
218  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_003
219  * @tc.name  : RunTest003
220  * @tc.desc  : Test for get glyph index in paragraph
221  * @tc.size  : MediumTest
222  * @tc.type  : Function
223  * @tc.level : Level 0
224  */
225 HWTEST_F(NativeTextRunTest, RunTest003, Function | MediumTest | Level0)
226 {
227     text_ = "Hello 你好 World⌚����‍����‍��‍��‍����مرحبا中国 测文本\n 123";
228     PrepareCreateTextLine();
229     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
230     EXPECT_TRUE(textLines != nullptr);
231     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
232     ASSERT_GT(size, 0);
233     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
234 
235     OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
236     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
237     ASSERT_GT(runsSize, 0);
238     OH_Drawing_Run* run1 = OH_Drawing_GetRunByIndex(runs, 1);
239     uint32_t count = OH_Drawing_GetRunGlyphCount(run1);
240     auto glyphIndexArr = OH_Drawing_GetRunStringIndices(run1, 0, count);
241     auto glyphIndexArrSize = OH_Drawing_GetDrawingArraySize(glyphIndexArr);
242     std::vector<int32_t> indexndexArr = {6, 7};
243     for (int j = 0; j < glyphIndexArrSize; j++) {
244         auto glyphIndex = OH_Drawing_GetRunStringIndicesByIndex(glyphIndexArr, j);
245         EXPECT_EQ(glyphIndex, indexndexArr[j]);
246     }
247     // branchCoverage
248     OH_Drawing_GetRunStringIndices(nullptr, -1, -1);
249     OH_Drawing_GetRunStringIndicesByIndex(glyphIndexArr, glyphIndexArrSize);
250     OH_Drawing_DestroyRunStringIndices(glyphIndexArr);
251     OH_Drawing_GetRunGlyphCount(nullptr);
252     OH_Drawing_DestroyRuns(runs);
253     OH_Drawing_DestroyTextLines(textLines);
254 }
255 
256 /*
257  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_004
258  * @tc.name  : RunTest004
259  * @tc.desc  : Test for get run string range
260  * @tc.size  : MediumTest
261  * @tc.type  : Function
262  * @tc.level : Level 0
263  */
264 HWTEST_F(NativeTextRunTest, RunTest004, Function | MediumTest | Level0)
265 {
266     text_ = "Hello 你好 World⌚����‍����‍��‍��‍����مرحبا中国 测文本\n 123";
267     PrepareCreateTextLine();
268     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
269     EXPECT_TRUE(textLines != nullptr);
270     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
271     ASSERT_GT(size, 0);
272     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
273 
274     OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
275     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
276     ASSERT_GT(runsSize, 0);
277 
278     std::vector<int32_t> locationArr = {0, 6, 8, 9, 14, 19};
279     std::vector<int32_t> lengthArr = {6, 2, 1, 5, 5, 5};
280     for (int i = 0; i < runsSize; i++) {
281         OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(runs, i);
282         uint64_t location = 0;
283         uint64_t length = 0;
284         OH_Drawing_GetRunStringRange(run, &location, &length);
285         EXPECT_EQ(location, locationArr[i]);
286         EXPECT_EQ(length, lengthArr[i]);
287         // branchCoverage
288         OH_Drawing_GetRunStringRange(run, nullptr, nullptr);
289     }
290 
291     OH_Drawing_DestroyRuns(runs);
292     OH_Drawing_DestroyTextLines(textLines);
293 }
294 
295 /*
296  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_005
297  * @tc.name  : RunTest005
298  * @tc.desc  : Test for get run typographic bounds
299  * @tc.size  : MediumTest
300  * @tc.type  : Function
301  * @tc.level : Level 0
302  */
303 HWTEST_F(NativeTextRunTest, RunTest005, Function | MediumTest | Level0)
304 {
305     text_ = "Hello 你好 World⌚����‍����‍��‍��‍����مرحبا中国 测文本\n 123";
306     PrepareCreateTextLine();
307     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
308     EXPECT_TRUE(textLines != nullptr);
309     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
310     ASSERT_GT(size, 0);
311     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
312 
313     OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
314     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
315     ASSERT_GT(runsSize, 0);
316 
317     std::vector<float> widthArr = {78.929932, 59.999939, 8.099991, 81.509903, 187.187500, 64.349945};
318     std::vector<float> ascentArr = {-27.840000, -27.840000, -27.840000, -27.840000, -27.798166, -35.369999};
319     std::vector<float> descentArr = {7.320000, 7.320000, 7.320000, 7.320000, 7.431193, 9.690001};
320     for (int i = 0; i < runsSize; i++) {
321         OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(runs, i);
322         float ascent = 0.0;
323         float descent = 0.0;
324         float leading = 0.0;
325         float width = OH_Drawing_GetRunTypographicBounds(run, &ascent, &descent, &leading);
326         EXPECT_EQ(leading, 0);
327         EXPECT_NEAR(ascent, ascentArr[i], FLOAT_DATA_EPSILON);
328         EXPECT_NEAR(descent, descentArr[i], FLOAT_DATA_EPSILON);
329         EXPECT_NEAR(width, widthArr[i], FLOAT_DATA_EPSILON);
330         // branchCoverage
331         OH_Drawing_GetRunTypographicBounds(run, nullptr, nullptr, nullptr);
332         OH_Drawing_GetRunTypographicBounds(nullptr, &ascent, &descent, &leading);
333     }
334 
335     OH_Drawing_DestroyRuns(runs);
336     OH_Drawing_DestroyTextLines(textLines);
337 }
338 
339 /*
340  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_006
341  * @tc.name  : RunTest006
342  * @tc.desc  : Test for get run glyphs
343  * @tc.size  : MediumTest
344  * @tc.type  : Function
345  * @tc.level : Level 0
346  */
347 HWTEST_F(NativeTextRunTest, RunTest006, Function | MediumTest | Level0)
348 {
349     text_ = "Hello 你好 World⌚����‍����‍��‍��‍����مرحبا中国 测文本\n 123";
350     PrepareCreateTextLine();
351     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
352     EXPECT_TRUE(textLines != nullptr);
353     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
354     ASSERT_GT(size, 0);
355     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
356 
357     OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
358     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
359     ASSERT_GT(runsSize, 0);
360 
361     std::vector<int32_t> glyphSizeArr = {6, 2, 1, 5, 5, 5};
362     std::vector<int32_t> glyphArr = {7824, 10413};
363     for (int i = 0; i < runsSize; i++) {
364         OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(runs, i);
365         uint32_t count = OH_Drawing_GetRunGlyphCount(run);
366         OH_Drawing_Array* glyphs = OH_Drawing_GetRunGlyphs(run, 0, count);
367         size_t glyphSize = OH_Drawing_GetDrawingArraySize(glyphs);
368         EXPECT_EQ(glyphSize, glyphSizeArr[i]);
369         if (i == 1) {
370             for (int j = 0; j < glyphSize; j++) {
371                 EXPECT_EQ(OH_Drawing_GetRunGlyphsByIndex(glyphs, j), glyphArr[j]);
372             }
373         }
374         // branchCoverage
375         OH_Drawing_GetRunGlyphsByIndex(glyphs, glyphSize);
376         OH_Drawing_DestroyRunGlyphs(glyphs);
377     }
378     // branchCoverage
379     OH_Drawing_GetRunGlyphs(nullptr, -1, -1);
380     OH_Drawing_DestroyRuns(runs);
381     OH_Drawing_DestroyTextLines(textLines);
382 }
383 
384 /*
385  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_007
386  * @tc.name  : RunTest007
387  * @tc.desc  : Test for get run positions
388  * @tc.size  : MediumTest
389  * @tc.type  : Function
390  * @tc.level : Level 0
391  */
392  HWTEST_F(NativeTextRunTest, RunTest007, Function | MediumTest | Level0)
393  {
394     text_ = "Hello 你好 World⌚����‍����‍��‍��‍����مرحبا中国 测文本\n 123";
395     PrepareCreateTextLine();
396     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
397     EXPECT_TRUE(textLines != nullptr);
398     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
399     ASSERT_GT(size, 0);
400     OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, 0);
401 
402     OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
403     size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
404     ASSERT_GT(runsSize, 0);
405 
406     std::vector<int32_t> positionSizeArr = {6, 2, 1, 5, 5, 5};
407     std::vector<float> posXArr = {0, 29.999969};
408     OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(runs, 1);
409     uint32_t count = OH_Drawing_GetRunGlyphCount(run);
410     OH_Drawing_Array* positions = OH_Drawing_GetRunPositions(run, 0, count);
411     EXPECT_TRUE(positions != nullptr);
412     size_t positionSize = OH_Drawing_GetDrawingArraySize(positions);
413     for (size_t posIndex = 0; posIndex < positionSize; posIndex++) {
414         OH_Drawing_Point* pos = OH_Drawing_GetRunPositionsByIndex(positions, posIndex);
415         EXPECT_TRUE(pos != nullptr);
416     }
417     EXPECT_EQ(positionSize, 2);
418 
419     // branchCoverage
420     OH_Drawing_GetRunPositionsByIndex(positions, positionSize);
421     OH_Drawing_DestroyRunPositions(positions);
422     OH_Drawing_GetRunPositions(nullptr, -1, -1);
423     OH_Drawing_DestroyRuns(runs);
424     OH_Drawing_DestroyTextLines(textLines);
425 }
426 
427 /*
428  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_008
429  * @tc.name  : RunTest008
430  * @tc.desc  : Test for special value input parameters testing
431  * @tc.size  : MediumTest
432  * @tc.type  : Function
433  * @tc.level : Level 0
434  */
435 HWTEST_F(NativeTextRunTest, RunTest008, Function | MediumTest | Level0)
436 {
437     text_ = "Hello\t中国 World \n !@#%^&*){}[] 123456789 -= ,."
438         "< >、/ Draclp11⌚��������‍����‍��‍��‍����مرحبا中国 测文本\n 123";
439     PrepareCreateTextLine();
440     OH_Drawing_Array* textLines = OH_Drawing_TypographyGetTextLines(typography_);
441     EXPECT_TRUE(textLines != nullptr);
442     size_t size = OH_Drawing_GetDrawingArraySize(textLines);
443     for (size_t index = 0; index < size; index++) {
444         OH_Drawing_TextLine* textLine = OH_Drawing_GetTextLineByIndex(textLines, index);
445         EXPECT_TRUE(textLine != nullptr);
446         OH_Drawing_Array* runs = OH_Drawing_TextLineGetGlyphRuns(textLine);
447         EXPECT_TRUE(runs != nullptr);
448         size_t runsSize = OH_Drawing_GetDrawingArraySize(runs);
449         for (size_t runIndex = 0; runIndex < runsSize; runIndex++) {
450             OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(runs, runIndex);
451             EXPECT_TRUE(run != nullptr);
452             // Get the actual size of the run
453             uint32_t count = OH_Drawing_GetRunGlyphCount(run);
454             EXPECT_TRUE(count > 0);
455             // If both start and end are 0, all data of the current run
456             OH_Drawing_Array* positions = OH_Drawing_GetRunPositions(run, 0, 0);
457             EXPECT_TRUE(positions != nullptr);
458             size_t positionSize = OH_Drawing_GetDrawingArraySize(positions);
459             EXPECT_EQ(positionSize, count);
460             OH_Drawing_DestroyRunPositions(positions);
461 
462             // If both start and end are 0, all data of the current run
463             OH_Drawing_Array* glyphs = OH_Drawing_GetRunGlyphs(run, 0, 0);
464             EXPECT_TRUE(glyphs != nullptr);
465             size_t glyphSize = OH_Drawing_GetDrawingArraySize(glyphs);
466             EXPECT_EQ(glyphSize, count);
467             OH_Drawing_DestroyRunGlyphs(glyphs);
468 
469             // If both start and end are 0, all data of the current run
470             OH_Drawing_Array* indices = OH_Drawing_GetRunStringIndices(run, 0, 0);
471             EXPECT_TRUE(indices != nullptr);
472             size_t indiceSize = OH_Drawing_GetDrawingArraySize(indices);
473             EXPECT_EQ(indiceSize, count);
474             OH_Drawing_DestroyRunStringIndices(indices);
475         }
476         OH_Drawing_DestroyRuns(runs);
477     }
478     OH_Drawing_DestroyTextLines(textLines);
479 }
480 
481 /*
482  * @tc.number: SUB_GRAPHIC_GRAPHIC_2D_RunTest_009
483  * @tc.name  : RunTest009
484  * @tc.desc  : Test for the run of nullptr pointer testing
485  * @tc.size  : MediumTest
486  * @tc.type  : Function
487  * @tc.level : Level 0
488  */
489 HWTEST_F(NativeTextRunTest, RunTest009, Function | MediumTest | Level0)
490 {
491     OH_Drawing_Run* run = OH_Drawing_GetRunByIndex(nullptr, 0);
492     EXPECT_TRUE(run == nullptr);
493     uint32_t count = OH_Drawing_GetRunGlyphCount(nullptr);
494     EXPECT_EQ(count, 0);
495     uint64_t location = 0;
496     uint64_t length = 0;
497     OH_Drawing_GetRunStringRange(nullptr, &location, &length);
498     EXPECT_EQ(location, 0);
499     EXPECT_EQ(length, 0);
500     EXPECT_TRUE(OH_Drawing_GetRunStringIndices(nullptr, 0, 0) == nullptr);
501     EXPECT_TRUE(OH_Drawing_GetRunGlyphs(nullptr, 0, 0) == nullptr);
502     EXPECT_TRUE(OH_Drawing_GetRunPositions(nullptr, 0, 0) == nullptr);
503     EXPECT_TRUE(OH_Drawing_GetRunImageBounds(nullptr) == nullptr);
504     OH_Drawing_RunPaint(nullptr, nullptr, 0, 0);
505     float ascent = 0.0;
506     float descent = 0.0;
507     float leading = 0.0;
508     float width = OH_Drawing_GetRunTypographicBounds(nullptr, &ascent, &descent, &leading);
509     EXPECT_EQ(ascent, 0.0);
510     EXPECT_EQ(descent, 0.0);
511     EXPECT_EQ(leading, 0.0);
512     EXPECT_EQ(width, 0.0);
513 }
514 }  // namespace OHOS