1 /*
2  * Copyright (c) 2023 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/region.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace Drawing {
26 class RegionTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp() override;
31     void TearDown() override;
32 };
33 
SetUpTestCase()34 void RegionTest::SetUpTestCase() {}
TearDownTestCase()35 void RegionTest::TearDownTestCase() {}
SetUp()36 void RegionTest::SetUp() {}
TearDown()37 void RegionTest::TearDown() {}
38 
39 /**
40  * @tc.name: CreateRegion001
41  * @tc.desc: test for creating Regin.
42  * @tc.type: FUNC
43  * @tc.require: I766AZ
44  */
45 HWTEST_F(RegionTest, CreateRegion001, TestSize.Level1)
46 {
47     std::unique_ptr<Region> region = std::make_unique<Region>();
48     ASSERT_TRUE(region != nullptr);
49 }
50 
51 /**
52  * @tc.name: SetRectTest001
53  * @tc.desc: test for constructs a rectangular Region matching the bounds of rect.
54  * @tc.type: FUNC
55  * @tc.require: I766AZ
56  */
57 HWTEST_F(RegionTest, SetRectTest001, TestSize.Level1)
58 {
59     std::unique_ptr<Region> region = std::make_unique<Region>();
60     ASSERT_TRUE(region != nullptr);
61     RectI rectI;
62     EXPECT_FALSE(region->SetRect(rectI));
63 }
64 
65 /**
66  * @tc.name: SetRectTest002
67  * @tc.desc: test for constructs a rectangular Region matching the bounds of rect.
68  * @tc.type: FUNC
69  * @tc.require: I766AZ
70  */
71 HWTEST_F(RegionTest, SetRectTest002, TestSize.Level1)
72 {
73     std::unique_ptr<Region> region = std::make_unique<Region>();
74     ASSERT_TRUE(region != nullptr);
75     RectI rectI(0, 0, 256, 256);
76     EXPECT_TRUE(region->SetRect(rectI));
77 }
78 
79 /**
80  * @tc.name: SetPathTest001
81  * @tc.desc: test for constructs Region to match outline of path within clip.
82  * @tc.type: FUNC
83  * @tc.require: I766AZ
84  */
85 HWTEST_F(RegionTest, SetPathTest001, TestSize.Level1)
86 {
87     std::unique_ptr<Region> region = std::make_unique<Region>();
88     ASSERT_TRUE(region != nullptr);
89     Path path;
90     Region clip;
91     EXPECT_FALSE(region->SetPath(path, clip));
92 }
93 
94 /**
95  * @tc.name: SetPathTest002
96  * @tc.desc: test for constructs Region to match outline of path within clip.
97  * @tc.type: FUNC
98  * @tc.require: I766AZ
99  */
100 HWTEST_F(RegionTest, SetPathTest002, TestSize.Level1)
101 {
102     std::unique_ptr<Region> region = std::make_unique<Region>();
103     ASSERT_TRUE(region != nullptr);
104     Path path;
105     path.AddRect(1.0f, 4.0f, 3.0f, 2.0f, PathDirection::CCW_DIRECTION);
106     Region clip;
107     EXPECT_FALSE(region->SetPath(path, clip));
108 }
109 
110 /**
111  * @tc.name: IsIntersectsTest001
112  * @tc.desc: test for IsIntersects function
113  * @tc.type: FUNC
114  * @tc.require: I766AZ
115  */
116 HWTEST_F(RegionTest, IsIntersectsTest001, TestSize.Level1)
117 {
118     std::unique_ptr<Region> region = std::make_unique<Region>();
119     ASSERT_TRUE(region != nullptr);
120     Region other;
121     EXPECT_FALSE(region->IsIntersects(other));
122 }
123 
124 /**
125  * @tc.name: IsIntersectsTest002
126  * @tc.desc: test for IsIntersects function
127  * @tc.type: FUNC
128  * @tc.require: I766AZ
129  */
130 HWTEST_F(RegionTest, IsIntersectsTest002, TestSize.Level1)
131 {
132     std::unique_ptr<Region> region = std::make_unique<Region>();
133     ASSERT_TRUE(region != nullptr);
134     RectI rectI(0, 0, 256, 256);
135     region->SetRect(rectI);
136     Region other;
137     other.SetRect(rectI);
138     EXPECT_TRUE(region->IsIntersects(other));
139 }
140 
141 /**
142  * @tc.name: OpTest001
143  * @tc.desc: test for OP function with DIFFERENCE option
144  * @tc.type: FUNC
145  * @tc.require: I766AZ
146  */
147 HWTEST_F(RegionTest, OpTest001, TestSize.Level1)
148 {
149     std::unique_ptr<Region> region = std::make_unique<Region>();
150     ASSERT_TRUE(region != nullptr);
151     Region other;
152     EXPECT_FALSE(region->Op(other, RegionOp::DIFFERENCE));
153 }
154 
155 /**
156  * @tc.name: OpTest002
157  * @tc.desc: test for OP function with DIFFERENCE option
158  * @tc.type: FUNC
159  * @tc.require: I766AZ
160  */
161 HWTEST_F(RegionTest, OpTest002, TestSize.Level1)
162 {
163     std::unique_ptr<Region> region = std::make_unique<Region>();
164     ASSERT_TRUE(region != nullptr);
165     RectI rectI(0, 0, 256, 256);
166     RectI otherRectI(0, 400, 500, 600);
167     region->SetRect(rectI);
168     Region other;
169     other.SetRect(otherRectI);
170     EXPECT_TRUE(region->Op(other, RegionOp::DIFFERENCE));
171 }
172 
173 /**
174  * @tc.name: OpTest003
175  * @tc.desc: test for OP function with INTERSECT option
176  * @tc.type: FUNC
177  * @tc.require: I766AZ
178  */
179 HWTEST_F(RegionTest, OpTest003, TestSize.Level1)
180 {
181     std::unique_ptr<Region> region = std::make_unique<Region>();
182     ASSERT_TRUE(region != nullptr);
183     RectI rectI(0, 0, 256, 256);
184     RectI otherRectI(0, 0, 256, 256);
185     region->SetRect(rectI);
186     Region other;
187     other.SetRect(otherRectI);
188     EXPECT_TRUE(region->Op(other, RegionOp::INTERSECT));
189 }
190 
191 /**
192  * @tc.name: OpTest004
193  * @tc.desc: test for OP function with UNION option
194  * @tc.type: FUNC
195  * @tc.require: I766AZ
196  */
197 HWTEST_F(RegionTest, OpTest004, TestSize.Level1)
198 {
199     std::unique_ptr<Region> region = std::make_unique<Region>();
200     ASSERT_TRUE(region != nullptr);
201     RectI rectI(0, 0, 256, 256);
202     RectI otherRectI(0, 400, 500, 600);
203     region->SetRect(rectI);
204     Region other;
205     other.SetRect(otherRectI);
206     EXPECT_TRUE(region->Op(other, RegionOp::UNION));
207 }
208 
209 /**
210  * @tc.name: OpTest005
211  * @tc.desc: test for OP function with XOR option
212  * @tc.type: FUNC
213  * @tc.require: I766AZ
214  */
215 HWTEST_F(RegionTest, OpTest005, TestSize.Level1)
216 {
217     std::unique_ptr<Region> region = std::make_unique<Region>();
218     ASSERT_TRUE(region != nullptr);
219     RectI rectI(0, 0, 256, 256);
220     RectI otherRectI(0, 400, 500, 600);
221     region->SetRect(rectI);
222     Region other;
223     other.SetRect(otherRectI);
224     EXPECT_TRUE(region->Op(other, RegionOp::XOR));
225 }
226 
227 /**
228  * @tc.name: OpTest006
229  * @tc.desc: test for OP function with REVERSE_DIFFERENCE option
230  * @tc.type: FUNC
231  * @tc.require: I766AZ
232  */
233 HWTEST_F(RegionTest, OpTest006, TestSize.Level1)
234 {
235     std::unique_ptr<Region> region = std::make_unique<Region>();
236     ASSERT_TRUE(region != nullptr);
237     RectI rectI(0, 0, 256, 256);
238     RectI otherRectI(0, 400, 500, 600);
239     region->SetRect(rectI);
240     Region other;
241     other.SetRect(otherRectI);
242     EXPECT_TRUE(region->Op(other, RegionOp::REVERSE_DIFFERENCE));
243 }
244 
245 /**
246  * @tc.name: OpTest007
247  * @tc.desc: test for OP function with REPLACE option
248  * @tc.type: FUNC
249  * @tc.require: I766AZ
250  */
251 HWTEST_F(RegionTest, OpTest007, TestSize.Level1)
252 {
253     std::unique_ptr<Region> region = std::make_unique<Region>();
254     ASSERT_TRUE(region != nullptr);
255     RectI rectI(0, 0, 256, 256);
256     RectI otherRectI(0, 400, 500, 600);
257     region->SetRect(rectI);
258     Region other;
259     other.SetRect(otherRectI);
260     EXPECT_TRUE(region->Op(other, RegionOp::REPLACE));
261 }
262 } // namespace Drawing
263 } // namespace Rosen
264 } // namespace OHOS
265