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 Testing::MockCanvas canvas;
42 } // namespace
43
44 class EllipsePainterTestNg : public testing::Test {
45 public:
46 void CallBack(Testing::MockCanvas& rSCanvas);
47 };
48
CallBack(Testing::MockCanvas & rSCanvas)49 void EllipsePainterTestNg::CallBack(Testing::MockCanvas& rSCanvas)
50 {
51 EXPECT_CALL(rSCanvas, AttachBrush(_)).WillOnce(ReturnRef(rSCanvas));
52 EXPECT_CALL(rSCanvas, DetachBrush()).WillOnce(ReturnRef(rSCanvas));
53 EXPECT_CALL(rSCanvas, AttachPen(_)).WillOnce(ReturnRef(rSCanvas));
54 EXPECT_CALL(rSCanvas, DetachPen()).WillOnce(ReturnRef(rSCanvas));
55 }
56
57 /**
58 * @tc.name: EllipsePainterTestNg001
59 * @tc.desc: Test cast to EllipsePainterTestNg
60 * @tc.type: FUNC
61 */
62 HWTEST_F(EllipsePainterTestNg, EllipsePainterTestNg001, TestSize.Level1)
63 {
64 /**
65 * @tc.steps1: create canvas and shapePaintProperty object.
66 */
67 CallBack(canvas);
68 NG::ShapePaintProperty shapePaintProperty;
69
70 /**
71 * @tc.steps2: call DrawEllipse.
72 * @tc.expected: .
73 */
74 NG::EllipsePainter::DrawEllipse(canvas, TEST_RECT, shapePaintProperty);
75 EXPECT_FALSE(shapePaintProperty.HasStrokeWidth());
76
77 /**
78 * @tc.steps3: call DrawEllipse and UpdateStrokeWidth with STROKE_WIDTH.
79 * @tc.expected: .
80 */
81 shapePaintProperty.UpdateStrokeWidth(STROKE_WIDTH);
82 CallBack(canvas);
83 NG::EllipsePainter::DrawEllipse(canvas, TEST_RECT, shapePaintProperty);
84 EXPECT_TRUE(shapePaintProperty.HasStrokeWidth());
85 }
86 } // namespace OHOS::Ace
87