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 #include "distributed_input_ipc_test.h"
17
18 #include "nlohmann/json.hpp"
19
20 #include "dinput_errcode.h"
21
22 using namespace testing::ext;
23 using namespace OHOS::DistributedHardware::DistributedInput;
24 using namespace std;
25 namespace OHOS {
26 namespace DistributedHardware {
27 namespace DistributedInput {
SetUp()28 void DistributedInputIpcTest::SetUp()
29 {
30 }
31
TearDown()32 void DistributedInputIpcTest::TearDown()
33 {
34 }
35
SetUpTestCase()36 void DistributedInputIpcTest::SetUpTestCase()
37 {
38 }
39
TearDownTestCase()40 void DistributedInputIpcTest::TearDownTestCase()
41 {
42 }
43
OnNodeOnLine(const std::string srcDevId,const std::string sinkDevId,const std::string sinkNodeId,const std::string sinkNodeDesc)44 void DistributedInputIpcTest::TestInputNodeListener::OnNodeOnLine(const std::string srcDevId,
45 const std::string sinkDevId, const std::string sinkNodeId, const std::string sinkNodeDesc)
46 {
47 (void)srcDevId;
48 (void)sinkDevId;
49 (void)sinkNodeId;
50 (void)sinkNodeDesc;
51 return;
52 }
53
OnNodeOffLine(const std::string srcDevId,const std::string sinkDevId,const std::string sinkNodeId)54 void DistributedInputIpcTest::TestInputNodeListener::OnNodeOffLine(const std::string srcDevId,
55 const std::string sinkDevId, const std::string sinkNodeId)
56 {
57 (void)srcDevId;
58 (void)sinkDevId;
59 (void)sinkNodeId;
60 return;
61 }
62
OnSimulationEvent(uint32_t type,uint32_t code,int32_t value)63 int32_t DistributedInputIpcTest::TestSimulationEventListenerStub::OnSimulationEvent(
64 uint32_t type, uint32_t code, int32_t value)
65 {
66 (void)type;
67 (void)code;
68 (void)value;
69 return DH_SUCCESS;
70 }
71
72 HWTEST_F(DistributedInputIpcTest, GetDInputSinkProxy01, testing::ext::TestSize.Level1)
73 {
74 bool ret = DInputSAManager::GetInstance().GetDInputSinkProxy();
75 EXPECT_EQ(false, ret);
76 }
77
78 HWTEST_F(DistributedInputIpcTest, CheckSourceRegisterCallback01, testing::ext::TestSize.Level1)
79 {
80 std::string deviceId = "46qweqwe46q5qw4e";
81 BusinessEvent event;
82 DistributedInputClient::GetInstance().CheckSourceRegisterCallback();
83 bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
84 EXPECT_EQ(false, ret);
85 }
86
87 HWTEST_F(DistributedInputIpcTest, CheckSinkRegisterCallback01, testing::ext::TestSize.Level1)
88 {
89 std::string deviceId = "46qweqwe46q5qw4e";
90 BusinessEvent event;
91 DistributedInputClient::GetInstance().CheckSinkRegisterCallback();
92 bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
93 EXPECT_EQ(false, ret);
94 }
95
96 HWTEST_F(DistributedInputIpcTest, CheckSharingDhIdsCallback01, testing::ext::TestSize.Level1)
97 {
98 std::string deviceId = "46qweqwe46q5qw4e";
99 BusinessEvent event;
100 DistributedInputClient::GetInstance().CheckSharingDhIdsCallback();
101 bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
102 EXPECT_EQ(false, ret);
103 }
104
105 HWTEST_F(DistributedInputIpcTest, CheckSinkScreenInfoCallback01, testing::ext::TestSize.Level1)
106 {
107 std::string deviceId = "46qweqwe46q5qw4e";
108 BusinessEvent event;
109 DistributedInputClient::GetInstance().CheckSinkScreenInfoCallback();
110 bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
111 EXPECT_EQ(false, ret);
112 }
113
114 HWTEST_F(DistributedInputIpcTest, IsNeedFilterOut01, testing::ext::TestSize.Level1)
115 {
116 std::string deviceId = "46qweqwe46q5qw4e";
117 BusinessEvent event;
118 bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
119 EXPECT_EQ(false, ret);
120 }
121
122 HWTEST_F(DistributedInputIpcTest, IsNeedFilterOut02, testing::ext::TestSize.Level1)
123 {
124 std::string deviceId;
125 BusinessEvent event;
126 bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
127 EXPECT_EQ(false, ret);
128 }
129
130 HWTEST_F(DistributedInputIpcTest, IsNeedFilterOut03, testing::ext::TestSize.Level1)
131 {
132 std::string deviceId(280, 'e');
133 BusinessEvent event;
134 bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
135 EXPECT_EQ(false, ret);
136 }
137
138 HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut01, testing::ext::TestSize.Level1)
139 {
140 TouchScreenEvent event = {100, 100};
141 bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event);
142 EXPECT_EQ(false, ret);
143 }
144
145 HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut02, testing::ext::TestSize.Level1)
146 {
147 TouchScreenEvent event = {100, 100};
148 nlohmann::json jsonObj;
149 jsonObj = {{10, 10, 100, 100}};
150 DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump());
151 bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event);
152 EXPECT_EQ(true, ret);
153 }
154
155 HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut03, testing::ext::TestSize.Level1)
156 {
157 TouchScreenEvent event = {100, 100};
158 nlohmann::json jsonObj;
159 jsonObj = {{10, 10, 100, 80}};
160 DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump());
161 bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event);
162 EXPECT_EQ(false, ret);
163 }
164
165 HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut04, testing::ext::TestSize.Level1)
166 {
167 TouchScreenEvent event = {100, 100};
168 nlohmann::json jsonObj;
169 jsonObj = {{10, 10, 80, 100}};
170 DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump());
171 bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event);
172 EXPECT_EQ(false, ret);
173 }
174
175 HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut05, testing::ext::TestSize.Level1)
176 {
177 TouchScreenEvent event = {100, 100};
178 nlohmann::json jsonObj;
179 jsonObj = {{110, 10, 100, 100}};
180 DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump());
181 bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event);
182 EXPECT_EQ(false, ret);
183 }
184
185 HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut06, testing::ext::TestSize.Level1)
186 {
187 TouchScreenEvent event = {100, 100};
188 nlohmann::json jsonObj;
189 jsonObj = {{10, 110, 100, 100}};
190 DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump());
191 bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event);
192 EXPECT_EQ(false, ret);
193 }
194
195 HWTEST_F(DistributedInputIpcTest, IsStartDistributedInput01, testing::ext::TestSize.Level1)
196 {
197 std::string dhId;
198 bool ret = DistributedInputClient::GetInstance().IsStartDistributedInput(dhId);
199 EXPECT_EQ(false, ret);
200 }
201
202 HWTEST_F(DistributedInputIpcTest, IsStartDistributedInput02, testing::ext::TestSize.Level1)
203 {
204 std::string dhId = "654ew6qw4f6w1e6f1w6e5f";
205 bool ret = DistributedInputClient::GetInstance().IsStartDistributedInput(dhId);
206 EXPECT_EQ(false, ret);
207 }
208
209 HWTEST_F(DistributedInputIpcTest, IsStartDistributedInput03, testing::ext::TestSize.Level1)
210 {
211 std::string dhId(280, 'e');
212 bool ret = DistributedInputClient::GetInstance().IsStartDistributedInput(dhId);
213 EXPECT_EQ(false, ret);
214 }
215
216 HWTEST_F(DistributedInputIpcTest, RegisterInputNodeListener01, testing::ext::TestSize.Level1)
217 {
218 sptr<TestInputNodeListener> listener = nullptr;
219 int32_t ret = DistributedInputClient::GetInstance().RegisterInputNodeListener(listener);
220 EXPECT_EQ(ERR_DH_INPUT_CLIENT_REG_NODE_CB_FAIL, ret);
221 }
222
223 HWTEST_F(DistributedInputIpcTest, RegisterInputNodeListener02, testing::ext::TestSize.Level1)
224 {
225 sptr<TestInputNodeListener> listener(new TestInputNodeListener());
226 int32_t ret = DistributedInputClient::GetInstance().RegisterInputNodeListener(listener);
227 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
228 }
229
230 HWTEST_F(DistributedInputIpcTest, UnregisterInputNodeListener01, testing::ext::TestSize.Level1)
231 {
232 sptr<TestInputNodeListener> listener = nullptr;
233 int32_t ret = DistributedInputClient::GetInstance().UnregisterInputNodeListener(listener);
234 EXPECT_EQ(ERR_DH_INPUT_CLIENT_UNREG_NODE_CB_FAIL, ret);
235 }
236
237 HWTEST_F(DistributedInputIpcTest, UnregisterInputNodeListener02, testing::ext::TestSize.Level1)
238 {
239 sptr<TestInputNodeListener> listener(new TestInputNodeListener());
240 int32_t ret = DistributedInputClient::GetInstance().UnregisterInputNodeListener(listener);
241 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
242 }
243
244 HWTEST_F(DistributedInputIpcTest, RegisterSimulationEventListener01, testing::ext::TestSize.Level1)
245 {
246 sptr<TestSimulationEventListenerStub> listener = nullptr;
247 int32_t ret = DistributedInputClient::GetInstance().RegisterSimulationEventListener(listener);
248 EXPECT_EQ(ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL, ret);
249 }
250
251 HWTEST_F(DistributedInputIpcTest, RegisterSimulationEventListener02, testing::ext::TestSize.Level1)
252 {
253 sptr<TestSimulationEventListenerStub> listener(new TestSimulationEventListenerStub());
254 int32_t ret = DistributedInputClient::GetInstance().RegisterSimulationEventListener(listener);
255 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
256 }
257
258 HWTEST_F(DistributedInputIpcTest, UnregisterSimulationEventListener01, testing::ext::TestSize.Level1)
259 {
260 sptr<TestSimulationEventListenerStub> listener = nullptr;
261 int32_t ret = DistributedInputClient::GetInstance().UnregisterSimulationEventListener(listener);
262 EXPECT_EQ(ERR_DH_INPUT_CLIENT_REG_UNREG_KEY_STATE_FAIL, ret);
263 }
264
265 HWTEST_F(DistributedInputIpcTest, UnregisterSimulationEventListener02, testing::ext::TestSize.Level1)
266 {
267 sptr<TestSimulationEventListenerStub> listener(new TestSimulationEventListenerStub());
268 int32_t ret = DistributedInputClient::GetInstance().UnregisterSimulationEventListener(listener);
269 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
270 }
271
272 HWTEST_F(DistributedInputIpcTest, IsJsonData01, testing::ext::TestSize.Level1)
273 {
274 std::string strData = "123";
275 bool ret = DistributedInputClient::GetInstance().IsJsonData(strData);
276 EXPECT_EQ(false, ret);
277 }
278
279 HWTEST_F(DistributedInputIpcTest, IsJsonData02, testing::ext::TestSize.Level1)
280 {
281 std::string strData = "{{{}}}";
282 bool ret = DistributedInputClient::GetInstance().IsJsonData(strData);
283 EXPECT_EQ(true, ret);
284 }
285
286 HWTEST_F(DistributedInputIpcTest, IsJsonData03, testing::ext::TestSize.Level1)
287 {
288 std::string strData = "{3413";
289 bool ret = DistributedInputClient::GetInstance().IsJsonData(strData);
290 EXPECT_EQ(false, ret);
291 }
292
293 HWTEST_F(DistributedInputIpcTest, AddWhiteListInfos01, testing::ext::TestSize.Level1)
294 {
295 std::string deviceId = "4646565465asdqweqwe";
296 std::string strJson = "[[[2000][2000][1]]]";
297 DistributedInputClient::GetInstance().AddWhiteListInfos(deviceId, strJson);
298 std::string strData = "{3413";
299 bool ret = DistributedInputClient::GetInstance().IsJsonData(strData);
300 EXPECT_EQ(false, ret);
301 }
302
303 HWTEST_F(DistributedInputIpcTest, AddWhiteListInfos02, testing::ext::TestSize.Level1)
304 {
305 std::string deviceId = "4646565465asdqweqwe";
306 std::string strJson = "";
307 DistributedInputClient::GetInstance().AddWhiteListInfos(deviceId, strJson);
308 std::string strData = "{3413";
309 bool ret = DistributedInputClient::GetInstance().IsJsonData(strData);
310 EXPECT_EQ(false, ret);
311 }
312
313 HWTEST_F(DistributedInputIpcTest, DelWhiteListInfos01, testing::ext::TestSize.Level1)
314 {
315 std::string deviceId = "4646565465asdqweqwe";
316 DistributedInputClient::GetInstance().DelWhiteListInfos(deviceId);
317 std::string strData = "{3413";
318 bool ret = DistributedInputClient::GetInstance().IsJsonData(strData);
319 EXPECT_EQ(false, ret);
320 }
321
322 HWTEST_F(DistributedInputIpcTest, UpdateSinkScreenInfos01, testing::ext::TestSize.Level1)
323 {
324 nlohmann::json jsonObj;
325 jsonObj = {{1080, 720, 10, 10}};
326 DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump());
327 std::string strData = "{3413";
328 bool ret = DistributedInputClient::GetInstance().IsJsonData(strData);
329 EXPECT_EQ(false, ret);
330 }
331
332 HWTEST_F(DistributedInputIpcTest, NotifyStartDScreen01, testing::ext::TestSize.Level1)
333 {
334 std::string sinkDevId = "46qw4e61dq6w1dq6w5e4q6";
335 std::string srcDevId = "erq6w54e9q8w4eqw19q6d1";
336 uint64_t srcWinId = 5;
337 int32_t ret = DistributedInputClient::GetInstance().NotifyStartDScreen(sinkDevId, srcDevId, srcWinId);
338 EXPECT_EQ(ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL, ret);
339 }
340
341 HWTEST_F(DistributedInputIpcTest, NotifyStopDScreen01, testing::ext::TestSize.Level1)
342 {
343 std::string networkId = "46qw4e61dq6w1dq6w5e4q6";
344 std::string srcScreenInfoKey = "q65we46qw54e6q5we46q";
345 int32_t ret = DistributedInputClient::GetInstance().NotifyStopDScreen(networkId, srcScreenInfoKey);
346 EXPECT_EQ(ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL, ret);
347 }
348
349 HWTEST_F(DistributedInputIpcTest, RegisterDistributedHardware01, testing::ext::TestSize.Level1)
350 {
351 std::string devId;
352 std::string dhId;
353 std::string parameters;
354 std::shared_ptr<RegisterCallback> callback = nullptr;
355 int32_t ret = DistributedInputClient::GetInstance().RegisterDistributedHardware(devId, dhId, parameters, callback);
356 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
357 }
358
359 HWTEST_F(DistributedInputIpcTest, UnregisterDistributedHardware01, testing::ext::TestSize.Level1)
360 {
361 std::string devId;
362 std::string dhId;
363 std::shared_ptr<UnregisterCallback> callback = nullptr;
364 int32_t ret = DistributedInputClient::GetInstance().UnregisterDistributedHardware(devId, dhId, callback);
365 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
366 }
367
368 HWTEST_F(DistributedInputIpcTest, PrepareRemoteInput01, testing::ext::TestSize.Level1)
369 {
370 string deviceId = "PrepareRemoteInput01";
371 sptr<IPrepareDInputCallback> callback = nullptr;
372 int32_t ret = DistributedInputClient::GetInstance().PrepareRemoteInput(deviceId, callback);
373 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
374 }
375
376 HWTEST_F(DistributedInputIpcTest, UnprepareRemoteInput01, testing::ext::TestSize.Level0)
377 {
378 string deviceId = "UnprepareRemoteInput01";
379 sptr<IUnprepareDInputCallback> callback = nullptr;
380 int32_t ret = DistributedInputClient::GetInstance().UnprepareRemoteInput(deviceId, callback);
381 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
382 }
383
384 HWTEST_F(DistributedInputIpcTest, StartRemoteInput01, testing::ext::TestSize.Level0)
385 {
386 string deviceId = "StartRemoteInput01";
387 sptr<IStartDInputCallback> callback = nullptr;
388 int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(
389 deviceId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
390 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
391 }
392
393 HWTEST_F(DistributedInputIpcTest, StartRemoteInput02, testing::ext::TestSize.Level0)
394 {
395 std::string sinkId = "StartRemoteInput_sink";
396 std::vector<std::string> dhIds = {"dhIds_test"};
397 sptr<IStartStopDInputsCallback> callback = nullptr;
398 int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(sinkId, dhIds, callback);
399 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
400 }
401
402 HWTEST_F(DistributedInputIpcTest, StartRemoteInput03, testing::ext::TestSize.Level0)
403 {
404 string srcId = "StartRemoteInput01-src";
405 string sinkId = "StartRemoteInput01-sink";
406 sptr<IStartDInputCallback> callback = nullptr;
407 int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(
408 srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
409 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
410 }
411
412 HWTEST_F(DistributedInputIpcTest, StartRemoteInput04, testing::ext::TestSize.Level0)
413 {
414 string srcId = "StartRemoteInput01-src";
415 string sinkId = "StartRemoteInput01-sink";
416 std::vector<std::string> dhIds = {"dhIds_test"};
417 sptr<IStartStopDInputsCallback> callback = nullptr;
418 int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, dhIds, callback);
419 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
420 }
421
422 HWTEST_F(DistributedInputIpcTest, StopRemoteInput01, testing::ext::TestSize.Level0)
423 {
424 string deviceId = "StopRemoteInput01";
425 sptr<IStopDInputCallback> callback = nullptr;
426 int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(
427 deviceId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
428 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
429 }
430
431 HWTEST_F(DistributedInputIpcTest, StopRemoteInput02, testing::ext::TestSize.Level0)
432 {
433 std::string sinkId = "StartRemoteInput_test";
434 std::vector<std::string> dhIds = {"dhIds_test"};
435 sptr<IStartStopDInputsCallback> callback = nullptr;
436 int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(sinkId, dhIds, callback);
437 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
438 }
439
440 HWTEST_F(DistributedInputIpcTest, StopRemoteInput03, testing::ext::TestSize.Level0)
441 {
442 string srcId = "StopRemoteInput03-src";
443 string sinkId = "StopRemoteInput03-sink";
444 sptr<IStopDInputCallback> callback = nullptr;
445 int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(
446 srcId, sinkId, static_cast<uint32_t>(DInputDeviceType::ALL), callback);
447 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
448 }
449
450 HWTEST_F(DistributedInputIpcTest, StopRemoteInput04, testing::ext::TestSize.Level0)
451 {
452 string srcId = "StartRemoteInput01-src";
453 string sinkId = "StartRemoteInput01-sink";
454 std::vector<std::string> dhIds = {"dhIds_test"};
455 sptr<IStartStopDInputsCallback> callback = nullptr;
456 int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, dhIds, callback);
457 EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret);
458 }
459
460 } // namespace DistributedInput
461 } // namespace DistributedHardware
462 } // namespace OHOS