• 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, 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 "pip_util.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace Rosen {
24 class PiPUtilTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30 };
31 
SetUpTestCase()32 void PiPUtilTest::SetUpTestCase()
33 {
34 }
35 
TearDownTestCase()36 void PiPUtilTest::TearDownTestCase()
37 {
38 }
39 
SetUp()40 void PiPUtilTest::SetUp()
41 {
42 }
43 
TearDown()44 void PiPUtilTest::TearDown()
45 {
46 }
47 
48 namespace {
49 /**
50  * @tc.name: UpdateRectPivot
51  * @tc.desc: UpdateRectPivot test
52  * @tc.type: FUNC
53  */
54 HWTEST_F(PiPUtilTest, UpdateRectPivot, Function | SmallTest | Level2)
55 {
56     auto pivot1 = PiPScalePivot::UNDEFINED;
57     PiPUtil::UpdateRectPivot(10, 20, 100, pivot1);
58     ASSERT_EQ(PiPScalePivot::START, pivot1);
59 
60     auto pivot2 = PiPScalePivot::UNDEFINED;
61     PiPUtil::UpdateRectPivot(40, 20, 100, pivot2);
62     ASSERT_EQ(PiPScalePivot::MIDDLE, pivot2);
63 
64     auto pivot3 = PiPScalePivot::UNDEFINED;
65     PiPUtil::UpdateRectPivot(70, 20, 100, pivot3);
66     ASSERT_EQ(PiPScalePivot::END, pivot3);
67 }
68 
69 /**
70  * @tc.name: GetRectByPivot
71  * @tc.desc: GetRectByPivot test
72  * @tc.type: FUNC
73  */
74 HWTEST_F(PiPUtilTest, GetRectByPivot, Function | SmallTest | Level2)
75 {
76     auto pivot1 = PiPScalePivot::UNDEFINED;
77     int32_t start1 = 100;
78     PiPUtil::GetRectByPivot(start1, 100, 200, 300, pivot1);
79     ASSERT_EQ(100, start1);
80 
81     auto pivot2 = PiPScalePivot::UNDEFINED;
82     int32_t start2 = 100;
83     PiPUtil::GetRectByPivot(start2, 100, 200, 300, pivot2);
84     ASSERT_EQ(100, start2);
85 
86     auto pivot3 = PiPScalePivot::UNDEFINED;
87     int32_t start3 = 100;
88     PiPUtil::GetRectByPivot(start3, 100, 200, 300, pivot3);
89     ASSERT_EQ(100, start3);
90 }
91 
92 /**
93  * @tc.name: GetRectByScale
94  * @tc.desc: GetRectByScale test
95  * @tc.type: FUNC
96  */
97 HWTEST_F(PiPUtilTest, GetRectByScale, Function | SmallTest | Level2)
98 {
99     Rect rect1 = {0, 0, 100, 100};
100     auto level1 = PiPScaleLevel::PIP_SCALE_LEVEL_SMALLEST;
101     PiPUtil::GetRectByScale(200, 200, level1, rect1, false);
102     ASSERT_EQ(60, rect1.width_);
103     ASSERT_EQ(60, rect1.height_);
104 
105     Rect rect2 = {0, 0, 100, 100};
106     auto level2 = PiPScaleLevel::PIP_SCALE_LEVEL_SMALLEST;
107     PiPUtil::GetRectByScale(200, 200, level2, rect2, false);
108     ASSERT_EQ(60, rect2.width_);
109     ASSERT_EQ(60, rect2.height_);
110 }
111 
112 /**
113  * @tc.name: GetValidRect
114  * @tc.desc: GetValidRect test
115  * @tc.type: FUNC
116  */
117 HWTEST_F(PiPUtilTest, GetValidRect, Function | SmallTest | Level2)
118 {
119     Rect rect1 = {0, PiPUtil::SAFE_PADDING_VERTICAL_TOP, 100, 100};
120     ASSERT_EQ(true, PiPUtil::GetValidRect(1000, 1000, rect1));
121     ASSERT_EQ(PiPUtil::SAFE_PADDING_HORIZONTAL_VP, rect1.posX_);
122     ASSERT_EQ(PiPUtil::SAFE_PADDING_VERTICAL_TOP, rect1.posY_);
123 
124     Rect rect2 = {1000, PiPUtil::SAFE_PADDING_VERTICAL_TOP, 100, 100};
125     ASSERT_EQ(true, PiPUtil::GetValidRect(1000, 1000, rect2));
126     ASSERT_EQ(1000 - rect2.width_ - PiPUtil::SAFE_PADDING_HORIZONTAL_VP, rect2.posX_);
127     ASSERT_EQ(PiPUtil::SAFE_PADDING_VERTICAL_TOP, rect2.posY_);
128 
129     Rect rect3 = {PiPUtil::SAFE_PADDING_HORIZONTAL_VP, 0, 100, 100};
130     ASSERT_EQ(true, PiPUtil::GetValidRect(1000, 1000, rect3));
131     ASSERT_EQ(PiPUtil::SAFE_PADDING_HORIZONTAL_VP, rect3.posX_);
132     ASSERT_EQ(PiPUtil::SAFE_PADDING_VERTICAL_TOP, rect3.posY_);
133 
134     Rect rect4 = {PiPUtil::SAFE_PADDING_HORIZONTAL_VP, 1000, 100, 100};
135     ASSERT_EQ(true, PiPUtil::GetValidRect(1000, 1000, rect4));
136     ASSERT_EQ(PiPUtil::SAFE_PADDING_HORIZONTAL_VP, rect4.posX_);
137     ASSERT_EQ(1000 - 100 - PiPUtil::SAFE_PADDING_VERTICAL_BOTTOM, rect4.posY_);
138 
139     Rect rect5 = {PiPUtil::SAFE_PADDING_HORIZONTAL_VP, PiPUtil::SAFE_PADDING_VERTICAL_TOP, 100, 100};
140     ASSERT_EQ(false, PiPUtil::GetValidRect(1000, 1000, rect5));
141     ASSERT_EQ(PiPUtil::SAFE_PADDING_HORIZONTAL_VP, rect5.posX_);
142     ASSERT_EQ(PiPUtil::SAFE_PADDING_VERTICAL_TOP, rect5.posY_);
143 }
144 }
145 } // namespace Rosen
146 } // namespace OHOS