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_window_adapter_test.h"
17 
18 using namespace testing::ext;
19 
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void ScreenClientWindowAdapterTest::SetUpTestCase(void) {}
23 
TearDownTestCase(void)24 void ScreenClientWindowAdapterTest::TearDownTestCase(void) {}
25 
SetUp()26 void ScreenClientWindowAdapterTest::SetUp() {}
27 
TearDown()28 void ScreenClientWindowAdapterTest::TearDown() {}
29 
30 /**
31  * @tc.name: CreateWindow_001
32  * @tc.desc: Verify the CreateWindow function.
33  * @tc.type: FUNC
34  * @tc.require: Issue Number
35  */
36 HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_001, TestSize.Level1)
37 {
38     std::shared_ptr<WindowProperty> windowProperty = nullptr;
39     EXPECT_EQ(nullptr, ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, 0));
40 }
41 
42 /**
43  * @tc.name: CreateWindow_002
44  * @tc.desc: Verify the CreateWindow function.
45  * @tc.type: FUNC
46  * @tc.require: Issue Number
47  */
48 HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_002, TestSize.Level1)
49 {
50     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
51     int32_t windowId = 0;
52     sptr<Surface> actualSurface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
53     EXPECT_NE(nullptr, actualSurface);
54     int32_t ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
55     EXPECT_EQ(DH_SUCCESS, ret);
56 }
57 
58 /**
59  * @tc.name: ShowWindow_001
60  * @tc.desc: Verify the ShowWindow function.
61  * @tc.type: FUNC
62  * @tc.require: Issue Number
63  */
64 HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_001, TestSize.Level1)
65 {
66     int32_t ret = ScreenClientWindowAdapter::GetInstance().ShowWindow(100);
67     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, ret);
68 }
69 
70 /**
71  * @tc.name: ShowWindow_002
72  * @tc.desc: Verify the ShowWindow function.
73  * @tc.type: FUNC
74  * @tc.require: Issue Number
75  */
76 HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_002, TestSize.Level1)
77 {
78     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
79     int32_t windowId = 100;
80     ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
81     int32_t ret = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId);
82     EXPECT_EQ(DH_SUCCESS, ret);
83     ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
84     EXPECT_EQ(DH_SUCCESS, ret);
85 }
86 
87 /**
88  * @tc.name: ShowWindow_003
89  * @tc.desc: Verify the ShowWindow function.
90  * @tc.type: FUNC
91  * @tc.require: Issue Number
92  */
93 HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_003, TestSize.Level1)
94 {
95     int32_t windowId = 0;
96     ScreenClientWindowAdapter::GetInstance().windowIdMap_.emplace(windowId, nullptr);
97     int32_t ret = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId);
98     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, ret);
99     ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
100     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
101 }
102 /**
103  * @tc.name: HideWindow_001
104  * @tc.desc: Verify the HideWindow function.
105  * @tc.type: FUNC
106  * @tc.require: Issue Number
107  */
108 HWTEST_F(ScreenClientWindowAdapterTest, HideWindow_001, TestSize.Level1)
109 {
110     int32_t ret = ScreenClientWindowAdapter::GetInstance().HideWindow(0);
111     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR, ret);
112 }
113 
114 /**
115  * @tc.name: HideWindow_001
116  * @tc.desc: Verify the HideWindow function.
117  * @tc.type: FUNC
118  * @tc.require: Issue Number
119  */
120 HWTEST_F(ScreenClientWindowAdapterTest, HideWindow_002, TestSize.Level1)
121 {
122     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
123     int32_t windowId = 0;
124     ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
125     int32_t ret = ScreenClientWindowAdapter::GetInstance().HideWindow(windowId);
126     EXPECT_EQ(DH_SUCCESS, ret);
127     ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
128     EXPECT_EQ(DH_SUCCESS, ret);
129 }
130 
131 /**
132  * @tc.name: HideWindow_003
133  * @tc.desc: Verify the HideWindow function.
134  * @tc.type: FUNC
135  * @tc.require: Issue Number
136  */
137 HWTEST_F(ScreenClientWindowAdapterTest, HideWindow_003, TestSize.Level1)
138 {
139     int32_t windowId = 0;
140     ScreenClientWindowAdapter::GetInstance().windowIdMap_.emplace(windowId, nullptr);
141     int32_t ret = ScreenClientWindowAdapter::GetInstance().HideWindow(windowId);
142     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR, ret);
143     ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
144     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
145 }
146 
147 /**
148  * @tc.name: MoveWindow_001
149  * @tc.desc: Verify the MoveWindow function.
150  * @tc.type: FUNC
151  * @tc.require: Issue Number
152  */
153 HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_001, TestSize.Level1)
154 {
155     int32_t ret = ScreenClientWindowAdapter::GetInstance().MoveWindow(0, 0, 0);
156     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, ret);
157 }
158 
159 /**
160  * @tc.name: MoveWindow_002
161  * @tc.desc: Verify the MoveWindow function.
162  * @tc.type: FUNC
163  * @tc.require: Issue Number
164  */
165 HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_002, TestSize.Level1)
166 {
167     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
168     int32_t windowId = 0;
169     ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
170     int32_t ret = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, 0, 0);
171     EXPECT_EQ(DH_SUCCESS, ret);
172     ret = ScreenClientWindowAdapter::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(ScreenClientWindowAdapterTest, MoveWindow_003, TestSize.Level1)
183 {
184     int32_t windowId = 0;
185     ScreenClientWindowAdapter::GetInstance().windowIdMap_.emplace(windowId, nullptr);
186     int32_t ret = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, 0, 0);
187     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, ret);
188     ret = ScreenClientWindowAdapter::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(ScreenClientWindowAdapterTest, RemoveWindow_001, TestSize.Level1)
199 {
200     int32_t ret = ScreenClientWindowAdapter::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(ScreenClientWindowAdapterTest, RemoveWindow_002, TestSize.Level1)
211 {
212     std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
213     int32_t windowId = 0;
214     ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
215     int32_t ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
216     EXPECT_EQ(DH_SUCCESS, ret);
217 }
218 
219 /**
220  * @tc.name: RemoveWindow_003
221  * @tc.desc: Verify the RemoveWindow function.
222  * @tc.type: FUNC
223  * @tc.require: Issue Number
224  */
225 HWTEST_F(ScreenClientWindowAdapterTest, RemoveWindow_003, TestSize.Level1)
226 {
227     int32_t windowId = 0;
228     ScreenClientWindowAdapter::GetInstance().windowIdMap_.emplace(windowId, nullptr);
229     int32_t ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
230     EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, ret);
231 }
232 
233 /**
234  * @tc.name: DestroyAllWindow_001
235  * @tc.desc: Verify the DestroyAllWindow function.
236  * @tc.type: FUNC
237  * @tc.require: Issue Number
238  */
239 HWTEST_F(ScreenClientWindowAdapterTest, DestroyAllWindow_001, TestSize.Level1)
240 {
241     ScreenClientWindowAdapter::GetInstance().windowIdMap_.emplace(0, nullptr);
242     int32_t ret = ScreenClientWindowAdapter::GetInstance().DestroyAllWindow();
243     EXPECT_EQ(DH_SUCCESS, ret);
244 }
245 
246 /**
247  * @tc.name: ScreenClientInputEventListener_OnInputEvent_001
248  * @tc.desc: Verify the OnInputEvent function.
249  * @tc.type: FUNC
250  * @tc.require: Issue Number
251  */
252 HWTEST_F(ScreenClientWindowAdapterTest, ScreenClientInputEventListener_OnInputEvent_001, TestSize.Level1)
253 {
254     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
255     std::shared_ptr<ScreenClientInputEventListener> listener = std::make_shared<ScreenClientInputEventListener>();
256     EXPECT_FALSE(listener->OnInputEvent(pointerEvent));
257 }
258 
259 /**
260  * @tc.name: ScreenClientInputEventListener_OnInputEvent_002
261  * @tc.desc: Verify the OnInputEvent function.
262  * @tc.type: FUNC
263  * @tc.require: Issue Number
264  */
265 HWTEST_F(ScreenClientWindowAdapterTest, ScreenClientInputEventListener_OnInputEvent_002, TestSize.Level1)
266 {
267     std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
268     std::shared_ptr<ScreenClientInputEventListener> listener = std::make_shared<ScreenClientInputEventListener>();
269     EXPECT_FALSE(listener->OnInputEvent(keyEvent));
270 }
271 
272 /**
273  * @tc.name: ScreenClientInputEventListener_OnInputEvent_003
274  * @tc.desc: Verify the OnInputEvent function.
275  * @tc.type: FUNC
276  * @tc.require: Issue Number
277  */
278 HWTEST_F(ScreenClientWindowAdapterTest, ScreenClientInputEventListener_OnInputEvent_003, TestSize.Level1)
279 {
280     std::shared_ptr<MMI::AxisEvent> axisEvent = nullptr;
281     std::shared_ptr<ScreenClientInputEventListener> listener = std::make_shared<ScreenClientInputEventListener>();
282     EXPECT_FALSE(listener->OnInputEvent(axisEvent));
283 }
284 } // DistributedHardware
285 } // OHOS