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