• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) Co.,Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 
18 #include "base/utils/utils.h"
19 
20 #define protected public
21 #define private public
22 #include "test/mock/core/rosen/mock_canvas.h"
23 
24 #include "base/geometry/ng/rect_t.h"
25 #include "core/components_ng/render/canvas_image.h"
26 #include "core/components_ng/render/drawing.h"
27 #include "core/components_ng/render/ellipse_painter.h"
28 #include "core/components_ng/render/shape_painter.h"
29 
30 #undef private
31 #undef protected
32 
33 using namespace testing;
34 using namespace testing::ext;
35 
36 namespace OHOS::Ace {
37 namespace {
38 const Dimension STROKE_WIDTH { 0.0, DimensionUnit::PX };
39 const NG::RectF TEST_RECT { 10.0f, 20.0f, 15.0f, 15.0f };
40 
41 } // namespace
42 
43 class EllipsePainterTestNg : public testing::Test {
44 public:
45     void CallBack(Testing::MockCanvas& rSCanvas);
46 };
47 
CallBack(Testing::MockCanvas & rSCanvas)48 void EllipsePainterTestNg::CallBack(Testing::MockCanvas& rSCanvas)
49 {
50     EXPECT_CALL(rSCanvas, AttachBrush(_)).WillOnce(ReturnRef(rSCanvas));
51     EXPECT_CALL(rSCanvas, DetachBrush()).WillOnce(ReturnRef(rSCanvas));
52     EXPECT_CALL(rSCanvas, AttachPen(_)).WillOnce(ReturnRef(rSCanvas));
53     EXPECT_CALL(rSCanvas, DetachPen()).WillOnce(ReturnRef(rSCanvas));
54 }
55 
56 /**
57  * @tc.name: EllipsePainterTestNg001
58  * @tc.desc: Test cast to EllipsePainterTestNg
59  * @tc.type: FUNC
60  */
61 HWTEST_F(EllipsePainterTestNg, EllipsePainterTestNg001, TestSize.Level1)
62 {
63     Testing::MockCanvas* canvasPtr = new Testing::MockCanvas();
64     Testing::MockCanvas& canvas = *canvasPtr;
65     /**
66      * @tc.steps1: create canvas and shapePaintProperty object.
67      */
68     CallBack(canvas);
69     NG::ShapePaintProperty shapePaintProperty;
70 
71     /**
72      * @tc.steps2: call DrawEllipse.
73      * @tc.expected: .
74      */
75     NG::EllipsePainter::DrawEllipse(canvas, TEST_RECT, shapePaintProperty);
76     EXPECT_FALSE(shapePaintProperty.HasStrokeWidth());
77 
78     /**
79      * @tc.steps3: call DrawEllipse and UpdateStrokeWidth with STROKE_WIDTH.
80      * @tc.expected: .
81      */
82     shapePaintProperty.UpdateStrokeWidth(STROKE_WIDTH);
83     CallBack(canvas);
84     NG::EllipsePainter::DrawEllipse(canvas, TEST_RECT, shapePaintProperty);
85     EXPECT_TRUE(shapePaintProperty.HasStrokeWidth());
86     testing::Mock::AllowLeak(canvasPtr);
87 }
88 } // namespace OHOS::Ace
89