ui_canvas_unit_test.cpp 59.6 KB
Newer Older
M
mamingshuai 已提交
1
/*
2
 * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
M
mamingshuai 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "components/root_view.h"
#include "components/ui_canvas.h"
#include "components/ui_view_group.h"
19
#include "components/ui_view_group.h"
M
mamingshuai 已提交
20 21 22

#include <climits>
#include <gtest/gtest.h>
23
#include "test_resource_config.h"
M
mamingshuai 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
using namespace testing::ext;
namespace OHOS {
namespace {
    const int16_t POS_X = 50;
    const int16_t POS_Y = 100;
    const uint16_t WIDTH = 100;
    const uint16_t HEIGHT = 100;
    const int16_t START1_X = 10;
    const int16_t START1_Y = 20;
    const int16_t LINE1_X = 40;
    const int16_t LINE1_Y = 100;
    const int16_t LINE2_X = 50;
    const int16_t LINE2_Y = 120;
    const int16_t CENTER_X = 150;
    const int16_t CENTER_Y = 150;
    const int16_t RADIUS = 50;
    const int16_t START_ANGLE = 30;
    const int16_t END_ANGLE = 250;
    const int16_t RECT_X = 250;
    const int16_t RECT_Y = 50;
    const int16_t RECT_WIDTH = 100;
    const int16_t RECT_HEIGHT = 50;
46 47 48
    const float LINE_OFFSET1 = 10.0;
    const float LINE_OFFSET2 = 50.0;
    const float LINE_OFFSET3 = 150.0;
49 50 51
    const float MITERLIMIT1 = 11.05;
    const float MITERLIMIT2 = 4.6;
    const float MITERLIMIT3 = -5.6;
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    const int16_t IMAGE_X = 20;
    const int16_t IMAGE_Y = 10;
    const uint8_t FONT_SIZE = 15;
    const int16_t LETTER_SPACE = 2;
    const float SCALE_X = 0.5;
    const float SCALE_Y = 0.5;
    const float SHEAR_X = -0.5;
    const float SHEAR_Y = 0.5;
    const float TRANSLATE_X = 30;
    const float TRANSLATE_Y = 10;
    const float GLOBALALPHA = 0.5;
    const int16_t DOUBLENUMBER = 2;
    const double START_X = 180.0;
    const double START_Y = 140.0;
    const double START_R = 10.0;
    const double END_X = 150.0;
    const double END_Y = 100.0;
    const double END_R = 80.0;
    const double COLOR_STOP_0 = 0.0;
    const double COLOR_STOP_1 = 0.3;
    const double COLOR_STOP_2 = 0.6;
    const double COLOR_STOP_3 = 1.0;
    const float ROTATE = 10;
    const int16_t LINE_X = 30;
    const int16_t LINE_Y = 70;
M
mamingshuai 已提交
77 78 79 80 81 82 83
}

class TestUICanvas : public UICanvas {
public:
    TestUICanvas() {}
    virtual ~TestUICanvas() {}

84
    const UICanvasVertices* GetPath() const
M
mamingshuai 已提交
85
    {
86
        return vertices_;
M
mamingshuai 已提交
87 88 89 90
    }

    Point GetStartPos() const
    {
91 92 93 94 95 96
        float x;
        float y;
        if (GetPath() != nullptr) {
            vertices_->Rewind(0);
            vertices_->GenerateVertex(&x, &y);
            return { (int16_t)x, (int16_t)y };
M
mamingshuai 已提交
97 98 99 100 101 102 103
        } else {
            return { COORD_MIN, COORD_MIN };
        }
    }

    Point GetEndPos() const
    {
104 105 106 107 108
        float x;
        float y;
        if (GetPath() != nullptr) {
            vertices_->LastVertex(&x, &y);
            return { (int16_t)x, (int16_t)y };
M
mamingshuai 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
        } else {
            return { COORD_MIN, COORD_MIN };
        }
    }
};

class UICanvasTest : public testing::Test {
public:
    static void SetUpTestCase() {}
    static void TearDownTestCase() {}
    void SetUp();
    void TearDown();
    static Paint* paint_;
    static TestUICanvas* canvas_;
};

Paint* UICanvasTest::paint_ = nullptr;
TestUICanvas* UICanvasTest::canvas_ = nullptr;
void UICanvasTest::SetUp()
{
    if (paint_ == nullptr) {
        paint_ = new Paint();
    }
    if (canvas_ == nullptr) {
        canvas_ = new TestUICanvas();
    }
}

void UICanvasTest::TearDown()
{
    if (paint_ != nullptr) {
        delete paint_;
        paint_ = nullptr;
    }
    if (canvas_ != nullptr) {
        delete canvas_;
        canvas_ = nullptr;
    }
}
/**
 * @tc.name: UICanvasSetPaintStyle_001
 * @tc.desc: Verify SetStyle function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
HWTEST_F(UICanvasTest, UICanvasSetPaintStyle_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    Paint::PaintStyle paintStyle = Paint::PaintStyle::FILL_STYLE;

    paint_->SetStyle(Paint::PaintStyle::FILL_STYLE);
    EXPECT_EQ(paint_->GetStyle(), paintStyle);
}

/**
 * @tc.name: UICanvasSetStrokeWidth_001
 * @tc.desc: Verify SetStrokeWidth function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
邓志豪 已提交
172
HWTEST_F(UICanvasTest, UICanvasSetStrokeWidth_001, TestSize.Level1)
M
mamingshuai 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetStrokeWidth(WIDTH);
    EXPECT_EQ(paint_->GetStrokeWidth(), WIDTH);
}

/**
 * @tc.name: UICanvasSetStrokeColor_001
 * @tc.desc: Verify SetStrokeColor function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
邓志豪 已提交
188
HWTEST_F(UICanvasTest, UICanvasSetStrokeColor_001, TestSize.Level1)
M
mamingshuai 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    ColorType color = Color::Red();

    paint_->SetStrokeColor(color);
    EXPECT_EQ(paint_->GetStrokeColor().full, color.full);
}

/**
 * @tc.name: UICanvasSetFillColor_001
 * @tc.desc: Verify SetFillColor function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
邓志豪 已提交
206
HWTEST_F(UICanvasTest, UICanvasSetFillColor_001, TestSize.Level1)
M
mamingshuai 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    ColorType color = Color::Red();

    paint_->SetFillColor(color);
    EXPECT_EQ(paint_->GetFillColor().full, color.full);
}

/**
 * @tc.name: UICanvasSetOpacity_001
 * @tc.desc: Verify SetOpacity function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
邓志豪 已提交
224
HWTEST_F(UICanvasTest, UICanvasSetOpacity_001, TestSize.Level1)
M
mamingshuai 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetOpacity(OPA_OPAQUE);
    EXPECT_EQ(paint_->GetOpacity(), OPA_OPAQUE);
}

/**
 * @tc.name: UICanvasSetStartPosition_001
 * @tc.desc: Verify SetStartPosition function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
邓志豪 已提交
240
HWTEST_F(UICanvasTest, UICanvasSetStartPosition_001, TestSize.Level1)
M
mamingshuai 已提交
241 242 243 244 245
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
246
    canvas_->SetStartPosition({POS_X, POS_Y});
M
mamingshuai 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
    EXPECT_EQ(canvas_->GetStartPosition().x, POS_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, POS_Y);
}

/**
 * @tc.name: UICanvasDrawLine_001
 * @tc.desc: Verify DrawLine function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
HWTEST_F(UICanvasTest, UICanvasDrawLine_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    RootView* rootView = RootView::GetInstance();
    UIViewGroup* viewGroup = static_cast<UIViewGroup*>(rootView);
    Paint paint;
    Point startPoint = { 0, 50 };
    Point endPoint = { 50, 100 };

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);
    canvas_->DrawLine(startPoint, endPoint, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, endPoint.x);
    EXPECT_EQ(canvas_->GetStartPosition().y, endPoint.y);
    viewGroup->Remove(canvas_);
}

/**
 * @tc.name: UICanvasDrawCurve_001
 * @tc.desc: Verify DrawCurve function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMPV
 */
