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 "gtest/gtest.h" 17 #include "rosen_text/text_style.h" 18 #include "convert.h" 19 #include "symbol_engine/hm_symbol_run.h" 20 21 using namespace testing; 22 using namespace testing::ext; 23 24 namespace OHOS { 25 namespace Rosen { 26 class OHHmSymbolTxtTest : public testing::Test {}; 27 28 /* 29 * @tc.name: IsSymbolGlyph001 30 * @tc.desc: test for font isSymbolGlyph 31 * @tc.type: FUNC 32 */ 33 HWTEST_F(OHHmSymbolTxtTest, IsSymbolGlyph001, TestSize.Level0) 34 { 35 TextStyle style; 36 SPText::TextStyle textStyle; 37 style.isSymbolGlyph = true; 38 textStyle = AdapterTxt::Convert(style); 39 EXPECT_EQ(textStyle.isSymbolGlyph, true); 40 } 41 42 /* 43 * @tc.name: SetRenderMode001 44 * @tc.desc: test SetRenderMode with single 45 * @tc.type: FUNC 46 */ 47 HWTEST_F(OHHmSymbolTxtTest, SetRenderMode001, TestSize.Level0) 48 { 49 TextStyle style; 50 style.isSymbolGlyph = true; 51 SPText::TextStyle textStyle; 52 style.symbol.SetRenderMode(0); // this 0 is single 53 textStyle = AdapterTxt::Convert(style); 54 EXPECT_EQ(textStyle.symbol.GetRenderMode(), Drawing::DrawingSymbolRenderingStrategy::SINGLE); 55 } 56 57 /* 58 * @tc.name: SetRenderMode002 59 * @tc.desc: test SetRenderMode with multiple color 60 * @tc.type: FUNC 61 */ 62 HWTEST_F(OHHmSymbolTxtTest, SetRenderMode002, TestSize.Level0) 63 { 64 TextStyle style; 65 style.isSymbolGlyph = true; 66 SPText::TextStyle textStyle; 67 68 style.symbol.SetRenderMode(1); // this 1 is multiple color 69 textStyle = AdapterTxt::Convert(style); 70 EXPECT_EQ(textStyle.symbol.GetRenderMode(), Drawing::DrawingSymbolRenderingStrategy::MULTIPLE_COLOR); 71 } 72 73 /* 74 * @tc.name: SetRenderMode003 75 * @tc.desc: test SetRenderMode with multi opacity 76 * @tc.type: FUNC 77 */ 78 HWTEST_F(OHHmSymbolTxtTest, SetRenderMode003, TestSize.Level0) 79 { 80 TextStyle style; 81 style.isSymbolGlyph = true; 82 SPText::TextStyle textStyle; 83 84 style.symbol.SetRenderMode(2); // this 2 is multiple opacity 85 textStyle = AdapterTxt::Convert(style); 86 EXPECT_EQ(textStyle.symbol.GetRenderMode(), Drawing::DrawingSymbolRenderingStrategy::MULTIPLE_OPACITY); 87 } 88 89 /* 90 * @tc.name: SetRenderMode004 91 * @tc.desc: test SetRenderMode with invalid value 92 * @tc.type: FUNC 93 */ 94 HWTEST_F(OHHmSymbolTxtTest, SetRenderMode004, TestSize.Level0) 95 { 96 TextStyle style; 97 style.isSymbolGlyph = true; 98 SPText::TextStyle textStyle; 99 100 style.symbol.SetRenderMode(0); // this 0 is single 101 textStyle = AdapterTxt::Convert(style); 102 EXPECT_EQ(textStyle.symbol.GetRenderMode(), Drawing::DrawingSymbolRenderingStrategy::SINGLE); 103 104 style.symbol.SetRenderMode(5); // this 5 is Incorrect input parameter. 105 textStyle = AdapterTxt::Convert(style); 106 EXPECT_EQ(textStyle.symbol.GetRenderMode(), Drawing::DrawingSymbolRenderingStrategy::SINGLE); 107 } 108 109 /* 110 * @tc.name: GetSymbolLayers001 111 * @tc.desc: test for symbol GetSymbolLayers 112 * @tc.type: FUNC 113 */ 114 HWTEST_F(OHHmSymbolTxtTest, GetSymbolLayers001, TestSize.Level0) 115 { 116 uint16_t glyphId = 0; 117 SPText::TextStyle textStyle; 118 const char* str = "A"; 119 Drawing::Font font; 120 auto textblob = Drawing::TextBlob::MakeFromText(str, strlen(str), font, Drawing::TextEncoding::UTF8); 121 SPText::HMSymbolTxt symbolTxt; 122 std::function<bool(const std::shared_ptr<OHOS::Rosen::TextEngine::SymbolAnimationConfig>&)> 123 animationFunc = nullptr; 124 SPText::HMSymbolRun hmSymbolRun = SPText::HMSymbolRun(0, symbolTxt, textblob, animationFunc); 125 auto symbolInfo = hmSymbolRun.GetSymbolLayers(glyphId, textStyle.symbol); 126 bool flag = symbolInfo.renderGroups.empty() && symbolInfo.layers.empty(); 127 EXPECT_TRUE(flag); 128 } 129 130 /* 131 * @tc.name: SetRenderColor001 132 * @tc.desc: test for symbol SetRenderColor 133 * @tc.type: FUNC 134 */ 135 HWTEST_F(OHHmSymbolTxtTest, SetRenderColor001, TestSize.Level0) 136 { 137 HMSymbolTxt symbol; 138 Drawing::Color color1 = Drawing::Color::COLOR_BLUE; 139 Drawing::Color color2 = Drawing::Color::COLOR_GREEN; 140 Drawing::Color color3 = Drawing::Color::COLOR_RED; 141 std::vector<Drawing::Color> colors = {color1, color2, color3}; 142 symbol.SetRenderColor(colors); 143 auto colors1 = symbol.GetRenderColor(); 144 EXPECT_EQ(colors1.size(), 3); // this 3 is the size of RenderColor 145 146 symbol.SetRenderColor(color1); 147 auto colors2 = symbol.GetRenderColor(); 148 EXPECT_EQ(colors2.size(), 1); // this 1 is the size of RenderColor 149 150 RSSColor color4 = {1.0, 255, 0, 0}; // the 1.0 is alpha, 255, 0, 0 is RGB 151 RSSColor color5 = {1.0, 0, 0, 0}; // the 1.0 is alpha, 0, 0, 0 is RGB 152 std::vector<RSSColor> rsscolors = {color4, color5}; 153 symbol.SetRenderColor(rsscolors); 154 auto colors3 = symbol.GetRenderColor(); 155 EXPECT_EQ(colors3.size(), 2); // this 2 is the size of RenderColor 156 157 symbol.SetRenderColor(color4); 158 auto colors4 = symbol.GetRenderColor(); 159 EXPECT_EQ(colors4.size(), 1); // this 1 is the size of RenderColor 160 } 161 162 /* 163 * @tc.name: SetEffectStrategy001 164 * @tc.desc: test SetEffectStrategy for None animaiton 165 * @tc.type: FUNC 166 */ 167 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy001, TestSize.Level0) 168 { 169 TextStyle style; 170 style.isSymbolGlyph = true; 171 SPText::TextStyle textStyle; 172 173 style.symbol.SetSymbolEffect(0); // this 0 is NONE animation 174 textStyle = AdapterTxt::Convert(style); 175 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::NONE); 176 } 177 178 /* 179 * @tc.name: SetEffectStrategy002 180 * @tc.desc: test SetEffectStrategy for scale animaiton 181 * @tc.type: FUNC 182 */ 183 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy002, TestSize.Level0) 184 { 185 TextStyle style; 186 style.isSymbolGlyph = true; 187 SPText::TextStyle textStyle; 188 189 style.symbol.SetSymbolEffect(1); // this 1 is scale animation 190 textStyle = AdapterTxt::Convert(style); 191 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::SCALE); 192 } 193 194 /* 195 * @tc.name: SetEffectStrategy003 196 * @tc.desc: test SetEffectStrategy for variable color animation 197 * @tc.type: FUNC 198 */ 199 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy003, TestSize.Level0) 200 { 201 TextStyle style; 202 style.isSymbolGlyph = true; 203 SPText::TextStyle textStyle; 204 205 style.symbol.SetSymbolEffect(2); // this 2 is variable color animation 206 textStyle = AdapterTxt::Convert(style); 207 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::VARIABLE_COLOR); 208 } 209 210 /* 211 * @tc.name: SetEffectStrategy004 212 * @tc.desc: test SetEffectStrategy for appear animation 213 * @tc.type: FUNC 214 */ 215 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy004, TestSize.Level0) 216 { 217 TextStyle style; 218 style.isSymbolGlyph = true; 219 SPText::TextStyle textStyle; 220 221 style.symbol.SetSymbolEffect(3); // this 3 is appear animation 222 textStyle = AdapterTxt::Convert(style); 223 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::APPEAR); 224 } 225 226 /* 227 * @tc.name: SetEffectStrategy005 228 * @tc.desc: test SetEffectStrategy for disappear animation 229 * @tc.type: FUNC 230 */ 231 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy005, TestSize.Level0) 232 { 233 TextStyle style; 234 style.isSymbolGlyph = true; 235 SPText::TextStyle textStyle; 236 237 style.symbol.SetSymbolEffect(4); // this 4 is disappear animation 238 textStyle = AdapterTxt::Convert(style); 239 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::DISAPPEAR); 240 } 241 242 /* 243 * @tc.name: SetEffectStrategy006 244 * @tc.desc: test SetEffectStrategy for bounce animation 245 * @tc.type: FUNC 246 */ 247 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy006, TestSize.Level0) 248 { 249 TextStyle style; 250 style.isSymbolGlyph = true; 251 SPText::TextStyle textStyle; 252 253 style.symbol.SetSymbolEffect(5); // this 5 is bounce animation 254 textStyle = AdapterTxt::Convert(style); 255 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::BOUNCE); 256 } 257 258 /* 259 * @tc.name: SetEffectStrategy007 260 * @tc.desc: test SetEffectStrategy for pulse animation 261 * @tc.type: FUNC 262 */ 263 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy007, TestSize.Level0) 264 { 265 TextStyle style; 266 style.isSymbolGlyph = true; 267 SPText::TextStyle textStyle; 268 269 style.symbol.SetSymbolEffect(6); // this 6 is pulse animation 270 textStyle = AdapterTxt::Convert(style); 271 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::PULSE); 272 } 273 274 /* 275 * @tc.name: SetEffectStrategy008 276 * @tc.desc: test SetEffectStrategy for replace_appear animation 277 * @tc.type: FUNC 278 */ 279 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy008, TestSize.Level0) 280 { 281 TextStyle style; 282 style.isSymbolGlyph = true; 283 SPText::TextStyle textStyle; 284 285 style.symbol.SetSymbolEffect(7); // this 7 is replace_appear animation 286 textStyle = AdapterTxt::Convert(style); 287 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::REPLACE_APPEAR); 288 } 289 290 /* 291 * @tc.name: SetEffectStrategy009 292 * @tc.desc: test SetEffectStrategy for invalid value 293 * @tc.type: FUNC 294 */ 295 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy009, TestSize.Level0) 296 { 297 TextStyle style; 298 style.isSymbolGlyph = true; 299 SPText::TextStyle textStyle; 300 301 style.symbol.SetSymbolEffect(100); // this 100 is wrong value 302 textStyle = AdapterTxt::Convert(style); 303 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::NONE); 304 } 305 306 /* 307 * @tc.name: SetEffectStrategy0010 308 * @tc.desc: test SetEffectStrategy for replace_appear animation 309 * @tc.type: FUNC 310 */ 311 HWTEST_F(OHHmSymbolTxtTest, SetEffectStrategy0010, TestSize.Level0) 312 { 313 TextStyle style; 314 style.isSymbolGlyph = true; 315 SPText::TextStyle textStyle; 316 317 style.symbol.SetSymbolEffect(9); // this 9 is quick_replace_appear animation 318 textStyle = AdapterTxt::Convert(style); 319 EXPECT_EQ(textStyle.symbol.GetEffectStrategy(), Drawing::DrawingEffectStrategy::QUICK_REPLACE_APPEAR); 320 } 321 322 /* 323 * @tc.name: SetAnimationMode001 324 * @tc.desc: test for SetAnimationMode with cumulative effect 325 * @tc.type: FUNC 326 */ 327 HWTEST_F(OHHmSymbolTxtTest, SetAnimationMode001, TestSize.Level0) 328 { 329 TextStyle style; 330 style.isSymbolGlyph = true; 331 SPText::TextStyle textStyle; 332 style.symbol.SetAnimationMode(0); // the 0 is the wholeSymbol or cumulative effect 333 textStyle = AdapterTxt::Convert(style); 334 EXPECT_EQ(textStyle.symbol.GetAnimationMode(), 0); 335 } 336 337 /* 338 * @tc.name: SetAnimationMode002 339 * @tc.desc: test for SetAnimationMode with iteratuve effect 340 * @tc.type: FUNC 341 */ 342 HWTEST_F(OHHmSymbolTxtTest, SetAnimationMode002, TestSize.Level0) 343 { 344 TextStyle style; 345 style.isSymbolGlyph = true; 346 SPText::TextStyle textStyle; 347 348 style.symbol.SetAnimationMode(1); // the 1 is the byLayer or iteratuve effect 349 textStyle = AdapterTxt::Convert(style); 350 EXPECT_EQ(textStyle.symbol.GetAnimationMode(), 1); 351 } 352 353 /* 354 * @tc.name: SetAnimationMode003 355 * @tc.desc: test for SetAnimationMode with invalid value 356 * @tc.type: FUNC 357 */ 358 HWTEST_F(OHHmSymbolTxtTest, SetAnimationMode003, TestSize.Level0) 359 { 360 TextStyle style; 361 style.isSymbolGlyph = true; 362 SPText::TextStyle textStyle; 363 364 style.symbol.SetAnimationMode(500); // 500 is test Boundary Value 365 textStyle = AdapterTxt::Convert(style); 366 EXPECT_NE(textStyle.symbol.GetAnimationMode(), 500); 367 EXPECT_EQ(textStyle.symbol.GetAnimationMode(), 1); 368 } 369 370 /* 371 * @tc.name: SetRepeatCount001 372 * @tc.desc: test for symbol SetRepeatCount 373 * @tc.type: FUNC 374 */ 375 HWTEST_F(OHHmSymbolTxtTest, SetRepeatCount001, TestSize.Level0) 376 { 377 TextStyle style; 378 style.isSymbolGlyph = true; 379 SPText::TextStyle textStyle; 380 int count = 5; // the numbers of animation playback 381 style.symbol.SetRepeatCount(count); // the 0 is the wholeSymbol or cumulative effect 382 textStyle = AdapterTxt::Convert(style); 383 EXPECT_EQ(textStyle.symbol.GetRepeatCount(), count); 384 } 385 386 /* 387 * @tc.name: SetAnimationStart001 388 * @tc.desc: test SetAnimationStart with true 389 * @tc.type: FUNC 390 */ 391 HWTEST_F(OHHmSymbolTxtTest, SetAnimationStart001, TestSize.Level0) 392 { 393 TextStyle style; 394 style.isSymbolGlyph = true; 395 SPText::TextStyle textStyle; 396 style.symbol.SetAnimationStart(true); 397 textStyle = AdapterTxt::Convert(style); 398 EXPECT_EQ(textStyle.symbol.GetAnimationStart(), true); 399 } 400 401 /* 402 * @tc.name: SetAnimationStart002 403 * @tc.desc: test SetAnimationStart with false 404 * @tc.type: FUNC 405 */ 406 HWTEST_F(OHHmSymbolTxtTest, SetAnimationStart002, TestSize.Level0) 407 { 408 TextStyle style; 409 style.isSymbolGlyph = true; 410 SPText::TextStyle textStyle; 411 style.symbol.SetAnimationStart(false); 412 textStyle = AdapterTxt::Convert(style); 413 EXPECT_EQ(textStyle.symbol.GetAnimationStart(), false); 414 } 415 416 /* 417 * @tc.name: SetVisualMode001 418 * @tc.desc: test SetVisualMode with VISUAL_SMALL 419 * @tc.type: FUNC 420 */ 421 HWTEST_F(OHHmSymbolTxtTest, SetVisualMode001, TestSize.Level0) 422 { 423 TextStyle style; 424 style.isSymbolGlyph = true; 425 SPText::TextStyle textStyle; 426 style.symbol.SetVisualMode(VisualMode::VISUAL_SMALL); 427 auto visualMap = style.symbol.GetVisualMap(); 428 EXPECT_EQ(visualMap.empty(), false); 429 } 430 431 /* 432 * @tc.name: SetVisualMode002 433 * @tc.desc: test SetVisualMode with VISUAL_LARGER 434 * @tc.type: FUNC 435 */ 436 HWTEST_F(OHHmSymbolTxtTest, SetVisualMode002, TestSize.Level0) 437 { 438 TextStyle style; 439 style.isSymbolGlyph = true; 440 SPText::TextStyle textStyle; 441 442 style.symbol.SetVisualMode(VisualMode::VISUAL_LARGER); 443 auto visualMap = style.symbol.GetVisualMap(); 444 EXPECT_EQ(visualMap.empty(), false); 445 } 446 447 /* 448 * @tc.name: SetVisualMode003 449 * @tc.desc: test SetVisualMode with VISUAL_MEDIUM 450 * @tc.type: FUNC 451 */ 452 HWTEST_F(OHHmSymbolTxtTest, SetVisualMode003, TestSize.Level0) 453 { 454 TextStyle style; 455 style.isSymbolGlyph = true; 456 SPText::TextStyle textStyle; 457 458 style.symbol.SetVisualMode(VisualMode::VISUAL_MEDIUM); 459 auto visualMap = style.symbol.GetVisualMap(); 460 EXPECT_EQ(visualMap.empty(), true); 461 } 462 463 /* 464 * @tc.name: SetCommonSubType001 465 * @tc.desc: test SetCommonSubType with DOWN 466 * @tc.type: FUNC 467 */ 468 HWTEST_F(OHHmSymbolTxtTest, SetCommonSubType001, TestSize.Level0) 469 { 470 TextStyle style; 471 style.isSymbolGlyph = true; 472 SPText::TextStyle textStyle; 473 474 style.symbol.SetCommonSubType(Drawing::DrawingCommonSubType::DOWN); 475 textStyle = AdapterTxt::Convert(style); 476 EXPECT_EQ(textStyle.symbol.GetCommonSubType(), Drawing::DrawingCommonSubType::DOWN); 477 } 478 479 /* 480 * @tc.name: SetCommonSubType002 481 * @tc.desc: test SetCommonSubType with UP 482 * @tc.type: FUNC 483 */ 484 HWTEST_F(OHHmSymbolTxtTest, SetCommonSubType002, TestSize.Level0) 485 { 486 TextStyle style; 487 style.isSymbolGlyph = true; 488 SPText::TextStyle textStyle; 489 490 style.symbol.SetCommonSubType(Drawing::DrawingCommonSubType::UP); 491 textStyle = AdapterTxt::Convert(style); 492 EXPECT_EQ(textStyle.symbol.GetCommonSubType(), Drawing::DrawingCommonSubType::UP); 493 } 494 495 /* 496 * @tc.name: HMSymbolTxtOperator001 497 * @tc.desc: test for symbol HMSymbolTxt::operator== 498 * @tc.type: FUNC 499 */ 500 HWTEST_F(OHHmSymbolTxtTest, HMSymbolTxtOperator001, TestSize.Level0) 501 { 502 RSSColor color1 = {1.0, 255, 0, 0}; // the 1.0 is alpha, 255, 0, 0 is RGB 503 RSSColor color2 = {1.0, 0, 0, 0}; // the 1.0 is alpha, 0, 0, 0 is RGB 504 RSSColor color3 = {1.0, 255, 255, 0}; // the 1.0 is alpha, 255, 255, 0 is RGB 505 RSSColor color4 = {1.0, 255, 0, 255}; // the 1.0 is alpha, 255, 0, 255 is RGB 506 RSSColor color5 = {0.5, 255, 0, 0}; // the 0.5 is alpha, 255, 0, 0 is RGB 507 std::vector<RSSColor> colors = {color1, color2}; 508 SPText::HMSymbolTxt symbolTxt; 509 symbolTxt.SetRenderColor(color1); 510 SPText::HMSymbolTxt symbolTxt1; 511 EXPECT_EQ(symbolTxt == symbolTxt1, false); 512 513 symbolTxt1.SetRenderColor(color2); 514 EXPECT_EQ(symbolTxt == symbolTxt1, false); 515 516 symbolTxt1.SetRenderColor(color3); 517 EXPECT_EQ(symbolTxt == symbolTxt1, false); 518 519 symbolTxt1.SetRenderColor(color4); 520 EXPECT_EQ(symbolTxt == symbolTxt1, false); 521 522 symbolTxt1.SetRenderColor(color5); 523 EXPECT_EQ(symbolTxt == symbolTxt1, false); 524 525 symbolTxt.SetRenderColor(colors); 526 symbolTxt1.SetRenderColor(colors); 527 EXPECT_EQ(symbolTxt == symbolTxt1, true); 528 529 symbolTxt.SetRenderMode(Drawing::DrawingSymbolRenderingStrategy::MULTIPLE_OPACITY); 530 symbolTxt1.SetRenderMode(Drawing::DrawingSymbolRenderingStrategy::MULTIPLE_COLOR); 531 EXPECT_EQ(symbolTxt == symbolTxt1, false); 532 533 symbolTxt.SetSymbolEffect(Drawing::DrawingEffectStrategy::SCALE); 534 symbolTxt1.SetSymbolEffect(Drawing::DrawingEffectStrategy::APPEAR); 535 EXPECT_EQ(symbolTxt == symbolTxt1, false); 536 537 symbolTxt.SetSymbolEffect(Drawing::DrawingEffectStrategy::SCALE); 538 symbolTxt1.SetSymbolEffect(Drawing::DrawingEffectStrategy::APPEAR); 539 symbolTxt.SetRenderMode(Drawing::DrawingSymbolRenderingStrategy::SINGLE); 540 symbolTxt1.SetRenderMode(Drawing::DrawingSymbolRenderingStrategy::SINGLE); 541 EXPECT_EQ(symbolTxt == symbolTxt1, false); 542 543 symbolTxt.SetSymbolEffect(Drawing::DrawingEffectStrategy::SCALE); 544 symbolTxt1.SetSymbolEffect(Drawing::DrawingEffectStrategy::SCALE); 545 symbolTxt.SetRenderMode(Drawing::DrawingSymbolRenderingStrategy::SINGLE); 546 symbolTxt1.SetRenderMode(Drawing::DrawingSymbolRenderingStrategy::SINGLE); 547 EXPECT_EQ(symbolTxt == symbolTxt1, true); 548 } 549 550 /* 551 * @tc.name: HMSymbolTxtOperator002 552 * @tc.desc: test for symbol HMSymbolTxt::operator== 553 * @tc.type: FUNC 554 */ 555 HWTEST_F(OHHmSymbolTxtTest, HMSymbolTxtOperator002, TestSize.Level0) 556 { 557 auto color1 = std::make_shared<SymbolGradient>(); 558 color1->SetColors({0XFFFF0000}); // 0XFFFF0000 is ARGB 559 auto color2 = std::make_shared<SymbolGradient>(); 560 color2->SetColors({0XFF0000FF}); // 0XFF0000FF is ARGB 561 OHOS::Rosen::SymbolColor symbolColor = {SymbolColorType::COLOR_TYPE, {color1, color2}}; 562 563 SPText::HMSymbolTxt symbolTxt; 564 symbolTxt.SetSymbolColor(symbolColor); 565 SPText::HMSymbolTxt symbolTxt1; 566 symbolTxt1.SetSymbolColor(symbolTxt.GetSymbolColor()); 567 EXPECT_TRUE(symbolTxt == symbolTxt1); 568 569 auto gradients = symbolTxt.GetGradients(); 570 ASSERT_FALSE(gradients.empty()); 571 gradients[0] = nullptr; 572 symbolTxt.symbolColor_.gradients = gradients; 573 EXPECT_FALSE(symbolTxt == symbolTxt1); 574 symbolTxt1.symbolColor_.gradients = gradients; 575 EXPECT_TRUE(symbolTxt == symbolTxt1); 576 } 577 578 /* 579 * @tc.name: SymbolUid001 580 * @tc.desc: test GetSymbolUid and SetSymbolUid 581 * @tc.type: FUNC 582 */ 583 HWTEST_F(OHHmSymbolTxtTest, SymbolUid001, TestSize.Level0) 584 { 585 SPText::HMSymbolTxt symbolTxt; 586 EXPECT_EQ(symbolTxt.GetSymbolUid(), 0); 587 symbolTxt.SetSymbolUid(100); 588 EXPECT_EQ(symbolTxt.GetSymbolUid(), 100); 589 } 590 591 /* 592 * @tc.name: SymbolBitmap001 593 * @tc.desc: test GetSymbolBitmap and SetSymbolBitmap 594 * @tc.type: FUNC 595 */ 596 HWTEST_F(OHHmSymbolTxtTest, SymbolBitmap001, TestSize.Level0) 597 { 598 SPText::HMSymbolTxt symbolTxt; 599 // test get method 600 auto bitmap = symbolTxt.GetSymbolBitmap(); 601 EXPECT_TRUE(bitmap.none()); 602 603 // test set method 604 SymbolBitmapType symbolBitmap; 605 symbolBitmap.flip(); 606 symbolTxt.SetSymbolBitmap(symbolBitmap); 607 int symbolAttrLen = static_cast<int>(RelayoutSymbolStyleAttribute::SYMBOL_ATTRIBUTE_BUTT); 608 EXPECT_EQ(symbolTxt.GetSymbolBitmap().size(), symbolAttrLen); 609 } 610 611 /* 612 * @tc.name: GetRenderColor001 613 * @tc.desc: test GetRenderColor 614 * @tc.type: FUNC 615 */ 616 HWTEST_F(OHHmSymbolTxtTest, GetRenderColor001, TestSize.Level0) 617 { 618 SPText::HMSymbolTxt symbolTxt; 619 auto color1 = std::make_shared<SymbolGradient>(); 620 color1->SetColors({0XFFFF0000}); // 0XFFFF0000 is ARGB 621 auto color2 = nullptr; 622 OHOS::Rosen::SymbolColor symbolColor = {SymbolColorType::COLOR_TYPE, {color1, color2}}; 623 symbolTxt.SetSymbolColor(symbolColor); 624 auto colors = symbolTxt.GetRenderColor(); 625 EXPECT_FALSE(colors.empty()); 626 } 627 628 /* 629 * @tc.name: GradientColorTest001 630 * @tc.desc: test for gradient colors 631 * @tc.type: FUNC 632 */ 633 HWTEST_F(OHHmSymbolTxtTest, GradientColorTest001, TestSize.Level1) 634 { 635 OHOS::Rosen::HMSymbolTxt symbolTxt; 636 auto gradient1 = std::make_shared<SymbolGradient>(); 637 gradient1->SetColors({0XFFFF0000}); // 0XFFFF0000 is ARGB 638 auto gradient2 = nullptr; 639 OHOS::Rosen::SymbolColor symbolColor = {SymbolColorType::GRADIENT_TYPE, {gradient1, gradient2}}; 640 symbolTxt.SetSymbolColor(symbolColor); 641 auto localSymbolColor = symbolTxt.GetSymbolColor(); 642 EXPECT_FALSE(localSymbolColor.gradients.empty()); 643 EXPECT_EQ(localSymbolColor.colorType, SymbolColorType::GRADIENT_TYPE); // 2 is colors size 644 EXPECT_EQ(localSymbolColor.gradients.size(), 2); // 2 is colors size 645 } 646 647 /* 648 * @tc.name: CommonColorTest001 649 * @tc.desc: test for common colors 650 * @tc.type: FUNC 651 */ 652 HWTEST_F(OHHmSymbolTxtTest, CommonColorTest001, TestSize.Level0) 653 { 654 OHOS::Rosen::HMSymbolTxt symbolTxt; 655 auto gradient1 = std::make_shared<SymbolGradient>(); 656 gradient1->SetColors({0XFFFF0000}); // 0XFFFF0000 is ARGB 657 auto gradient2 = nullptr; 658 OHOS::Rosen::SymbolColor symbolColor = {SymbolColorType::COLOR_TYPE, {gradient1, gradient2}}; 659 symbolTxt.SetSymbolColor(symbolColor); 660 auto localSymbolColor = symbolTxt.GetRenderColor(); 661 EXPECT_EQ(localSymbolColor.size(), 1); // 1 is colors size 662 } 663 } // namespace Rosen 664 } // namespace OHOS