1 /*
2 * Copyright (c) 2022-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, 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 #include <hilog/log.h>
18 #include <memory>
19 #include <unistd.h>
20 #include "common/rs_occlusion_region.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS::Rosen {
26 class RSRegionTest : public testing::Test {
27 public:
28 static constexpr HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0XD001400, "RSRegionTest" };
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void RSRegionTest::SetUpTestCase() {}
TearDownTestCase()36 void RSRegionTest::TearDownTestCase() {}
SetUp()37 void RSRegionTest::SetUp() {}
TearDown()38 void RSRegionTest::TearDown() {}
39
40 /**
41 * @tc.name: OperatorSub
42 * @tc.desc: Function sub
43 * @tc.type: FUNC
44 * @tc.require: issuesI5PYNC
45 */
46 HWTEST_F(RSRegionTest, OperatorSub, Function | SmallTest | Level2)
47 {
48 Occlusion::Rect rect1 { 0, 0, 100, 100 };
49 Occlusion::Region resgion1 { rect1 };
50 Occlusion::Rect rect2 { 50, 50, 150, 150 };
51 Occlusion::Region resgion2 { rect2 };
52 Occlusion::Region sub = resgion1.Sub(resgion2);
53
54 Occlusion::Rect res {0, 0, 100, 100};
55 EXPECT_EQ(sub.GetSize(), 2);
56 EXPECT_EQ(sub.GetBound(), res);
57 }
58
59 /**
60 * @tc.name: OperatorOr
61 * @tc.desc: Function or
62 * @tc.type: FUNC
63 * @tc.require: issuesI5PYNC
64 */
65 HWTEST_F(RSRegionTest, OperatorOr, Function | SmallTest | Level2)
66 {
67 Occlusion::Rect rect1 { 0, 0, 100, 100 };
68 Occlusion::Region resgion1 { rect1 };
69 Occlusion::Rect rect2 { 50, 50, 150, 150 };
70 Occlusion::Region resgion2 { rect2 };
71 Occlusion::Region resOr = resgion1.Or(resgion2);
72
73 Occlusion::Rect res {0, 0, 150, 150};
74 EXPECT_EQ(resOr.GetSize(), 3);
75 EXPECT_EQ(resOr.GetBound(), res);
76 }
77
78 /**
79 * @tc.name: OperatorAnd
80 * @tc.desc: Function and
81 * @tc.type: FUNC
82 * @tc.require: issuesI5PYNC
83 */
84 HWTEST_F(RSRegionTest, OperatorAnd, Function | SmallTest | Level2)
85 {
86 Occlusion::Rect rect1 { 0, 0, 100, 100 };
87 Occlusion::Region resgion1 { rect1 };
88 Occlusion::Rect rect2 { 50, 50, 150, 150 };
89 Occlusion::Region resgion2 { rect2 };
90 Occlusion::Region resAnd = resgion1.And(resgion2);
91
92 Occlusion::Rect res {50, 50, 100, 100};
93 EXPECT_EQ(resAnd.GetSize(), 1);
94 EXPECT_EQ(resAnd.GetBound(), res);
95 }
96 } // namespace OHOS::Rosen
97