HWTEST_F(UICanvasTest, UICanvasDrawCurve_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    RootView* rootView = RootView::GetInstance();
    UIViewGroup* viewGroup = static_cast<UIViewGroup*>(rootView);
    Paint paint;
    Point startPoint = { 100, 100 };
    Point endPoint = { 150, 200 };
    Point control1Point = { 150, 100 };
    Point control2Point = { 150, 100 };

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);
    canvas_->DrawCurve(startPoint, control1Point, control2Point, endPoint, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, endPoint.x);
    EXPECT_EQ(canvas_->GetStartPosition().y, endPoint.y);
    viewGroup->Remove(canvas_);
}

/**
 * @tc.name: UICanvasBeginPath_001
 * @tc.desc: Verify BeginPath function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
HWTEST_F(UICanvasTest, UICanvasBeginPath_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    EXPECT_EQ(canvas_->GetPath(), nullptr);
    canvas_->BeginPath();
    EXPECT_NE(canvas_->GetPath(), nullptr);
}

/**
 * @tc.name: UICanvasMoveTo_001
 * @tc.desc: Verify MoveTo function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
HWTEST_F(UICanvasTest, UICanvasMoveTo_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
340
    canvas_->MoveTo({START1_X, START1_Y});
M
mamingshuai 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
    Point start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, START1_X);
    EXPECT_EQ(start.y, START1_Y);

    Point end = canvas_->GetEndPos();
    EXPECT_EQ(end.x, START1_X);
    EXPECT_EQ(end.y, START1_Y);
}

/**
 * @tc.name: UICanvasLineTo_001
 * @tc.desc: Verify LineTo function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
HWTEST_F(UICanvasTest, UICanvasLineTo_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
363
    canvas_->LineTo({LINE1_X, LINE1_Y});
M
mamingshuai 已提交
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
    Point start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, LINE1_X);
    EXPECT_EQ(start.y, LINE1_Y);

    Point end = canvas_->GetEndPos();
    EXPECT_EQ(end.x, LINE1_X);
    EXPECT_EQ(end.y, LINE1_Y);
}

/**
 * @tc.name: UICanvasLineTo_002
 * @tc.desc: Verify LineTo function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
邓志豪 已提交
379
HWTEST_F(UICanvasTest, UICanvasLineTo_002, TestSize.Level1)
M
mamingshuai 已提交
380 381 382 383 384 385
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
386 387
    canvas_->MoveTo({START1_X, START1_Y});
    canvas_->LineTo({LINE1_X, LINE1_Y});
M
mamingshuai 已提交
388 389 390 391 392 393 394 395
    Point start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, START1_X);
    EXPECT_EQ(start.y, START1_Y);

    Point end = canvas_->GetEndPos();
    EXPECT_EQ(end.x, LINE1_X);
    EXPECT_EQ(end.y, LINE1_Y);

396
    canvas_->LineTo({LINE2_X, LINE2_Y});
M
mamingshuai 已提交
397 398 399 400 401
    end = canvas_->GetEndPos();
    EXPECT_EQ(end.x, LINE2_X);
    EXPECT_EQ(end.y, LINE2_Y);
}

402
#if GRAPHIC_ENABLE_ARC_FLAG
M
mamingshuai 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415
/**
 * @tc.name: UICanvasArcTo_001
 * @tc.desc: Verify ArcTo function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
HWTEST_F(UICanvasTest, UICanvasArcTo_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
416
    canvas_->ArcTo({CENTER_X, CENTER_Y}, RADIUS, START_ANGLE, END_ANGLE);
M
mamingshuai 已提交
417 418 419 420

    float sinma = RADIUS * Sin(START_ANGLE);
    float cosma = RADIUS * Sin(QUARTER_IN_DEGREE - START_ANGLE);
    Point start = canvas_->GetStartPos();
421 422
    EXPECT_EQ(start.x, int16_t(CENTER_X + sinma));
    EXPECT_EQ(start.y, int16_t(CENTER_Y - cosma));
M
mamingshuai 已提交
423 424 425 426

    sinma = RADIUS * Sin(END_ANGLE);
    cosma = RADIUS * Sin(QUARTER_IN_DEGREE - END_ANGLE);
    Point end = canvas_->GetEndPos();
427 428
    EXPECT_EQ(end.x, int16_t(CENTER_X + sinma));
    EXPECT_EQ(end.y, int16_t(CENTER_Y - cosma));
M
mamingshuai 已提交
429 430 431 432 433 434 435 436
}

/**
 * @tc.name: UICanvasArcTo_002
 * @tc.desc: Verify ArcTo function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
邓志豪 已提交
437
HWTEST_F(UICanvasTest, UICanvasArcTo_002, TestSize.Level1)
M
mamingshuai 已提交
438 439 440 441 442 443
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
444 445
    canvas_->ArcTo({CENTER_X, CENTER_Y}, RADIUS, START_ANGLE,
                   START_ANGLE + CIRCLE_IN_DEGREE + QUARTER_IN_DEGREE);
M
mamingshuai 已提交
446 447 448 449

    float sinma = RADIUS * Sin(START_ANGLE);
    float cosma = RADIUS * Sin(QUARTER_IN_DEGREE - START_ANGLE);
    Point start = canvas_->GetStartPos();
450 451
    EXPECT_EQ(start.x, int16_t(CENTER_X + sinma));
    EXPECT_EQ(start.y, int16_t(CENTER_Y - cosma));
M
mamingshuai 已提交
452 453 454 455 456 457 458 459 460 461 462 463 464 465

    sinma = RADIUS * Sin(END_ANGLE);
    cosma = RADIUS * Sin(QUARTER_IN_DEGREE - END_ANGLE);
    Point end = canvas_->GetEndPos();
    EXPECT_EQ(end.x, start.x);
    EXPECT_EQ(end.y, start.y);
}

/**
 * @tc.name: UICanvasArcTo_003
 * @tc.desc: Verify ArcTo function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
邓志豪 已提交
466
HWTEST_F(UICanvasTest, UICanvasArcTo_003, TestSize.Level1)
M
mamingshuai 已提交
467 468 469 470 471 472
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
473 474
    canvas_->MoveTo({START1_X, START1_Y});
    canvas_->ArcTo({CENTER_X, CENTER_Y}, RADIUS, START_ANGLE, END_ANGLE);
M
mamingshuai 已提交
475 476 477 478 479 480 481 482

    Point start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, START1_X);
    EXPECT_EQ(start.y, START1_Y);

    float sinma = RADIUS * Sin(END_ANGLE);
    float cosma = RADIUS * Sin(QUARTER_IN_DEGREE - END_ANGLE);
    Point end = canvas_->GetEndPos();
483 484
    EXPECT_EQ(end.x, int16_t(CENTER_X + sinma));
    EXPECT_EQ(end.y, int16_t(CENTER_Y - cosma));
M
mamingshuai 已提交
485
}
486
#endif
M
mamingshuai 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500

/**
 * @tc.name: UICanvasAddRect_001
 * @tc.desc: Verify AddRect function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
HWTEST_F(UICanvasTest, UICanvasAddRect_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
501
    canvas_->AddRect({RECT_X, RECT_Y}, RECT_HEIGHT, RECT_WIDTH);
M
mamingshuai 已提交
502 503 504 505 506 507

    Point start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, RECT_X);
    EXPECT_EQ(start.y, RECT_Y);

    Point end = canvas_->GetEndPos();
508 509
    EXPECT_EQ(end.x, 0);
    EXPECT_EQ(end.y, 0);
M
mamingshuai 已提交
510 511 512 513 514 515 516 517
}

/**
 * @tc.name: UICanvasAddRect_002
 * @tc.desc: Verify AddRect function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
邓志豪 已提交
518
HWTEST_F(UICanvasTest, UICanvasAddRect_002, TestSize.Level1)
M
mamingshuai 已提交
519 520 521 522 523 524
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
525 526 527
    canvas_->MoveTo({START1_X, START1_Y});
    canvas_->LineTo({LINE1_X, LINE1_Y});
    canvas_->AddRect({RECT_X, RECT_Y}, RECT_HEIGHT, RECT_WIDTH);
M
mamingshuai 已提交
528 529

    Point start = canvas_->GetStartPos();
530 531
    EXPECT_EQ(start.x, START1_X);
    EXPECT_EQ(start.y, START1_Y);
M
mamingshuai 已提交
532 533

    Point end = canvas_->GetEndPos();
534 535
    EXPECT_EQ(end.x, 0);
    EXPECT_EQ(end.y, 0);
M
mamingshuai 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
}

/**
 * @tc.name: UICanvasClosePath_001
 * @tc.desc: Verify ClosePath function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EVN8V
 */
