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 EXPECT_EQ(retTextDecoration, RSTextDecoration::LINE_THROUGH); 327 break; 328 case TextDecoration::UNDERLINE: 329 EXPECT_EQ(retTextDecoration, RSTextDecoration::UNDERLINE); 330 break; 331 default: 332 EXPECT_EQ(retTextDecoration, RSTextDecoration::NONE); 333 break; 334 } 335 } 336 } 337 338 /** 339 * @tc.name: DrawingPropConvertorTestNg011 340 * @tc.desc: Test cast to DrawingPropConvertorTestNg 341 * @tc.type: FUNC 342 */ 343 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg011, TestSize.Level1) 344 { 345 /** 346 * @tc.steps1: create textStyle object. 347 */ 348 TextStyle textStyle(FONT_FAMILIES, FONT_SIZE, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED); 349 RefPtr<PipelineBase> context; 350 351 /** 352 * @tc.steps2: call ToRSTextStyle. 353 * @tc.expected: retTextStyle.ellipsis_ is default value. 354 */ 355 RSTextStyle retTextStyle = ToRSTextStyle(context, textStyle); 356 EXPECT_NE(retTextStyle.ellipsis, StringUtils::Str8ToStr16(StringUtils::ELLIPSIS)); 357 /** 358 * @tc.steps3: call ToRSTextStyle and set input textStyle.textOverflow_ is TextOverflow::ELLIPSIS. 359 * @tc.expected: the return retTextStyle is expected. 360 */ 361 textStyle.propTextOverflow_ = TextOverflow::ELLIPSIS; 362 textStyle.propWordSpacing_.value = WORD_SPACING_PX; 363 retTextStyle = ToRSTextStyle(context, textStyle); 364 EXPECT_EQ(retTextStyle.ellipsis, StringUtils::Str8ToStr16(StringUtils::ELLIPSIS)); 365 EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE); 366 EXPECT_EQ(retTextStyle.wordSpacing, WORD_SPACING_PX.value_); 367 EXPECT_FALSE(retTextStyle.heightOnly); 368 369 /** 370 * @tc.steps4: call ToRSTextStyle and set input textStyle.lineHeight_ is not equal to textStyle.fontSize_. 371 * @tc.expected: retTextStyle.heightScale is expected value. 372 */ 373 textStyle.lineHeight_.value = LINE_HIGHT_PX; 374 retTextStyle = ToRSTextStyle(context, textStyle); 375 EXPECT_EQ(retTextStyle.heightScale, LINE_HIGHT_PX.value_ / FONT_SIZE); 376 377 /** 378 * @tc.steps5: call ToRSTextStyle and set input textStyle.wordSpacing_ is WORD_SPACING_PERCENT. 379 * @tc.expected: retTextStyle.heightScale is equal to LINE_HIGHT_PERCENT.value_. 380 */ 381 textStyle.propWordSpacing_.value = WORD_SPACING_PERCENT; 382 textStyle.lineHeight_.value = LINE_HIGHT_PERCENT; 383 retTextStyle = ToRSTextStyle(context, textStyle); 384 EXPECT_EQ(retTextStyle.wordSpacing, WORD_SPACING_PERCENT.value_ * FONT_SIZE); 385 EXPECT_EQ(retTextStyle.heightScale, LINE_HIGHT_PERCENT.value_); 386 EXPECT_TRUE(retTextStyle.heightOnly); 387 } 388 389 /** 390 * @tc.name: DrawingPropConvertorTestNg012 391 * @tc.desc: Test cast to DrawingPropConvertorTestNg 392 * @tc.type: FUNC 393 */ 394 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg012, TestSize.Level1) 395 { 396 /** 397 * @tc.steps1: create textStyle object and set input context is not null. 398 */ 399 TextStyle textStyle(FONT_FAMILIES, FONT_SIZE, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED); 400 RefPtr<PipelineBase> pipelineContext = NG::MockPipelineContext::pipeline_; 401 402 /** 403 * @tc.steps2: call ToRSTextStyle and set values of textStyle. 404 * @tc.expected: retTextSty is expected and retTextStyle.letterSpacing_ is equal to WORD_SPACING_PX.value_. 405 */ 406 textStyle.propLetterSpacing_.value = LETTER_SPACING; 407 textStyle.propWordSpacing_.value = WORD_SPACING_PX; 408 textStyle.lineHeight_.value = LINE_HIGHT_PX; 409 RSTextStyle retTextStyle = ToRSTextStyle(pipelineContext, textStyle); 410 EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE * pipelineContext->fontScale_); 411 EXPECT_EQ(retTextStyle.letterSpacing, LETTER_SPACING.value_); 412 EXPECT_EQ(retTextStyle.wordSpacing, WORD_SPACING_PX.value_); 413 EXPECT_EQ(retTextStyle.heightScale, LINE_HIGHT_PX.value_ / FONT_SIZE); 414 415 /** 416 * @tc.steps3: call ToRSTextStyle and set textStyle.allowScale_ is false. 417 * @tc.expected: retTextStyle.fontSize is equal to FONT_SIZE. 418 */ 419 textStyle.propAllowScale_ = false; 420 retTextStyle = ToRSTextStyle(pipelineContext, textStyle); 421 EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE); 422 423 /** 424 * @tc.steps4: call ToRSTextStyle and set textStyle.fontSize_ is FONT_SIZE_FP. 425 * @tc.expected: retTextStyle.fontSize is equal to FONT_SIZE. 426 */ 427 textStyle.fontSize_.value = FONT_SIZE_FP; 428 retTextStyle = ToRSTextStyle(pipelineContext, textStyle); 429 EXPECT_EQ(retTextStyle.fontSize, FONT_SIZE_FP.value_); 430 } 431 432 /** 433 * @tc.name: DrawingPropConvertorTestNg013 434 * @tc.desc: Test cast to DrawingPropConvertorTestNg 435 * @tc.type: FUNC 436 */ 437 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg013, TestSize.Level1) 438 { 439 /** 440 * @tc.steps1: create textStyle object. 441 */ 442 TextStyle textStyle(FONT_FAMILIES, FONT_SIZE_5, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED); 443 RefPtr<PipelineBase> context; 444 445 /** 446 * @tc.steps2: call ToRSTextStyle and set input textStyle.lineHeight_ is LINE_HIGHT_PX. 447 * @tc.expected: retTextStyle.height_ is equal to 1.0. 448 */ 449 textStyle.lineHeight_.value = LINE_HIGHT_PX; 450 RSTextStyle retTextStyle = ToRSTextStyle(context, textStyle); 451 EXPECT_EQ(retTextStyle.heightScale, 1.0); 452 453 /** 454 * @tc.steps3: call ToRSTextStyle and set input textStyle.fontSize_ is FONT_SIZE_PX_0. 455 * @tc.expected: retTextStyle.height_ is equal to 1.0. 456 */ 457 textStyle.fontSize_.value = FONT_SIZE_PX_0; 458 retTextStyle = ToRSTextStyle(context, textStyle); 459 EXPECT_EQ(retTextStyle.heightScale, 1.0); 460 } 461 462 /** 463 * @tc.name: DrawingPropConvertorTestNg014 464 * @tc.desc: Test cast to DrawingPropConvertorTestNg 465 * @tc.type: FUNC 466 */ 467 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg014, TestSize.Level1) 468 { 469 /** 470 * @tc.steps1: create textStyle object. 471 */ 472 TextStyle testTextStyle(FONT_FAMILIES, FONT_SIZE_0, FONT_WEIGHT, FONT_STYLE, TEXT_COLOR_RED); 473 RefPtr<PipelineBase> pipelineContext = NG::MockPipelineContext::pipeline_; 474 475 /** 476 * @tc.steps2: call ToRSTextStyle and set pipelineContext->minPlatformVersion_ is 6. 477 * @tc.expected: retTextStyle.hasHeightOverride_ is false. 478 */ 479 pipelineContext->minPlatformVersion_ = 6; 480 RSTextStyle retTextStyle = ToRSTextStyle(pipelineContext, testTextStyle); 481 EXPECT_FALSE(retTextStyle.heightOnly); 482 483 /** 484 * @tc.steps3: call ToRSTextStyle and set testTextStyle.fontSize_ is FONT_SIZE_PX_5. 485 * @tc.expected: retTextStyle.hasHeightOverride_ is false. 486 */ 487 testTextStyle.fontSize_.value = FONT_SIZE_PX_5; 488 testTextStyle.lineHeight_.value = LINE_HIGHT_PX; 489 retTextStyle = ToRSTextStyle(pipelineContext, testTextStyle); 490 EXPECT_FALSE(retTextStyle.heightOnly); 491 } 492 493 /** 494 * @tc.name: DrawingPropConvertorTestNg015 495 * @tc.desc: Test function to ToRSTextAlign ToRSEllipsisMode 496 * @tc.type: FUNC 497 */ 498 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg015, TestSize.Level1) 499 { 500 /** 501 * @tc.steps1: call ToRSTextAlign ToRSEllipsisMode. 502 * @tc.expected: the return result is the same as input align. 503 */ 504 auto testTextAlign = static_cast<TextAlign>(7); // 7 is not a valid TextAlign. 505 506 RSTextAlign retTextAlign = ToRSTextAlign(testTextAlign); 507 EXPECT_EQ(retTextAlign, RSTextAlign::START); 508 EXPECT_EQ(ToRSTextAlign(TextAlign::LEFT), RSTextAlign::LEFT); 509 EXPECT_EQ(ToRSTextAlign(TextAlign::RIGHT), RSTextAlign::RIGHT); 510 EXPECT_EQ(ToRSTextAlign(TextAlign::JUSTIFY), RSTextAlign::JUSTIFY); 511 EXPECT_EQ(ToRSTextAlign(TextAlign::END), RSTextAlign::END); 512 EXPECT_EQ(ToRSTextAlign(TextAlign::CENTER), RSTextAlign::CENTER); 513 EXPECT_EQ(ToRSTextAlign(TextAlign::START), RSTextAlign::START); 514 EXPECT_EQ(ToRSEllipsisMode(EllipsisMode::HEAD), RSEllipsisMode::HEAD); 515 } 516 517 /** 518 * @tc.name: DrawingPropConvertorTestNg016 519 * @tc.desc: Test function to ToRSTextDecorationStyle 520 * @tc.type: FUNC 521 */ 522 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg016, TestSize.Level1) 523 { 524 /** 525 * @tc.steps1: call ToRSTextDecorationStyle. 526 * @tc.expected: the return result is the same as input align. 527 */ 528 TextStyle textStyle; 529 textStyle.SetTextDecorationStyle(TextDecorationStyle::DASHED); 530 EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle, RSTextDecorationStyle::DASHED); 531 textStyle.SetTextDecorationStyle(TextDecorationStyle::DOTTED); 532 EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle, RSTextDecorationStyle::DOTTED); 533 textStyle.SetTextDecorationStyle(TextDecorationStyle::DOUBLE); 534 EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle, RSTextDecorationStyle::DOUBLE); 535 textStyle.SetTextDecorationStyle(TextDecorationStyle::WAVY); 536 EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle, RSTextDecorationStyle::WAVY); 537 textStyle.SetTextDecorationStyle(TextDecorationStyle::INHERIT); 538 EXPECT_EQ(ToRSTextStyle(nullptr, textStyle).decorationStyle, RSTextDecorationStyle::SOLID); 539 } 540 541 /** 542 * @tc.name: DrawingPropConvertorTestNg017 543 * @tc.desc: Test cast to DrawingPropConvertorTestNg 544 * @tc.type: FUNC 545 */ 546 HWTEST_F(DrawingPropConvertorTestNg, DrawingPropConvertorTestNg017, TestSize.Level1) 547 { 548 /** 549 * @tc.steps1: call ToRSWordBreakType and set input testWordBreak is HYPHENATION. 550 * @tc.expected: the return retWordBreakType is the same as RSWordBreakType::WordBreakTypeHyphenation. 551 */ 552 auto testWordBreak = static_cast<WordBreak>(3); 553 554 RSWordBreakType retWordBreakType = ToRSWordBreakType(testWordBreak); 555 EXPECT_EQ(retWordBreakType, RSWordBreakType::WordBreakTypeHyphenation); 556 } 557 } // namespace OHOS::Ace 558