• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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, Hardware
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 "utils/rect.h"
19 #include "utils/round_rect.h"
20 #include "utils/scalar.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class RoundRectTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 };
35 
SetUpTestCase()36 void RoundRectTest::SetUpTestCase() {}
TearDownTestCase()37 void RoundRectTest::TearDownTestCase() {}
SetUp()38 void RoundRectTest::SetUp() {}
TearDown()39 void RoundRectTest::TearDown() {}
40 
41 /**
42  * @tc.name: RoundRectCreateAndDestroy001
43  * @tc.desc:
44  * @tc.type: FUNC
45  * @tc.require:AR000GGNV3
46  * @tc.author:
47  */
48 HWTEST_F(RoundRectTest, RoundRectCreateAndDestroy001, TestSize.Level1)
49 {
50     // The best way to create RoundRect.
51     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>();
52     ASSERT_TRUE(roundRect != nullptr);
53 }
54 
55 /**
56  * @tc.name: RoundRectCreateAndDestroy002
57  * @tc.desc:
58  * @tc.type: FUNC
59  * @tc.require:AR000GGNV3
60  * @tc.author:
61  */
62 HWTEST_F(RoundRectTest, RoundRectCreateAndDestroy002, TestSize.Level1)
63 {
64     // The best way to create RoundRect.
65     const RoundRect roundRect1;
66     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>(roundRect1);
67     ASSERT_TRUE(roundRect != nullptr);
68 }
69 
70 /**
71  * @tc.name: RoundRectCreateAndDestroy003
72  * @tc.desc:
73  * @tc.type: FUNC
74  * @tc.require:AR000GGNV3
75  * @tc.author:
76  */
77 HWTEST_F(RoundRectTest, RoundRectRectCreateAndDestroy003, TestSize.Level1)
78 {
79     // The best way to create RoundRect.
80     Rect rect;
81     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>(rect, 12.6f, 77.4f);
82     ASSERT_TRUE(roundRect != nullptr);
83 }
84 
85 /**
86  * @tc.name: RoundRectCreateAndDestroy004
87  * @tc.desc:
88  * @tc.type: FUNC
89  * @tc.require:AR000GGNV3
90  * @tc.author:
91  */
92 HWTEST_F(RoundRectTest, RoundRectRectCreateAndDestroy004, TestSize.Level1)
93 {
94     // The best way to create RoundRect.
95     Rect rect;
96     std::vector<Point> radiusXY = { { 1, 3 } };
97     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>(rect, radiusXY);
98     ASSERT_TRUE(roundRect != nullptr);
99 }
100 
101 /**
102  * @tc.name: RoundRectSetAndGetCornerRadius001
103  * @tc.desc:
104  * @tc.type: FUNC
105  * @tc.require:AR000GGNV3
106  * @tc.author:
107  */
108 HWTEST_F(RoundRectTest, RoundRectRectSetAndGetCornerRadius001, TestSize.Level1)
109 {
110     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>();
111     ASSERT_TRUE(roundRect != nullptr);
112     roundRect->SetCornerRadius(Drawing::RoundRect::TOP_RIGHT_POS, 111.3f, 84.5f);
113     ASSERT_EQ(roundRect->GetCornerRadius(Drawing::RoundRect::TOP_RIGHT_POS).GetX(), 111.3f);
114     ASSERT_EQ(roundRect->GetCornerRadius(Drawing::RoundRect::TOP_RIGHT_POS).GetY(), 84.5f);
115 }
116 
117 /**
118  * @tc.name: RoundRectSetAndGetCornerRadius002
119  * @tc.desc:
120  * @tc.type: FUNC
121  * @tc.require:AR000GGNV3
122  * @tc.author:
123  */
124 HWTEST_F(RoundRectTest, RoundRectSetAndGetCornerRadius002, TestSize.Level1)
125 {
126     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>();
127     ASSERT_TRUE(roundRect != nullptr);
128     roundRect->SetCornerRadius(Drawing::RoundRect::BOTTOM_RIGHT_POS, 120.0f, 90.5f);
129     ASSERT_EQ(roundRect->GetCornerRadius(Drawing::RoundRect::BOTTOM_RIGHT_POS).GetX(), 120.0f);
130     ASSERT_EQ(roundRect->GetCornerRadius(Drawing::RoundRect::BOTTOM_RIGHT_POS).GetY(), 90.5f);
131 }
132 
133 /**
134  * @tc.name: RoundRectSetAndGetRect001
135  * @tc.desc:
136  * @tc.type: FUNC
137  * @tc.require:AR000GGNV3
138  * @tc.author:
139  */
140 HWTEST_F(RoundRectTest, RoundRectSetAndGetRect001, TestSize.Level1)
141 {
142     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>();
143     ASSERT_TRUE(roundRect != nullptr);
144     Rect rect1;
145     roundRect->SetRect(rect1);
146     Rect rect2 = roundRect->GetRect();
147     EXPECT_EQ(rect2, rect1);
148 }
149 
150 /**
151  * @tc.name: RoundRectSetAndGetRect002
152  * @tc.desc:
153  * @tc.type: FUNC
154  * @tc.require:AR000GGNV3
155  * @tc.author:
156  */
157 HWTEST_F(RoundRectTest, RoundRectSetAndGetRect002, TestSize.Level1)
158 {
159     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>();
160     ASSERT_TRUE(roundRect != nullptr);
161     const Rect rect2;
162     roundRect->SetRect(rect2);
163     EXPECT_EQ(rect2, roundRect->GetRect());
164 }
165 
166 /**
167  * @tc.name: RoundRectRoundRectOffsetTest001
168  * @tc.desc:
169  * @tc.type: FUNC
170  * @tc.require:AR000GGNV3
171  * @tc.author:
172  */
173 HWTEST_F(RoundRectTest, RoundRectRoundRectOffsetTest001, TestSize.Level1)
174 {
175     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>();
176     ASSERT_TRUE(roundRect != nullptr);
177     roundRect->Offset(54.6f, 432.8f);
178 }
179 
180 /**
181  * @tc.name: RoundRectRoundRectOffsetTest002
182  * @tc.desc:
183  * @tc.type: FUNC
184  * @tc.require:AR000GGNV3
185  * @tc.author:
186  */
187 HWTEST_F(RoundRectTest, RoundRectRoundRectOffsetTest002, TestSize.Level1)
188 {
189     std::unique_ptr<RoundRect> roundRect = std::make_unique<RoundRect>();
190     ASSERT_TRUE(roundRect != nullptr);
191     roundRect->Offset(200.0f, 40.8f);
192 }
193 } // namespace Drawing
194 } // namespace Rosen
195 } // namespace OHOS