HWTEST_F(UICanvasTest, UICanvasClosePath_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    canvas_->BeginPath();
551 552
    canvas_->MoveTo({START1_X, START1_Y});
    canvas_->LineTo({LINE1_X, LINE1_Y});
M
mamingshuai 已提交
553 554 555 556 557 558 559
    canvas_->ClosePath();

    Point start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, START1_X);
    EXPECT_EQ(start.y, START1_Y);

    Point end = canvas_->GetEndPos();
560 561
    EXPECT_EQ(end.x, 0);
    EXPECT_EQ(end.y, 0);
M
mamingshuai 已提交
562 563 564 565 566 567 568 569
}

/**
 * @tc.name: UICanvasClosePath_002
 * @tc.desc: Verify ClosePath function, equal.
 * @tc.type: FUNC
 * @tc.require: SR000EVN8R
 */
邓志豪 已提交
570
HWTEST_F(UICanvasTest, UICanvasClosePath_002, TestSize.Level1)
M
mamingshuai 已提交
571 572 573 574 575 576 577 578 579 580 581 582
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    canvas_->BeginPath();
583 584
    canvas_->MoveTo({START1_X, START1_Y});
    canvas_->LineTo({LINE1_X, LINE1_Y});
M
mamingshuai 已提交
585 586 587 588 589 590 591 592
    canvas_->ClosePath();
    canvas_->DrawPath(*paint_);

    Point start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, START1_X);
    EXPECT_EQ(start.y, START1_Y);

    Point end = canvas_->GetEndPos();
593 594
    EXPECT_EQ(end.x, 0);
    EXPECT_EQ(end.y, 0);
M
mamingshuai 已提交
595 596

    canvas_->BeginPath();
597
    canvas_->LineTo({LINE2_X, LINE2_Y});
M
mamingshuai 已提交
598 599 600 601 602 603 604
    canvas_->ClosePath();

    start = canvas_->GetStartPos();
    EXPECT_EQ(start.x, LINE2_X);
    EXPECT_EQ(start.y, LINE2_Y);

    end = canvas_->GetEndPos();
605 606 607 608 609
    EXPECT_EQ(end.x, 0);
    EXPECT_EQ(end.y, 0);
}

