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