• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <cstdio>
17 #include <cinttypes>
18 
19 #include <gtest/gtest.h>
20 #include "display_event_monitor.h"
21 #include "input_event_handler.h"
22 #include "libinput.h"
23 #include "pixel_map.h"
24 #include "sec_comp_enhance_kit.h"
25 
26 #include "authorize_helper.h"
27 #include "define_multimodal.h"
28 #include "image_source.h"
29 #include "inject_notice_manager.h"
30 #include "input_device_manager.h"
31 #include "mmi_log.h"
32 #include "pointer_event.h"
33 #include "server_msg_handler.h"
34 #include "stream_buffer.h"
35 
36 #undef MMI_LOG_TAG
37 #define MMI_LOG_TAG "ServerMsgHandlerTest"
38 
39 namespace OHOS {
40 namespace MMI {
41 namespace {
42 using namespace testing::ext;
43 constexpr int32_t UID_ROOT { 0 };
44 static constexpr char PROGRAM_NAME[] = "uds_sesion_test";
45 int32_t g_moduleType = 3;
46 int32_t g_pid = 0;
47 int32_t g_writeFd = -1;
48 constexpr int32_t NUM_LOCK_FUNCTION_KEY = 0;
49 constexpr int32_t CAPS_LOCK_FUNCTION_KEY = 1;
50 constexpr int32_t SCROLL_LOCK_FUNCTION_KEY = 2;
51 constexpr int32_t SECURITY_COMPONENT_SERVICE_ID = 3050;
52 constexpr int32_t MOUSE_ICON_SIZE = 64;
53 constexpr int32_t COMMON_PERMISSION_CHECK_ERROR { 201 };
54 constexpr int32_t ERR_DEVICE_NOT_EXIST { 3900002 };
55 constexpr int32_t ERR_NON_INPUT_APPLICATION { 3900003 };
56 
57 class RemoteObjectTest : public IRemoteObject {
58 public:
RemoteObjectTest(std::u16string descriptor)59     explicit RemoteObjectTest(std::u16string descriptor) : IRemoteObject(descriptor) {}
~RemoteObjectTest()60     ~RemoteObjectTest() {}
61 
GetObjectRefCount()62     int32_t GetObjectRefCount() { return 0; }
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)63     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { return 0; }
AddDeathRecipient(const sptr<DeathRecipient> & recipient)64     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) { return true; }
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)65     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) { return true; }
Dump(int fd,const std::vector<std::u16string> & args)66     int Dump(int fd, const std::vector<std::u16string> &args) { return 0; }
67 };
68 } // namespace
69 
70 class ServerMsgHandlerTest : public testing::Test {
71 public:
SetUpTestCase(void)72     static void SetUpTestCase(void) {}
TearDownTestCase(void)73     static void TearDownTestCase(void) {}
SetUp()74     void SetUp() {}
TearDoen()75     void TearDoen() {}
76     std::unique_ptr<OHOS::Media::PixelMap> SetMouseIconTest(const std::string iconPath);
77 };
78 
SetMouseIconTest(const std::string iconPath)79 std::unique_ptr<OHOS::Media::PixelMap> ServerMsgHandlerTest::SetMouseIconTest(const std::string iconPath)
80 {
81     CALL_DEBUG_ENTER;
82     OHOS::Media::SourceOptions opts;
83     opts.formatHint = "image/svg+xml";
84     uint32_t ret = 0;
85     auto imageSource = OHOS::Media::ImageSource::CreateImageSource(iconPath, opts, ret);
86     CHKPP(imageSource);
87     std::set<std::string> formats;
88     ret = imageSource->GetSupportedFormats(formats);
89     MMI_HILOGD("Get supported format ret:%{public}u", ret);
90     OHOS::Media::DecodeOptions decodeOpts;
91     decodeOpts.desiredSize = {.width = MOUSE_ICON_SIZE, .height = MOUSE_ICON_SIZE};
92     std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
93     CHKPL(pixelMap);
94     return pixelMap;
95 }
96 
97 /**
98  * @tc.name: ServerMsgHandlerTest_SetPixelMapData
99  * @tc.desc: Test SetPixelMapData
100  * @tc.type: FUNC
101  * @tc.require:
102  */
103 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetPixelMapData, TestSize.Level1)
104 {
105     CALL_TEST_DEBUG;
106     ServerMsgHandler servermsghandler;
107     int32_t infoId = -1;
108     void* pixelMap = nullptr;
109     int32_t result = servermsghandler.SetPixelMapData(infoId, pixelMap);
110     EXPECT_EQ(result, ERR_INVALID_VALUE);
111 }
112 
113 /**
114  * @tc.name: ServerMsgHandlerTest_SetShieldStatus_01
115  * @tc.desc: Test SetShieldStatus
116  * @tc.type: FUNC
117  * @tc.require:
118  */
119 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetShieldStatus_01, TestSize.Level1)
120 {
121     CALL_TEST_DEBUG;
122     ServerMsgHandler servermsghandler;
123     int32_t shieldMode = -1;
124     bool isShield = false;
125     int32_t result = servermsghandler.SetShieldStatus(shieldMode, isShield);
126     EXPECT_EQ(result, RET_ERR);
127 }
128 
129 /**
130  * @tc.name: ServerMsgHandlerTest_SetShieldStatus_02
131  * @tc.desc: Test SetShieldStatus
132  * @tc.type: FUNC
133  * @tc.require:
134  */
135 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetShieldStatus_02, TestSize.Level1)
136 {
137     CALL_TEST_DEBUG;
138     ServerMsgHandler servermsghandler;
139     int32_t shieldMode = 1;
140     bool isShield = true;
141     int32_t result = servermsghandler.SetShieldStatus(shieldMode, isShield);
142     EXPECT_EQ(result, RET_OK);
143 }
144 
145 /**
146  * @tc.name: ServerMsgHandlerTest_GetShieldStatus_01
147  * @tc.desc: Test GetShieldStatus
148  * @tc.type: FUNC
149  * @tc.require:
150  */
151 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_GetShieldStatus_01, TestSize.Level1)
152 {
153     CALL_TEST_DEBUG;
154     ServerMsgHandler servermsghandler;
155     int32_t shieldMode = -1;
156     bool isShield = false;
157     int32_t result = servermsghandler.GetShieldStatus(shieldMode, isShield);
158     EXPECT_EQ(result, RET_ERR);
159 }
160 
161 /**
162  * @tc.name: ServerMsgHandlerTest_GetShieldStatus_02
163  * @tc.desc: Test GetShieldStatus
164  * @tc.type: FUNC
165  * @tc.require:
166  */
167 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_GetShieldStatus_02, TestSize.Level1)
168 {
169     CALL_TEST_DEBUG;
170     ServerMsgHandler servermsghandler;
171     int32_t shieldMode = 1;
172     bool isShield = true;
173     int32_t result = servermsghandler.GetShieldStatus(shieldMode, isShield);
174     EXPECT_EQ(result, RET_OK);
175 }
176 
177 /**
178  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent
179  * @tc.desc: Test OnInjectPointerEvent
180  * @tc.type: FUNC
181  * @tc.require:
182  */
183 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent, TestSize.Level1)
184 {
185     CALL_TEST_DEBUG;
186     ServerMsgHandler servermsghandler;
187     auto pointerEvent = PointerEvent::Create();
188     ASSERT_NE(pointerEvent, nullptr);
189     int32_t pid = 1;
190     bool isNativeInject = true;
191     int32_t result = servermsghandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false);
192     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
193 }
194 
195 /**
196  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_01
197  * @tc.desc: Test FixTargetWindowId
198  * @tc.type: FUNC
199  * @tc.require:
200  */
201 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_01, TestSize.Level1)
202 {
203     CALL_TEST_DEBUG;
204     ServerMsgHandler servermsghandler;
205     auto pointerEvent = PointerEvent::Create();
206     ASSERT_NE(pointerEvent, nullptr);
207     int32_t action = PointerEvent::POINTER_ACTION_HOVER_ENTER;
208     bool result = servermsghandler.FixTargetWindowId(pointerEvent, action, false);
209     ASSERT_FALSE(result);
210 }
211 
212 /**
213  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_02
214  * @tc.desc: Test FixTargetWindowId
215  * @tc.type: FUNC
216  * @tc.require:
217  */
218 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_02, TestSize.Level1)
219 {
220     CALL_TEST_DEBUG;
221     ServerMsgHandler servermsghandler;
222     auto pointerEvent = PointerEvent::Create();
223     ASSERT_NE(pointerEvent, nullptr);
224     int32_t action = PointerEvent::POINTER_ACTION_DOWN;
225     bool result = servermsghandler.FixTargetWindowId(pointerEvent, action, false);
226     ASSERT_FALSE(result);
227 }
228 
229 /**
230  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_03
231  * @tc.desc: Test FixTargetWindowId
232  * @tc.type: FUNC
233  * @tc.require:
234  */
235 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_03, TestSize.Level1)
236 {
237     CALL_TEST_DEBUG;
238     ServerMsgHandler servermsghandler;
239     auto pointerEvent = PointerEvent::Create();
240     ASSERT_NE(pointerEvent, nullptr);
241     int32_t action = PointerEvent::POINTER_ACTION_UNKNOWN;
242     auto pointerIds = pointerEvent->GetPointerIds();
243     EXPECT_TRUE(pointerIds.empty());
244     bool result = servermsghandler.FixTargetWindowId(pointerEvent, action, false);
245     ASSERT_FALSE(result);
246 }
247 
248 /**
249  * @tc.name: ServerMsgHandlerTest_Init
250  * @tc.desc: Test Init
251  * @tc.type: FUNC
252  * @tc.require:
253  */
254 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_Init, TestSize.Level1)
255 {
256     CALL_TEST_DEBUG;
257     ServerMsgHandler servermsghandler;
258     UDSServer udsServerFirst;
259     ASSERT_NO_FATAL_FAILURE(servermsghandler.Init(udsServerFirst));
260     UDSServer udsServerSecond;
261     ASSERT_NO_FATAL_FAILURE(servermsghandler.Init(udsServerSecond));
262 }
263 
264 /**
265  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithNullSession
266  * @tc.desc: Test OnAddInputHandler
267  * @tc.type: FUNC
268  * @tc.require:
269  */
270 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithNullSession, TestSize.Level1)
271 {
272     CALL_TEST_DEBUG;
273     ServerMsgHandler servermsghandler;
274     SessionPtr sess = nullptr;
275     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
276     HandleEventType eventType = 1;
277     int32_t priority = 1;
278     uint32_t deviceTags = 0x01;
279     EXPECT_EQ(servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags),
280         ERROR_NULL_POINTER);
281 }
282 
283 /**
284  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler001
285  * @tc.desc: Test OnAddInputHandler
286  * @tc.type: FUNC
287  * @tc.require:
288  */
289 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler001, TestSize.Level1)
290 {
291     CALL_TEST_DEBUG;
292     ServerMsgHandler servermsghandler;
293     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
294     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
295     HandleEventType eventType = 1;
296     int32_t priority = 1;
297     uint32_t deviceTags = 0x01;
298     EXPECT_EQ(servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags),
299         ERROR_NULL_POINTER);
300 }
301 
302 /**
303  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler001
304  * @tc.desc: Test OnAddInputHandler
305  * @tc.type: FUNC
306  * @tc.require:
307  */
308 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler001, TestSize.Level1)
309 {
310     CALL_TEST_DEBUG;
311     ServerMsgHandler servermsghandler;
312     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
313     InputHandlerType handlerType = InputHandlerType::MONITOR;
314     HandleEventType eventType = 1;
315     int32_t priority = 1;
316     uint32_t deviceTags = 0x01;
317     EXPECT_EQ(servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags),
318         ERROR_NULL_POINTER);
319 }
320 
321 /**
322  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithNullSession
323  * @tc.desc: Test OnRemoveInputHandler
324  * @tc.type: FUNC
325  * @tc.require:
326  */
327 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithNullSession, TestSize.Level1)
328 {
329     CALL_TEST_DEBUG;
330     ServerMsgHandler servermsghandler;
331     SessionPtr sess = nullptr;
332     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
333     HandleEventType eventType = 1;
334     int32_t priority = 1;
335     uint32_t deviceTags = 0x01;
336     EXPECT_EQ(servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags),
337         ERROR_NULL_POINTER);
338 }
339 
340 /**
341  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler001
342  * @tc.desc: Test OnRemoveInputHandler
343  * @tc.type: FUNC
344  * @tc.require:
345  */
346 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler001, TestSize.Level1)
347 {
348     CALL_TEST_DEBUG;
349     ServerMsgHandler servermsghandler;
350     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
351     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
352     HandleEventType eventType = 1;
353     int32_t priority = 1;
354     uint32_t deviceTags = 0x01;
355     EXPECT_EQ(servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags),
356         ERROR_NULL_POINTER);
357 }
358 
359 /**
360  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler001
361  * @tc.desc: Test OnRemoveInputHandler
362  * @tc.type: FUNC
363  * @tc.require:
364  */
365 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler001, TestSize.Level1)
366 {
367     CALL_TEST_DEBUG;
368     ServerMsgHandler servermsghandler;
369     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
370     InputHandlerType handlerType = InputHandlerType::MONITOR;
371     HandleEventType eventType = 1;
372     int32_t priority = 1;
373     uint32_t deviceTags = 0x01;
374     EXPECT_EQ(servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags),
375         ERROR_NULL_POINTER);
376 }
377 
378 /**
379  * @tc.name: ServerMsgHandlerTest_OnMarkConsumedWithNullSession
380  * @tc.desc: Test OnMarkConsumed
381  * @tc.type: FUNC
382  * @tc.require:
383  */
384 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMarkConsumedWithNullSession, TestSize.Level1)
385 {
386     CALL_TEST_DEBUG;
387     ServerMsgHandler servermsghandler;
388     SessionPtr sess = nullptr;
389     int32_t eventId = 11;
390     EXPECT_EQ(servermsghandler.OnMarkConsumed(sess, eventId), ERROR_NULL_POINTER);
391 }
392 
393 /**
394  * @tc.name: ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler001
395  * @tc.desc: Test OnMarkConsumed
396  * @tc.type: FUNC
397  * @tc.require:
398  */
399 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler001, TestSize.Level1)
400 {
401     CALL_TEST_DEBUG;
402     ServerMsgHandler servermsghandler;
403     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
404     int32_t eventId = 11;
405     EXPECT_EQ(servermsghandler.OnMarkConsumed(sess, eventId), ERROR_NULL_POINTER);
406 }
407 
408 /**
409  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler002
410  * @tc.desc: Test OnAddInputHandler
411  * @tc.type: FUNC
412  * @tc.require:
413  */
414 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler002, TestSize.Level1)
415 {
416     CALL_TEST_DEBUG;
417     ServerMsgHandler servermsghandler;
418     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
419     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
420     HandleEventType eventType = 1;
421     int32_t priority = 1;
422     uint32_t deviceTags = 0x01;
423     InputHandler->BuildInputHandlerChain();
424     EXPECT_EQ(servermsghandler.OnAddInputHandler(
425         sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
426 }
427 
428 /**
429  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler002
430  * @tc.desc: Test OnAddInputHandler
431  * @tc.type: FUNC
432  * @tc.require:
433  */
434 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler002, TestSize.Level1)
435 {
436     CALL_TEST_DEBUG;
437     ServerMsgHandler servermsghandler;
438     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
439     InputHandlerType handlerType = InputHandlerType::MONITOR;
440     HandleEventType eventType = 1;
441     int32_t priority = 1;
442     uint32_t deviceTags = 0x01;
443     EXPECT_EQ(servermsghandler.OnAddInputHandler(
444         sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
445 }
446 
447 /**
448  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler002
449  * @tc.desc: Test OnRemoveInputHandler
450  * @tc.type: FUNC
451  * @tc.require:
452  */
453 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler002, TestSize.Level1)
454 {
455     CALL_TEST_DEBUG;
456     ServerMsgHandler servermsghandler;
457     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
458     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
459     HandleEventType eventType = 1;
460     int32_t priority = 1;
461     uint32_t deviceTags = 0x01;
462     EXPECT_EQ(servermsghandler.OnRemoveInputHandler(
463         sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
464 }
465 
466 /**
467  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler002
468  * @tc.desc: Test OnRemoveInputHandler
469  * @tc.type: FUNC
470  * @tc.require:
471  */
472 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler002, TestSize.Level1)
473 {
474     CALL_TEST_DEBUG;
475     ServerMsgHandler servermsghandler;
476     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
477     InputHandlerType handlerType = InputHandlerType::MONITOR;
478     HandleEventType eventType = 1;
479     int32_t priority = 1;
480     uint32_t deviceTags = 0x01;
481     EXPECT_EQ(servermsghandler.OnRemoveInputHandler(
482         sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
483 }
484 
485 /**
486  * @tc.name: ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler002
487  * @tc.desc: Test OnMarkConsumed
488  * @tc.type: FUNC
489  * @tc.require:
490  */
491 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler002, TestSize.Level1)
492 {
493     CALL_TEST_DEBUG;
494     ServerMsgHandler servermsghandler;
495     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
496     int32_t eventId = 11;
497     EXPECT_EQ(servermsghandler.OnMarkConsumed(sess, eventId), ERROR_NULL_POINTER);
498 }
499 
500 /**
501  * @tc.name: ServerMsgHandlerTest_OnGetFunctionKeyState_001
502  * @tc.desc: Test the function OnGetFunctionKeyState
503  * @tc.type: FUNC
504  * @tc.require:
505  */
506 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnGetFunctionKeyState_001, TestSize.Level1)
507 {
508     CALL_TEST_DEBUG;
509     ServerMsgHandler handler;
510     int32_t funcKey = NUM_LOCK_FUNCTION_KEY;
511     bool state = false;
512     int32_t ret = handler.OnGetFunctionKeyState(funcKey, state);
513     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
514     funcKey = CAPS_LOCK_FUNCTION_KEY;
515     ret = handler.OnGetFunctionKeyState(funcKey, state);
516     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
517     funcKey = SCROLL_LOCK_FUNCTION_KEY;
518     ret = handler.OnGetFunctionKeyState(funcKey, state);
519     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
520     funcKey = 10;
521     state = true;
522     ret = handler.OnGetFunctionKeyState(funcKey, state);
523     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
524 }
525 
526 /**
527  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEventExt_001
528  * @tc.desc: Test the function OnInjectPointerEventExt
529  * @tc.type: FUNC
530  * @tc.require:
531  */
532 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEventExt_001, TestSize.Level1)
533 {
534     CALL_TEST_DEBUG;
535     ServerMsgHandler handler;
536     std::shared_ptr<PointerEvent> pointerEvent = nullptr;
537     int32_t ret = handler.OnInjectPointerEventExt(pointerEvent, false);
538     EXPECT_EQ(ret, ERROR_NULL_POINTER);
539     pointerEvent = PointerEvent::Create();
540     EXPECT_NE(pointerEvent, nullptr);
541     int32_t sourceType = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
542     ret = handler.OnInjectPointerEventExt(pointerEvent, false);
543     EXPECT_EQ(ret, ERROR_NULL_POINTER);
544     sourceType = PointerEvent::SOURCE_TYPE_MOUSE;
545     EXPECT_NO_FATAL_FAILURE(handler.OnInjectPointerEventExt(pointerEvent, false));
546     sourceType = PointerEvent::SOURCE_TYPE_JOYSTICK;
547     EXPECT_NO_FATAL_FAILURE(handler.OnInjectPointerEventExt(pointerEvent, false));
548     sourceType = PointerEvent::SOURCE_TYPE_TOUCHPAD;
549     EXPECT_NO_FATAL_FAILURE(handler.OnInjectPointerEventExt(pointerEvent, false));
550 }
551 
552 /**
553  * @tc.name: ServerMsgHandlerTest_OnEnhanceConfig_001
554  * @tc.desc: Test the function OnEnhanceConfig
555  * @tc.type: FUNC
556  * @tc.require:
557  */
558 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnEnhanceConfig_001, TestSize.Level1)
559 {
560     CALL_TEST_DEBUG;
561     ServerMsgHandler handler;
562     SessionPtr sess = nullptr;
563     MmiMessageId idMsg = MmiMessageId::INVALID;
564     NetPacket pkt(idMsg);
565     int32_t ret = handler.OnEnhanceConfig(sess, pkt);
566     EXPECT_EQ(ret, ERROR_NULL_POINTER);
567     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
568     int32_t uid = 1;
569     ret = handler.OnEnhanceConfig(sess, pkt);
570     EXPECT_EQ(ret, RET_ERR);
571     uid = SECURITY_COMPONENT_SERVICE_ID;
572     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
573     ret = handler.OnEnhanceConfig(sess, pkt);
574     EXPECT_EQ(ret, RET_ERR);
575     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
576     EXPECT_NO_FATAL_FAILURE(handler.OnEnhanceConfig(sess, pkt));
577 }
578 
579 /**
580  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_001
581  * @tc.desc: Test the function AccelerateMotion
582  * @tc.type: FUNC
583  * @tc.require:
584  */
585 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_001, TestSize.Level1)
586 {
587     CALL_TEST_DEBUG;
588     ServerMsgHandler handler;
589     auto pointerEvent = PointerEvent::Create();
590     ASSERT_NE(pointerEvent, nullptr);
591     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
592     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
593     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
594     int32_t pointerId = 1;
595     PointerEvent::PointerItem item;
596     item.SetPointerId(pointerId);
597     pointerEvent->AddPointerItem(item);
598     pointerEvent->SetPointerId(0);
599     DisplayInfo displayInfo;
600     displayInfo.id = -1;
601     int32_t ret = handler.AccelerateMotion(pointerEvent);
602     EXPECT_EQ(ret, RET_OK);
603 }
604 
605 /**
606  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_002
607  * @tc.desc: Test the function AccelerateMotion
608  * @tc.type: FUNC
609  * @tc.require:
610  */
611 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_002, TestSize.Level1)
612 {
613     CALL_TEST_DEBUG;
614     ServerMsgHandler handler;
615     auto pointerEvent = PointerEvent::Create();
616     ASSERT_NE(pointerEvent, nullptr);
617     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
618     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
619     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
620     int32_t pointerId = 1;
621     PointerEvent::PointerItem item;
622     item.SetPointerId(pointerId);
623     pointerEvent->AddPointerItem(item);
624     pointerEvent->SetPointerId(0);
625     DisplayInfo displayInfo;
626     displayInfo.id = -1;
627     int32_t ret = handler.AccelerateMotion(pointerEvent);
628     EXPECT_EQ(ret, RET_ERR);
629 }
630 
631 /**
632  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_003
633  * @tc.desc: Test the function AccelerateMotion
634  * @tc.type: FUNC
635  * @tc.require:
636  */
637 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_003, TestSize.Level1)
638 {
639     CALL_TEST_DEBUG;
640     ServerMsgHandler handler;
641     auto pointerEvent = PointerEvent::Create();
642     ASSERT_NE(pointerEvent, nullptr);
643     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
644     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
645     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
646     int32_t pointerId = 0;
647     PointerEvent::PointerItem item;
648     item.SetPointerId(pointerId);
649     pointerEvent->AddPointerItem(item);
650     pointerEvent->SetPointerId(0);
651     DisplayInfo displayInfo;
652     displayInfo.id = -1;
653     int32_t ret = handler.AccelerateMotion(pointerEvent);
654     EXPECT_EQ(ret, RET_ERR);
655 }
656 
657 /**
658  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_004
659  * @tc.desc: Test the function AccelerateMotion
660  * @tc.type: FUNC
661  * @tc.require:
662  */
663 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_004, TestSize.Level1)
664 {
665     CALL_TEST_DEBUG;
666     ServerMsgHandler handler;
667     auto pointerEvent = PointerEvent::Create();
668     ASSERT_NE(pointerEvent, nullptr);
669     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
670     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
671     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
672     int32_t pointerId = 0;
673     PointerEvent::PointerItem item;
674     item.SetPointerId(pointerId);
675     pointerEvent->AddPointerItem(item);
676     pointerEvent->SetPointerId(0);
677     DisplayInfo displayInfo;
678     displayInfo.id = 1;
679     displayInfo.displayDirection = DIRECTION0;
680     int32_t ret = handler.AccelerateMotion(pointerEvent);
681     EXPECT_EQ(ret, RET_ERR);
682 }
683 
684 /**
685  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_005
686  * @tc.desc: Test the function AccelerateMotion
687  * @tc.type: FUNC
688  * @tc.require:
689  */
690 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_005, TestSize.Level1)
691 {
692     CALL_TEST_DEBUG;
693     ServerMsgHandler handler;
694     auto pointerEvent = PointerEvent::Create();
695     ASSERT_NE(pointerEvent, nullptr);
696     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
697     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
698     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
699     int32_t pointerId = 0;
700     PointerEvent::PointerItem item;
701     item.SetPointerId(pointerId);
702     pointerEvent->AddPointerItem(item);
703     pointerEvent->SetPointerId(0);
704     DisplayInfo displayInfo;
705     displayInfo.id = 1;
706     displayInfo.displayDirection = DIRECTION90;
707     int32_t ret = handler.AccelerateMotion(pointerEvent);
708     EXPECT_EQ(ret, RET_ERR);
709 }
710 
711 /**
712  * @tc.name: ServerMsgHandlerTest_UpdatePointerEvent_001
713  * @tc.desc: Test the function UpdatePointerEvent
714  * @tc.type: FUNC
715  * @tc.require:
716  */
717 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdatePointerEvent_001, TestSize.Level1)
718 {
719     CALL_TEST_DEBUG;
720     ServerMsgHandler handler;
721     auto pointerEvent = PointerEvent::Create();
722     ASSERT_NE(pointerEvent, nullptr);
723     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
724     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
725     int32_t pointerId = 0;
726     PointerEvent::PointerItem item;
727     item.SetPointerId(pointerId);
728     pointerEvent->AddPointerItem(item);
729     pointerEvent->SetPointerId(0);
730     ASSERT_NO_FATAL_FAILURE(handler.UpdatePointerEvent(pointerEvent));
731 }
732 
733 /**
734  * @tc.name: ServerMsgHandlerTest_UpdatePointerEvent_002
735  * @tc.desc: Test the function UpdatePointerEvent
736  * @tc.type: FUNC
737  * @tc.require:
738  */
739 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdatePointerEvent_002, TestSize.Level1)
740 {
741     CALL_TEST_DEBUG;
742     ServerMsgHandler handler;
743     auto pointerEvent = PointerEvent::Create();
744     ASSERT_NE(pointerEvent, nullptr);
745     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
746     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
747     int32_t pointerId = 0;
748     PointerEvent::PointerItem item;
749     item.SetPointerId(pointerId);
750     pointerEvent->AddPointerItem(item);
751     pointerEvent->SetPointerId(0);
752     ASSERT_NO_FATAL_FAILURE(handler.UpdatePointerEvent(pointerEvent));
753 }
754 
755 /**
756  * @tc.name: ServerMsgHandlerTest_UpdatePointerEvent_003
757  * @tc.desc: Test the function UpdatePointerEvent
758  * @tc.type: FUNC
759  * @tc.require:
760  */
761 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdatePointerEvent_003, TestSize.Level1)
762 {
763     CALL_TEST_DEBUG;
764     ServerMsgHandler handler;
765     auto pointerEvent = PointerEvent::Create();
766     ASSERT_NE(pointerEvent, nullptr);
767     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
768     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
769     int32_t pointerId = 1;
770     PointerEvent::PointerItem item;
771     item.SetPointerId(pointerId);
772     pointerEvent->AddPointerItem(item);
773     pointerEvent->SetPointerId(0);
774     ASSERT_NO_FATAL_FAILURE(handler.UpdatePointerEvent(pointerEvent));
775 }
776 
777 /**
778  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_001
779  * @tc.desc: Test the function SaveTargetWindowId
780  * @tc.type: FUNC
781  * @tc.require:
782  */
783 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_001, TestSize.Level1)
784 {
785     CALL_TEST_DEBUG;
786     ServerMsgHandler handler;
787     auto pointerEvent = PointerEvent::Create();
788     ASSERT_NE(pointerEvent, nullptr);
789     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
790     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
791     int32_t pointerId = 1;
792     PointerEvent::PointerItem item;
793     item.SetPointerId(pointerId);
794     pointerEvent->AddPointerItem(item);
795     pointerEvent->SetPointerId(0);
796     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
797     EXPECT_EQ(ret, RET_ERR);
798 }
799 
800 /**
801  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_002
802  * @tc.desc: Test the function SaveTargetWindowId
803  * @tc.type: FUNC
804  * @tc.require:
805  */
806 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_002, TestSize.Level1)
807 {
808     CALL_TEST_DEBUG;
809     ServerMsgHandler handler;
810     auto pointerEvent = PointerEvent::Create();
811     ASSERT_NE(pointerEvent, nullptr);
812     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
813     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
814     int32_t pointerId = 0;
815     PointerEvent::PointerItem item;
816     item.SetPointerId(pointerId);
817     pointerEvent->AddPointerItem(item);
818     pointerEvent->SetPointerId(0);
819     DisplayInfo displayInfo;
820     displayInfo.id = 1;
821     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
822     EXPECT_EQ(ret, RET_OK);
823 }
824 
825 /**
826  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_003
827  * @tc.desc: Test the function SaveTargetWindowId
828  * @tc.type: FUNC
829  * @tc.require:
830  */
831 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_003, TestSize.Level1)
832 {
833     CALL_TEST_DEBUG;
834     ServerMsgHandler handler;
835     auto pointerEvent = PointerEvent::Create();
836     ASSERT_NE(pointerEvent, nullptr);
837     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
838     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_MOVE);
839     int32_t pointerId = 0;
840     PointerEvent::PointerItem item;
841     item.SetPointerId(pointerId);
842     pointerEvent->AddPointerItem(item);
843     pointerEvent->SetPointerId(0);
844     DisplayInfo displayInfo;
845     displayInfo.id = 1;
846     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
847     EXPECT_EQ(ret, RET_OK);
848 }
849 
850 /**
851  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_004
852  * @tc.desc: Test the function SaveTargetWindowId
853  * @tc.type: FUNC
854  * @tc.require:
855  */
856 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_004, TestSize.Level1)
857 {
858     CALL_TEST_DEBUG;
859     ServerMsgHandler handler;
860     auto pointerEvent = PointerEvent::Create();
861     ASSERT_NE(pointerEvent, nullptr);
862     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
863     EXPECT_EQ(ret, RET_OK);
864 }
865 
866 /**
867  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_001
868  * @tc.desc: Test FixTargetWindowId
869  * @tc.type: FUNC
870  * @tc.require:
871  */
872 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_001, TestSize.Level1)
873 {
874     CALL_TEST_DEBUG;
875     ServerMsgHandler handler;
876     auto pointerEvent = PointerEvent::Create();
877     ASSERT_NE(pointerEvent, nullptr);
878     int32_t action = PointerEvent::POINTER_ACTION_UNKNOWN;
879     pointerEvent->SetPointerId(1);
880     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
881     ASSERT_FALSE(result);
882 }
883 
884 /**
885  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_002
886  * @tc.desc: Test FixTargetWindowId
887  * @tc.type: FUNC
888  * @tc.require:
889  */
890 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_002, TestSize.Level1)
891 {
892     CALL_TEST_DEBUG;
893     ServerMsgHandler handler;
894     auto pointerEvent = PointerEvent::Create();
895     ASSERT_NE(pointerEvent, nullptr);
896     int32_t action = PointerEvent::POINTER_ACTION_HOVER_ENTER;
897     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
898     ASSERT_FALSE(result);
899 }
900 
901 /**
902  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_003
903  * @tc.desc: Test FixTargetWindowId
904  * @tc.type: FUNC
905  * @tc.require:
906  */
907 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_003, TestSize.Level1)
908 {
909     CALL_TEST_DEBUG;
910     ServerMsgHandler handler;
911     auto pointerEvent = PointerEvent::Create();
912     ASSERT_NE(pointerEvent, nullptr);
913     int32_t action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
914     pointerEvent->SetPointerId(1);
915     std::vector<int32_t> pointerIds { pointerEvent->GetPointerIds() };
916     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
917     ASSERT_FALSE(result);
918 }
919 
920 /**
921  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_004
922  * @tc.desc: Test FixTargetWindowId
923  * @tc.type: FUNC
924  * @tc.require:
925  */
926 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_004, TestSize.Level1)
927 {
928     CALL_TEST_DEBUG;
929     ServerMsgHandler handler;
930     auto pointerEvent = PointerEvent::Create();
931     ASSERT_NE(pointerEvent, nullptr);
932     int32_t action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
933     pointerEvent->SetPointerId(1);
934     std::vector<int32_t> pointerIds { pointerEvent->GetPointerIds() };
935     int32_t pointerId = 0;
936     PointerEvent::PointerItem item;
937     item.SetPointerId(pointerId);
938     pointerEvent->AddPointerItem(item);
939     pointerEvent->SetPointerId(0);
940     DisplayInfo displayInfo;
941     displayInfo.id = 1;
942     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
943     ASSERT_TRUE(result);
944 }
945 
946 /**
947  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_005
948  * @tc.desc: Test FixTargetWindowId
949  * @tc.type: FUNC
950  * @tc.require:
951  */
952 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_005, TestSize.Level1)
953 {
954     CALL_TEST_DEBUG;
955     ServerMsgHandler handler;
956     auto pointerEvent = PointerEvent::Create();
957     ASSERT_NE(pointerEvent, nullptr);
958     int32_t action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
959     pointerEvent->SetPointerId(1);
960     std::vector<int32_t> pointerIds { pointerEvent->GetPointerIds() };
961     int32_t pointerId = 1;
962     PointerEvent::PointerItem item;
963     item.SetPointerId(pointerId);
964     pointerEvent->AddPointerItem(item);
965     pointerEvent->SetPointerId(0);
966     DisplayInfo displayInfo;
967     displayInfo.id = 1;
968     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
969     ASSERT_FALSE(result);
970 }
971 
972 /**
973  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandler_001
974  * @tc.desc: Test the function OnRemoveInputHandler
975  * @tc.type: FUNC
976  * @tc.require:
977  */
978 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandler_001, TestSize.Level1)
979 {
980     CALL_TEST_DEBUG;
981     ServerMsgHandler handler;
982     SessionPtr sess = nullptr;
983     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
984     HandleEventType eventType =1;
985     int32_t priority = 2;
986     uint32_t deviceTags = 3;
987     int32_t ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
988     EXPECT_EQ(ret, ERROR_NULL_POINTER);
989     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
990     ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
991     EXPECT_EQ(ret, ERROR_NULL_POINTER);
992     handlerType = InputHandlerType::MONITOR;
993     ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
994     EXPECT_EQ(ret, ERROR_NULL_POINTER);
995     handlerType = InputHandlerType::NONE;
996     ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
997     EXPECT_EQ(ret, RET_OK);
998 }
999 
1000 /**
1001  * @tc.name: ServerMsgHandlerTest_OnAddInputHandler_001
1002  * @tc.desc: Test the function OnAddInputHandler
1003  * @tc.type: FUNC
1004  * @tc.require:
1005  */
1006 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandler_001, TestSize.Level1)
1007 {
1008     CALL_TEST_DEBUG;
1009     ServerMsgHandler handler;
1010     SessionPtr sess = nullptr;
1011     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
1012     HandleEventType eventType =1;
1013     int32_t priority = 2;
1014     uint32_t deviceTags = 3;
1015     int32_t ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1016     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1017     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1018     ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1019     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1020     handlerType = InputHandlerType::MONITOR;
1021     ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1022     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1023     handlerType = InputHandlerType::NONE;
1024     ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1025     EXPECT_EQ(ret, RET_OK);
1026 }
1027 
1028 /**
1029  * @tc.name: ServerMsgHandlerTest_OnMoveMouse_001
1030  * @tc.desc: Test the function OnMoveMouse
1031  * @tc.type: FUNC
1032  * @tc.require:
1033  */
1034 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMoveMouse_001, TestSize.Level1)
1035 {
1036     CALL_TEST_DEBUG;
1037     ServerMsgHandler handler;
1038     int32_t offsetX = 10;
1039     int32_t offsetY = 20;
1040     std::shared_ptr<PointerEvent> pointerEvent_ = PointerEvent::Create();
1041     ASSERT_NE(pointerEvent_, nullptr);
1042     int32_t ret = handler.OnMoveMouse(offsetX, offsetY);
1043     EXPECT_EQ(ret, RET_OK);
1044 }
1045 
1046 /**
1047  * @tc.name: ServerMsgHandlerTest_OnCancelInjection_001
1048  * @tc.desc: Test the function OnCancelInjection
1049  * @tc.type: FUNC
1050  * @tc.require:
1051  */
1052 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnCancelInjection_001, TestSize.Level1)
1053 {
1054     CALL_TEST_DEBUG;
1055     ServerMsgHandler handler;
1056     handler.authorizationCollection_.insert(std::make_pair(12, AuthorizationStatus::AUTHORIZED));
1057     handler.CurrentPID_ = 12;
1058     int32_t ret = handler.OnCancelInjection();
1059     EXPECT_EQ(ret, ERR_OK);
1060     handler.CurrentPID_ = 1;
1061     ret = handler.OnCancelInjection();
1062     EXPECT_EQ(ret, ERR_OK);
1063 }
1064 
1065 /**
1066  * @tc.name: ServerMsgHandlerTest_SetWindowInfo_001
1067  * @tc.desc: Test the function SetWindowInfo
1068  * @tc.type: FUNC
1069  * @tc.require:
1070  */
1071 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetWindowInfo_001, TestSize.Level1)
1072 {
1073     CALL_TEST_DEBUG;
1074     ServerMsgHandler handler;
1075     int32_t infoId = 1;
1076     WindowInfo info;
1077     const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1078     handler.transparentWins_.insert(std::make_pair(1, SetMouseIconTest(iconPath)));
1079     EXPECT_NO_FATAL_FAILURE(handler.SetWindowInfo(infoId, info));
1080     infoId = 2;
1081     EXPECT_NO_FATAL_FAILURE(handler.SetWindowInfo(infoId, info));
1082 }
1083 
1084 /**
1085  * @tc.name: ServerMsgHandlerTest_OnEnhanceConfig_002
1086  * @tc.desc: Test the function OnEnhanceConfig
1087  * @tc.type: FUNC
1088  * @tc.require:
1089  */
1090 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnEnhanceConfig_002, TestSize.Level1)
1091 {
1092     CALL_TEST_DEBUG;
1093     ServerMsgHandler handler;
1094     SessionPtr sess = nullptr;
1095     MmiMessageId idMsg = MmiMessageId::ADD_INPUT_DEVICE_LISTENER;
1096     NetPacket pkt(idMsg);
1097     int32_t ret = handler.OnEnhanceConfig(sess, pkt);
1098     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1099     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1100     int32_t uid = 123;
1101     ret = handler.OnEnhanceConfig(sess, pkt);
1102     EXPECT_EQ(ret, RET_ERR);
1103     uid = SECURITY_COMPONENT_SERVICE_ID;
1104     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1105     ret = handler.OnEnhanceConfig(sess, pkt);
1106     EXPECT_EQ(ret, RET_ERR);
1107     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1108     EXPECT_NO_FATAL_FAILURE(handler.OnEnhanceConfig(sess, pkt));
1109 }
1110 
1111 /**
1112  * @tc.name: ServerMsgHandlerTest_OnMsgHandler
1113  * @tc.desc: Test if (callback == nullptr) branch success
1114  * @tc.type: FUNC
1115  * @tc.require:
1116  */
1117 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMsgHandler, TestSize.Level1)
1118 {
1119     CALL_TEST_DEBUG;
1120     ServerMsgHandler msgHandler;
1121     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1122     MmiMessageId idMsg = MmiMessageId::INVALID;
1123     NetPacket pkt(idMsg);
1124     EXPECT_NO_FATAL_FAILURE(msgHandler.OnMsgHandler(sess, pkt));
1125 }
1126 
1127 /**
1128  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEventExt
1129  * @tc.desc: Test OnInjectPointerEventExt
1130  * @tc.type: FUNC
1131  * @tc.require:
1132  */
1133 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEventExt, TestSize.Level1)
1134 {
1135     CALL_TEST_DEBUG;
1136     ServerMsgHandler msgHandler;
1137     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1138     ASSERT_NE(pointerEvent, nullptr);
1139     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1140     pointerEvent->SetId(1);
1141     pointerEvent->eventType_ = 1;
1142     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1143     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1144     msgHandler.nativeTargetWindowIds_.insert(std::make_pair(pointerEvent->GetPointerId(), 10));
1145     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false), RET_ERR);
1146 
1147     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1148     pointerEvent->SetPointerId(1);
1149     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1150     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT;
1151     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false), RET_ERR);
1152 
1153     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
1154     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1155     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NONE);
1156     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false), RET_OK);
1157 
1158     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
1159     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_HIDE_POINTER;
1160     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false), RET_OK);
1161 }
1162 
1163 /**
1164  * @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_001
1165  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch success
1166  * @tc.type: FUNC
1167  * @tc.require:
1168  */
1169 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_001, TestSize.Level1)
1170 {
1171     CALL_TEST_DEBUG;
1172     ServerMsgHandler msgHandler;
1173     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1174     ASSERT_NE(keyEvent, nullptr);
1175     int32_t pid = 15;
1176     bool isNativeInject = true;
1177     keyEvent->SetId(1);
1178     keyEvent->eventType_ = 1;
1179     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1180     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNAUTHORIZED));
1181     EXPECT_EQ(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), COMMON_PERMISSION_CHECK_ERROR);
1182 }
1183 
1184 /**
1185  * @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_002
1186  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch failed
1187  * @tc.type: FUNC
1188  * @tc.require:
1189  */
1190 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_002, TestSize.Level1)
1191 {
1192     CALL_TEST_DEBUG;
1193     ServerMsgHandler msgHandler;
1194     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1195     ASSERT_NE(keyEvent, nullptr);
1196     int32_t pid = 15;
1197     bool isNativeInject = true;
1198     keyEvent->SetId(1);
1199     keyEvent->eventType_ = 1;
1200     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1201     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNKNOWN));
1202     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1203     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1204 }
1205 
1206 /**
1207  * @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_003
1208  * @tc.desc: Test if (isNativeInject) branch failed
1209  * @tc.type: FUNC
1210  * @tc.require:
1211  */
1212 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_003, TestSize.Level1)
1213 {
1214     CALL_TEST_DEBUG;
1215     ServerMsgHandler msgHandler;
1216     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1217     ASSERT_NE(keyEvent, nullptr);
1218     int32_t pid = 15;
1219     bool isNativeInject = false;
1220     keyEvent->SetId(1);
1221     keyEvent->eventType_ = 1;
1222     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1223     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1224     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1225 }
1226 
1227 /**
1228  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent_002
1229  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch success
1230  * @tc.type: FUNC
1231  * @tc.require:
1232  */
1233 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent_002, TestSize.Level1)
1234 {
1235     CALL_TEST_DEBUG;
1236     ServerMsgHandler msgHandler;
1237     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1238     ASSERT_NE(pointerEvent, nullptr);
1239     int32_t pid = 15;
1240     bool isNativeInject = true;
1241     pointerEvent->SetId(1);
1242     pointerEvent->eventType_ = 1;
1243     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1244     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNAUTHORIZED));
1245     EXPECT_EQ(msgHandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false), COMMON_PERMISSION_CHECK_ERROR);
1246 }
1247 
1248 /**
1249  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent_003
1250  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch failed
1251  * @tc.type: FUNC
1252  * @tc.require:
1253  */
1254 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent_003, TestSize.Level1)
1255 {
1256     CALL_TEST_DEBUG;
1257     ServerMsgHandler msgHandler;
1258     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1259     ASSERT_NE(pointerEvent, nullptr);
1260     int32_t pid = 15;
1261     bool isNativeInject = true;
1262     pointerEvent->SetId(1);
1263     pointerEvent->eventType_ = 1;
1264     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1265     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN);
1266     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNKNOWN));
1267     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1268     EXPECT_NE(msgHandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false), RET_OK);
1269 }
1270 
1271 /**
1272  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent_004
1273  * @tc.desc: Test if (isNativeInject) branch failed
1274  * @tc.type: FUNC
1275  * @tc.require:
1276  */
1277 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent_004, TestSize.Level1)
1278 {
1279     CALL_TEST_DEBUG;
1280     ServerMsgHandler msgHandler;
1281     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1282     ASSERT_NE(pointerEvent, nullptr);
1283     int32_t pid = 15;
1284     bool isNativeInject = false;
1285     pointerEvent->SetId(1);
1286     pointerEvent->eventType_ = 1;
1287     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1288     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1289     EXPECT_NE(msgHandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false), RET_OK);
1290 }
1291 
1292 /**
1293  * @tc.name: ServerMsgHandlerTest_OnWindowGroupInfo_001
1294  * @tc.desc: Test the function OnWindowGroupInfo
1295  * @tc.type: FUNC
1296  * @tc.require:
1297  */
1298 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnWindowGroupInfo_001, TestSize.Level1)
1299 {
1300     CALL_TEST_DEBUG;
1301     ServerMsgHandler handler;
1302     SessionPtr sess = nullptr;
1303     MmiMessageId idMsg = MmiMessageId::INVALID;
1304     NetPacket pkt(idMsg);
1305     int32_t ret = handler.OnWindowGroupInfo(sess, pkt);
1306     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1307     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1308     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1309     ret = handler.OnWindowGroupInfo(sess, pkt);
1310     EXPECT_EQ(ret, RET_ERR);
1311     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1312     ret = handler.OnWindowGroupInfo(sess, pkt);
1313     EXPECT_EQ(ret, RET_ERR);
1314 }
1315 
1316 /**
1317  * @tc.name: ServerMsgHandlerTest_OnEnhanceConfig_003
1318  * @tc.desc: Test the function OnEnhanceConfig
1319  * @tc.type: FUNC
1320  * @tc.require:
1321  */
1322 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnEnhanceConfig_003, TestSize.Level1)
1323 {
1324     CALL_TEST_DEBUG;
1325     ServerMsgHandler handler;
1326     MmiMessageId idMsg = MmiMessageId::ADD_INPUT_DEVICE_LISTENER;
1327     NetPacket pkt(idMsg);
1328     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME,
1329         g_moduleType, g_writeFd, SECURITY_COMPONENT_SERVICE_ID - 1, g_pid);
1330     int32_t ret = handler.OnEnhanceConfig(sess, pkt);
1331     EXPECT_EQ(ret, RET_ERR);
1332     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd,
1333         SECURITY_COMPONENT_SERVICE_ID, g_pid);
1334     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1335     ret = handler.OnEnhanceConfig(sess, pkt);
1336     EXPECT_EQ(ret, RET_ERR);
1337     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1338     EXPECT_NO_FATAL_FAILURE(handler.OnEnhanceConfig(sess, pkt));
1339 }
1340 
1341 /**
1342  * @tc.name: ServerMsgHandlerTest_SetPixelMapData_001
1343  * @tc.desc: Test the function SetPixelMapData
1344  * @tc.type: FUNC
1345  * @tc.require:
1346  */
1347 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetPixelMapData_001, TestSize.Level1)
1348 {
1349     CALL_TEST_DEBUG;
1350     ServerMsgHandler handler;
1351     int32_t infoId = -5;
1352     void* pixelMap = nullptr;
1353     int32_t result = handler.SetPixelMapData(infoId, pixelMap);
1354     EXPECT_EQ(result, ERR_INVALID_VALUE);
1355     infoId = 2;
1356     result = handler.SetPixelMapData(infoId, pixelMap);
1357     EXPECT_EQ(result, ERR_INVALID_VALUE);
1358 }
1359 
1360 /**
1361  * @tc.name: ServerMsgHandlerTest_InitInjectNoticeSource_001
1362  * @tc.desc: Test the function InitInjectNoticeSource
1363  * @tc.type: FUNC
1364  * @tc.require:
1365  */
1366 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_InitInjectNoticeSource_001, TestSize.Level1)
1367 {
1368     CALL_TEST_DEBUG;
1369     ServerMsgHandler handler;
1370     InjectNoticeManager manager;
1371     handler.injectNotice_ =nullptr;
1372     bool ret = handler.InitInjectNoticeSource();
1373     EXPECT_FALSE(ret);
1374     handler.injectNotice_ = std::make_shared<InjectNoticeManager>();
1375     manager.isStartSrv_ = false;
1376     ret = handler.InitInjectNoticeSource();
1377     EXPECT_FALSE(ret);
1378     manager.isStartSrv_ = true;
1379     ret = handler.InitInjectNoticeSource();
1380     EXPECT_FALSE(ret);
1381     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
1382     manager.connectionCallback_->isConnected_ = false;
1383     ret = handler.InitInjectNoticeSource();
1384     EXPECT_FALSE(ret);
1385     manager.connectionCallback_->isConnected_ = true;
1386     ret = handler.InitInjectNoticeSource();
1387     EXPECT_FALSE(ret);
1388 }
1389 
1390 /**
1391  * @tc.name: ServerMsgHandlerTest_CalculateOffset
1392  * @tc.desc: Test the function CalculateOffset
1393  * @tc.type: FUNC
1394  * @tc.require:
1395  */
1396 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_CalculateOffset, TestSize.Level1)
1397 {
1398     CALL_TEST_DEBUG;
1399     ServerMsgHandler handler;
1400     Direction direction = DIRECTION90;
1401     Offset offset;
1402     offset.dx = 100;
1403     offset.dy = 100;
1404     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1405     direction = DIRECTION180;
1406     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1407     direction = DIRECTION270;
1408     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1409     direction = DIRECTION0;
1410     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1411 }
1412 
1413 /**
1414  * @tc.name: ServerMsgHandlerTest_OnDisplayInfo
1415  * @tc.desc: Test the function OnDisplayInfo
1416  * @tc.type: FUNC
1417  * @tc.require:
1418  */
1419 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo, TestSize.Level1)
1420 {
1421     CALL_TEST_DEBUG;
1422     ServerMsgHandler handler;
1423     int32_t num = 1;
1424     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1425     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
1426     DisplayGroupInfo displayGroupInfo {
1427         .width = 100,
1428         .height = 100,
1429         .focusWindowId = 10,
1430         .currentUserId = 20,
1431     };
1432     pkt << displayGroupInfo.width << displayGroupInfo.height
1433         << displayGroupInfo.focusWindowId << displayGroupInfo.currentUserId << num;
1434     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_WRITE;
1435     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_ERR);
1436 }
1437 
1438 /**
1439  * @tc.name: ServerMsgHandlerTest_OnTransferBinderClientSrv_001
1440  * @tc.desc: Test OnTransferBinderClientSrv
1441  * @tc.type: FUNC
1442  * @tc.require:
1443  */
1444 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnTransferBinderClientSrv_001, TestSize.Level1)
1445 {
1446     CALL_TEST_DEBUG;
1447     ServerMsgHandler handler;
1448     sptr<RemoteObjectTest> binderClientObject = new RemoteObjectTest(u"test");
1449     int32_t pid = 12345;
1450     EXPECT_EQ(RET_OK, handler.OnTransferBinderClientSrv(binderClientObject, pid));
1451 }
1452 
1453 /**
1454  * @tc.name: ServerMsgHandlerTest_OnTransferBinderClientSrv_002
1455  * @tc.desc: Test OnTransferBinderClientSrv
1456  * @tc.type: FUNC
1457  * @tc.require:
1458  */
1459 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnTransferBinderClientSrv_002, TestSize.Level1)
1460 {
1461     CALL_TEST_DEBUG;
1462     ServerMsgHandler handler;
1463     sptr<IRemoteObject> binderClientObject = nullptr;
1464     int32_t pid = 12345;
1465     EXPECT_EQ(RET_ERR, handler.OnTransferBinderClientSrv(binderClientObject, pid));
1466 }
1467 
1468 /**
1469  * @tc.name: ServerMsgHandlerTest_CloseInjectNotice_001
1470  * @tc.desc: Test CloseInjectNotice
1471  * @tc.type: FUNC
1472  * @tc.require:
1473  */
1474 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_CloseInjectNotice_001, TestSize.Level1)
1475 {
1476     CALL_TEST_DEBUG;
1477     ServerMsgHandler handler;
1478     handler.InitInjectNoticeSource();
1479     int32_t pid = 12345;
1480     bool result = handler.CloseInjectNotice(pid);
1481     ASSERT_FALSE(result);
1482 }
1483 
1484 /**
1485  * @tc.name: ServerMsgHandlerTest_InitInjectNoticeSource_002
1486  * @tc.desc: Test the function InitInjectNoticeSource
1487  * @tc.type: FUNC
1488  * @tc.require:
1489  */
1490 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_InitInjectNoticeSource_002, TestSize.Level1)
1491 {
1492     CALL_TEST_DEBUG;
1493     ServerMsgHandler handler;
1494     InjectNoticeManager manager;
1495     handler.injectNotice_ =nullptr;
1496     bool ret = handler.InitInjectNoticeSource();
1497     handler.injectNotice_->isStartSrv_ = true;
1498     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
1499     EXPECT_NE(nullptr, manager.connectionCallback_);
1500     auto connection = handler.injectNotice_->GetConnection();
1501     connection->isConnected_ = false;
1502     ret = handler.InitInjectNoticeSource();
1503     EXPECT_FALSE(ret);
1504 }
1505 
1506 /**
1507  * @tc.name: ServerMsgHandlerTest_InitInjectNoticeSource_003
1508  * @tc.desc: Test the function InitInjectNoticeSource
1509  * @tc.type: FUNC
1510  * @tc.require:
1511  */
1512 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_InitInjectNoticeSource_003, TestSize.Level1)
1513 {
1514     CALL_TEST_DEBUG;
1515     ServerMsgHandler handler;
1516     InjectNoticeManager manager;
1517     handler.injectNotice_ =nullptr;
1518     bool ret = handler.InitInjectNoticeSource();
1519     handler.injectNotice_->isStartSrv_ = true;
1520     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
1521     EXPECT_NE(nullptr, manager.connectionCallback_);
1522     auto connection = handler.injectNotice_->GetConnection();
1523     connection->isConnected_ = true;
1524     ret = handler.InitInjectNoticeSource();
1525     EXPECT_TRUE(ret);
1526 }
1527 
1528 /**
1529  * @tc.name: ServerMsgHandlerTest_AddInjectNotice_001
1530  * @tc.desc: Test the function AddInjectNotice
1531  * @tc.type: FUNC
1532  * @tc.require:
1533  */
1534 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AddInjectNotice_001, TestSize.Level1)
1535 {
1536     CALL_TEST_DEBUG;
1537     ServerMsgHandler handler;
1538     InjectNoticeManager manager;
1539     InjectNoticeInfo noticeInfo;
1540     handler.injectNotice_ =nullptr;
1541     bool ret = handler.InitInjectNoticeSource();
1542     handler.injectNotice_->isStartSrv_ = true;
1543     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
1544     EXPECT_NE(nullptr, manager.connectionCallback_);
1545     auto connection = handler.injectNotice_->GetConnection();
1546     connection->isConnected_ = false;
1547     ret = handler.AddInjectNotice(noticeInfo);
1548     EXPECT_FALSE(ret);
1549 }
1550 
1551 /**
1552  * @tc.name: ServerMsgHandlerTest_OnCancelInjection_002
1553  * @tc.desc: Test the function OnCancelInjection
1554  * @tc.type: FUNC
1555  * @tc.require:
1556  */
1557 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnCancelInjection_002, TestSize.Level1)
1558 {
1559     CALL_TEST_DEBUG;
1560     ServerMsgHandler handler;
1561     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
1562     int32_t ret = handler.OnCancelInjection();
1563     EXPECT_FALSE(ret != ERR_OK);
1564 }
1565 
1566 /**
1567  * @tc.name: ServerMsgHandlerTest_OnAuthorize_002
1568  * @tc.desc: Test the function OnAuthorize
1569  * @tc.type: FUNC
1570  * @tc.require:
1571  */
1572 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAuthorize_002, TestSize.Level1)
1573 {
1574     CALL_TEST_DEBUG;
1575     ServerMsgHandler handler;
1576     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
1577     int32_t result = handler.OnAuthorize(false);
1578     EXPECT_EQ(result, ERR_OK);
1579 }
1580 
1581 /**
1582  * @tc.name: ServerMsgHandlerTest_OnMoveMouse_002
1583  * @tc.desc: Test the function OnMoveMouse
1584  * @tc.type: FUNC
1585  * @tc.require:
1586  */
1587 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMoveMouse_002, TestSize.Level1)
1588 {
1589     CALL_TEST_DEBUG;
1590     ServerMsgHandler handler;
1591     int32_t offsetX = 0;
1592     int32_t offsetY = 0;
1593     std::shared_ptr<PointerEvent> pointerEvent_ = PointerEvent::Create();
1594     ASSERT_NE(pointerEvent_, nullptr);
1595     int32_t ret = handler.OnMoveMouse(offsetX, offsetY);
1596     EXPECT_EQ(ret, RET_OK);
1597 }
1598 
1599 /**
1600  * @tc.name: ServerMsgHandlerTest_OnAuthorize_004
1601  * @tc.desc: Test the function OnAuthorize
1602  * @tc.type: FUNC
1603  * @tc.require:
1604  */
1605 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAuthorize_004, TestSize.Level1)
1606 {
1607     CALL_TEST_DEBUG;
1608     ServerMsgHandler handler;
1609     handler.CurrentPID_ = 12345;
1610     handler.authorizationCollection_[12345] = AuthorizationStatus::UNAUTHORIZED;
1611     int32_t result = handler.OnAuthorize(false);
1612     EXPECT_EQ(result, ERR_OK);
1613     EXPECT_EQ(handler.authorizationCollection_[12345], AuthorizationStatus::UNAUTHORIZED);
1614 }
1615 
1616 /**
1617  * @tc.name: ServerMsgHandlerTest_OnMsgHandler_001
1618  * @tc.desc: Test if (callback == nullptr) branch success
1619  * @tc.type: FUNC
1620  * @tc.require:
1621  */
1622 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMsgHandler_001, TestSize.Level1)
1623 {
1624     CALL_TEST_DEBUG;
1625     ServerMsgHandler msgHandler;
1626     MsgHandler<int, int> handler;
1627     handler.callbacks_[0] = 1;
1628     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1629     MmiMessageId idMsg = MmiMessageId::INVALID;
1630     NetPacket pkt(idMsg);
1631     EXPECT_NO_FATAL_FAILURE(msgHandler.OnMsgHandler(sess, pkt));
1632 }
1633 
1634 /**
1635  * @tc.name: ServerMsgHandlerTest_OnSetFunctionKeyState_002
1636  * @tc.desc: Test the function OnSetFunctionKeyState
1637  * @tc.type: FUNC
1638  * @tc.require:
1639  */
1640 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSetFunctionKeyState_002, TestSize.Level1)
1641 {
1642     CALL_TEST_DEBUG;
1643     ServerMsgHandler handler;
1644     int32_t funcKey = 1;
1645     int32_t pid = 15;
1646     bool enable = true;
1647     INPUT_DEV_MGR->IsKeyboardDevice(nullptr);
1648     EXPECT_EQ(handler.OnSetFunctionKeyState(pid, funcKey, enable), ERR_NON_INPUT_APPLICATION);
1649 }
1650 
1651 /**
1652  * @tc.name: ServerMsgHandlerTest_IsNavigationWindowInjectEvent
1653  * @tc.desc: Test the function IsNavigationWindowInjectEvent
1654  * @tc.type: FUNC
1655  * @tc.require:
1656  */
1657 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_IsNavigationWindowInjectEvent, TestSize.Level1)
1658 {
1659     CALL_TEST_DEBUG;
1660     ServerMsgHandler handler;
1661     auto pointerEvent = PointerEvent::Create();
1662     pointerEvent->zOrder_ = 1;
1663     bool ret = false;
1664     ret = handler.IsNavigationWindowInjectEvent(pointerEvent);
1665     ASSERT_TRUE(ret);
1666 }
1667 
1668 /**
1669  * @tc.name: ServerMsgHandlerTest_OnRemoveGestureMonitor
1670  * @tc.desc: Test the function OnRemoveGestureMonitor
1671  * @tc.type: FUNC
1672  * @tc.require:
1673  */
1674 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveGestureMonitor, TestSize.Level1)
1675 {
1676     CALL_TEST_DEBUG;
1677     ServerMsgHandler handler;
1678     auto udsSe = std::make_shared<UDSSession>("mytest", 2, 3, 4, 5);
1679     InputHandlerType inputHandlerType = InputHandlerType::MONITOR;
1680     uint32_t eventType = HANDLE_EVENT_TYPE_KEY;
1681     uint32_t gestureType = TOUCH_GESTURE_TYPE_PINCH;
1682     uint32_t fingers = 3;
1683     InputHandler->eventMonitorHandler_ = std::make_shared<EventMonitorHandler>();
1684     int32_t ret = handler.OnRemoveGestureMonitor(udsSe, inputHandlerType, eventType, gestureType, fingers);
1685     ASSERT_NE(ret, RET_OK);
1686 }
1687 
1688 /**
1689  * @tc.name: ServerMsgHandlerTest_OnAddGestureMonitor
1690  * @tc.desc: Test the function OnAddGestureMonitor
1691  * @tc.type: FUNC
1692  * @tc.require:
1693  */
1694 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddGestureMonitor, TestSize.Level1)
1695 {
1696     CALL_TEST_DEBUG;
1697     ServerMsgHandler handler;
1698     auto udsSe = std::make_shared<UDSSession>("mytest", 2, 3, 4, 5);
1699     InputHandlerType handlerType = InputHandlerType::MONITOR;
1700     uint32_t eventType = HANDLE_EVENT_TYPE_KEY;
1701     uint32_t gestureType = TOUCH_GESTURE_TYPE_PINCH;
1702     uint32_t fingers = 3;
1703     InputHandler->eventMonitorHandler_ = std::make_shared<EventMonitorHandler>();
1704     int32_t ret = handler.OnAddGestureMonitor(udsSe, handlerType, eventType, gestureType, fingers);
1705     ASSERT_NE(ret, RET_OK);
1706 
1707     handlerType = InputHandlerType::NONE;
1708     ret = handler.OnAddGestureMonitor(udsSe, handlerType, eventType, gestureType, fingers);
1709     ASSERT_EQ(ret, RET_OK);
1710 }
1711 } // namespace MMI
1712 } // namespace OHOS