• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define private public
17 #include "screen_client_test.h"
18 #undef private
19 
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace DistributedHardware {
SetUpTestCase(void)24 void ScreenClientTest::SetUpTestCase(void) {}
25 
TearDownTestCase(void)26 void ScreenClientTest::TearDownTestCase(void) {}
27 
SetUp()28 void ScreenClientTest::SetUp() {}
29 
TearDown()30 void ScreenClientTest::TearDown() {}
31 
32 /**
33  * @tc.name: AddWindow_001
34  * @tc.desc: Verify the AddWindow function.
35  * @tc.type: FUNC
36  * @tc.require: Issue Number
37  */
38 HWTEST_F(ScreenClientTest, AddWindow_001, TestSize.Level1)
39 {
40     std::shared_ptr<WindowProperty> windowProperty = nullptr;
41     int32_t ret = ScreenClient::GetInstance().AddWindow(windowProperty);
42     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR, ret);
43 }
44 
45 /**
46  * @tc.name: AddWindow_002
47  * @tc.desc: Verify the AddWindow function.
48  * @tc.type: FUNC
49  * @tc.require: Issue Number
50  */
51 HWTEST_F(ScreenClientTest, AddWindow_002, TestSize.Level1)
52 {
53     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
54     int32_t expectId = ScreenClient::GetInstance().AddWindow(windowProperty);
55     EXPECT_EQ(0, expectId);
56     int32_t ret = ScreenClient::GetInstance().RemoveWindow(expectId);
57     EXPECT_EQ(DH_SUCCESS, ret);
58 }
59 
60 /**
61  * @tc.name: ShowWindow_001
62  * @tc.desc: Verify the ShowWindow function.
63  * @tc.type: FUNC
64  * @tc.require: Issue Number
65  */
66 HWTEST_F(ScreenClientTest, ShowWindow_001, TestSize.Level1)
67 {
68     int32_t ret = ScreenClient::GetInstance().ShowWindow(0);
69     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, ret);
70 }
71 
72 /**
73  * @tc.name: ShowWindow_002
74  * @tc.desc: Verify the ShowWindow function.
75  * @tc.type: FUNC
76  * @tc.require: Issue Number
77  */
78 HWTEST_F(ScreenClientTest, ShowWindow_002, TestSize.Level1)
79 {
80     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
81     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty);
82     int32_t ret = ScreenClient::GetInstance().ShowWindow(windowId);
83     EXPECT_EQ(DH_SUCCESS, ret);
84     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
85     EXPECT_EQ(DH_SUCCESS, ret);
86 }
87 
88 /**
89  * @tc.name: ShowWindow_003
90  * @tc.desc: Verify the ShowWindow function.
91  * @tc.type: FUNC
92  * @tc.require: Issue Number
93  */
94 HWTEST_F(ScreenClientTest, ShowWindow_003, TestSize.Level1)
95 {
96     int32_t windowId = 100;
97     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
98     int32_t ret = ScreenClient::GetInstance().ShowWindow(windowId);
99     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, ret);
100     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
101     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
102 }
103 
104 /**
105  * @tc.name: HideWindow_001
106  * @tc.desc: Verify the HideWindow function.
107  * @tc.type: FUNC
108  * @tc.require: Issue Number
109  */
110 HWTEST_F(ScreenClientTest, HideWindow_001, TestSize.Level1)
111 {
112     int32_t ret = ScreenClient::GetInstance().HideWindow(0);
113     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR, ret);
114 }
115 
116 /**
117  * @tc.name: HideWindow_002
118  * @tc.desc: Verify the HideWindow function.
119  * @tc.type: FUNC
120  * @tc.require: Issue Number
121  */
122 HWTEST_F(ScreenClientTest, HideWindow_002, TestSize.Level1)
123 {
124     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
125     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty);
126     int32_t ret = ScreenClient::GetInstance().HideWindow(windowId);
127     EXPECT_EQ(DH_SUCCESS, ret);
128     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
129     EXPECT_EQ(DH_SUCCESS, ret);
130 }
131 
132 /**
133  * @tc.name: HideWindow_003
134  * @tc.desc: Verify the HideWindow function.
135  * @tc.type: FUNC
136  * @tc.require: Issue Number
137  */
138 HWTEST_F(ScreenClientTest, HideWindow_003, TestSize.Level1)
139 {
140     int32_t windowId = 0;
141     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
142     int32_t ret = ScreenClient::GetInstance().HideWindow(windowId);
143     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR, ret);
144     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
145     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
146 }
147 
148 /**
149  * @tc.name: MoveWindow_001
150  * @tc.desc: Verify the MoveWindow function.
151  * @tc.type: FUNC
152  * @tc.require: Issue Number
153  */
154 HWTEST_F(ScreenClientTest, MoveWindow_001, TestSize.Level1)
155 {
156     int32_t ret = ScreenClient::GetInstance().MoveWindow(0, 0, 0);
157     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, ret);
158 }
159 
160 /**
161  * @tc.name: MoveWindow_002
162  * @tc.desc: Verify the MoveWindow function.
163  * @tc.type: FUNC
164  * @tc.require: Issue Number
165  */
166 HWTEST_F(ScreenClientTest, MoveWindow_002, TestSize.Level1)
167 {
168     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
169     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty);
170     int32_t ret = ScreenClient::GetInstance().MoveWindow(windowId, 0, 0);
171     EXPECT_EQ(DH_SUCCESS, ret);
172     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
173     EXPECT_EQ(DH_SUCCESS, ret);
174 }
175 
176 /**
177  * @tc.name: MoveWindow_003
178  * @tc.desc: Verify the MoveWindow function.
179  * @tc.type: FUNC
180  * @tc.require: Issue Number
181  */
182 HWTEST_F(ScreenClientTest, MoveWindow_003, TestSize.Level1)
183 {
184     int32_t windowId = 0;
185     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
186     int32_t ret = ScreenClient::GetInstance().MoveWindow(windowId, 0, 0);
187     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, ret);
188     ret = ScreenClient::GetInstance().RemoveWindow(windowId);
189     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
190 }
191 
192 /**
193  * @tc.name: RemoveWindow_001
194  * @tc.desc: Verify the RemoveWindow function.
195  * @tc.type: FUNC
196  * @tc.require: Issue Number
197  */
198 HWTEST_F(ScreenClientTest, RemoveWindow_001, TestSize.Level1)
199 {
200     int32_t ret = ScreenClient::GetInstance().RemoveWindow(0);
201     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
202 }
203 
204 /**
205  * @tc.name: RemoveWindow_002
206  * @tc.desc: Verify the RemoveWindow function.
207  * @tc.type: FUNC
208  * @tc.require: Issue Number
209  */
210 HWTEST_F(ScreenClientTest, RemoveWindow_002, TestSize.Level1)
211 {
212     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
213     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty);
214     int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId);
215     EXPECT_EQ(DH_SUCCESS, ret);
216 }
217 
218 /**
219  * @tc.name: RemoveWindow_002
220  * @tc.desc: Verify the RemoveWindow function.
221  * @tc.type: FUNC
222  * @tc.require: Issue Number
223  */
224 HWTEST_F(ScreenClientTest, RemoveWindow_003, TestSize.Level1)
225 {
226     int32_t windowId = 0;
227     ScreenClient::GetInstance().surfaceMap_.emplace(windowId, nullptr);
228     int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId);
229     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
230 }
231 
232 /**
233  * @tc.name: GetSurface_001
234  * @tc.desc: Verify the GetSurface function.
235  * @tc.type: FUNC
236  * @tc.require: Issue Number
237  */
238 HWTEST_F(ScreenClientTest, GetSurface_001, TestSize.Level1)
239 {
240     EXPECT_EQ(nullptr, ScreenClient::GetInstance().GetSurface(0));
241 }
242 
243 /**
244  * @tc.name: GetSurface_002
245  * @tc.desc: Verify the GetSurface function.
246  * @tc.type: FUNC
247  * @tc.require: Issue Number
248  */
249 HWTEST_F(ScreenClientTest, GetSurface_002, TestSize.Level1)
250 {
251     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
252     int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty);
253     sptr<Surface> actualSurface = ScreenClient::GetInstance().GetSurface(windowId);
254     EXPECT_NE(nullptr, actualSurface);
255     int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId);
256     EXPECT_EQ(DH_SUCCESS, ret);
257 }
258 
259 /**
260  * @tc.name: DestroyAllWindow_001
261  * @tc.desc: Verify the DestroyAllWindow function.
262  * @tc.type: FUNC
263  * @tc.require: Issue Number
264  */
265 HWTEST_F(ScreenClientTest, DestroyAllWindow_001, TestSize.Level1)
266 {
267     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
268     ScreenClient::GetInstance().AddWindow(windowProperty);
269     int32_t ret = ScreenClient::GetInstance().DestroyAllWindow();
270     EXPECT_EQ(DH_SUCCESS, ret);
271 }
272 
273 } // DistributedHardware
274 } // OHOS