#if GRAPHIC_ENABLE_LINECAP_FLAG
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
/**
 * @tc.name: UICanvasSetLineCap_001
 * @tc.desc: Verify SetLineCap function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetLineCap_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    paint_->SetLineCap(LineCap::BUTT_CAP);
    EXPECT_EQ(paint_->GetLineCap(), LineCap::BUTT_CAP);
    
    paint_->SetLineCap(LineCap::SQUARE_CAP);
    EXPECT_EQ(paint_->GetLineCap(), LineCap::SQUARE_CAP);

    paint_->SetLineCap(LineCap::ROUND_CAP);
    EXPECT_EQ(paint_->GetLineCap(), LineCap::ROUND_CAP);
}

/**
 * @tc.name: UICanvasSetLineCap_002
 * @tc.desc: Verify SetLineCap function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetLineCap_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetLineCap(LineCap::ROUND_CAP);
    EXPECT_EQ(paint_->GetLineCap(), LineCap::ROUND_CAP);

    paint_->SetLineCap(LineCap::BUTT_CAP);
    EXPECT_EQ(paint_->GetLineCap(), LineCap::BUTT_CAP);

    paint_->SetLineCap(LineCap::SQUARE_CAP);
    EXPECT_EQ(paint_->GetLineCap(), LineCap::SQUARE_CAP);
}
652 653 654
#endif

#if GRAPHIC_ENABLE_LINEJOIN_FLAG
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
/**
 * @tc.name: UICanvasSetLineJoin_001
 * @tc.desc: Verify SetLineJoin function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetLineJoin_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetLineJoin(LineJoin::MITER_JOIN);
    EXPECT_EQ(paint_->GetLineJoin(), LineJoin::MITER_JOIN);

    paint_->SetLineJoin(LineJoin::ROUND_JOIN);
    EXPECT_EQ(paint_->GetLineJoin(), LineJoin::ROUND_JOIN);

    paint_->SetLineJoin(LineJoin::BEVEL_JOIN);
    EXPECT_EQ(paint_->GetLineJoin(), LineJoin::BEVEL_JOIN);
}

/**
 * @tc.name: UICanvasSetLineJoin_002
 * @tc.desc: Verify SetLineJoin function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetLineJoin_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetLineJoin(LineJoin::MITER_JOIN);
    EXPECT_EQ(paint_->GetLineJoin(), LineJoin::MITER_JOIN);

    paint_->SetLineJoin(LineJoin::ROUND_JOIN);
    EXPECT_EQ(paint_->GetLineJoin(), LineJoin::ROUND_JOIN);

    paint_->SetLineJoin(LineJoin::BEVEL_JOIN);
    EXPECT_EQ(paint_->GetLineJoin(), LineJoin::BEVEL_JOIN);
}
696 697 698
#endif

#if GRAPHIC_ENABLE_DASH_GENERATE_FLAG
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
/**
 * @tc.name: UICanvasSetLineDashOffset_001
 * @tc.desc: Verify SetLineDashOffset function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetLineDashOffset_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetLineDashOffset(LINE_OFFSET1);
    EXPECT_EQ(paint_->GetLineDashOffset(), LINE_OFFSET1);

    paint_->SetLineDashOffset(LINE_OFFSET2);
    EXPECT_EQ(paint_->GetLineDashOffset(), LINE_OFFSET2);

    paint_->SetLineDashOffset(LINE_OFFSET3);
    EXPECT_EQ(paint_->GetLineDashOffset(), LINE_OFFSET3);
}

/**
 * @tc.name: UICanvasSetLineDashOffset_002
 * @tc.desc: Verify SetLineDashOffset function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetLineDashOffset_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetLineDashOffset(LINE_OFFSET1);
    EXPECT_EQ(paint_->GetLineDashOffset(), LINE_OFFSET1);

    paint_->SetLineDashOffset(LINE_OFFSET2);
    EXPECT_EQ(paint_->GetLineDashOffset(), LINE_OFFSET2);

    paint_->SetLineDashOffset(LINE_OFFSET3);
    EXPECT_EQ(paint_->GetLineDashOffset(), LINE_OFFSET3);
}
740 741 742
#endif

#if GRAPHIC_ENABLE_LINEJOIN_FLAG
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
/**
 * @tc.name: UICanvasMiterLimit_001
 * @tc.desc: Verify MiterLimit function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasMiterLimit_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetMiterLimit(MITERLIMIT1);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT1);

    paint_->SetMiterLimit(MITERLIMIT2);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT2);

    paint_->SetMiterLimit(MITERLIMIT3);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT3);
}

/**
 * @tc.name: UICanvasMiterLimit_002
 * @tc.desc: Verify MiterLimit function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasMiterLimit_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetMiterLimit(MITERLIMIT1);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT1);

    paint_->SetMiterLimit(MITERLIMIT2);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT2);

    paint_->SetMiterLimit(MITERLIMIT3);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT3);
}

/**
 * @tc.name: UICanvasMiterLimit_003
 * @tc.desc: Verify MiterLimit function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasMiterLimit_003, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetMiterLimit(MITERLIMIT1);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT1);

    paint_->SetMiterLimit(MITERLIMIT2 + MITERLIMIT1);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT2 + MITERLIMIT1);

    paint_->SetMiterLimit(MITERLIMIT3 + MITERLIMIT2);
    EXPECT_EQ(paint_->GetMiterLimit(), MITERLIMIT3 + MITERLIMIT2);
}
805 806 807
#endif

#if GRAPHIC_ENABLE_DASH_GENERATE_FLAG
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
/**
 * @tc.name: UICanvasSetLineDash_001
 * @tc.desc: Verify SetLineDash function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetLineDash_001, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    const int32_t dashCount = 4;
    float dash[dashCount] = {1, 1.5, 2, 2.5};
    paint_->SetLineDash(dash, dashCount);
    EXPECT_EQ(paint_->GetLineDashCount(), dashCount);

    paint_->ClearLineDash();
    EXPECT_EQ(paint_->GetLineDashCount(), 0);
    
    paint_->SetLineDash(dash, dashCount);
    int32_t dashLen = paint_->GetLineDashCount();
    float* dashArr = paint_->GetLineDash();
    for (int32_t i = 0; i < dashLen; i++) {
        EXPECT_EQ(dashArr[i], dash[i]);
    }

    EXPECT_EQ(paint_->IsLineDash(), 1);

    paint_->ClearLineDash();
    EXPECT_EQ(paint_->GetLineDashCount(), 0);

    EXPECT_EQ(paint_->IsLineDash(), 0);
}
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
#endif
/**
 * @tc.name: UICanvasStrokeRect_001
 * @tc.desc: Verify StrokeRect function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasStrokeRect_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    RootView* rootView = RootView::GetInstance();
    UIViewGroup* viewGroup = static_cast<UIViewGroup*>(rootView);
    Paint paint;

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);
    canvas_->StrokeRect({RECT_X, RECT_Y}, RECT_HEIGHT, RECT_WIDTH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, RECT_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, RECT_Y);
    viewGroup->Remove(canvas_);

    viewGroup->SetPosition(10, 20);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);
    canvas_->StrokeRect({0, 0}, RECT_HEIGHT, RECT_WIDTH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, 0);
    EXPECT_EQ(canvas_->GetStartPosition().y, 0);
    viewGroup->Remove(canvas_);
}

/**
887 888
 * @tc.name: UICanvasCleanRect_001
 * @tc.desc: Verify CleanRect function, equal.
889 890
 * @tc.type: FUNC
 */
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
HWTEST_F(UICanvasTest, UICanvasCleanRect_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    RootView* rootView = RootView::GetInstance();
    UIViewGroup* viewGroup = static_cast<UIViewGroup*>(rootView);
    Paint paint;

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);

    paint.SetStyle(Paint::PaintStyle::FILL_STYLE);
    paint.SetFillColor(Color::Red());

    canvas_->DrawRect({RECT_X, RECT_Y}, RECT_HEIGHT, RECT_WIDTH, paint);
    viewGroup->Add(canvas_);
    
    canvas_->ClearRect({RECT_X + RECT_X / 2, RECT_Y + RECT_Y / 2},
                      RECT_HEIGHT / 2, RECT_WIDTH / 2);
    EXPECT_EQ(canvas_->GetStartPos().x, RECT_X + RECT_X / 2);
    EXPECT_EQ(canvas_->GetStartPos().y, RECT_Y + RECT_Y / 2);

    viewGroup->Remove(canvas_);

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);
    paint.SetStyle(Paint::PaintStyle::FILL_STYLE);
    paint.SetFillColor(Color::Blue());
    canvas_->StrokeRect({0, 0}, RECT_HEIGHT, RECT_WIDTH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, 0);
    EXPECT_EQ(canvas_->GetStartPosition().y, 0);

    canvas_->ClearRect({RECT_X - 10, RECT_Y - 10},
                       RECT_HEIGHT + 10, RECT_WIDTH + 10);
    EXPECT_EQ(canvas_->GetStartPos().x, RECT_X - 10);
    EXPECT_EQ(canvas_->GetStartPos().y, RECT_Y - 10);
    viewGroup->Remove(canvas_);
}
#if GRAPHIC_ENABLE_DRAW_IMAGE_FLAG
/**
 * @tc.name: UICanvasDrawImage_001
 * @tc.desc: Verify DrawImage function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasDrawImage_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    RootView* rootView = RootView::GetInstance();
    UIViewGroup* viewGroup = static_cast<UIViewGroup*>(rootView);
    Paint paint;

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);

    canvas_->DrawImage({0, 0}, JPEG_IMAGE_PATH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, 0);
    EXPECT_EQ(canvas_->GetStartPosition().y, 0);
    
    canvas_->ClearRect({RECT_X + RECT_X / DOUBLENUMBER, RECT_Y + RECT_Y / DOUBLENUMBER},
                       RECT_HEIGHT / DOUBLENUMBER, RECT_WIDTH / DOUBLENUMBER);
    EXPECT_EQ(canvas_->GetStartPos().x, RECT_X + RECT_X / DOUBLENUMBER);
    EXPECT_EQ(canvas_->GetStartPos().y, RECT_Y + RECT_Y / DOUBLENUMBER);

    viewGroup->Remove(canvas_);

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);
    
    canvas_->DrawImage({IMAGE_X, IMAGE_Y}, JPEG_IMAGE_PATH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, IMAGE_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, IMAGE_Y);

    canvas_->DrawImage({IMAGE_X, IMAGE_Y}, JPEG_IMAGE_PATH, paint);
    EXPECT_EQ(canvas_->GetStartPosition().x, IMAGE_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, IMAGE_Y);
    viewGroup->Remove(canvas_);
}

/**
 * @tc.name: UICanvasDrawImage_002
 * @tc.desc: Verify DrawImage function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasDrawImage_002, TestSize.Level1)
997
{
998 999 1000 1001
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
1002 1003 1004 1005 1006
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
    RootView* rootView = RootView::GetInstance();
    UIViewGroup* viewGroup = static_cast<UIViewGroup*>(rootView);
    Paint paint;

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);

    canvas_->DrawImage({0, 0}, JPEG_IMAGE_PATH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, 0);
    EXPECT_EQ(canvas_->GetStartPosition().y, 0);

    canvas_->ClearRect({RECT_X + RECT_X / DOUBLENUMBER, RECT_Y + RECT_Y / DOUBLENUMBER},
                       RECT_HEIGHT / DOUBLENUMBER, RECT_WIDTH / DOUBLENUMBER);
    EXPECT_EQ(canvas_->GetStartPos().x, RECT_X + RECT_X / DOUBLENUMBER);
    EXPECT_EQ(canvas_->GetStartPos().y, RECT_Y + RECT_Y / DOUBLENUMBER);

    viewGroup->Remove(canvas_);

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);

    canvas_->DrawImage({IMAGE_X, IMAGE_Y}, PNG_1_PALETTE_IMAGE_PATH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, IMAGE_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, IMAGE_Y);

    canvas_->DrawImage({IMAGE_X, IMAGE_Y}, PNG_1_PALETTE_IMAGE_PATH, paint);
    EXPECT_EQ(canvas_->GetStartPosition().x, IMAGE_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, IMAGE_Y);
    viewGroup->Remove(canvas_);
}

/**
 * @tc.name: UICanvasDrawImage_003
 * @tc.desc: Verify DrawImage function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasDrawImage_003, TestSize.Level1)
{
    // ͼ�β���
1050 1051 1052 1053
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
1054 1055 1056 1057
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
1058

1059 1060 1061
    RootView* rootView = RootView::GetInstance();
    UIViewGroup* viewGroup = static_cast<UIViewGroup*>(rootView);
    Paint paint;
1062

1063 1064 1065
    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);
1066

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
    canvas_->DrawImage({0, 0}, JPEG_IMAGE_PATH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, 0);
    EXPECT_EQ(canvas_->GetStartPosition().y, 0);

    canvas_->ClearRect({RECT_X + RECT_X / DOUBLENUMBER, RECT_Y + RECT_Y / DOUBLENUMBER},
                       RECT_HEIGHT / DOUBLENUMBER, RECT_WIDTH / DOUBLENUMBER);
    EXPECT_EQ(canvas_->GetStartPos().x, RECT_X + RECT_X / DOUBLENUMBER);
    EXPECT_EQ(canvas_->GetStartPos().y, RECT_Y + RECT_Y / DOUBLENUMBER);

    viewGroup->Remove(canvas_);

    viewGroup->SetPosition(0, 0);
    viewGroup->SetWidth(WIDTH);
    viewGroup->SetHeight(HEIGHT);

    canvas_->DrawImage({IMAGE_X, IMAGE_Y}, GIF_IMAGE_PATH, paint);
    viewGroup->Add(canvas_);
    EXPECT_EQ(canvas_->GetStartPosition().x, IMAGE_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, IMAGE_Y);

    canvas_->DrawImage({IMAGE_X, IMAGE_Y}, GIF_IMAGE_PATH, paint);
    EXPECT_EQ(canvas_->GetStartPosition().x, IMAGE_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, IMAGE_Y);
    viewGroup->Remove(canvas_);
}
#endif

#if GRAPHIC_ENABLE_DRAW_TEXT_FLAG
/**
 * @tc.name: UICanvasStrokeText_001
 * @tc.desc: Verify StrokeText function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasStrokeText_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
}

/**
 * @tc.name: UICanvasStrokeText_002
 * @tc.desc: Verify StrokeText function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasStrokeText_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;
    canvas_->StrokeText("hello world", {POS_X, POS_Y}, fontStyle, *paint_);

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(canvas_->GetStartPosition().x, POS_X);
    EXPECT_EQ(canvas_->GetStartPosition().y, POS_Y);
}
#endif

/**
 * @tc.name: UICanvasMeasureText_001
 * @tc.desc: Verify MeasureText function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasMeasureText_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
}

/**
 * @tc.name: UICanvasMeasureText_001
 * @tc.desc: Verify MeasureText function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasMeasureText_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;
    canvas_->MeasureText("hello world", fontStyle);

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
}

/**
 * @tc.name: UICanvasSetScale_001
 * @tc.desc: Verify SetScale function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetScale_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->Scale(SCALE_X, SCALE_Y);

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetScaleX(), SCALE_X);
    EXPECT_EQ(paint_->GetScaleY(), SCALE_Y);
}

/**
 * @tc.name: UICanvasSetScale_002
 * @tc.desc: Verify SetScale function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetScale_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->Scale(SCALE_X, SCALE_Y);
#if GRAPHIC_ENABLE_DRAW_TEXT_FLAG
    canvas_->StrokeText("hello world", {POS_X, POS_Y}, fontStyle, *paint_);
#endif

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetScaleX(), SCALE_X);
    EXPECT_EQ(paint_->GetScaleY(), SCALE_Y);
}

/**
 * @tc.name: UICanvasSetTranslate_001
 * @tc.desc: Verify SetTranslate function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetTranslate_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->Translate(TRANSLATE_X, TRANSLATE_Y);

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetTranslateX(), TRANSLATE_X);
    EXPECT_EQ(paint_->GetTranslateY(), TRANSLATE_Y);
}

/**
 * @tc.name: UICanvasSetTranslate_002
 * @tc.desc: Verify SetTranslate function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetTranslate_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->Translate(TRANSLATE_X, TRANSLATE_Y);
#if GRAPHIC_ENABLE_DRAW_TEXT_FLAG
    canvas_->StrokeText("hello world", {POS_X, POS_Y}, fontStyle, *paint_);
#endif

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetTranslateX(), TRANSLATE_X);
    EXPECT_EQ(paint_->GetTranslateY(), TRANSLATE_Y);
}

/**
 * @tc.name: UICanvasTransform_001
 * @tc.desc: Verify Transform function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasTransform_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->Transform(SCALE_X, SHEAR_X, SHEAR_Y, SCALE_Y, TRANSLATE_X, TRANSLATE_Y);

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetScaleX(), SCALE_X);
    EXPECT_EQ(paint_->GetScaleY(), SCALE_Y);
    EXPECT_EQ(paint_->GetTranslateX(), TRANSLATE_X);
    EXPECT_EQ(paint_->GetTranslateY(), TRANSLATE_Y);
1406 1407 1408
}

/**
1409 1410
 * @tc.name: UICanvasTransform_002
 * @tc.desc: Verify Transform function, equal.
1411 1412
 * @tc.type: FUNC
 */
