1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 "gtest/gtest.h"
17 
18 #define protected public
19 #define private public
20 
21 #include "base/utils/utils.h"
22 #include "core/components_ng/render/drawing_prop_convertor.h"
23 
24 #include "core/components/common/layout/constants.h"
25 #include "core/components/common/properties/text_style.h"
26 #include "test/mock/core/pipeline/mock_pipeline_context.h"
27 
28 #undef private
29 #undef protected
30 
31 using namespace testing;
32 using namespace testing::ext;
33 
34 namespace OHOS::Ace {
35 namespace {
36 std::vector<std::string> FONT_FAMILIES {"test"};
37 
38 constexpr uint8_t NUM1 = 1;
39 constexpr uint8_t NUM55 = 55;
40 constexpr uint8_t NUM155 = 155;
41 constexpr uint8_t NUM255 = 255;
42 constexpr double FONT_SIZE = 10.0;
43 constexpr double FONT_SIZE_5 = 5.0;
44 constexpr double FONT_SIZE_0 = 0.0;
45 
46 const Color TEST_COLOR = Color::FromARGB(1, 55, 155, 255);
47 const Color TEXT_COLOR_RED = Color::RED;
48 
49 const NG::RectF TEST_RECT = {10.0f, 10.0f, 20.0f, 20.0f};
50 const NG::PointF TEST_POINT = {10.0f, 20.0f};
51 
52 const FontWeight FONT_WEIGHT {0};
53 const FontStyle FONT_STYLE {0};
54 
55 const Dimension WORD_SPACING_PX {1.0, DimensionUnit::PX};
56 const Dimension WORD_SPACING_PERCENT {10.0, DimensionUnit::PERCENT};
57 const Dimension LINE_HIGHT_PX {5.0, DimensionUnit::PX};
58 const Dimension LINE_HIGHT_PERCENT {10.0, DimensionUnit::PERCENT};
59 const Dimension LETTER_SPACING {2.0, DimensionUnit::PX};
60 const Dimension FONT_SIZE_FP {14.0, DimensionUnit::FP};
61 const Dimension FONT_SIZE_PX_0 {0.0, DimensionUnit::PX};
62 const Dimension FONT_SIZE_PX_5 {5.0, DimensionUnit::PX};
63 }
64 
65 class DrawingPropConvertorTestNg : public testing::Test {
66 public:
SetUpTestSuite()67     static void SetUpTestSuite()
68     {
69         NG::MockPipelineContext::SetUp();
70     }
TearDownTestSuite()71     static void TearDownTestSuite()
72     {
73         NG::MockPipelineContext::TearDown();
74     }
75 };
76 
77 /**
78  * @tc.name: DrawingPropConvertorTestNg001
79  * @tc.desc: Test cast to DrawingPropConvertorTestNg
80  * @tc.type: FUNC
81  */
82 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg001, TestSize.Level1)
83 {
84     /**
85      * @tc.steps1: call ToRSColor.
86      * @tc.expected: retRSColor value is the same as TEST_COLOR.
87      */
88     RSColor retRSColor = ToRSColor(TEST_COLOR);
89     EXPECT_EQ(retRSColor.GetAlphaF(), NUM1);
90     EXPECT_EQ(retRSColor.GetRed(), NUM55);
91     EXPECT_EQ(retRSColor.GetGreen(), NUM155);
92     EXPECT_EQ(retRSColor.GetBlue(), NUM255);
93 }
94 
95 /**
96  * @tc.name: DrawingPropConvertorTestNg002
97  * @tc.desc: Test cast to DrawingPropConvertorTestNg
98  * @tc.type: FUNC
99  */
100 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg002, TestSize.Level1)
101 {
102     /**
103      * @tc.steps1: call ToRSColor.
104      * @tc.expected: retRSColor.GetRed() is equal to 255.
105      */
106     RSColor retRSColor = ToRSColor(LinearColor::RED);
107 
108     EXPECT_EQ(retRSColor.GetAlphaF(), 1);
109     EXPECT_EQ(retRSColor.GetRed(), 255);
110     EXPECT_EQ(retRSColor.GetGreen(), 0);
111     EXPECT_EQ(retRSColor.GetBlue(), 0);
112 }
113 
114 /**
115  * @tc.name: DrawingPropConvertorTestNg003
116  * @tc.desc: Test cast to DrawingPropConvertorTestNg
117  * @tc.type: FUNC
118  */
119 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg003, TestSize.Level1)
120 {
121     /**
122      * @tc.steps1: call ToRSRect.
123      * @tc.expected: return expected values.
124      */
125     RSRect retRect = ToRSRect(TEST_RECT);
126     EXPECT_EQ(retRect.GetLeft(), 10);
127     EXPECT_EQ(retRect.GetTop(), 10);
128     EXPECT_EQ(retRect.GetRight(), 30);
129     EXPECT_EQ(retRect.GetBottom(), 30);
130 }
131 
132 /**
133  * @tc.name: DrawingPropConvertorTestNg004
134  * @tc.desc: Test cast to DrawingPropConvertorTestNg
135  * @tc.type: FUNC
136  */
137 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg004, TestSize.Level1)
138 {
139     /**
140      * @tc.steps1: call ToRSPoint.
141      * @tc.expected: retPoint value is the same as TEST_POINT.
142      */
143     RSPoint retPoint = ToRSPoint(TEST_POINT);
144     EXPECT_EQ(retPoint.GetX(), 10);
145     EXPECT_EQ(retPoint.GetY(), 20);
146 }
147 
148 /**
149  * @tc.name: DrawingPropConvertorTestNg005
150  * @tc.desc: Test cast to DrawingPropConvertorTestNg
151  * @tc.type: FUNC
152  */
153 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg005, TestSize.Level1)
154 {
155     /**
156      * @tc.steps1: call ToRSCapStyle and set input lineCap is ROUND.
157      * @tc.expected: the return retCapStyle is the same as RSPen::CapStyle::ROUND_CAP.
158      */
159     auto testLineCap = static_cast<LineCap>(0);
160 
161     RSPen::CapStyle retCapStyle = ToRSCapStyle(testLineCap);
162     EXPECT_EQ(retCapStyle, RSPen::CapStyle::FLAT_CAP);
163 
164     /**
165      * @tc.steps2: call ToRSCapStyle and set input lineCap is SQUARE.
166      * @tc.expected: the return retCapStyle is the same as RSPen::CapStyle::SQUARE_CAP.
167      */
168     testLineCap = static_cast<LineCap>(1);
169 
170     retCapStyle = ToRSCapStyle(testLineCap);
171     EXPECT_EQ(retCapStyle, RSPen::CapStyle::ROUND_CAP);
172 
173     /**
174      * @tc.steps3: call ToRSCapStyle and set input lineCap is BUTT.
175      * @tc.expected: the return retCapStyle is the same as RSPen::CapStyle::FLAT_CAP.
176      */
177     testLineCap = static_cast<LineCap>(2);
178 
179     retCapStyle = ToRSCapStyle(testLineCap);
180     EXPECT_EQ(retCapStyle, RSPen::CapStyle::SQUARE_CAP);
181 }
182 
183 /**
184  * @tc.name: DrawingPropConvertorTestNg006
185  * @tc.desc: Test cast to DrawingPropConvertorTestNg
186  * @tc.type: FUNC
187  */
188 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg006, TestSize.Level1)
189 {
190     /**
191      * @tc.steps1: call ToRSTextDirection and set input TextDirection is LTR.
192      * @tc.expected: the return retPoint is the same as RSTextDirection::LTR.
193      */
194     auto testTextDirection = static_cast<TextDirection>(0);
195 
196     RSTextDirection retTextDirection = ToRSTextDirection(testTextDirection);
197     EXPECT_EQ(retTextDirection, RSTextDirection::LTR);
198 
199     /**
200      * @tc.steps2: call ToRSTextDirection and set input TextDirection is RTL.
201      * @tc.expected: the return retPoint is the same as RSTextDirection::RTL.
202      */
203     testTextDirection = static_cast<TextDirection>(1);
204 
205     retTextDirection = ToRSTextDirection(testTextDirection);
206     EXPECT_EQ(retTextDirection, RSTextDirection::RTL);
207 
208     /**
209      * @tc.steps3: call ToRSTextDirection and set input TextDirection is INHERIT.
210      * @tc.expected: the return retPoint is the same as RSTextDirection::RTL.
211      */
212     testTextDirection = static_cast<TextDirection>(2);
213 
214     retTextDirection = ToRSTextDirection(testTextDirection);
215     EXPECT_EQ(retTextDirection, RSTextDirection::LTR);
216 }
217 
218 /**
219  * @tc.name: DrawingPropConvertorTestNg007
220  * @tc.desc: Test cast to DrawingPropConvertorTestNg
221  * @tc.type: FUNC
222  */
223 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg007, TestSize.Level1)
224 {
225     /**
226      * @tc.steps1: call ToRSTextAlign and set input align is LEFT.
227      * @tc.expected: the return retTextAlign is the same as RSTextAlign::LEFT.
228      */
229     auto testTextAlign = static_cast<TextAlign>(4);
230 
231     RSTextAlign retTextAlign = ToRSTextAlign(testTextAlign);
232     EXPECT_EQ(retTextAlign, RSTextAlign::LEFT);
233 }
234 
235 /**
236  * @tc.name: DrawingPropConvertorTestNg008
237  * @tc.desc: Test cast to DrawingPropConvertorTestNg
238  * @tc.type: FUNC
239  */
240 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg008, TestSize.Level1)
241 {
242     /**
243      * @tc.steps1: call ToRSFontWeight and set different input values.
244      * @tc.expected: the return retFontWeight is expected.
245      */
246     for (int32_t index = 0; index <= 15; index++) {
247         auto testFontWeight = static_cast<FontWeight>(index);
248         RSFontWeight retFontWeight = ToRSFontWeight(testFontWeight);
249         switch (testFontWeight) {
250             case FontWeight::W100:
251             case FontWeight::LIGHTER:
252                 EXPECT_EQ(retFontWeight, RSFontWeight::W100);
253                 break;
254             case FontWeight::W200:
255                 EXPECT_EQ(retFontWeight, RSFontWeight::W200);
256                 break;
257             case FontWeight::W300:
258                 EXPECT_EQ(retFontWeight, RSFontWeight::W300);
259                 break;
260             case FontWeight::W400:
261             case FontWeight::NORMAL:
262             case FontWeight::REGULAR:
263                 EXPECT_EQ(retFontWeight, RSFontWeight::W400);
264                 break;
265             case FontWeight::W500:
266             case FontWeight::MEDIUM:
267                 EXPECT_EQ(retFontWeight, RSFontWeight::W500);
268                 break;
269             case FontWeight::W600:
270                 EXPECT_EQ(retFontWeight, RSFontWeight::W600);
271                 break;
272             case FontWeight::W700:
273             case FontWeight::BOLD:
274                 EXPECT_EQ(retFontWeight, RSFontWeight::W700);
275                 break;
276             case FontWeight::W800:
277                 EXPECT_EQ(retFontWeight, RSFontWeight::W800);
278                 break;
279             case FontWeight::W900:
280             case FontWeight::BOLDER:
281                 EXPECT_EQ(retFontWeight, RSFontWeight::W900);
282                 break;
283             default:
284                 EXPECT_EQ(retFontWeight, RSFontWeight::W400);
285                 break;
286         }
287     }
288 }
289 
290 /**
291  * @tc.name: DrawingPropConvertorTestNg009
292  * @tc.desc: Test cast to DrawingPropConvertorTestNg
293  * @tc.type: FUNC
294  */
295 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg009, TestSize.Level1)
296 {
297     /**
298      * @tc.steps1: call ToRSWordBreakType and set input testWordBreak is NORMAL.
299      * @tc.expected: the return retWordBreakType is the same as RSWordBreakType::WordBreakTypeNormal.
300      */
301     auto testWordBreak = static_cast<WordBreak>(0);
302 
303     RSWordBreakType retWordBreakType = ToRSWordBreakType(testWordBreak);
304     EXPECT_EQ(retWordBreakType, RSWordBreakType::WordBreakTypeNormal);
305 }
306 
307 /**
308  * @tc.name: DrawingPropConvertorTestNg010
309  * @tc.desc: Test cast to DrawingPropConvertorTestNg
310  * @tc.type: FUNC
311  */
312 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg010, TestSize.Level1)
313 {
314     /**
315      * @tc.steps1: call ToRSTextDecoration and set different input values.
316      * @tc.expected: the return retTextDecoration is expected.
317      */
318     for (int32_t index = 0; index <= 4; index++) {
319         auto testTextDecoration = static_cast<TextDecoration>(index);
320         RSTextDecoration retTextDecoration = ToRSTextDecoration(testTextDecoration);
321         switch (testTextDecoration) {
322             case TextDecoration::OVERLINE:
323                 EXPECT_EQ(retTextDecoration, RSTextDecoration::OVERLINE);
324                 break;
325             case TextDecoration::LINE_THROUGH:
326 #ifndef USE_GRAPHIC_TEXT_GINE
327                 EXPECT_EQ(retTextDecoration, RSTextDecoration::LINETHROUGH);
328 #else
329                 EXPECT_EQ(retTextDecoration, RSTextDecoration::LINE_THROUGH);
330 #endif
331                 break;
332             case TextDecoration::UNDERLINE:
333                 EXPECT_EQ(retTextDecoration, RSTextDecoration::UNDERLINE);
334                 break;
335             default:
336                 EXPECT_EQ(retTextDecoration, RSTextDecoration::NONE);
337                 break;
338             }
339     }
340 }
341 
342 /**
343  * @tc.name: DrawingPropConvertorTestNg011
344  * @tc.desc: Test cast to DrawingPropConvertorTestNg
345  * @tc.type: FUNC
346  */
347 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg011, TestSize.Level1)
348 {
349     /**
350      * @tc.steps1: create textStyle object.
351      */
352     TextStyle textStyle(FONT_FAMILIES, FONT_SIZE, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED);
353     RefPtr<PipelineBase> context;
354 
355     /**
356      * @tc.steps2: call ToRSTextStyle.
357      * @tc.expected: retTextStyle.ellipsis_ is default value.
358      */
359     RSTextStyle retTextStyle = ToRSTextStyle(context, textStyle);
360 #ifndef USE_GRAPHIC_TEXT_GINE
361     EXPECT_NE(retTextStyle.ellipsis_, StringUtils::Str8ToStr16(StringUtils::ELLIPSIS));
362 #else
363     EXPECT_NE(retTextStyle.ellipsis, StringUtils::Str8ToStr16(StringUtils::ELLIPSIS));
364 #endif
365     /**
366      * @tc.steps3: call ToRSTextStyle and set input textStyle.textOverflow_ is TextOverflow::ELLIPSIS.
367      * @tc.expected: the return retTextStyle is expected.
368      */
369     textStyle.textOverflow_ = TextOverflow::ELLIPSIS;
370     textStyle.wordSpacing_ = WORD_SPACING_PX;
371     retTextStyle = ToRSTextStyle(context, textStyle);
372 #ifndef USE_GRAPHIC_TEXT_GINE
373     EXPECT_EQ(retTextStyle.ellipsis_, StringUtils::Str8ToStr16(StringUtils::ELLIPSIS));
374     EXPECT_EQ(retTextStyle.fontSize_, FONT_SIZE);
375     EXPECT_EQ(retTextStyle.wordSpacing_, WORD_SPACING_PX.value_);
376     EXPECT_FALSE(retTextStyle.hasHeightOverride_);
377 #else
378     EXPECT_EQ(retTextStyle.ellipsis, StringUtils::Str8ToStr16(StringUtils::ELLIPSIS));
379     EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE);
380     EXPECT_EQ(retTextStyle.wordSpacing, WORD_SPACING_PX.value_);
381     EXPECT_FALSE(retTextStyle.heightOnly);
382 #endif
383 
384 #ifndef USE_GRAPHIC_TEXT_GINE
385     /**
386      * @tc.steps4: call ToRSTextStyle and set input textStyle.lineHeight_ is not equal to textStyle.fontSize_.
387      * @tc.expected: retTextStyle.height_ is expected value.
388      */
389     textStyle.lineHeight_ = LINE_HIGHT_PX;
390     retTextStyle = ToRSTextStyle(context, textStyle);
391     EXPECT_EQ(retTextStyle.height_, LINE_HIGHT_PX.value_ / FONT_SIZE);
392 #else
393     /**
394      * @tc.steps4: call ToRSTextStyle and set input textStyle.lineHeight_ is not equal to textStyle.fontSize_.
395      * @tc.expected: retTextStyle.heightScale is expected value.
396      */
397     textStyle.lineHeight_ = LINE_HIGHT_PX;
398     retTextStyle = ToRSTextStyle(context, textStyle);
399     EXPECT_EQ(retTextStyle.heightScale, LINE_HIGHT_PX.value_ / FONT_SIZE);
400 #endif
401 
402 #ifndef USE_GRAPHIC_TEXT_GINE
403     /**
404      * @tc.steps5: call ToRSTextStyle and set input textStyle.wordSpacing_ is WORD_SPACING_PERCENT.
405      * @tc.expected: retTextStyle.height_ is equal to LINE_HIGHT_PERCENT.value_.
406      */
407     textStyle.wordSpacing_ = WORD_SPACING_PERCENT;
408     textStyle.lineHeight_ = LINE_HIGHT_PERCENT;
409     retTextStyle = ToRSTextStyle(context, textStyle);
410     EXPECT_EQ(retTextStyle.wordSpacing_, WORD_SPACING_PERCENT.value_ * FONT_SIZE);
411     EXPECT_EQ(retTextStyle.height_, LINE_HIGHT_PERCENT.value_);
412     EXPECT_TRUE(retTextStyle.hasHeightOverride_);
413 #else
414     /**
415      * @tc.steps5: call ToRSTextStyle and set input textStyle.wordSpacing_ is WORD_SPACING_PERCENT.
416      * @tc.expected: retTextStyle.heightScale is equal to LINE_HIGHT_PERCENT.value_.
417      */
418     textStyle.wordSpacing_ = WORD_SPACING_PERCENT;
419     textStyle.lineHeight_ = LINE_HIGHT_PERCENT;
420     retTextStyle = ToRSTextStyle(context, textStyle);
421     EXPECT_EQ(retTextStyle.wordSpacing, WORD_SPACING_PERCENT.value_ * FONT_SIZE);
422     EXPECT_EQ(retTextStyle.heightScale, LINE_HIGHT_PERCENT.value_);
423     EXPECT_TRUE(retTextStyle.heightOnly);
424 #endif
425 }
426 
427 /**
428  * @tc.name: DrawingPropConvertorTestNg012
429  * @tc.desc: Test cast to DrawingPropConvertorTestNg
430  * @tc.type: FUNC
431  */
432 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg012, TestSize.Level1)
433 {
434     /**
435      * @tc.steps1: create textStyle object and set input context is not null.
436      */
437     TextStyle textStyle(FONT_FAMILIES, FONT_SIZE, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED);
438     RefPtr<PipelineBase> pipelineContext = NG::MockPipelineContext::pipeline_;
439 
440     /**
441      * @tc.steps2: call ToRSTextStyle and set values of textStyle.
442      * @tc.expected: retTextSty is expected and retTextStyle.letterSpacing_ is equal to WORD_SPACING_PX.value_.
443      */
444     textStyle.letterSpacing_ = LETTER_SPACING;
445     textStyle.wordSpacing_ = WORD_SPACING_PX;
446     textStyle.lineHeight_ = LINE_HIGHT_PX;
447     RSTextStyle retTextStyle = ToRSTextStyle(pipelineContext, textStyle);
448 #ifndef USE_GRAPHIC_TEXT_GINE
449     EXPECT_EQ(retTextStyle.fontSize_, FONT_SIZE * pipelineContext->fontScale_);
450     EXPECT_EQ(retTextStyle.letterSpacing_, LETTER_SPACING.value_);
451     EXPECT_EQ(retTextStyle.wordSpacing_, WORD_SPACING_PX.value_);
452     EXPECT_EQ(retTextStyle.height_, LINE_HIGHT_PX.value_ / FONT_SIZE);
453 #else
454     EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE * pipelineContext->fontScale_);
455     EXPECT_EQ(retTextStyle.letterSpacing, LETTER_SPACING.value_);
456     EXPECT_EQ(retTextStyle.wordSpacing, WORD_SPACING_PX.value_);
457     EXPECT_EQ(retTextStyle.heightScale, LINE_HIGHT_PX.value_ / FONT_SIZE);
458 #endif
459 
460 #ifndef USE_GRAPHIC_TEXT_GINE
461     /**
462      * @tc.steps3: call ToRSTextStyle and set textStyle.allowScale_ is false.
463      * @tc.expected: retTextStyle.fontSize_ is equal to FONT_SIZE.
464      */
465     textStyle.allowScale_ = false;
466     retTextStyle = ToRSTextStyle(pipelineContext, textStyle);
467     EXPECT_EQ(retTextStyle.fontSize_, FONT_SIZE);
468 #else
469     /**
470      * @tc.steps3: call ToRSTextStyle and set textStyle.allowScale_ is false.
471      * @tc.expected: retTextStyle.fontSize is equal to FONT_SIZE.
472      */
473     textStyle.allowScale_ = false;
474     retTextStyle = ToRSTextStyle(pipelineContext, textStyle);
475     EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE);
476 #endif
477 
478 #ifndef USE_GRAPHIC_TEXT_GINE
479     /**
480      * @tc.steps4: call ToRSTextStyle and set textStyle.fontSize_ is FONT_SIZE_FP.
481      * @tc.expected: retTextStyle.fontSize_ is equal to FONT_SIZE.
482      */
483     textStyle.fontSize_ = FONT_SIZE_FP;
484     retTextStyle = ToRSTextStyle(pipelineContext, textStyle);
485     EXPECT_EQ(retTextStyle.fontSize_, FONT_SIZE_FP.value_);
486 #else
487     /**
488      * @tc.steps4: call ToRSTextStyle and set textStyle.fontSize_ is FONT_SIZE_FP.
489      * @tc.expected: retTextStyle.fontSize is equal to FONT_SIZE.
490      */
491     textStyle.fontSize_ = FONT_SIZE_FP;
492     retTextStyle = ToRSTextStyle(pipelineContext, textStyle);
493     EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE_FP.value_);
494 #endif
495 }
496 
497 /**
498  * @tc.name: DrawingPropConvertorTestNg013
499  * @tc.desc: Test cast to DrawingPropConvertorTestNg
500  * @tc.type: FUNC
501  */
502 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg013, TestSize.Level1)
503 {
504     /**
505      * @tc.steps1: create textStyle object.
506      */
507     TextStyle textStyle(FONT_FAMILIES, FONT_SIZE_5, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED);
508     RefPtr<PipelineBase> context;
509 
510     /**
511      * @tc.steps2: call ToRSTextStyle and set input textStyle.lineHeight_ is LINE_HIGHT_PX.
512      * @tc.expected: retTextStyle.height_ is equal to 1.0.
513      */
514     textStyle.lineHeight_ = LINE_HIGHT_PX;
515     RSTextStyle retTextStyle = ToRSTextStyle(context, textStyle);
516 #ifndef USE_GRAPHIC_TEXT_GINE
517     EXPECT_EQ(retTextStyle.height_, 1.0);
518 #else
519     EXPECT_EQ(retTextStyle.heightScale, 1.0);
520 #endif
521 
522     /**
523      * @tc.steps3: call ToRSTextStyle and set input textStyle.fontSize_ is FONT_SIZE_PX_0.
524      * @tc.expected: retTextStyle.height_ is equal to 1.0.
525      */
526     textStyle.fontSize_ = FONT_SIZE_PX_0;
527     retTextStyle = ToRSTextStyle(context, textStyle);
528 #ifndef USE_GRAPHIC_TEXT_GINE
529     EXPECT_EQ(retTextStyle.height_, 1.0);
530 #else
531     EXPECT_EQ(retTextStyle.heightScale, 1.0);
532 #endif
533 }
534 
535 /**
536  * @tc.name: DrawingPropConvertorTestNg014
537  * @tc.desc: Test cast to DrawingPropConvertorTestNg
538  * @tc.type: FUNC
539  */
540 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg014, TestSize.Level1)
541 {
542     /**
543      * @tc.steps1: create textStyle object.
544      */
545     TextStyle testTextStyle(FONT_FAMILIES, FONT_SIZE_0, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED);
546     RefPtr<PipelineBase> pipelineContext = NG::MockPipelineContext::pipeline_;
547 
548     /**
549      * @tc.steps2: call ToRSTextStyle and set pipelineContext->minPlatformVersion_ is 6.
550      * @tc.expected: retTextStyle.hasHeightOverride_ is false.
551      */
552     pipelineContext->minPlatformVersion_ = 6;
553     RSTextStyle retTextStyle = ToRSTextStyle(pipelineContext, testTextStyle);
554 #ifndef USE_GRAPHIC_TEXT_GINE
555     EXPECT_FALSE(retTextStyle.hasHeightOverride_);
556 #else
557     EXPECT_FALSE(retTextStyle.heightOnly);
558 #endif
559 
560     /**
561      * @tc.steps3: call ToRSTextStyle and set testTextStyle.fontSize_ is FONT_SIZE_PX_5.
562      * @tc.expected: retTextStyle.hasHeightOverride_ is false.
563      */
564     testTextStyle.fontSize_ = FONT_SIZE_PX_5;
565     testTextStyle.lineHeight_ = LINE_HIGHT_PX;
566     retTextStyle = ToRSTextStyle(pipelineContext, testTextStyle);
567 #ifndef USE_GRAPHIC_TEXT_GINE
568     EXPECT_FALSE(retTextStyle.hasHeightOverride_);
569 #else
570     EXPECT_FALSE(retTextStyle.heightOnly);
571 #endif
572 }
573 
574 /**
575  * @tc.name: DrawingPropConvertorTestNg015
576  * @tc.desc: Test function to ToRSTextAlign ToRSEllipsisMode
577  * @tc.type: FUNC
578  */
579 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg015, TestSize.Level1)
580 {
581     /**
582      * @tc.steps1: call ToRSTextAlign ToRSEllipsisMode.
583      * @tc.expected: the return result is the same as input align.
584      */
585     auto testTextAlign = static_cast<TextAlign>(7); // 7 is not a valid TextAlign.
586 
587     RSTextAlign retTextAlign = ToRSTextAlign(testTextAlign);
588     EXPECT_EQ(retTextAlign, RSTextAlign::START);
589     EXPECT_EQ(ToRSTextAlign(TextAlign::LEFT), RSTextAlign::LEFT);
590     EXPECT_EQ(ToRSTextAlign(TextAlign::RIGHT), RSTextAlign::RIGHT);
591     EXPECT_EQ(ToRSTextAlign(TextAlign::JUSTIFY), RSTextAlign::JUSTIFY);
592     EXPECT_EQ(ToRSTextAlign(TextAlign::END), RSTextAlign::END);
593     EXPECT_EQ(ToRSTextAlign(TextAlign::CENTER), RSTextAlign::CENTER);
594     EXPECT_EQ(ToRSTextAlign(TextAlign::START), RSTextAlign::START);
595     EXPECT_EQ(ToRSEllipsisMode(EllipsisMode::HEAD), RSEllipsisMode::HEAD);
596 }
597 
598 /**
599  * @tc.name: DrawingPropConvertorTestNg016
600  * @tc.desc: Test function to ToRSTextDecorationStyle
601  * @tc.type: FUNC
602  */
603 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg016, TestSize.Level1)
604 {
605     /**
606      * @tc.steps1: call ToRSTextDecorationStyle.
607      * @tc.expected: the return result is the same as input align.
608      */
609     TextStyle textStyle;
610     textStyle.SetTextDecorationStyle(TextDecorationStyle::DASHED);
611     EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle_, RSTextDecorationStyle::DASHED);
612     textStyle.SetTextDecorationStyle(TextDecorationStyle::DOTTED);
613     EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle_, RSTextDecorationStyle::DOTTED);
614     textStyle.SetTextDecorationStyle(TextDecorationStyle::DOUBLE);
615     EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle_, RSTextDecorationStyle::DOUBLE);
616     textStyle.SetTextDecorationStyle(TextDecorationStyle::WAVY);
617     EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle_, RSTextDecorationStyle::WAVY);
618     textStyle.SetTextDecorationStyle(TextDecorationStyle::INHERIT);
619     EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle_, RSTextDecorationStyle::SOLID);
620 }
621 } // namespace OHOS::Ace
622