1 /*
2 * Copyright (c) 2020-2021 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 "components/ui_surface_view.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace {
24 const int16_t INIT_POS_X = 10;
25 const int16_t INIT_POS_Y = 20;
26 const int16_t INIT_WIDTH = 50;
27 const int16_t INIT_HEIGHT = 30;
28 }
29
30 class UISurfaceViewTest : public testing::Test {
31 public:
UISurfaceViewTest()32 UISurfaceViewTest() : surface_(nullptr) {}
~UISurfaceViewTest()33 virtual ~UISurfaceViewTest() {}
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp();
37 void TearDown();
38 UISurfaceView* surface_;
39 };
40
SetUpTestCase()41 void UISurfaceViewTest::SetUpTestCase()
42 {
43 }
44
TearDownTestCase()45 void UISurfaceViewTest::TearDownTestCase()
46 {
47 }
48
SetUp()49 void UISurfaceViewTest::SetUp()
50 {
51 if (surface_ == nullptr) {
52 surface_ = new UISurfaceView();
53 }
54 }
55
TearDown()56 void UISurfaceViewTest::TearDown()
57 {
58 if (surface_ != nullptr) {
59 delete surface_;
60 surface_ = nullptr;
61 }
62 }
63 /**
64 * @tc.name: UISurfaceViewSetPosition_001
65 * @tc.desc: Verify SetPosition function, equal.
66 * @tc.type: FUNC
67 * @tc.require: AR000EEMQJ
68 */
69 HWTEST_F(UISurfaceViewTest, UISurfaceViewSetPosition_001, TestSize.Level0)
70 {
71 if (surface_ == nullptr) {
72 EXPECT_NE(0, 0);
73 return;
74 }
75 surface_->SetPosition(INIT_POS_X, INIT_POS_Y);
76 EXPECT_EQ(surface_->GetX(), INIT_POS_X);
77 EXPECT_EQ(surface_->GetY(), INIT_POS_Y);
78
79 surface_->SetPosition(INIT_POS_X + 1, INIT_POS_Y + 1, INIT_WIDTH, INIT_HEIGHT);
80 EXPECT_EQ(surface_->GetX(), INIT_POS_X + 1);
81 EXPECT_EQ(surface_->GetY(), INIT_POS_Y + 1);
82 EXPECT_EQ(surface_->GetWidth(), INIT_WIDTH);
83 EXPECT_EQ(surface_->GetHeight(), INIT_HEIGHT);
84 }
85
86 /**
87 * @tc.name: UISurfaceViewResize_001
88 * @tc.desc: Verify Resize function, equal.
89 * @tc.type: FUNC
90 * @tc.require: AR000EEMQJ
91 */
92 HWTEST_F(UISurfaceViewTest, UISurfaceViewResize_001, TestSize.Level1)
93 {
94 if (surface_ == nullptr) {
95 EXPECT_NE(0, 0);
96 return;
97 }
98 surface_->Resize(INIT_WIDTH, INIT_HEIGHT);
99 EXPECT_EQ(surface_->GetWidth(), INIT_WIDTH);
100 EXPECT_EQ(surface_->GetHeight(), INIT_HEIGHT);
101 }
102
103 /**
104 * @tc.name: UISurfaceViewSetX_001
105 * @tc.desc: Verify SetX function, equal.
106 * @tc.type: FUNC
107 * @tc.require: AR000EEMQJ
108 */
109 HWTEST_F(UISurfaceViewTest, UISurfaceViewSetX_001, TestSize.Level1)
110 {
111 if (surface_ == nullptr) {
112 EXPECT_NE(0, 0);
113 return;
114 }
115 surface_->SetX(INIT_POS_X);
116 EXPECT_EQ(surface_->GetX(), INIT_POS_X);
117 }
118
119 /**
120 * @tc.name: UISurfaceViewSetY_001
121 * @tc.desc: Verify SetY function, equal.
122 * @tc.type: FUNC
123 * @tc.require: AR000EEMQJ
124 */
125 HWTEST_F(UISurfaceViewTest, UISurfaceViewSetY_001, TestSize.Level1)
126 {
127 if (surface_ == nullptr) {
128 EXPECT_NE(0, 0);
129 return;
130 }
131 surface_->SetY(INIT_POS_Y);
132 EXPECT_EQ(surface_->GetY(), INIT_POS_Y);
133 }
134
135 /**
136 * @tc.name: UISurfaceViewSetWidth_001
137 * @tc.desc: Verify SetWidth function, equal.
138 * @tc.type: FUNC
139 * @tc.require: AR000EEMQJ
140 */
141 HWTEST_F(UISurfaceViewTest, UISurfaceViewSetWidth_001, TestSize.Level1)
142 {
143 if (surface_ == nullptr) {
144 EXPECT_NE(0, 0);
145 return;
146 }
147 surface_->SetWidth(INIT_WIDTH);
148 EXPECT_EQ(surface_->GetWidth(), INIT_WIDTH);
149 }
150
151 /**
152 * @tc.name: UISurfaceViewSetHeight_001
153 * @tc.desc: Verify SetHeight function, equal.
154 * @tc.type: FUNC
155 * @tc.require: AR000EEMQJ
156 */
157 HWTEST_F(UISurfaceViewTest, UISurfaceViewSetHeight_001, TestSize.Level1)
158 {
159 if (surface_ == nullptr) {
160 EXPECT_NE(0, 0);
161 return;
162 }
163 surface_->SetHeight(INIT_HEIGHT);
164 EXPECT_EQ(surface_->GetHeight(), INIT_HEIGHT);
165 }
166
167 /**
168 * @tc.name: UISurfaceViewSetVisible_001
169 * @tc.desc: Verify SetVisible function, equal.
170 * @tc.type: FUNC
171 * @tc.require: AR000EEMQJ
172 */
173 HWTEST_F(UISurfaceViewTest, UISurfaceViewSetVisible_001, TestSize.Level1)
174 {
175 if (surface_ == nullptr) {
176 EXPECT_NE(0, 0);
177 return;
178 }
179 bool visible = surface_->IsVisible();
180 surface_->SetVisible(!visible);
181 EXPECT_EQ(surface_->IsVisible(), !visible);
182 }
183 } // namespace OHOS
184