1413
HWTEST_F(UICanvasTest, UICanvasTransform_002, TestSize.Level1)
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

1432 1433 1434 1435
    paint_->Transform(SCALE_X, SHEAR_X, SHEAR_Y, SCALE_Y, TRANSLATE_X, TRANSLATE_Y);
#if GRAPHIC_ENABLE_DRAW_TEXT_FLAG
    canvas_->StrokeText("hello world", {POS_X, POS_Y}, fontStyle, *paint_);
#endif
1436 1437 1438 1439 1440 1441

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
1442 1443
    EXPECT_EQ(paint_->GetScaleX(), SCALE_X);
    EXPECT_EQ(paint_->GetScaleY(), SCALE_Y);
1444 1445 1446 1447 1448
    EXPECT_EQ(paint_->GetTranslateX(), TRANSLATE_X);
    EXPECT_EQ(paint_->GetTranslateY(), TRANSLATE_Y);
}

/**
1449 1450
 * @tc.name: UICanvasSetTransform_001
 * @tc.desc: Verify SetTransform function, equal.
1451 1452
 * @tc.type: FUNC
 */
1453
HWTEST_F(UICanvasTest, UICanvasSetTransform_001, TestSize.Level0)
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

1472
    paint_->SetTransform(SCALE_X, SHEAR_X, SHEAR_Y, SCALE_Y, TRANSLATE_X, TRANSLATE_Y);
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetScaleX(), SCALE_X);
    EXPECT_EQ(paint_->GetScaleY(), SCALE_Y);
    EXPECT_EQ(paint_->GetTranslateX(), TRANSLATE_X);
    EXPECT_EQ(paint_->GetTranslateY(), TRANSLATE_Y);
}

