1 /*
2 * Copyright (c) 2024 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, 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 <cstddef>
17 #include "gtest/gtest.h"
18 #include "skia_adapter/skia_region.h"
19 #include "utils/region.h"
20 #include "utils/rect.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class SkiaRegionTest : 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 SkiaRegionTest::SetUpTestCase() {}
TearDownTestCase()37 void SkiaRegionTest::TearDownTestCase() {}
SetUp()38 void SkiaRegionTest::SetUp() {}
TearDown()39 void SkiaRegionTest::TearDown() {}
40
41 /**
42 * @tc.name: SetPath001
43 * @tc.desc: Test SetPath
44 * @tc.type: FUNC
45 * @tc.require: I8VQSW
46 */
47 HWTEST_F(SkiaRegionTest, SetPath001, TestSize.Level1)
48 {
49 std::shared_ptr<SkiaRegion> skiaRegion = std::make_shared<SkiaRegion>();
50 Path path;
51 Region region;
52 ASSERT_FALSE(skiaRegion->SetPath(path, region));
53 }
54
55 /**
56 * @tc.name: GetBoundaryPath001
57 * @tc.desc: Test GetBoundaryPath
58 * @tc.type: FUNC
59 * @tc.require: I8VQSW
60 */
61 HWTEST_F(SkiaRegionTest, GetBoundaryPath001, TestSize.Level1)
62 {
63 std::shared_ptr<SkiaRegion> skiaRegion = std::make_shared<SkiaRegion>();
64 Path path;
65 ASSERT_FALSE(skiaRegion->GetBoundaryPath(&path));
66 ASSERT_FALSE(skiaRegion->GetBoundaryPath(nullptr));
67 }
68
69 /**
70 * @tc.name: IsIntersects001
71 * @tc.desc: Test IsIntersects
72 * @tc.type: FUNC
73 * @tc.require: I8VQSW
74 */
75 HWTEST_F(SkiaRegionTest, IsIntersects001, TestSize.Level1)
76 {
77 std::shared_ptr<SkiaRegion> skiaRegion = std::make_shared<SkiaRegion>();
78 Region region;
79 auto ret = skiaRegion->IsIntersects(region);
80 EXPECT_TRUE(!ret);
81 }
82
83 /**
84 * @tc.name: Clone001
85 * @tc.desc: Test Clone
86 * @tc.type: FUNC
87 * @tc.require: I8VQSW
88 */
89 HWTEST_F(SkiaRegionTest, Clone001, TestSize.Level1)
90 {
91 std::shared_ptr<SkiaRegion> skiaRegion = std::make_shared<SkiaRegion>();
92 Region region;
93 skiaRegion->Clone(region);
94 EXPECT_TRUE(skiaRegion->IsEmpty());
95 }
96
97 /**
98 * @tc.name: Deserialize001
99 * @tc.desc: Test Deserialize
100 * @tc.type: FUNC
101 * @tc.require: I8VQSW
102 */
103 HWTEST_F(SkiaRegionTest, Deserialize001, TestSize.Level1)
104 {
105 std::shared_ptr<SkiaRegion> skiaRegion = std::make_shared<SkiaRegion>();
106 EXPECT_FALSE(skiaRegion->Deserialize(nullptr));
107 }
108
109 /**
110 * @tc.name: Contains001
111 * @tc.desc: Test Contains
112 * @tc.type: FUNC
113 * @tc.require: I8VQSW
114 */
115 HWTEST_F(SkiaRegionTest, Contains001, TestSize.Level1)
116 {
117 std::shared_ptr<SkiaRegion> skiaRegion = std::make_shared<SkiaRegion>();
118 RectI rect(0, 100, 100, 200);
119 skiaRegion->SetRect(rect);
120 auto ret = skiaRegion->Contains(300, 300); // 300, 300 is point
121 EXPECT_FALSE(ret);
122 ret = skiaRegion->Contains(50, 150); // 50, 100 is point
123 EXPECT_TRUE(ret);
124 }
125
126 /**
127 * @tc.name: Equals001
128 * @tc.desc: Test Contains
129 * @tc.type: FUNC
130 * @tc.require: I8VQSW
131 */
132 HWTEST_F(SkiaRegionTest, EqualsTest001, TestSize.Level1)
133 {
134 SkiaRegion region;
135 Region region2;
136 EXPECT_TRUE(region.Equals(region2));
137 RectI rectI(0, 0, 256, 256);
138 region.SetRect(rectI);
139 ASSERT_FALSE(region.Equals(region2));
140 }
141
142 /**
143 * @tc.name: SetEmpty001
144 * @tc.desc: Test SetEmpty
145 * @tc.type: FUNC
146 * @tc.require: I8VQSW
147 */
148 HWTEST_F(SkiaRegionTest, SetEmptyTest001, TestSize.Level1)
149 {
150 SkiaRegion region;
151 RectI rectI(0, 0, 256, 256);
152 region.SetRect(rectI);
153 region.SetEmpty();
154 ASSERT_TRUE(region.IsEmpty());
155 }
156
157 /**
158 * @tc.name: SetRegion001
159 * @tc.desc: Test SetRegion
160 * @tc.type: FUNC
161 * @tc.require: I8VQSW
162 */
163 HWTEST_F(SkiaRegionTest, SetRegionTest001, TestSize.Level1)
164 {
165 SkiaRegion region;
166 Region reg;
167 RectI rectI(0, 0, 256, 256);
168 reg.SetRect(rectI);
169 region.SetRegion(reg);
170 ASSERT_TRUE(rectI == region.GetBounds());
171 }
172
173 /**
174 * @tc.name: GetBounds001
175 * @tc.desc: Test GetBounds
176 * @tc.type: FUNC
177 * @tc.require: I8VQSW
178 */
179 HWTEST_F(SkiaRegionTest, GetBoundsTest001, TestSize.Level1)
180 {
181 SkiaRegion region;
182 RectI rectI(0, 0, 256, 256);
183 region.SetRect(rectI);
184 ASSERT_TRUE(rectI == region.GetBounds());
185 }
186
187 /**
188 * @tc.name: IsComplex001
189 * @tc.desc: Test IsComplex
190 * @tc.type: FUNC
191 * @tc.require: I8VQSW
192 */
193 HWTEST_F(SkiaRegionTest, IsComplexTest001, TestSize.Level1)
194 {
195 SkiaRegion region;
196 SkiaRegion region2;
197 RectI rectI(0, 0, 256, 256);
198 RectI otherRectI(50, 50, 400, 400);
199 region.SetRect(rectI);
200 ASSERT_FALSE(region.IsComplex());
201 }
202
203 /**
204 * @tc.name: QuickReject001
205 * @tc.desc: Test QuickReject
206 * @tc.type: FUNC
207 * @tc.require: I8VQSW
208 */
209 HWTEST_F(SkiaRegionTest, QuickRejectTest001, TestSize.Level1)
210 {
211 SkiaRegion region;
212 Region region2;
213 RectI rectI(0, 0, 256, 256);
214 RectI otherRectI(50, 50, 400, 400);
215 region.SetRect(rectI);
216 region2.SetRect(otherRectI);
217 ASSERT_FALSE(region.QuickReject(region2));
218 }
219
220 /**
221 * @tc.name: Translate001
222 * @tc.desc: Test Translate
223 * @tc.type: FUNC
224 * @tc.require: I8VQSW
225 */
226 HWTEST_F(SkiaRegionTest, TranslateTest001, TestSize.Level1)
227 {
228 SkiaRegion region;
229 SkiaRegion region2;
230 RectI rectI(0, 0, 100, 100);
231 RectI otherRectI(100, 100, 200, 200);
232 region.SetRect(rectI);
233 region2.SetRect(otherRectI);
234 region.Translate(100, 100);
235 ASSERT_FALSE(region.GetSkRegion() == region2.GetSkRegion());
236 }
237 } // namespace Drawing
238 } // namespace Rosen
239 } // namespace OHOS