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     bool ret = skiaRegion->Deserialize(nullptr);
107     EXPECT_FALSE(ret);
108 }
109 
110 /**
111  * @tc.name: Contains001
112  * @tc.desc: Test Contains
113  * @tc.type: FUNC
114  * @tc.require: I8VQSW
115  */
116 HWTEST_F(SkiaRegionTest, Contains001, TestSize.Level1)
117 {
118     std::shared_ptr<SkiaRegion> skiaRegion = std::make_shared<SkiaRegion>();
119     RectI rect(0, 100, 100, 200);
120     skiaRegion->SetRect(rect);
121     auto ret = skiaRegion->Contains(300, 300); // 300, 300 is point
122     EXPECT_FALSE(ret);
123     ret = skiaRegion->Contains(50, 150); // 50, 100 is point
124     EXPECT_TRUE(ret);
125 }
126 } // namespace Drawing
127 } // namespace Rosen
128 } // namespace OHOS