/**
1486
 * @tc.name: UICanvasSetTransform_002
1487 1488 1489
 * @tc.desc: Verify SetTransform function, equal.
 * @tc.type: FUNC
 */
1490
HWTEST_F(UICanvasTest, UICanvasSetTransform_002, TestSize.Level1)
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->SetTransform(SCALE_X, SHEAR_X, SHEAR_Y, SCALE_Y, TRANSLATE_X, TRANSLATE_Y);
1510 1511 1512
#if GRAPHIC_ENABLE_DRAW_TEXT_FLAG
    canvas_->StrokeText("hello world", {POS_X, POS_Y}, fontStyle, *paint_);
#endif
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetScaleX(), SCALE_X);
    EXPECT_EQ(paint_->GetScaleY(), SCALE_Y);
    EXPECT_EQ(paint_->GetTranslateX(), TRANSLATE_X);
    EXPECT_EQ(paint_->GetTranslateY(), TRANSLATE_Y);
}

/**
 * @tc.name: UICanvasGlobalAlpha_001
 * @tc.desc: Verify GlobalAlpha function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasGlobalAlpha_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    paint_->SetGlobalAlpha(GLOBALALPHA);
    EXPECT_EQ(paint_->GetGlobalAlpha(), GLOBALALPHA);
}

/**
 * @tc.name: UICanvasGlobalAlpha_002
 * @tc.desc: Verify GlobalAlpha function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasGlobalAlpha_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    ColorType color = Color::Red();
    paint_->SetStyle(Paint::PaintStyle::STROKE_FILL_STYLE);
    paint_->SetFillColor(color);
    canvas_->DrawRect({RECT_X, RECT_Y}, RECT_WIDTH, RECT_HEIGHT, *paint_);
    paint_->SetStyle(Paint::PaintStyle::FILL_STYLE);
    color = Color::Green();
    paint_->SetFillColor(color);
    paint_->SetGlobalAlpha(GLOBALALPHA);
    canvas_->DrawRect({POS_X, POS_Y}, WIDTH, HEIGHT, *paint_);

    EXPECT_EQ(paint_->GetGlobalAlpha(), GLOBALALPHA);
}

/**
 * @tc.name: UICanvasGetGlobalAlpha_001
 * @tc.desc: Verify GetGlobalAlpha function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasGetGlobalAlpha_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    paint_->SetGlobalAlpha(GLOBALALPHA);
    EXPECT_EQ(paint_->GetGlobalAlpha(), GLOBALALPHA);
}

/**
 * @tc.name: UICanvasGetGlobalAlpha_002
 * @tc.desc: Verify GetGlobalAlpha function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasGetGlobalAlpha_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    ColorType color = Color::Green();
    paint_->SetStyle(Paint::PaintStyle::FILL_STYLE);
    paint_->SetFillColor(color);
    paint_->SetGlobalAlpha(GLOBALALPHA);
    canvas_->DrawRect({POS_X, POS_Y}, WIDTH, HEIGHT, *paint_);

    EXPECT_EQ(paint_->GetGlobalAlpha(), GLOBALALPHA);
}

1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
/**
 * @tc.name: UICanvasSetGlobalCompositeOperation_001
 * @tc.desc: Verify SetGlobalCompositeOperation function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetGlobalCompositeOperation_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    paint_->SetGlobalCompositeOperation(OHOS::COPY);
    EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::COPY);
}

/**
 * @tc.name: UICanvasSetGlobalCompositeOperation_002
 * @tc.desc: Verify SetGlobalCompositeOperation function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetGlobalCompositeOperation_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    paint_->SetFillColor(Color::Blue());
    canvas_->BeginPath();
    canvas_->MoveTo({START1_X, START1_Y});
    canvas_->LineTo({START1_X, POS_Y});
    canvas_->LineTo({POS_X, POS_Y});
    canvas_->LineTo({POS_X, START1_Y});
    canvas_->ClosePath();
    canvas_->FillPath(*paint_);
    paint_->SetGlobalCompositeOperation(OHOS::COPY);

    paint_->SetFillColor(Color::Green());
    canvas_->BeginPath();
    canvas_->MoveTo({LINE_X, LINE_X});
    canvas_->LineTo({LINE_X, LINE_Y});
    canvas_->LineTo({LINE_Y, LINE_Y});
    canvas_->LineTo({LINE_Y, LINE_X});
    canvas_->ClosePath();
    canvas_->FillPath(*paint_);

    EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::COPY);
}

/**
 * @tc.name: UICanvasGetGlobalCompositeOperation_001
 * @tc.desc: Verify GetGlobalCompositeOperation function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasGetGlobalCompositeOperation_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    paint_->SetGlobalCompositeOperation(OHOS::SOURCE_OVER);
    EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::SOURCE_OVER);
}

/**
 * @tc.name: UICanvasGetGlobalCompositeOperation_002
 * @tc.desc: Verify GetGlobalCompositeOperation function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasGetGlobalCompositeOperation_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    
    paint_->SetFillColor(Color::Blue());
    canvas_->BeginPath();
    canvas_->MoveTo({LINE_X, LINE_X});
    canvas_->LineTo({LINE_X, LINE_Y});
    canvas_->LineTo({LINE_Y, LINE_Y});
    canvas_->LineTo({LINE_Y, LINE_X});
    canvas_->ClosePath();
    canvas_->FillPath(*paint_);
    paint_->SetGlobalCompositeOperation(OHOS::SOURCE_OVER);
    
    paint_->SetFillColor(Color::Green());
    canvas_->BeginPath();
    canvas_->MoveTo({START1_X, START1_Y});
    canvas_->LineTo({START1_X, POS_Y});
    canvas_->LineTo({POS_X, POS_Y});
    canvas_->LineTo({POS_X, START1_Y});
    canvas_->ClosePath();
    canvas_->FillPath(*paint_);
    EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::SOURCE_OVER);
}

1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
/**
 * @tc.name: UICanvasSave_001
 * @tc.desc: Verify Save function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSave_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    ColorType color = Color::Red();
    paint_->SetFillColor(color);
    canvas_->Save(*paint_);
    EXPECT_EQ(paint_->GetFillColor().full, color.full);
}

/**
 * @tc.name: UICanvasSave_002
 * @tc.desc: Verify Save function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSave_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    ColorType color = Color::Red();
    paint_->SetFillColor(color);
    canvas_->Save(*paint_);
    canvas_->DrawRect({RECT_X, RECT_Y}, RECT_WIDTH, RECT_HEIGHT, *paint_);
    *paint_ = canvas_->Restore();
    canvas_->DrawRect({POS_X, POS_Y}, WIDTH, HEIGHT, *paint_);

    EXPECT_EQ(paint_->GetFillColor().full, color.full);
}

/**
 * @tc.name: UICanvasRestore_001
 * @tc.desc: Verify Restore function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasRestore_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    ColorType color = Color::Red();
    paint_->SetFillColor(color);
    canvas_->Save(*paint_);
    *paint_ = canvas_->Restore();

    EXPECT_EQ(paint_->GetFillColor().full, color.full);
}

/**
 * @tc.name: UICanvasRestore_002
 * @tc.desc: Verify Restore function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasRestore_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    ColorType color = Color::Red();
    paint_->SetFillColor(color);
    canvas_->Save(*paint_);
    canvas_->DrawRect({POS_X, POS_Y}, RECT_WIDTH, RECT_HEIGHT, *paint_);
    *paint_ = canvas_->Restore();
    canvas_->DrawRect({RECT_X, RECT_Y}, WIDTH, HEIGHT, *paint_);

    EXPECT_EQ(paint_->GetFillColor().full, color.full);
}
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
#if GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG
HWTEST_F(UICanvasTest, UICanvasShadowColor_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    ColorType color = Color::Red();
    paint_->SetShadowColor(color);
    EXPECT_EQ(paint_->GetShadowColor().full, color.full);
S
shiqichang 已提交
1853
    EXPECT_EQ(paint_->HaveShadow(), true);
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
}
HWTEST_F(UICanvasTest, UICanvasShadowColor_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    ColorType color = Color::Red();
    paint_->SetShadowColor(color);
    EXPECT_EQ(paint_->GetShadowColor().full, color.full);
}
#endif

#if GRAPHIC_ENABLE_BLUR_EFFECT_FLAG
HWTEST_F(UICanvasTest, UICanvasShadowBlur_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetShadowBlur(RADIUS);
    EXPECT_EQ(paint_->GetShadowBlur(), RADIUS);
}

HWTEST_F(UICanvasTest, UICanvasShadowBlur_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetShadowBlur(RADIUS);
    EXPECT_EQ(paint_->GetShadowBlur(), RADIUS);
}
#endif

#if GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG
HWTEST_F(UICanvasTest, UICanvasShadowOffsetX_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetShadowOffsetX(RADIUS);
    EXPECT_EQ(paint_->GetShadowOffsetX(), RADIUS);
}

HWTEST_F(UICanvasTest, UICanvasShadowOffsetX_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetShadowOffsetX(RADIUS);
    EXPECT_EQ(paint_->GetShadowOffsetX(), RADIUS);
}

HWTEST_F(UICanvasTest, UICanvasShadowOffsetY_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetShadowOffsetY(RADIUS);
    EXPECT_EQ(paint_->GetShadowOffsetY(), RADIUS);
}

HWTEST_F(UICanvasTest, UICanvasShadowOffsetY_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetShadowOffsetY(RADIUS);
    EXPECT_EQ(paint_->GetShadowOffsetY(), RADIUS);
}
#endif

#if GRAPHIC_ENABLE_GRADIENT_FILL_FLAG
HWTEST_F(UICanvasTest, UICanvasCreateLinearGradient_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->createLinearGradient(START_X, START_Y, END_X, END_Y);
    paint_->SetStyle(Paint::GRADIENT);
    EXPECT_EQ(paint_->GetLinearGradientPoint().x0, START_X);
    EXPECT_EQ(paint_->GetLinearGradientPoint().y0, START_Y);
    EXPECT_EQ(paint_->GetLinearGradientPoint().x1, END_X);
    EXPECT_EQ(paint_->GetLinearGradientPoint().y1, END_Y);
S
shiqichang 已提交
1944
    EXPECT_EQ(paint_->GetGradient(), Paint::Gradient::Linear);
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072
}

HWTEST_F(UICanvasTest, UICanvasCreateLinearGradient_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->createLinearGradient(START_X, START_Y, END_X, END_Y);
    paint_->SetStyle(Paint::GRADIENT);
    EXPECT_EQ(paint_->GetLinearGradientPoint().x0, START_X);
    EXPECT_EQ(paint_->GetLinearGradientPoint().y0, START_Y);
    EXPECT_EQ(paint_->GetLinearGradientPoint().x1, END_X);
    EXPECT_EQ(paint_->GetLinearGradientPoint().y1, END_Y);
}

HWTEST_F(UICanvasTest, UICanvasCreateRadialGradient_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->createRadialGradient(START_X, START_Y, START_R, END_X, END_Y, END_R);
    paint_->SetStyle(Paint::GRADIENT);
    EXPECT_EQ(paint_->GetRadialGradientPoint().x0, START_X);
    EXPECT_EQ(paint_->GetRadialGradientPoint().y0, START_Y);
    EXPECT_EQ(paint_->GetRadialGradientPoint().r0, START_R);
    EXPECT_EQ(paint_->GetRadialGradientPoint().x1, END_X);
    EXPECT_EQ(paint_->GetRadialGradientPoint().y1, END_Y);
    EXPECT_EQ(paint_->GetRadialGradientPoint().r1, END_R);
}

HWTEST_F(UICanvasTest, UICanvasCreateRadialGradient_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->createRadialGradient(START_X, START_Y, START_R, END_X, END_Y, END_R);
    paint_->SetStyle(Paint::GRADIENT);
    EXPECT_EQ(paint_->GetRadialGradientPoint().x0, START_X);
    EXPECT_EQ(paint_->GetRadialGradientPoint().y0, START_Y);
    EXPECT_EQ(paint_->GetRadialGradientPoint().r0, START_R);
    EXPECT_EQ(paint_->GetRadialGradientPoint().x1, END_X);
    EXPECT_EQ(paint_->GetRadialGradientPoint().y1, END_Y);
    EXPECT_EQ(paint_->GetRadialGradientPoint().r1, END_R);
}
#endif

#if GRAPHIC_ENABLE_PATTERN_FILL_FLAG
HWTEST_F(UICanvasTest, UICanvasCreatePattern_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->CreatePattern(RED_IMAGE_PATH, REPEAT);
    EXPECT_EQ(paint_->GetPatternImage(), RED_IMAGE_PATH);
    EXPECT_EQ(paint_->GetPatternRepeatMode(), REPEAT);
}

HWTEST_F(UICanvasTest, UICanvasCreatePattern_002, TestSize.Level0)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->CreatePattern(RED_IMAGE_PATH, REPEAT);
    EXPECT_EQ(paint_->GetPatternImage(), RED_IMAGE_PATH);
    EXPECT_EQ(paint_->GetPatternRepeatMode(), REPEAT);
}
#endif

#if GRAPHIC_ENABLE_GRADIENT_FILL_FLAG
HWTEST_F(UICanvasTest, UICanvasAddColorStop_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    ColorType colorStop0 = Color::Yellow();
    ColorType colorStop1 = Color::White();
    ColorType colorStop2 = Color::Green();
    ColorType colorStop3 = Color::Blue();
    paint_->createLinearGradient(START_X, START_Y, END_X, END_Y);
    paint_->addColorStop(COLOR_STOP_0, colorStop0);
    paint_->addColorStop(COLOR_STOP_1, colorStop1);
    paint_->addColorStop(COLOR_STOP_2, colorStop2);
    paint_->addColorStop(COLOR_STOP_3, colorStop3);
    List<Paint::StopAndColor> stopAndColor = paint_->getStopAndColor();
    EXPECT_EQ(stopAndColor.Head()->data_.stop, COLOR_STOP_0);
    EXPECT_EQ(stopAndColor.Head()->data_.color.full, colorStop0.full);
    stopAndColor.PopFront();
    EXPECT_EQ(stopAndColor.Head()->data_.stop, COLOR_STOP_1);
    EXPECT_EQ(stopAndColor.Head()->data_.color.full, colorStop1.full);
    stopAndColor.PopFront();
    EXPECT_EQ(stopAndColor.Head()->data_.stop, COLOR_STOP_2);
    EXPECT_EQ(stopAndColor.Head()->data_.color.full, colorStop2.full);
    stopAndColor.PopFront();
    EXPECT_EQ(stopAndColor.Head()->data_.stop, COLOR_STOP_3);
    EXPECT_EQ(stopAndColor.Head()->data_.color.full, colorStop3.full);
    stopAndColor.PopFront();
}

HWTEST_F(UICanvasTest, UICanvasFillStyle_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetStyle(Paint::PaintStyle::GRADIENT);
    EXPECT_EQ(paint_->GetStyle(), Paint::PaintStyle::GRADIENT);
    paint_->SetStyle(Paint::PaintStyle::PATTERN);
    EXPECT_EQ(paint_->GetStyle(), Paint::PaintStyle::PATTERN);
}

HWTEST_F(UICanvasTest, UICanvasStrokeStyle_001, TestSize.Level1)
{
    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    paint_->SetStyle(Paint::PaintStyle::GRADIENT);
    EXPECT_EQ(paint_->GetStyle(), Paint::PaintStyle::GRADIENT);
    paint_->SetStyle(Paint::PaintStyle::PATTERN);
    EXPECT_EQ(paint_->GetStyle(), Paint::PaintStyle::PATTERN);
}
#endif
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105

/**
 * @tc.name: UICanvasSetRotate_001
 * @tc.desc: Verify SetRotate function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetRotate_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->Rotate(ROTATE);

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetRotateAngle(), ROTATE);
M
mamingshuai 已提交
2106
}
2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144


/**
 * @tc.name: UICanvasSetRotate_002
 * @tc.desc: Verify SetRotate function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasSetRotate_002, TestSize.Level1)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    UICanvas::FontStyle fontStyle;
    fontStyle.align = TEXT_ALIGNMENT_CENTER;
    fontStyle.direct = TEXT_DIRECT_LTR;
    fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME;
    fontStyle.fontSize = FONT_SIZE;
    fontStyle.letterSpace = LETTER_SPACE;

    paint_->Rotate(ROTATE);
#if GRAPHIC_ENABLE_DRAW_TEXT_FLAG
    canvas_->StrokeText("hello world", {POS_X, POS_Y}, fontStyle, *paint_);
#endif

    EXPECT_EQ(fontStyle.align, TEXT_ALIGNMENT_CENTER);
    EXPECT_EQ(fontStyle.direct, TEXT_DIRECT_LTR);
    EXPECT_EQ(fontStyle.fontName, DEFAULT_VECTOR_FONT_FILENAME);
    EXPECT_EQ(fontStyle.fontSize, FONT_SIZE);
    EXPECT_EQ(fontStyle.letterSpace, LETTER_SPACE);
    EXPECT_EQ(paint_->GetRotateAngle(), ROTATE);
}
S
shiqichang 已提交
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192

/**
 * @tc.name: UICanvasInitDash_001
 * @tc.desc: Verify InitDash function, equal.
 * @tc.type: FUNC
 */
HWTEST_F(UICanvasTest, UICanvasInitDash_001, TestSize.Level0)
{
    if (canvas_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }

    if (paint_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
#if GRAPHIC_ENABLE_DASH_GENERATE_FLAG
    Paint* paint3 = new Paint();
    paint_->InitDash(*paint3);
    EXPECT_EQ(paint_->GetLineDash(), nullptr);
    delete paint3;
    paint3 = nullptr;
#endif
    Paint* paint1 = new Paint();
    paint1->Init(*paint_);
    EXPECT_EQ(paint1->GetChangeFlag(), false);

    ColorType color = Color::Red();
    paint1->SetStrokeStyle(color);
    EXPECT_EQ(paint1->GetStrokeColor().full, color.full);
    color = Color::Yellow();
    paint1->SetFillStyle(color);
    EXPECT_EQ(paint1->GetFillColor().full, color.full);

    paint1->SetStrokeStyle(Paint::PaintStyle::GRADIENT);
    EXPECT_EQ(paint1->GetStyle(), Paint::PaintStyle::GRADIENT);
    paint1->SetFillStyle(Paint::PaintStyle::STROKE_FILL_STYLE);
    EXPECT_EQ(paint1->GetStyle(), Paint::PaintStyle::STROKE_FILL_STYLE);

    paint1->GetTransAffine();
    paint1->SetUICanvas(canvas_);
    EXPECT_EQ(paint1->GetUICanvas(), canvas_);

    EXPECT_EQ(paint1->HaveComposite(), false);
    delete paint1;
    paint1 = nullptr;
}
2193
} // namespace OHOS