• 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 "event_log_helper.h"
29 #include "image_source.h"
30 #include "inject_notice_manager.h"
31 #include "input_device_manager.h"
32 #include "input_manager_impl.h"
33 #include "mmi_log.h"
34 #include "pointer_event.h"
35 #include "running_process_info.h"
36 #include "server_msg_handler.h"
37 #include "stream_buffer.h"
38 
39 #undef MMI_LOG_TAG
40 #define MMI_LOG_TAG "ServerMsgHandlerTest"
41 
42 namespace OHOS {
43 namespace MMI {
44 namespace {
45 using namespace testing::ext;
46 constexpr int32_t UID_ROOT {0};
47 static constexpr char PROGRAM_NAME[] = "uds_sesion_test";
48 int32_t g_moduleType = 3;
49 int32_t g_pid = 0;
50 int32_t g_writeFd = -1;
51 constexpr int32_t NUM_LOCK_FUNCTION_KEY = 0;
52 constexpr int32_t CAPS_LOCK_FUNCTION_KEY = 1;
53 constexpr int32_t SCROLL_LOCK_FUNCTION_KEY = 2;
54 constexpr int32_t SECURITY_COMPONENT_SERVICE_ID = 3050;
55 constexpr int32_t MOUSE_ICON_SIZE = 64;
56 constexpr int32_t COMMON_PERMISSION_CHECK_ERROR {201};
57 constexpr int32_t ERR_DEVICE_NOT_EXIST {3900002};
58 constexpr int32_t ERR_NON_INPUT_APPLICATION {3900003};
59 constexpr int32_t CAST_INPUT_DEVICEID {0xAAAAAAFF};
60 constexpr float FACTOR_0 {1.0f};
61 constexpr float FACTOR_8 {0.7f};
62 constexpr float FACTOR_18 {1.0f};
63 constexpr float FACTOR_27 {1.2f};
64 constexpr float FACTOR_55 {1.6f};
65 constexpr float FACTOR_MAX {2.4f};
66 class RemoteObjectTest : public IRemoteObject {
67 public:
RemoteObjectTest(std::u16string descriptor)68     explicit RemoteObjectTest(std::u16string descriptor) : IRemoteObject(descriptor) {}
~RemoteObjectTest()69     ~RemoteObjectTest() {}
70 
GetObjectRefCount()71     int32_t GetObjectRefCount()
72     {
73         return 0;
74     }
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)75     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
76     {
77         return 0;
78     }
AddDeathRecipient(const sptr<DeathRecipient> & recipient)79     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient)
80     {
81         return true;
82     }
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)83     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient)
84     {
85         return true;
86     }
Dump(int fd,const std::vector<std::u16string> & args)87     int Dump(int fd, const std::vector<std::u16string> &args)
88     {
89         return 0;
90     }
91 };
92 } // namespace
93 
94 class ServerMsgHandlerTest : public testing::Test {
95 public:
SetUpTestCase(void)96     static void SetUpTestCase(void) {}
TearDownTestCase(void)97     static void TearDownTestCase(void) {}
SetUp()98     void SetUp() {}
TearDoen()99     void TearDoen() {}
100     std::unique_ptr<OHOS::Media::PixelMap> SetMouseIconTest(const std::string iconPath);
101 };
102 
SetMouseIconTest(const std::string iconPath)103 std::unique_ptr<OHOS::Media::PixelMap> ServerMsgHandlerTest::SetMouseIconTest(const std::string iconPath)
104 {
105     CALL_DEBUG_ENTER;
106     OHOS::Media::SourceOptions opts;
107     opts.formatHint = "image/svg+xml";
108     uint32_t ret = 0;
109     auto imageSource = OHOS::Media::ImageSource::CreateImageSource(iconPath, opts, ret);
110     CHKPP(imageSource);
111     std::set<std::string> formats;
112     ret = imageSource->GetSupportedFormats(formats);
113     MMI_HILOGD("Get supported format ret:%{public}u", ret);
114     OHOS::Media::DecodeOptions decodeOpts;
115     decodeOpts.desiredSize = {.width = MOUSE_ICON_SIZE, .height = MOUSE_ICON_SIZE};
116     std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
117     CHKPL(pixelMap);
118     return pixelMap;
119 }
120 
121 /**
122  * @tc.name: ServerMsgHandlerTest_SetPixelMapData
123  * @tc.desc: Test SetPixelMapData
124  * @tc.type: FUNC
125  * @tc.require:
126  */
127 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetPixelMapData, TestSize.Level1)
128 {
129     CALL_TEST_DEBUG;
130     ServerMsgHandler servermsghandler;
131     int32_t infoId = -1;
132     void *pixelMap = nullptr;
133     int32_t result = servermsghandler.SetPixelMapData(infoId, pixelMap);
134     EXPECT_EQ(result, ERR_INVALID_VALUE);
135 }
136 
137 /**
138  * @tc.name: ServerMsgHandlerTest_SetShieldStatus_01
139  * @tc.desc: Test SetShieldStatus
140  * @tc.type: FUNC
141  * @tc.require:
142  */
143 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetShieldStatus_01, TestSize.Level1)
144 {
145     CALL_TEST_DEBUG;
146     ServerMsgHandler servermsghandler;
147     int32_t shieldMode = -1;
148     bool isShield = false;
149     int32_t result = servermsghandler.SetShieldStatus(shieldMode, isShield);
150     EXPECT_EQ(result, RET_ERR);
151 }
152 
153 /**
154  * @tc.name: ServerMsgHandlerTest_SetShieldStatus_02
155  * @tc.desc: Test SetShieldStatus
156  * @tc.type: FUNC
157  * @tc.require:
158  */
159 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetShieldStatus_02, TestSize.Level1)
160 {
161     CALL_TEST_DEBUG;
162     ServerMsgHandler servermsghandler;
163     int32_t shieldMode = 1;
164     bool isShield = true;
165     int32_t result = servermsghandler.SetShieldStatus(shieldMode, isShield);
166     EXPECT_EQ(result, RET_OK);
167 }
168 
169 /**
170  * @tc.name: ServerMsgHandlerTest_GetShieldStatus_01
171  * @tc.desc: Test GetShieldStatus
172  * @tc.type: FUNC
173  * @tc.require:
174  */
175 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_GetShieldStatus_01, TestSize.Level1)
176 {
177     CALL_TEST_DEBUG;
178     ServerMsgHandler servermsghandler;
179     int32_t shieldMode = -1;
180     bool isShield = false;
181     int32_t result = servermsghandler.GetShieldStatus(shieldMode, isShield);
182     EXPECT_EQ(result, RET_ERR);
183 }
184 
185 /**
186  * @tc.name: ServerMsgHandlerTest_GetShieldStatus_02
187  * @tc.desc: Test GetShieldStatus
188  * @tc.type: FUNC
189  * @tc.require:
190  */
191 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_GetShieldStatus_02, TestSize.Level1)
192 {
193     CALL_TEST_DEBUG;
194     ServerMsgHandler servermsghandler;
195     int32_t shieldMode = 1;
196     bool isShield = true;
197     int32_t result = servermsghandler.GetShieldStatus(shieldMode, isShield);
198     EXPECT_EQ(result, RET_OK);
199 }
200 
201 /**
202  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent
203  * @tc.desc: Test OnInjectPointerEvent
204  * @tc.type: FUNC
205  * @tc.require:
206  */
207 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent, TestSize.Level1)
208 {
209     CALL_TEST_DEBUG;
210     ServerMsgHandler servermsghandler;
211     auto pointerEvent = PointerEvent::Create();
212     ASSERT_NE(pointerEvent, nullptr);
213     int32_t pid = 1;
214     bool isNativeInject = true;
215     int32_t result = servermsghandler.OnInjectPointerEvent(
216         pointerEvent, pid, isNativeInject, false, PointerEvent::DISPLAY_COORDINATE);
217     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
218 }
219 
220 /**
221  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_01
222  * @tc.desc: Test FixTargetWindowId
223  * @tc.type: FUNC
224  * @tc.require:
225  */
226 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_01, TestSize.Level1)
227 {
228     CALL_TEST_DEBUG;
229     ServerMsgHandler servermsghandler;
230     auto pointerEvent = PointerEvent::Create();
231     ASSERT_NE(pointerEvent, nullptr);
232     int32_t action = PointerEvent::POINTER_ACTION_HOVER_ENTER;
233     bool result = servermsghandler.FixTargetWindowId(pointerEvent, action, false);
234     ASSERT_FALSE(result);
235 }
236 
237 /**
238  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_02
239  * @tc.desc: Test FixTargetWindowId
240  * @tc.type: FUNC
241  * @tc.require:
242  */
243 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_02, TestSize.Level1)
244 {
245     CALL_TEST_DEBUG;
246     ServerMsgHandler servermsghandler;
247     auto pointerEvent = PointerEvent::Create();
248     ASSERT_NE(pointerEvent, nullptr);
249     int32_t action = PointerEvent::POINTER_ACTION_DOWN;
250     bool result = servermsghandler.FixTargetWindowId(pointerEvent, action, false);
251     ASSERT_FALSE(result);
252 }
253 
254 /**
255  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_03
256  * @tc.desc: Test FixTargetWindowId
257  * @tc.type: FUNC
258  * @tc.require:
259  */
260 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_03, TestSize.Level1)
261 {
262     CALL_TEST_DEBUG;
263     ServerMsgHandler servermsghandler;
264     auto pointerEvent = PointerEvent::Create();
265     ASSERT_NE(pointerEvent, nullptr);
266     int32_t action = PointerEvent::POINTER_ACTION_UNKNOWN;
267     auto pointerIds = pointerEvent->GetPointerIds();
268     EXPECT_TRUE(pointerIds.empty());
269     bool result = servermsghandler.FixTargetWindowId(pointerEvent, action, false);
270     ASSERT_FALSE(result);
271 }
272 
273 /**
274  * @tc.name: ServerMsgHandlerTest_Init
275  * @tc.desc: Test Init
276  * @tc.type: FUNC
277  * @tc.require:
278  */
279 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_Init, TestSize.Level1)
280 {
281     CALL_TEST_DEBUG;
282     ServerMsgHandler servermsghandler;
283     UDSServer udsServerFirst;
284     ASSERT_NO_FATAL_FAILURE(servermsghandler.Init(udsServerFirst));
285     UDSServer udsServerSecond;
286     ASSERT_NO_FATAL_FAILURE(servermsghandler.Init(udsServerSecond));
287 }
288 
289 /**
290  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithNullSession
291  * @tc.desc: Test OnAddInputHandler
292  * @tc.type: FUNC
293  * @tc.require:
294  */
295 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithNullSession, TestSize.Level1)
296 {
297     CALL_TEST_DEBUG;
298     ServerMsgHandler servermsghandler;
299     SessionPtr sess = nullptr;
300     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
301     HandleEventType eventType = 1;
302     int32_t priority = 1;
303     uint32_t deviceTags = 0x01;
304     EXPECT_EQ(
305         servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
306 }
307 
308 /**
309  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler001
310  * @tc.desc: Test OnAddInputHandler
311  * @tc.type: FUNC
312  * @tc.require:
313  */
314 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler001, TestSize.Level1)
315 {
316     CALL_TEST_DEBUG;
317     ServerMsgHandler servermsghandler;
318     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
319     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
320     HandleEventType eventType = 1;
321     int32_t priority = 1;
322     uint32_t deviceTags = 0x01;
323     EXPECT_EQ(
324         servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
325 }
326 
327 /**
328  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler001
329  * @tc.desc: Test OnAddInputHandler
330  * @tc.type: FUNC
331  * @tc.require:
332  */
333 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler001, TestSize.Level1)
334 {
335     CALL_TEST_DEBUG;
336     ServerMsgHandler servermsghandler;
337     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
338     InputHandlerType handlerType = InputHandlerType::MONITOR;
339     HandleEventType eventType = 1;
340     int32_t priority = 1;
341     uint32_t deviceTags = 0x01;
342     EXPECT_EQ(
343         servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
344 }
345 
346 /**
347  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithNullSession
348  * @tc.desc: Test OnRemoveInputHandler
349  * @tc.type: FUNC
350  * @tc.require:
351  */
352 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithNullSession, TestSize.Level1)
353 {
354     CALL_TEST_DEBUG;
355     ServerMsgHandler servermsghandler;
356     SessionPtr sess = nullptr;
357     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
358     HandleEventType eventType = 1;
359     int32_t priority = 1;
360     uint32_t deviceTags = 0x01;
361     EXPECT_EQ(
362         servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
363 }
364 
365 /**
366  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler001
367  * @tc.desc: Test OnRemoveInputHandler
368  * @tc.type: FUNC
369  * @tc.require:
370  */
371 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler001, TestSize.Level1)
372 {
373     CALL_TEST_DEBUG;
374     ServerMsgHandler servermsghandler;
375     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
376     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
377     HandleEventType eventType = 1;
378     int32_t priority = 1;
379     uint32_t deviceTags = 0x01;
380     EXPECT_EQ(
381         servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
382 }
383 
384 /**
385  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler001
386  * @tc.desc: Test OnRemoveInputHandler
387  * @tc.type: FUNC
388  * @tc.require:
389  */
390 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler001, TestSize.Level1)
391 {
392     CALL_TEST_DEBUG;
393     ServerMsgHandler servermsghandler;
394     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
395     InputHandlerType handlerType = InputHandlerType::MONITOR;
396     HandleEventType eventType = 1;
397     int32_t priority = 1;
398     uint32_t deviceTags = 0x01;
399     EXPECT_EQ(
400         servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
401 }
402 
403 /**
404  * @tc.name: ServerMsgHandlerTest_OnMarkConsumedWithNullSession
405  * @tc.desc: Test OnMarkConsumed
406  * @tc.type: FUNC
407  * @tc.require:
408  */
409 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMarkConsumedWithNullSession, TestSize.Level1)
410 {
411     CALL_TEST_DEBUG;
412     ServerMsgHandler servermsghandler;
413     SessionPtr sess = nullptr;
414     int32_t eventId = 11;
415     EXPECT_EQ(servermsghandler.OnMarkConsumed(sess, eventId), ERROR_NULL_POINTER);
416 }
417 
418 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
419 /**
420  * @tc.name: ServerMsgHandlerTest_OnSubscribeKeyEvent
421  * @tc.desc: Test OnSubscribeKeyEvent
422  * @tc.type: FUNC
423  * @tc.require:
424  */
425 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSubscribeKeyEvent, TestSize.Level1)
426 {
427     CALL_TEST_DEBUG;
428     ServerMsgHandler servermsghandler;
429     UDSServer udsServer;
430     int32_t pid = 0;
431     int32_t subscribeId = 0;
432     std::shared_ptr<KeyOption> option = std::make_shared<KeyOption>();
433     option->SetPreKeys({1, 2, 3});
434     EXPECT_EQ(servermsghandler.OnSubscribeKeyEvent(&udsServer, pid, subscribeId, option), ERROR_NULL_POINTER);
435     EXPECT_EQ(servermsghandler.OnUnsubscribeKeyEvent(&udsServer, pid, subscribeId), ERROR_NULL_POINTER);
436 }
437 
438 /**
439  * @tc.name: ServerMsgHandlerTest_OnSubscribeHotkey
440  * @tc.desc: Test OnSubscribeHotkey
441  * @tc.type: FUNC
442  * @tc.require:
443  */
444 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSubscribeHotkey, TestSize.Level1)
445 {
446     CALL_TEST_DEBUG;
447     ServerMsgHandler servermsghandler;
448     UDSServer udsServer;
449     int32_t pid = 0;
450     int32_t subscribeId = 0;
451     std::shared_ptr<KeyOption> option = std::make_shared<KeyOption>();
452     option->SetPreKeys({1, 2, 3});
453     EXPECT_EQ(servermsghandler.OnSubscribeHotkey(&udsServer, pid, subscribeId, option), ERROR_NULL_POINTER);
454     EXPECT_EQ(servermsghandler.OnUnsubscribeHotkey(&udsServer, pid, subscribeId), ERROR_NULL_POINTER);
455 }
456 #endif
457 
458 #ifdef OHOS_BUILD_ENABLE_SWITCH
459 /**
460  * @tc.name: ServerMsgHandlerTest_OnSubscribeSwitchEvent
461  * @tc.desc: Test OnSubscribeSwitchEvent
462  * @tc.type: FUNC
463  * @tc.require:
464  */
465 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSubscribeSwitchEvent, TestSize.Level1)
466 {
467     CALL_TEST_DEBUG;
468     ServerMsgHandler servermsghandler;
469     UDSServer udsServer;
470     int32_t pid = 0;
471     int32_t subscribeId = 0;
472     int32_t switchType = 0;
473     EXPECT_EQ(servermsghandler.OnSubscribeSwitchEvent(&udsServer, pid, subscribeId, switchType), ERROR_NULL_POINTER);
474     EXPECT_EQ(servermsghandler.OnUnsubscribeSwitchEvent(&udsServer, pid, subscribeId), ERROR_NULL_POINTER);
475 }
476 
477 /**
478  * @tc.name: ServerMsgHandlerTest_OnQuerySwitchStatus
479  * @tc.desc: Test OnQuerySwitchStatus
480  * @tc.type: FUNC
481  * @tc.require:
482  */
483 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnQuerySwitchStatus, TestSize.Level1)
484 {
485     CALL_TEST_DEBUG;
486     ServerMsgHandler servermsghandler;
487     int32_t switchType = 0;
488     int32_t state = 0;
489     EXPECT_EQ(servermsghandler.OnQuerySwitchStatus(switchType, state), ERROR_NULL_POINTER);
490 }
491 #endif
492 
493 /**
494  * @tc.name: ServerMsgHandlerTest_OnSubscribeLongPressEvent
495  * @tc.desc: Test OnSubscribeLongPressEvent
496  * @tc.type: FUNC
497  * @tc.require:
498  */
499 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSubscribeLongPressEvent, TestSize.Level1)
500 {
501     CALL_TEST_DEBUG;
502     ServerMsgHandler servermsghandler;
503     UDSServer udsServer;
504     int32_t pid = 1;
505     int32_t subscribeId = 1;
506     LongPressRequest longPressRequest;
507     EXPECT_EQ(servermsghandler.OnSubscribeLongPressEvent(&udsServer, pid, subscribeId, longPressRequest),
508         ERROR_NULL_POINTER);
509     EXPECT_EQ(servermsghandler.OnUnsubscribeLongPressEvent(&udsServer, pid, subscribeId), ERROR_NULL_POINTER);
510 }
511 
512 /**
513  * @tc.name: ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler001
514  * @tc.desc: Test OnMarkConsumed
515  * @tc.type: FUNC
516  * @tc.require:
517  */
518 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler001, TestSize.Level1)
519 {
520     CALL_TEST_DEBUG;
521     ServerMsgHandler servermsghandler;
522     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
523     int32_t eventId = 11;
524     EXPECT_EQ(servermsghandler.OnMarkConsumed(sess, eventId), ERROR_NULL_POINTER);
525 }
526 
527 /**
528  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler002
529  * @tc.desc: Test OnAddInputHandler
530  * @tc.type: FUNC
531  * @tc.require:
532  */
533 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithInterceptorHandler002, TestSize.Level1)
534 {
535     CALL_TEST_DEBUG;
536     ServerMsgHandler servermsghandler;
537     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
538     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
539     HandleEventType eventType = 1;
540     int32_t priority = 1;
541     uint32_t deviceTags = 0x01;
542     InputHandler->BuildInputHandlerChain();
543     EXPECT_EQ(
544         servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
545 }
546 
547 /**
548  * @tc.name: ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler002
549  * @tc.desc: Test OnAddInputHandler
550  * @tc.type: FUNC
551  * @tc.require:
552  */
553 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandlerWithMonitorHandler002, TestSize.Level1)
554 {
555     CALL_TEST_DEBUG;
556     ServerMsgHandler servermsghandler;
557     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
558     InputHandlerType handlerType = InputHandlerType::MONITOR;
559     HandleEventType eventType = 1;
560     int32_t priority = 1;
561     uint32_t deviceTags = 0x01;
562     EXPECT_EQ(
563         servermsghandler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
564 }
565 
566 /**
567  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler002
568  * @tc.desc: Test OnRemoveInputHandler
569  * @tc.type: FUNC
570  * @tc.require:
571  */
572 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithInterceptorHandler002, TestSize.Level1)
573 {
574     CALL_TEST_DEBUG;
575     ServerMsgHandler servermsghandler;
576     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
577     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
578     HandleEventType eventType = 1;
579     int32_t priority = 1;
580     uint32_t deviceTags = 0x01;
581     EXPECT_EQ(
582         servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
583 }
584 
585 /**
586  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler002
587  * @tc.desc: Test OnRemoveInputHandler
588  * @tc.type: FUNC
589  * @tc.require:
590  */
591 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandlerWithMonitorHandler002, TestSize.Level1)
592 {
593     CALL_TEST_DEBUG;
594     ServerMsgHandler servermsghandler;
595     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
596     InputHandlerType handlerType = InputHandlerType::MONITOR;
597     HandleEventType eventType = 1;
598     int32_t priority = 1;
599     uint32_t deviceTags = 0x01;
600     EXPECT_EQ(
601         servermsghandler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
602 }
603 
604 /**
605  * @tc.name: ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler002
606  * @tc.desc: Test OnMarkConsumed
607  * @tc.type: FUNC
608  * @tc.require:
609  */
610 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMarkConsumedWithMonitorHandler002, TestSize.Level1)
611 {
612     CALL_TEST_DEBUG;
613     ServerMsgHandler servermsghandler;
614     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
615     int32_t eventId = 11;
616     EXPECT_EQ(servermsghandler.OnMarkConsumed(sess, eventId), ERROR_NULL_POINTER);
617 }
618 
619 /**
620  * @tc.name: ServerMsgHandlerTest_OnGetFunctionKeyState_001
621  * @tc.desc: Test the function OnGetFunctionKeyState
622  * @tc.type: FUNC
623  * @tc.require:
624  */
625 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnGetFunctionKeyState_001, TestSize.Level1)
626 {
627     CALL_TEST_DEBUG;
628     ServerMsgHandler handler;
629     int32_t funcKey = NUM_LOCK_FUNCTION_KEY;
630     bool state = false;
631     int32_t ret = handler.OnGetFunctionKeyState(funcKey, state);
632     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
633     funcKey = CAPS_LOCK_FUNCTION_KEY;
634     ret = handler.OnGetFunctionKeyState(funcKey, state);
635     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
636     funcKey = SCROLL_LOCK_FUNCTION_KEY;
637     ret = handler.OnGetFunctionKeyState(funcKey, state);
638     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
639     funcKey = 10;
640     state = true;
641     ret = handler.OnGetFunctionKeyState(funcKey, state);
642     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
643 }
644 
645 /**
646  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEventExt_001
647  * @tc.desc: Test the function OnInjectPointerEventExt
648  * @tc.type: FUNC
649  * @tc.require:
650  */
651 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEventExt_001, TestSize.Level1)
652 {
653     CALL_TEST_DEBUG;
654     ServerMsgHandler handler;
655     std::shared_ptr<PointerEvent> pointerEvent = nullptr;
656     int32_t ret = handler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE);
657     EXPECT_EQ(ret, ERROR_NULL_POINTER);
658     pointerEvent = PointerEvent::Create();
659     EXPECT_NE(pointerEvent, nullptr);
660     int32_t sourceType = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
661     ret = handler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE);
662     EXPECT_EQ(ret, ERROR_NULL_POINTER);
663     sourceType = PointerEvent::SOURCE_TYPE_MOUSE;
664     EXPECT_NO_FATAL_FAILURE(handler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE));
665     sourceType = PointerEvent::SOURCE_TYPE_JOYSTICK;
666     EXPECT_NO_FATAL_FAILURE(handler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE));
667     sourceType = PointerEvent::SOURCE_TYPE_TOUCHPAD;
668     EXPECT_NO_FATAL_FAILURE(handler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE));
669 }
670 
671 /**
672  * @tc.name: ServerMsgHandlerTest_OnEnhanceConfig_001
673  * @tc.desc: Test the function OnEnhanceConfig
674  * @tc.type: FUNC
675  * @tc.require:
676  */
677 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnEnhanceConfig_001, TestSize.Level1)
678 {
679     CALL_TEST_DEBUG;
680     ServerMsgHandler handler;
681     SessionPtr sess = nullptr;
682     MmiMessageId idMsg = MmiMessageId::INVALID;
683     NetPacket pkt(idMsg);
684     int32_t ret = handler.OnEnhanceConfig(sess, pkt);
685     EXPECT_EQ(ret, ERROR_NULL_POINTER);
686     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
687     int32_t uid = 1;
688     ret = handler.OnEnhanceConfig(sess, pkt);
689     EXPECT_EQ(ret, RET_ERR);
690     uid = SECURITY_COMPONENT_SERVICE_ID;
691     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
692     ret = handler.OnEnhanceConfig(sess, pkt);
693     EXPECT_EQ(ret, RET_ERR);
694     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
695     EXPECT_NO_FATAL_FAILURE(handler.OnEnhanceConfig(sess, pkt));
696 }
697 
698 /**
699  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_001
700  * @tc.desc: Test the function AccelerateMotion
701  * @tc.type: FUNC
702  * @tc.require:
703  */
704 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_001, TestSize.Level1)
705 {
706     CALL_TEST_DEBUG;
707     ServerMsgHandler handler;
708     auto pointerEvent = PointerEvent::Create();
709     ASSERT_NE(pointerEvent, nullptr);
710     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
711     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
712     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
713     int32_t pointerId = 1;
714     PointerEvent::PointerItem item;
715     item.SetPointerId(pointerId);
716     pointerEvent->AddPointerItem(item);
717     pointerEvent->SetPointerId(0);
718     int32_t ret = handler.AccelerateMotion(pointerEvent);
719     EXPECT_EQ(ret, RET_OK);
720 }
721 
722 /**
723  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_002
724  * @tc.desc: Test the function AccelerateMotion
725  * @tc.type: FUNC
726  * @tc.require:
727  */
728 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_002, TestSize.Level1)
729 {
730     CALL_TEST_DEBUG;
731     ServerMsgHandler handler;
732     auto pointerEvent = PointerEvent::Create();
733     ASSERT_NE(pointerEvent, nullptr);
734     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
735     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
736     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
737     int32_t pointerId = 1;
738     PointerEvent::PointerItem item;
739     item.SetPointerId(pointerId);
740     pointerEvent->AddPointerItem(item);
741     pointerEvent->SetPointerId(0);
742     int32_t ret = handler.AccelerateMotion(pointerEvent);
743     EXPECT_EQ(ret, RET_ERR);
744 }
745 
746 /**
747  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_003
748  * @tc.desc: Test the function AccelerateMotion
749  * @tc.type: FUNC
750  * @tc.require:
751  */
752 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_003, TestSize.Level1)
753 {
754     CALL_TEST_DEBUG;
755     ServerMsgHandler handler;
756     auto pointerEvent = PointerEvent::Create();
757     ASSERT_NE(pointerEvent, nullptr);
758     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
759     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
760     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
761     int32_t pointerId = 0;
762     PointerEvent::PointerItem item;
763     item.SetPointerId(pointerId);
764     pointerEvent->AddPointerItem(item);
765     pointerEvent->SetPointerId(0);
766     int32_t ret = handler.AccelerateMotion(pointerEvent);
767     EXPECT_EQ(ret, RET_ERR);
768 }
769 
770 /**
771  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_004
772  * @tc.desc: Test the function AccelerateMotion
773  * @tc.type: FUNC
774  * @tc.require:
775  */
776 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_004, TestSize.Level1)
777 {
778     CALL_TEST_DEBUG;
779     ServerMsgHandler handler;
780     auto pointerEvent = PointerEvent::Create();
781     ASSERT_NE(pointerEvent, nullptr);
782     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
783     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
784     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
785     int32_t pointerId = 0;
786     PointerEvent::PointerItem item;
787     item.SetPointerId(pointerId);
788     pointerEvent->AddPointerItem(item);
789     pointerEvent->SetPointerId(0);
790     int32_t ret = handler.AccelerateMotion(pointerEvent);
791     EXPECT_EQ(ret, RET_ERR);
792 }
793 
794 /**
795  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_005
796  * @tc.desc: Test the function AccelerateMotion
797  * @tc.type: FUNC
798  * @tc.require:
799  */
800 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_005, TestSize.Level1)
801 {
802     CALL_TEST_DEBUG;
803     ServerMsgHandler handler;
804     auto pointerEvent = PointerEvent::Create();
805     ASSERT_NE(pointerEvent, nullptr);
806     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
807     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
808     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
809     int32_t pointerId = 0;
810     PointerEvent::PointerItem item;
811     item.SetPointerId(pointerId);
812     pointerEvent->AddPointerItem(item);
813     pointerEvent->SetPointerId(0);
814     int32_t ret = handler.AccelerateMotion(pointerEvent);
815     EXPECT_EQ(ret, RET_ERR);
816 }
817 
818 /**
819  * @tc.name: ServerMsgHandlerTest_UpdatePointerEvent_001
820  * @tc.desc: Test the function UpdatePointerEvent
821  * @tc.type: FUNC
822  * @tc.require:
823  */
824 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdatePointerEvent_001, TestSize.Level1)
825 {
826     CALL_TEST_DEBUG;
827     ServerMsgHandler handler;
828     auto pointerEvent = PointerEvent::Create();
829     ASSERT_NE(pointerEvent, nullptr);
830     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
831     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
832     int32_t pointerId = 0;
833     PointerEvent::PointerItem item;
834     item.SetPointerId(pointerId);
835     pointerEvent->AddPointerItem(item);
836     pointerEvent->SetPointerId(0);
837     ASSERT_NO_FATAL_FAILURE(handler.UpdatePointerEvent(pointerEvent));
838 }
839 
840 /**
841  * @tc.name: ServerMsgHandlerTest_UpdatePointerEvent_002
842  * @tc.desc: Test the function UpdatePointerEvent
843  * @tc.type: FUNC
844  * @tc.require:
845  */
846 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdatePointerEvent_002, TestSize.Level1)
847 {
848     CALL_TEST_DEBUG;
849     ServerMsgHandler handler;
850     auto pointerEvent = PointerEvent::Create();
851     ASSERT_NE(pointerEvent, nullptr);
852     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
853     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
854     int32_t pointerId = 0;
855     PointerEvent::PointerItem item;
856     item.SetPointerId(pointerId);
857     pointerEvent->AddPointerItem(item);
858     pointerEvent->SetPointerId(0);
859     ASSERT_NO_FATAL_FAILURE(handler.UpdatePointerEvent(pointerEvent));
860 }
861 
862 /**
863  * @tc.name: ServerMsgHandlerTest_UpdatePointerEvent_003
864  * @tc.desc: Test the function UpdatePointerEvent
865  * @tc.type: FUNC
866  * @tc.require:
867  */
868 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdatePointerEvent_003, TestSize.Level1)
869 {
870     CALL_TEST_DEBUG;
871     ServerMsgHandler handler;
872     auto pointerEvent = PointerEvent::Create();
873     ASSERT_NE(pointerEvent, nullptr);
874     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
875     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
876     int32_t pointerId = 1;
877     PointerEvent::PointerItem item;
878     item.SetPointerId(pointerId);
879     pointerEvent->AddPointerItem(item);
880     pointerEvent->SetPointerId(0);
881     ASSERT_NO_FATAL_FAILURE(handler.UpdatePointerEvent(pointerEvent));
882 }
883 
884 /**
885  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_001
886  * @tc.desc: Test the function SaveTargetWindowId
887  * @tc.type: FUNC
888  * @tc.require:
889  */
890 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_001, TestSize.Level1)
891 {
892     CALL_TEST_DEBUG;
893     ServerMsgHandler handler;
894     auto pointerEvent = PointerEvent::Create();
895     ASSERT_NE(pointerEvent, nullptr);
896     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
897     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
898     int32_t pointerId = 1;
899     PointerEvent::PointerItem item;
900     item.SetPointerId(pointerId);
901     pointerEvent->AddPointerItem(item);
902     pointerEvent->SetPointerId(0);
903     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
904     EXPECT_EQ(ret, RET_ERR);
905 }
906 
907 /**
908  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_002
909  * @tc.desc: Test the function SaveTargetWindowId
910  * @tc.type: FUNC
911  * @tc.require:
912  */
913 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_002, TestSize.Level1)
914 {
915     CALL_TEST_DEBUG;
916     ServerMsgHandler handler;
917     auto pointerEvent = PointerEvent::Create();
918     ASSERT_NE(pointerEvent, nullptr);
919     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
920     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
921     int32_t pointerId = 0;
922     PointerEvent::PointerItem item;
923     item.SetPointerId(pointerId);
924     pointerEvent->AddPointerItem(item);
925     pointerEvent->SetPointerId(0);
926     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
927     EXPECT_EQ(ret, RET_OK);
928 }
929 
930 /**
931  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_003
932  * @tc.desc: Test the function SaveTargetWindowId
933  * @tc.type: FUNC
934  * @tc.require:
935  */
936 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_003, TestSize.Level1)
937 {
938     CALL_TEST_DEBUG;
939     ServerMsgHandler handler;
940     auto pointerEvent = PointerEvent::Create();
941     ASSERT_NE(pointerEvent, nullptr);
942     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
943     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_MOVE);
944     int32_t pointerId = 0;
945     PointerEvent::PointerItem item;
946     item.SetPointerId(pointerId);
947     pointerEvent->AddPointerItem(item);
948     pointerEvent->SetPointerId(0);
949     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
950     EXPECT_EQ(ret, RET_OK);
951 }
952 
953 /**
954  * @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_004
955  * @tc.desc: Test the function SaveTargetWindowId
956  * @tc.type: FUNC
957  * @tc.require:
958  */
959 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_004, TestSize.Level1)
960 {
961     CALL_TEST_DEBUG;
962     ServerMsgHandler handler;
963     auto pointerEvent = PointerEvent::Create();
964     ASSERT_NE(pointerEvent, nullptr);
965     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
966     EXPECT_EQ(ret, RET_OK);
967 }
968 
969 /**
970 @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_005
971 @tc.desc: Test the function SaveTargetWindowId
972 @tc.type: FUNC
973 @tc.require:
974 */
975 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_005, TestSize.Level1)
976 {
977     CALL_TEST_DEBUG;
978     ServerMsgHandler handler;
979     auto pointerEvent = PointerEvent::Create();
980     ASSERT_NE(pointerEvent, nullptr);
981     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
982     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
983     int32_t pointerId = 0;
984     PointerEvent::PointerItem item;
985     item.SetPointerId(pointerId);
986     pointerEvent->AddPointerItem(item);
987     pointerEvent->SetPointerId(0);
988     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
989     EXPECT_EQ(ret, RET_OK);
990     ret = handler.SaveTargetWindowId(pointerEvent, true);
991     EXPECT_EQ(ret, RET_OK);
992     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
993     ret = handler.SaveTargetWindowId(pointerEvent, true);
994     EXPECT_EQ(ret, RET_OK);
995     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
996     ret = handler.SaveTargetWindowId(pointerEvent, true);
997     EXPECT_EQ(ret, RET_OK);
998     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
999     ret = handler.SaveTargetWindowId(pointerEvent, true);
1000     EXPECT_EQ(ret, RET_OK);
1001 }
1002 
1003 /**
1004 @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_006
1005 @tc.desc: Test the function SaveTargetWindowId
1006 @tc.type: FUNC
1007 @tc.require:
1008 */
1009 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_006, TestSize.Level1)
1010 {
1011     CALL_TEST_DEBUG;
1012     ServerMsgHandler handler;
1013     auto pointerEvent = PointerEvent::Create();
1014     ASSERT_NE(pointerEvent, nullptr);
1015     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1016     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
1017     int32_t pointerId = 0;
1018     PointerEvent::PointerItem item;
1019     item.SetPointerId(pointerId);
1020     pointerEvent->AddPointerItem(item);
1021     pointerEvent->SetPointerId(0);
1022     pointerEvent->SetDeviceId(0xAAAAAAFF);
1023     pointerEvent->SetZOrder(1);
1024     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
1025     EXPECT_EQ(ret, RET_OK);
1026 }
1027 
1028 /**
1029 @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_007
1030 @tc.desc: Test the function SaveTargetWindowId
1031 @tc.type: FUNC
1032 @tc.require:
1033 */
1034 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_007, TestSize.Level1)
1035 {
1036     CALL_TEST_DEBUG;
1037     ServerMsgHandler handler;
1038     auto pointerEvent = PointerEvent::Create();
1039     ASSERT_NE(pointerEvent, nullptr);
1040     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1041     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
1042     int32_t pointerId = 0;
1043     PointerEvent::PointerItem item;
1044     item.SetPointerId(pointerId);
1045     pointerEvent->AddPointerItem(item);
1046     pointerEvent->SetPointerId(0);
1047     pointerEvent->SetDeviceId(0xAAAAAAFF);
1048     pointerEvent->SetZOrder(-1);
1049     int32_t ret = handler.SaveTargetWindowId(pointerEvent, false);
1050     EXPECT_EQ(ret, RET_OK);
1051     pointerEvent->SetDeviceId(0);
1052     pointerEvent->SetZOrder(1);
1053     ret = handler.SaveTargetWindowId(pointerEvent, false);
1054     EXPECT_EQ(ret, RET_OK);
1055     pointerEvent->SetDeviceId(0);
1056     pointerEvent->SetZOrder(-1);
1057     ret = handler.SaveTargetWindowId(pointerEvent, false);
1058     EXPECT_EQ(ret, RET_OK);
1059     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY);
1060     ret = handler.SaveTargetWindowId(pointerEvent, false);
1061     EXPECT_EQ(ret, RET_OK);
1062     pointerEvent->ClearFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY);
1063     ret = handler.SaveTargetWindowId(pointerEvent, false);
1064     EXPECT_EQ(ret, RET_OK);
1065 }
1066 
1067 /**
1068  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_001
1069  * @tc.desc: Test FixTargetWindowId
1070  * @tc.type: FUNC
1071  * @tc.require:
1072  */
1073 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_001, TestSize.Level1)
1074 {
1075     CALL_TEST_DEBUG;
1076     ServerMsgHandler handler;
1077     auto pointerEvent = PointerEvent::Create();
1078     ASSERT_NE(pointerEvent, nullptr);
1079     int32_t action = PointerEvent::POINTER_ACTION_UNKNOWN;
1080     pointerEvent->SetPointerId(1);
1081     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
1082     ASSERT_FALSE(result);
1083 }
1084 
1085 /**
1086  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_002
1087  * @tc.desc: Test FixTargetWindowId
1088  * @tc.type: FUNC
1089  * @tc.require:
1090  */
1091 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_002, TestSize.Level1)
1092 {
1093     CALL_TEST_DEBUG;
1094     ServerMsgHandler handler;
1095     auto pointerEvent = PointerEvent::Create();
1096     ASSERT_NE(pointerEvent, nullptr);
1097     int32_t action = PointerEvent::POINTER_ACTION_HOVER_ENTER;
1098     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
1099     ASSERT_FALSE(result);
1100 }
1101 
1102 /**
1103  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_003
1104  * @tc.desc: Test FixTargetWindowId
1105  * @tc.type: FUNC
1106  * @tc.require:
1107  */
1108 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_003, TestSize.Level1)
1109 {
1110     CALL_TEST_DEBUG;
1111     ServerMsgHandler handler;
1112     auto pointerEvent = PointerEvent::Create();
1113     ASSERT_NE(pointerEvent, nullptr);
1114     int32_t action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
1115     pointerEvent->SetPointerId(1);
1116     std::vector<int32_t> pointerIds {pointerEvent->GetPointerIds()};
1117     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
1118     ASSERT_FALSE(result);
1119 }
1120 
1121 /**
1122  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_004
1123  * @tc.desc: Test FixTargetWindowId
1124  * @tc.type: FUNC
1125  * @tc.require:
1126  */
1127 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_004, TestSize.Level1)
1128 {
1129     CALL_TEST_DEBUG;
1130     ServerMsgHandler handler;
1131     auto pointerEvent = PointerEvent::Create();
1132     ASSERT_NE(pointerEvent, nullptr);
1133     int32_t action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
1134     pointerEvent->SetPointerId(1);
1135     std::vector<int32_t> pointerIds {pointerEvent->GetPointerIds()};
1136     int32_t pointerId = 0;
1137     PointerEvent::PointerItem item;
1138     item.SetPointerId(pointerId);
1139     pointerEvent->AddPointerItem(item);
1140     pointerEvent->SetPointerId(0);
1141     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
1142     ASSERT_TRUE(result);
1143 }
1144 
1145 /**
1146  * @tc.name: ServerMsgHandlerTest_FixTargetWindowId_005
1147  * @tc.desc: Test FixTargetWindowId
1148  * @tc.type: FUNC
1149  * @tc.require:
1150  */
1151 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_005, TestSize.Level1)
1152 {
1153     CALL_TEST_DEBUG;
1154     ServerMsgHandler handler;
1155     auto pointerEvent = PointerEvent::Create();
1156     ASSERT_NE(pointerEvent, nullptr);
1157     int32_t action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
1158     pointerEvent->SetPointerId(1);
1159     std::vector<int32_t> pointerIds {pointerEvent->GetPointerIds()};
1160     int32_t pointerId = 1;
1161     PointerEvent::PointerItem item;
1162     item.SetPointerId(pointerId);
1163     pointerEvent->AddPointerItem(item);
1164     pointerEvent->SetPointerId(0);
1165     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
1166     ASSERT_FALSE(result);
1167 }
1168 
1169 /**
1170 @tc.name: ServerMsgHandlerTest_FixTargetWindowId_006
1171 @tc.desc: Test FixTargetWindowId
1172 @tc.type: FUNC
1173 @tc.require:
1174 */
1175 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_006, TestSize.Level1)
1176 {
1177     CALL_TEST_DEBUG;
1178     ServerMsgHandler handler;
1179     handler.shellTargetWindowIds_.clear();
1180     auto pointerEvent = PointerEvent::Create();
1181     ASSERT_NE(pointerEvent, nullptr);
1182     int32_t action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
1183     pointerEvent->SetPointerId(1);
1184     std::vector<int32_t> pointerIds {pointerEvent->GetPointerIds()};
1185     int32_t pointerId = 1;
1186     PointerEvent::PointerItem item;
1187     item.SetPointerId(pointerId);
1188     pointerEvent->AddPointerItem(item);
1189     pointerEvent->SetPointerId(0);
1190     bool result = handler.FixTargetWindowId(pointerEvent, action, true);
1191     ASSERT_FALSE(result);
1192     handler.shellTargetWindowIds_[0] = 0;
1193     result = handler.FixTargetWindowId(pointerEvent, action, true);
1194     ASSERT_FALSE(result);
1195     handler.shellTargetWindowIds_[0] = 1;
1196     result = handler.FixTargetWindowId(pointerEvent, action, true);
1197     ASSERT_FALSE(result);
1198     pointerEvent->pointers_.clear();
1199     action = PointerEvent::POINTER_ACTION_HOVER_MOVE;
1200     result = handler.FixTargetWindowId(pointerEvent, action, true);
1201     ASSERT_FALSE(result);
1202 }
1203 
1204 /**
1205 @tc.name: ServerMsgHandlerTest_FixTargetWindowId_007
1206 @tc.desc: Test FixTargetWindowId
1207 @tc.type: FUNC
1208 @tc.require:
1209 */
1210 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_007, TestSize.Level1)
1211 {
1212     CALL_TEST_DEBUG;
1213     ServerMsgHandler handler;
1214     handler.shellTargetWindowIds_.clear();
1215     auto pointerEvent = PointerEvent::Create();
1216     ASSERT_NE(pointerEvent, nullptr);
1217     int32_t action = PointerEvent::POINTER_ACTION_DOWN;
1218     int32_t pointerId = -1;
1219     PointerEvent::PointerItem item;
1220     item.SetPointerId(pointerId);
1221     pointerEvent->AddPointerItem(item);
1222     pointerEvent->SetPointerId(-1);
1223     handler.shellTargetWindowIds_[0] = -1;
1224     int32_t result = handler.FixTargetWindowId(pointerEvent, action, true);
1225     ASSERT_TRUE(result);
1226 }
1227 
1228 /**
1229 @tc.name: ServerMsgHandlerTest_OnUiExtentionWindowInfo_001
1230 @tc.desc: Test the function OnUiExtentionWindowInfo
1231 @tc.type: FUNC
1232 @tc.require:
1233 */
1234 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnUiExtentionWindowInfo_001, TestSize.Level1)
1235 {
1236     CALL_TEST_DEBUG;
1237     ServerMsgHandler handler;
1238     NetPacket pkt(MmiMessageId::ADD_INPUT_DEVICE_LISTENER);
1239     WindowInfo info;
1240     pkt << 2;
1241     pkt << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1 << 1;
1242     int32_t ret = handler.OnUiExtentionWindowInfo(pkt, info);
1243     EXPECT_EQ(ret, RET_ERR);
1244 }
1245 
1246 /**
1247  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandler_001
1248  * @tc.desc: Test the function OnRemoveInputHandler
1249  * @tc.type: FUNC
1250  * @tc.require:
1251  */
1252 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandler_001, TestSize.Level1)
1253 {
1254     CALL_TEST_DEBUG;
1255     ServerMsgHandler handler;
1256     SessionPtr sess = nullptr;
1257     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
1258     HandleEventType eventType = 1;
1259     int32_t priority = 2;
1260     uint32_t deviceTags = 3;
1261     int32_t ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
1262     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1263     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1264     ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
1265     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1266     handlerType = InputHandlerType::MONITOR;
1267     ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
1268     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1269     handlerType = InputHandlerType::NONE;
1270     ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
1271     EXPECT_EQ(ret, RET_OK);
1272 }
1273 
1274 /**
1275  * @tc.name: ServerMsgHandlerTest_OnAddInputHandler_001
1276  * @tc.desc: Test the function OnAddInputHandler
1277  * @tc.type: FUNC
1278  * @tc.require:
1279  */
1280 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddInputHandler_001, TestSize.Level1)
1281 {
1282     CALL_TEST_DEBUG;
1283     ServerMsgHandler handler;
1284     SessionPtr sess = nullptr;
1285     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
1286     HandleEventType eventType = 1;
1287     int32_t priority = 2;
1288     uint32_t deviceTags = 3;
1289     int32_t ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1290     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1291     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1292     ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1293     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1294     handlerType = InputHandlerType::MONITOR;
1295     ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1296     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1297     handlerType = InputHandlerType::NONE;
1298     ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
1299     EXPECT_EQ(ret, RET_OK);
1300 }
1301 
1302 /**
1303  * @tc.name: ServerMsgHandlerTest_OnMoveMouse_001
1304  * @tc.desc: Test the function OnMoveMouse
1305  * @tc.type: FUNC
1306  * @tc.require:
1307  */
1308 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMoveMouse_001, TestSize.Level1)
1309 {
1310     CALL_TEST_DEBUG;
1311     ServerMsgHandler handler;
1312     int32_t offsetX = 10;
1313     int32_t offsetY = 20;
1314     std::shared_ptr<PointerEvent> pointerEvent_ = PointerEvent::Create();
1315     ASSERT_NE(pointerEvent_, nullptr);
1316     int32_t ret = handler.OnMoveMouse(offsetX, offsetY);
1317     EXPECT_EQ(ret, RET_OK);
1318 }
1319 
1320 /**
1321  * @tc.name: ServerMsgHandlerTest_OnCancelInjection_001
1322  * @tc.desc: Test the function OnCancelInjection
1323  * @tc.type: FUNC
1324  * @tc.require:
1325  */
1326 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnCancelInjection_001, TestSize.Level1)
1327 {
1328     CALL_TEST_DEBUG;
1329     ServerMsgHandler handler;
1330     handler.authorizationCollection_.insert(std::make_pair(12, AuthorizationStatus::AUTHORIZED));
1331     handler.CurrentPID_ = 12;
1332     int32_t ret = handler.OnCancelInjection();
1333     EXPECT_EQ(ret, ERR_OK);
1334     handler.CurrentPID_ = 1;
1335     ret = handler.OnCancelInjection();
1336     EXPECT_EQ(ret, ERR_OK);
1337 }
1338 
1339 /**
1340  * @tc.name: ServerMsgHandlerTest_SetWindowInfo_001
1341  * @tc.desc: Test the function SetWindowInfo
1342  * @tc.type: FUNC
1343  * @tc.require:
1344  */
1345 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetWindowInfo_001, TestSize.Level1)
1346 {
1347     CALL_TEST_DEBUG;
1348     ServerMsgHandler handler;
1349     int32_t infoId = 1;
1350     WindowInfo info;
1351     const std::string iconPath = "/system/etc/multimodalinput/mouse_icon/North_South.svg";
1352     handler.transparentWins_.insert(std::make_pair(1, SetMouseIconTest(iconPath)));
1353     EXPECT_NO_FATAL_FAILURE(handler.SetWindowInfo(infoId, info));
1354     infoId = 2;
1355     EXPECT_NO_FATAL_FAILURE(handler.SetWindowInfo(infoId, info));
1356 }
1357 
1358 /**
1359  * @tc.name: ServerMsgHandlerTest_OnEnhanceConfig_002
1360  * @tc.desc: Test the function OnEnhanceConfig
1361  * @tc.type: FUNC
1362  * @tc.require:
1363  */
1364 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnEnhanceConfig_002, TestSize.Level1)
1365 {
1366     CALL_TEST_DEBUG;
1367     ServerMsgHandler handler;
1368     SessionPtr sess = nullptr;
1369     MmiMessageId idMsg = MmiMessageId::ADD_INPUT_DEVICE_LISTENER;
1370     NetPacket pkt(idMsg);
1371     int32_t ret = handler.OnEnhanceConfig(sess, pkt);
1372     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1373     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1374     int32_t uid = 123;
1375     ret = handler.OnEnhanceConfig(sess, pkt);
1376     EXPECT_EQ(ret, RET_ERR);
1377     uid = SECURITY_COMPONENT_SERVICE_ID;
1378     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1379     ret = handler.OnEnhanceConfig(sess, pkt);
1380     EXPECT_EQ(ret, RET_ERR);
1381     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1382     EXPECT_NO_FATAL_FAILURE(handler.OnEnhanceConfig(sess, pkt));
1383 }
1384 
1385 /**
1386  * @tc.name: ServerMsgHandlerTest_OnEnhanceConfig_003
1387  * @tc.desc: Test the function OnEnhanceConfig
1388  * @tc.type: FUNC
1389  * @tc.require:
1390  */
1391 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnEnhanceConfig_003, TestSize.Level1)
1392 {
1393     CALL_TEST_DEBUG;
1394     ServerMsgHandler handler;
1395     MmiMessageId idMsg = MmiMessageId::ADD_INPUT_DEVICE_LISTENER;
1396     NetPacket pkt(idMsg);
1397     SessionPtr sess =
1398         std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, SECURITY_COMPONENT_SERVICE_ID - 1, g_pid);
1399     int32_t ret = handler.OnEnhanceConfig(sess, pkt);
1400     EXPECT_EQ(ret, RET_ERR);
1401     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, SECURITY_COMPONENT_SERVICE_ID, g_pid);
1402     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1403     ret = handler.OnEnhanceConfig(sess, pkt);
1404     EXPECT_EQ(ret, RET_ERR);
1405     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1406     EXPECT_NO_FATAL_FAILURE(handler.OnEnhanceConfig(sess, pkt));
1407 }
1408 
1409 /**
1410 @tc.name: ServerMsgHandlerTest_OnEnhanceConfig_004
1411 @tc.desc: Test the function OnEnhanceConfig
1412 @tc.type: FUNC
1413 @tc.require:
1414 */
1415 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnEnhanceConfig_004, TestSize.Level1)
1416 {
1417     CALL_TEST_DEBUG;
1418     ServerMsgHandler handler;
1419     MmiMessageId idMsg = MmiMessageId::ADD_INPUT_DEVICE_LISTENER;
1420     NetPacket pkt(idMsg);
1421     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1422     pkt << 1 << 1;
1423     SessionPtr sess =
1424         std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, SECURITY_COMPONENT_SERVICE_ID, g_pid);
1425     int32_t ret = handler.OnEnhanceConfig(sess, pkt);
1426     EXPECT_EQ(ret, RET_ERR);
1427 }
1428 
1429 /**
1430  * @tc.name: ServerMsgHandlerTest_OnMsgHandler
1431  * @tc.desc: Test if (callback == nullptr) branch success
1432  * @tc.type: FUNC
1433  * @tc.require:
1434  */
1435 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMsgHandler, TestSize.Level1)
1436 {
1437     CALL_TEST_DEBUG;
1438     ServerMsgHandler msgHandler;
1439     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1440     MmiMessageId idMsg = MmiMessageId::INVALID;
1441     NetPacket pkt(idMsg);
1442     EXPECT_NO_FATAL_FAILURE(msgHandler.OnMsgHandler(sess, pkt));
1443 }
1444 
1445 /**
1446  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEventExt
1447  * @tc.desc: Test OnInjectPointerEventExt
1448  * @tc.type: FUNC
1449  * @tc.require:
1450  */
1451 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEventExt, TestSize.Level1)
1452 {
1453     CALL_TEST_DEBUG;
1454     ServerMsgHandler msgHandler;
1455     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1456     ASSERT_NE(pointerEvent, nullptr);
1457     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1458     pointerEvent->SetId(1);
1459     pointerEvent->eventType_ = 1;
1460     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1461     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
1462     msgHandler.nativeTargetWindowIds_.insert(std::make_pair(pointerEvent->GetPointerId(), 10));
1463     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE), RET_ERR);
1464 
1465     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
1466     pointerEvent->SetPointerId(1);
1467     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1468     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT;
1469     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE), RET_ERR);
1470 
1471     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
1472     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
1473     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NONE);
1474     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE), RET_OK);
1475 
1476     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
1477     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_HIDE_POINTER;
1478     EXPECT_NE(msgHandler.OnInjectPointerEventExt(pointerEvent, false, PointerEvent::DISPLAY_COORDINATE), RET_OK);
1479 }
1480 
1481 /**
1482  * @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_001
1483  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch success
1484  * @tc.type: FUNC
1485  * @tc.require:
1486  */
1487 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_001, TestSize.Level1)
1488 {
1489     CALL_TEST_DEBUG;
1490     ServerMsgHandler msgHandler;
1491     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1492     ASSERT_NE(keyEvent, nullptr);
1493     int32_t pid = 15;
1494     bool isNativeInject = true;
1495     keyEvent->SetId(1);
1496     keyEvent->eventType_ = 1;
1497     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1498     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNAUTHORIZED));
1499     EXPECT_EQ(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), COMMON_PERMISSION_CHECK_ERROR);
1500 }
1501 
1502 /**
1503  * @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_002
1504  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch failed
1505  * @tc.type: FUNC
1506  * @tc.require:
1507  */
1508 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_002, TestSize.Level1)
1509 {
1510     CALL_TEST_DEBUG;
1511     ServerMsgHandler msgHandler;
1512     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1513     ASSERT_NE(keyEvent, nullptr);
1514     int32_t pid = 15;
1515     bool isNativeInject = true;
1516     keyEvent->SetId(1);
1517     keyEvent->eventType_ = 1;
1518     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1519     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNKNOWN));
1520     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1521     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1522 }
1523 
1524 /**
1525  * @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_003
1526  * @tc.desc: Test if (isNativeInject) branch failed
1527  * @tc.type: FUNC
1528  * @tc.require:
1529  */
1530 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_003, TestSize.Level1)
1531 {
1532     CALL_TEST_DEBUG;
1533     ServerMsgHandler msgHandler;
1534     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1535     ASSERT_NE(keyEvent, nullptr);
1536     int32_t pid = 15;
1537     bool isNativeInject = false;
1538     keyEvent->SetId(1);
1539     keyEvent->eventType_ = 1;
1540     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1541     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1542     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1543 }
1544 
1545 /**
1546 @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_004
1547 @tc.desc: Test OnInjectKeyEvent
1548 @tc.type: FUNC
1549 @tc.require:
1550 */
1551 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_004, TestSize.Level1)
1552 {
1553     CALL_TEST_DEBUG;
1554     ServerMsgHandler msgHandler;
1555     std::shared_ptr keyEvent = KeyEvent::Create();
1556     ASSERT_NE(keyEvent, nullptr);
1557     int32_t pid = 15;
1558     bool isNativeInject = false;
1559     keyEvent->SetId(1);
1560     keyEvent->eventType_ = 1;
1561     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1562     keyEvent->AddFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER);
1563     InputHandler->BuildInputHandlerChain();
1564     EventLogHelper::userType_ = "beta";
1565     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1566 }
1567 
1568 /**
1569 @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_005
1570 @tc.desc: Test OnInjectKeyEvent
1571 @tc.type: FUNC
1572 @tc.require:
1573 */
1574 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_005, TestSize.Level1)
1575 {
1576     CALL_TEST_DEBUG;
1577     ServerMsgHandler msgHandler;
1578     std::shared_ptr keyEvent = KeyEvent::Create();
1579     ASSERT_NE(keyEvent, nullptr);
1580     int32_t pid = 15;
1581     bool isNativeInject = false;
1582     keyEvent->SetId(1);
1583     keyEvent->eventType_ = 1;
1584     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1585     keyEvent->AddFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE);
1586     InputHandler->BuildInputHandlerChain();
1587     EventLogHelper::userType_ = "beta";
1588     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1589 }
1590 
1591 /**
1592 @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_006
1593 @tc.desc: Test OnInjectKeyEvent
1594 @tc.type: FUNC
1595 @tc.require:
1596 */
1597 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_006, TestSize.Level1)
1598 {
1599     CALL_TEST_DEBUG;
1600     ServerMsgHandler msgHandler;
1601     std::shared_ptr keyEvent = KeyEvent::Create();
1602     ASSERT_NE(keyEvent, nullptr);
1603     int32_t pid = 15;
1604     bool isNativeInject = false;
1605     keyEvent->SetId(1);
1606     keyEvent->eventType_ = 1;
1607     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1608     keyEvent->AddFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE);
1609     InputHandler->BuildInputHandlerChain();
1610     EventLogHelper::userType_ = "default";
1611     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1612 }
1613 
1614 /**
1615 @tc.name: ServerMsgHandlerTest_OnInjectKeyEvent_007
1616 @tc.desc: Test OnInjectKeyEvent
1617 @tc.type: FUNC
1618 @tc.require:
1619 */
1620 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectKeyEvent_007, TestSize.Level1)
1621 {
1622     CALL_TEST_DEBUG;
1623     ServerMsgHandler msgHandler;
1624     std::shared_ptr keyEvent = KeyEvent::Create();
1625     ASSERT_NE(keyEvent, nullptr);
1626     int32_t pid = 15;
1627     bool isNativeInject = false;
1628     keyEvent->SetId(1);
1629     keyEvent->eventType_ = 1;
1630     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1631     keyEvent->AddFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER);
1632     InputHandler->BuildInputHandlerChain();
1633     EventLogHelper::userType_ = "default";
1634     EXPECT_NE(msgHandler.OnInjectKeyEvent(keyEvent, pid, isNativeInject), RET_OK);
1635 }
1636 
1637 /**
1638  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent_002
1639  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch success
1640  * @tc.type: FUNC
1641  * @tc.require:
1642  */
1643 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent_002, TestSize.Level1)
1644 {
1645     CALL_TEST_DEBUG;
1646     ServerMsgHandler msgHandler;
1647     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1648     ASSERT_NE(pointerEvent, nullptr);
1649     int32_t pid = 15;
1650     bool isNativeInject = true;
1651     pointerEvent->SetId(1);
1652     pointerEvent->eventType_ = 1;
1653     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1654     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNAUTHORIZED));
1655     EXPECT_EQ(
1656         msgHandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false, PointerEvent::DISPLAY_COORDINATE),
1657         COMMON_PERMISSION_CHECK_ERROR);
1658 }
1659 
1660 /**
1661  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent_003
1662  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch failed
1663  * @tc.type: FUNC
1664  * @tc.require:
1665  */
1666 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent_003, TestSize.Level1)
1667 {
1668     CALL_TEST_DEBUG;
1669     ServerMsgHandler msgHandler;
1670     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1671     ASSERT_NE(pointerEvent, nullptr);
1672     int32_t pid = 15;
1673     bool isNativeInject = true;
1674     pointerEvent->SetId(1);
1675     pointerEvent->eventType_ = 1;
1676     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1677     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN);
1678     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNKNOWN));
1679     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1680     EXPECT_NE(
1681         msgHandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false, PointerEvent::DISPLAY_COORDINATE),
1682         RET_OK);
1683 }
1684 
1685 /**
1686  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent_004
1687  * @tc.desc: Test if (isNativeInject) branch failed
1688  * @tc.type: FUNC
1689  * @tc.require:
1690  */
1691 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent_004, TestSize.Level1)
1692 {
1693     CALL_TEST_DEBUG;
1694     ServerMsgHandler msgHandler;
1695     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
1696     ASSERT_NE(pointerEvent, nullptr);
1697     int32_t pid = 15;
1698     bool isNativeInject = false;
1699     pointerEvent->SetId(1);
1700     pointerEvent->eventType_ = 1;
1701     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
1702     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
1703     EXPECT_NE(
1704         msgHandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false, PointerEvent::DISPLAY_COORDINATE),
1705         RET_OK);
1706 }
1707 
1708 /**
1709  * @tc.name: ServerMsgHandlerTest_OnWindowGroupInfo_001
1710  * @tc.desc: Test the function OnWindowGroupInfo
1711  * @tc.type: FUNC
1712  * @tc.require:
1713  */
1714 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnWindowGroupInfo_001, TestSize.Level1)
1715 {
1716     CALL_TEST_DEBUG;
1717     ServerMsgHandler handler;
1718     SessionPtr sess = nullptr;
1719     MmiMessageId idMsg = MmiMessageId::INVALID;
1720     NetPacket pkt(idMsg);
1721     int32_t ret = handler.OnWindowGroupInfo(sess, pkt);
1722     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1723     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1724     CircleStreamBuffer::ErrorStatus rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
1725     ret = handler.OnWindowGroupInfo(sess, pkt);
1726     EXPECT_EQ(ret, RET_ERR);
1727     rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1728     ret = handler.OnWindowGroupInfo(sess, pkt);
1729     EXPECT_EQ(ret, RET_ERR);
1730 }
1731 
1732 /**
1733 @tc.name: ServerMsgHandlerTest_OnWindowGroupInfo_002
1734 @tc.desc: Test the function OnWindowGroupInfo
1735 @tc.type: FUNC
1736 @tc.require:
1737 */
1738 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnWindowGroupInfo_002, TestSize.Level1)
1739 {
1740     CALL_TEST_DEBUG;
1741     ServerMsgHandler handler;
1742     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1743     sess->SetTokenType(TOKEN_NATIVE);
1744     MmiMessageId idMsg = MmiMessageId::INVALID;
1745     NetPacket pkt(idMsg);
1746     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1747     int32_t ret = handler.OnWindowGroupInfo(sess, pkt);
1748     EXPECT_EQ(ret, RET_ERR);
1749     sess->SetTokenType(TOKEN_SHELL);
1750     ret = handler.OnWindowGroupInfo(sess, pkt);
1751     EXPECT_EQ(ret, RET_ERR);
1752     sess->SetTokenType(TOKEN_SYSTEM_HAP);
1753     ret = handler.OnWindowGroupInfo(sess, pkt);
1754     EXPECT_EQ(ret, RET_ERR);
1755 }
1756 
1757 /**
1758 @tc.name: ServerMsgHandlerTest_OnWindowGroupInfo_003
1759 @tc.desc: Test the function OnWindowGroupInfo
1760 @tc.type: FUNC
1761 @tc.require:
1762 */
1763 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnWindowGroupInfo_003, TestSize.Level1)
1764 {
1765     CALL_TEST_DEBUG;
1766     ServerMsgHandler handler;
1767     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1768     sess->SetTokenType(TOKEN_NATIVE);
1769     MmiMessageId idMsg = MmiMessageId::DISPLAY_INFO;
1770     NetPacket pkt(idMsg);
1771     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1772     pkt << 1 << 1 << 2;
1773     int32_t ret = handler.OnWindowGroupInfo(sess, pkt);
1774     EXPECT_EQ(ret, RET_ERR);
1775 }
1776 
1777 /**
1778 @tc.name: ServerMsgHandlerTest_OnWindowGroupInfo_004
1779 @tc.desc: Test the function OnWindowGroupInfo
1780 @tc.type: FUNC
1781 @tc.require:
1782 */
1783 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnWindowGroupInfo_004, TestSize.Level1)
1784 {
1785     CALL_TEST_DEBUG;
1786     ServerMsgHandler handler;
1787     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1788     sess->SetTokenType(TOKEN_NATIVE);
1789     MmiMessageId idMsg = MmiMessageId::DISPLAY_INFO;
1790     NetPacket pkt(idMsg);
1791     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
1792     pkt << 1 << 1 << 2;
1793 
1794     Rect rec = {1, 1, 1, 1};
1795     std::vector recVec = {rec, rec};
1796     std::vector<int32_t> pChangeAreas = {1, 1, 1};
1797     std::vector transform = {1.0, 1.0, 1.0};
1798     pkt << 1 << 1 << 1 << rec << recVec << recVec << 1 << 1 << WINDOW_UPDATE_ACTION::ADD << 1 << 1.0 << pChangeAreas
1799         << transform << 1 << 1 << 1 << false;
1800     int32_t ret = handler.OnWindowGroupInfo(sess, pkt);
1801     EXPECT_EQ(ret, RET_ERR);
1802 }
1803 
1804 /**
1805 @tc.name: ServerMsgHandlerTest_RegisterWindowStateErrorCallback_001
1806 @tc.desc: Test the function RegisterWindowStateErrorCallback
1807 @tc.type: FUNC
1808 @tc.require:
1809 */
1810 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_RegisterWindowStateErrorCallback_001, TestSize.Level1)
1811 {
1812     CALL_TEST_DEBUG;
1813     ServerMsgHandler handler;
1814     MmiMessageId idMsg = MmiMessageId::ADD_INPUT_DEVICE_LISTENER;
1815     NetPacket pkt(idMsg);
1816     SessionPtr sess = nullptr;
1817     int32_t ret = handler.RegisterWindowStateErrorCallback(sess, pkt);
1818     EXPECT_EQ(ret, ERROR_NULL_POINTER);
1819     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1820     ret = handler.RegisterWindowStateErrorCallback(sess, pkt);
1821     EXPECT_EQ(ret, RET_ERR);
1822     sess->SetTokenType(TOKEN_HAP);
1823     ret = handler.RegisterWindowStateErrorCallback(sess, pkt);
1824     EXPECT_EQ(ret, RET_ERR);
1825     sess->SetTokenType(TOKEN_NATIVE);
1826     ret = handler.RegisterWindowStateErrorCallback(sess, pkt);
1827     EXPECT_EQ(ret, RET_OK);
1828     sess->SetTokenType(TOKEN_SHELL);
1829     ret = handler.RegisterWindowStateErrorCallback(sess, pkt);
1830     EXPECT_EQ(ret, RET_OK);
1831     sess->SetTokenType(TOKEN_SYSTEM_HAP);
1832     ret = handler.RegisterWindowStateErrorCallback(sess, pkt);
1833     EXPECT_EQ(ret, RET_OK);
1834 }
1835 
1836 /**
1837  * @tc.name: ServerMsgHandlerTest_SetPixelMapData_001
1838  * @tc.desc: Test the function SetPixelMapData
1839  * @tc.type: FUNC
1840  * @tc.require:
1841  */
1842 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SetPixelMapData_001, TestSize.Level1)
1843 {
1844     CALL_TEST_DEBUG;
1845     ServerMsgHandler handler;
1846     int32_t infoId = -5;
1847     void *pixelMap = nullptr;
1848     int32_t result = handler.SetPixelMapData(infoId, pixelMap);
1849     EXPECT_EQ(result, ERR_INVALID_VALUE);
1850     infoId = 2;
1851     result = handler.SetPixelMapData(infoId, pixelMap);
1852     EXPECT_EQ(result, ERR_INVALID_VALUE);
1853 }
1854 
1855 /**
1856  * @tc.name: ServerMsgHandlerTest_InitInjectNoticeSource_001
1857  * @tc.desc: Test the function InitInjectNoticeSource
1858  * @tc.type: FUNC
1859  * @tc.require:
1860  */
1861 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_InitInjectNoticeSource_001, TestSize.Level1)
1862 {
1863     CALL_TEST_DEBUG;
1864     ServerMsgHandler handler;
1865     InjectNoticeManager manager;
1866     handler.injectNotice_ = nullptr;
1867     bool ret = handler.InitInjectNoticeSource();
1868     EXPECT_FALSE(ret);
1869     handler.injectNotice_ = std::make_shared<InjectNoticeManager>();
1870     manager.isStartSrv_ = false;
1871     ret = handler.InitInjectNoticeSource();
1872     EXPECT_FALSE(ret);
1873     manager.isStartSrv_ = true;
1874     ret = handler.InitInjectNoticeSource();
1875     EXPECT_FALSE(ret);
1876     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
1877     ASSERT_NE(manager.connectionCallback_, nullptr);
1878     manager.connectionCallback_->isConnected_ = false;
1879     ret = handler.InitInjectNoticeSource();
1880     EXPECT_FALSE(ret);
1881     manager.connectionCallback_->isConnected_ = true;
1882     ret = handler.InitInjectNoticeSource();
1883     EXPECT_FALSE(ret);
1884     delete(manager.connectionCallback_);
1885     manager.connectionCallback_ = nullptr;
1886 }
1887 
1888 /**
1889  * @tc.name: ServerMsgHandlerTest_CalculateOffset
1890  * @tc.desc: Test the function CalculateOffset
1891  * @tc.type: FUNC
1892  * @tc.require:
1893  */
1894 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_CalculateOffset, TestSize.Level1)
1895 {
1896     CALL_TEST_DEBUG;
1897     ServerMsgHandler handler;
1898     Direction direction = DIRECTION90;
1899     Offset offset;
1900     offset.dx = 100;
1901     offset.dy = 100;
1902     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1903     direction = DIRECTION180;
1904     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1905     direction = DIRECTION270;
1906     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1907     direction = DIRECTION0;
1908     EXPECT_NO_FATAL_FAILURE(handler.CalculateOffset(direction, offset));
1909 }
1910 
1911 /**
1912  * @tc.name: ServerMsgHandlerTest_OnDisplayInfo
1913  * @tc.desc: Test the function OnDisplayInfo
1914  * @tc.type: FUNC
1915  * @tc.require:
1916  */
1917 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo, TestSize.Level1)
1918 {
1919     CALL_TEST_DEBUG;
1920     ServerMsgHandler handler;
1921     int32_t num = 1;
1922     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1923     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
1924     OLD::DisplayGroupInfo displayGroupInfo {
1925         .focusWindowId = 10,
1926         .currentUserId = 20,
1927     };
1928     pkt << displayGroupInfo.focusWindowId << displayGroupInfo.currentUserId << num;
1929     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_WRITE;
1930     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_ERR);
1931 }
1932 
1933 /**
1934  * @tc.name: ServerMsgHandlerTest_OnDisplayInfo_01
1935  * @tc.desc: Test the function OnDisplayInfo_01
1936  * @tc.type: FUNC
1937  * @tc.require:
1938  */
1939 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_01, TestSize.Level1)
1940 {
1941     CALL_TEST_DEBUG;
1942     UserScreenInfo userScreenInfo;
1943     userScreenInfo.userId = 0;
1944     DisplayGroupInfo group;
1945     group.id = 1;
1946     group.name = "MainGroup";
1947     group.type = GroupType::GROUP_DEFAULT;
1948     group.mainDisplayId = 2;
1949     group.focusWindowId = 123;
1950     group.windowsInfo.push_back(WindowInfo());
1951     group.displaysInfo.push_back(DisplayInfo());
1952     DisplayInfo display;
1953     display.width = 1920;
1954     display.height = 1080;
1955     group.displaysInfo.push_back(display);
1956     WindowInfo window;
1957     window.groupId = 0;
1958     window.id = 123;
1959     group.windowsInfo.push_back(window);
1960     userScreenInfo.displayGroups.push_back(group);
1961     userScreenInfo.screens.push_back(ScreenInfo());
1962 
1963     ServerMsgHandler handler;
1964     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
1965     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
1966     int32_t result = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
1967     EXPECT_EQ(result, 0);
1968     int32_t msgId;
1969     pkt >> msgId;
1970     EXPECT_NO_FATAL_FAILURE(handler.OnDisplayInfo(sess, pkt));
1971 }
1972 
1973 /**
1974  * @tc.name: ServerMsgHandlerTest_OnDisplayInfo_02
1975  * @tc.desc: Test the function OnDisplayInfo_02
1976  * @tc.type: FUNC
1977  * @tc.require:
1978  */
1979 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_02, TestSize.Level1)
1980 {
1981     CALL_TEST_DEBUG;
1982     UserScreenInfo userScreenInfo;
1983     userScreenInfo.userId = 0;
1984     DisplayGroupInfo group;
1985     group.id = 1;
1986     group.name = "MainGroup";
1987     group.type = GroupType::GROUP_DEFAULT;
1988     group.mainDisplayId = 2;
1989     group.focusWindowId = 123;
1990     group.windowsInfo.push_back(WindowInfo());
1991     for (int32_t i = 0; i <= 1000; i++) {
1992         group.displaysInfo.push_back(DisplayInfo());
1993     }
1994     DisplayInfo display;
1995     display.width = 1920;
1996     display.height = 1080;
1997     group.displaysInfo.push_back(display);
1998     WindowInfo window;
1999     window.groupId = 0;
2000     window.id = 123;
2001     group.windowsInfo.push_back(window);
2002     userScreenInfo.screens.push_back(ScreenInfo());
2003     ServerMsgHandler handler;
2004     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2005     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
2006     int32_t result = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
2007     EXPECT_EQ(result, 0);
2008     int32_t msgId;
2009     pkt >> msgId;
2010     EXPECT_NO_FATAL_FAILURE(handler.OnDisplayInfo(sess, pkt));
2011 }
2012 
2013 /**
2014  * @tc.name: ServerMsgHandlerTest_OnDisplayInfo_03
2015  * @tc.desc: Test the function OnDisplayInfo_03
2016  * @tc.type: FUNC
2017  * @tc.require:
2018  */
2019 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_03, TestSize.Level1)
2020 {
2021     CALL_TEST_DEBUG;
2022     UserScreenInfo userScreenInfo;
2023     userScreenInfo.userId = 0;
2024     DisplayGroupInfo group;
2025     group.id = 1;
2026     group.name = "MainGroup";
2027     group.type = GroupType::GROUP_DEFAULT;
2028     group.mainDisplayId = 2;
2029     group.focusWindowId = 123;
2030     group.windowsInfo.push_back(WindowInfo());
2031     group.displaysInfo.push_back(DisplayInfo());
2032     DisplayInfo display;
2033     display.width = 1920;
2034     display.height = 1080;
2035     group.displaysInfo.push_back(display);
2036     WindowInfo window;
2037     window.groupId = 0;
2038     window.id = 123;
2039     for (int32_t i = 0; i <= 1000; i++) {
2040         group.windowsInfo.push_back(window);
2041     }
2042     userScreenInfo.screens.push_back(ScreenInfo());
2043     ServerMsgHandler handler;
2044     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2045     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
2046     int32_t result = InputMgrImpl.PackDisplayData(pkt, userScreenInfo);
2047     EXPECT_EQ(result, 0);
2048     int32_t msgId;
2049     pkt >> msgId;
2050     EXPECT_NO_FATAL_FAILURE(handler.OnDisplayInfo(sess, pkt));
2051 }
2052 
2053 /**
2054  * @tc.name: ServerMsgHandlerTest_OnTransferBinderClientSrv_001
2055  * @tc.desc: Test OnTransferBinderClientSrv
2056  * @tc.type: FUNC
2057  * @tc.require:
2058  */
2059 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnTransferBinderClientSrv_001, TestSize.Level1)
2060 {
2061     CALL_TEST_DEBUG;
2062     ServerMsgHandler handler;
2063     sptr<RemoteObjectTest> binderClientObject = new RemoteObjectTest(u"test");
2064     int32_t pid = 12345;
2065     EXPECT_EQ(RET_OK, handler.OnTransferBinderClientSrv(binderClientObject, pid));
2066 }
2067 
2068 /**
2069  * @tc.name: ServerMsgHandlerTest_OnTransferBinderClientSrv_002
2070  * @tc.desc: Test OnTransferBinderClientSrv
2071  * @tc.type: FUNC
2072  * @tc.require:
2073  */
2074 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnTransferBinderClientSrv_002, TestSize.Level1)
2075 {
2076     CALL_TEST_DEBUG;
2077     ServerMsgHandler handler;
2078     sptr<IRemoteObject> binderClientObject = nullptr;
2079     int32_t pid = 12345;
2080     EXPECT_EQ(RET_ERR, handler.OnTransferBinderClientSrv(binderClientObject, pid));
2081 }
2082 
2083 /**
2084  * @tc.name: ServerMsgHandlerTest_CloseInjectNotice_001
2085  * @tc.desc: Test CloseInjectNotice
2086  * @tc.type: FUNC
2087  * @tc.require:
2088  */
2089 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_CloseInjectNotice_001, TestSize.Level1)
2090 {
2091     CALL_TEST_DEBUG;
2092     ServerMsgHandler handler;
2093     handler.InitInjectNoticeSource();
2094     int32_t pid = 12345;
2095     bool result = handler.CloseInjectNotice(pid);
2096     ASSERT_FALSE(result);
2097 }
2098 
2099 /**
2100  * @tc.name: ServerMsgHandlerTest_InitInjectNoticeSource_002
2101  * @tc.desc: Test the function InitInjectNoticeSource
2102  * @tc.type: FUNC
2103  * @tc.require:
2104  */
2105 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_InitInjectNoticeSource_002, TestSize.Level1)
2106 {
2107     CALL_TEST_DEBUG;
2108     ServerMsgHandler handler;
2109     InjectNoticeManager manager;
2110     handler.injectNotice_ = nullptr;
2111     bool ret = handler.InitInjectNoticeSource();
2112     handler.injectNotice_->isStartSrv_ = true;
2113     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
2114     EXPECT_NE(nullptr, manager.connectionCallback_);
2115     auto connection = handler.injectNotice_->GetConnection();
2116     connection->isConnected_ = false;
2117     ret = handler.InitInjectNoticeSource();
2118     EXPECT_FALSE(ret);
2119 }
2120 
2121 /**
2122  * @tc.name: ServerMsgHandlerTest_InitInjectNoticeSource_003
2123  * @tc.desc: Test the function InitInjectNoticeSource
2124  * @tc.type: FUNC
2125  * @tc.require:
2126  */
2127 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_InitInjectNoticeSource_003, TestSize.Level1)
2128 {
2129     CALL_TEST_DEBUG;
2130     ServerMsgHandler handler;
2131     InjectNoticeManager manager;
2132     handler.injectNotice_ = nullptr;
2133     bool ret = handler.InitInjectNoticeSource();
2134     handler.injectNotice_->isStartSrv_ = true;
2135     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
2136     EXPECT_NE(nullptr, manager.connectionCallback_);
2137     auto connection = handler.injectNotice_->GetConnection();
2138     connection->isConnected_ = true;
2139     ret = handler.InitInjectNoticeSource();
2140     EXPECT_TRUE(ret);
2141 }
2142 
2143 /**
2144  * @tc.name: ServerMsgHandlerTest_AddInjectNotice_001
2145  * @tc.desc: Test the function AddInjectNotice
2146  * @tc.type: FUNC
2147  * @tc.require:
2148  */
2149 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AddInjectNotice_001, TestSize.Level1)
2150 {
2151     CALL_TEST_DEBUG;
2152     ServerMsgHandler handler;
2153     InjectNoticeManager manager;
2154     InjectNoticeInfo noticeInfo;
2155     handler.injectNotice_ = nullptr;
2156     bool ret = handler.InitInjectNoticeSource();
2157     handler.injectNotice_->isStartSrv_ = true;
2158     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
2159     EXPECT_NE(nullptr, manager.connectionCallback_);
2160     auto connection = handler.injectNotice_->GetConnection();
2161     connection->isConnected_ = false;
2162     ret = handler.AddInjectNotice(noticeInfo);
2163     EXPECT_FALSE(ret);
2164 }
2165 
2166 /**
2167  * @tc.name: ServerMsgHandlerTest_OnCancelInjection_002
2168  * @tc.desc: Test the function OnCancelInjection
2169  * @tc.type: FUNC
2170  * @tc.require:
2171  */
2172 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnCancelInjection_002, TestSize.Level1)
2173 {
2174     CALL_TEST_DEBUG;
2175     ServerMsgHandler handler;
2176     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
2177     int32_t ret = handler.OnCancelInjection();
2178     EXPECT_FALSE(ret != ERR_OK);
2179 }
2180 
2181 /**
2182  * @tc.name: ServerMsgHandlerTest_OnAuthorize_002
2183  * @tc.desc: Test the function OnAuthorize
2184  * @tc.type: FUNC
2185  * @tc.require:
2186  */
2187 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAuthorize_002, TestSize.Level1)
2188 {
2189     CALL_TEST_DEBUG;
2190     ServerMsgHandler handler;
2191     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
2192     int32_t result = handler.OnAuthorize(false);
2193     EXPECT_EQ(result, ERR_OK);
2194 }
2195 
2196 /**
2197  * @tc.name: ServerMsgHandlerTest_QueryAuthorizedStatus
2198  * @tc.desc: Test the function QueryAuthorizedStatus
2199  * @tc.type: FUNC
2200  * @tc.require:
2201  */
2202 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_QueryAuthorizedStatus, TestSize.Level1)
2203 {
2204     CALL_TEST_DEBUG;
2205     ServerMsgHandler handler;
2206     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
2207     int32_t callingPid = 1;
2208     int32_t status = 1;
2209     int32_t result = handler.QueryAuthorizedStatus(callingPid, status);
2210     EXPECT_EQ(result, ERR_OK);
2211 }
2212 
2213 /**
2214  * @tc.name: ServerMsgHandlerTest_GetRequestInjectionCallbackReqId
2215  * @tc.desc: Test the function GetRequestInjectionCallbackReqId
2216  * @tc.type: FUNC
2217  * @tc.require:
2218  */
2219 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_GetRequestInjectionCallbackReqId, TestSize.Level1)
2220 {
2221     CALL_TEST_DEBUG;
2222     ServerMsgHandler handler;
2223     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
2224     int32_t result = handler.GetRequestInjectionCallbackReqId();
2225     EXPECT_EQ(result, 1);
2226 }
2227 
2228 /**
2229  * @tc.name: ServerMsgHandlerTest_CheckForRequestInjectionFrequentAccess
2230  * @tc.desc: Test the function CheckForRequestInjectionFrequentAccess
2231  * @tc.type: FUNC
2232  * @tc.require:
2233  */
2234 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_CheckForRequestInjectionFrequentAccess, TestSize.Level1)
2235 {
2236     CALL_TEST_DEBUG;
2237     ServerMsgHandler handler;
2238     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
2239     int32_t callingPid = 1;
2240     int64_t interval = 1;
2241     int32_t result = handler.CheckForRequestInjectionFrequentAccess(callingPid, interval);
2242     EXPECT_EQ(result, ERR_OK);
2243 }
2244 
2245 /**
2246  * @tc.name: ServerMsgHandlerTest_RequestInjection_001
2247  * @tc.desc: Test the function RequestInjection
2248  * @tc.type: FUNC
2249  * @tc.require:
2250  */
2251 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_RequestInjection_001, TestSize.Level1)
2252 {
2253     CALL_TEST_DEBUG;
2254     ServerMsgHandler handler;
2255     int32_t callingPid = 100000;
2256     int32_t status = 0;
2257     int32_t reqId = 0;
2258     auto isPC = handler.IsPC();
2259     int32_t result = ERR_OK;
2260     if (!isPC) {
2261         result = handler.RequestInjection(callingPid, status, reqId);
2262         EXPECT_EQ(result, ERROR_DEVICE_NOT_SUPPORTED);
2263         return;
2264     }
2265     handler.OnCancelInjection(callingPid);
2266     result = handler.OnAuthorize(false);
2267     EXPECT_EQ(result, ERR_OK);
2268     result = handler.RequestInjection(callingPid, status, reqId);
2269     EXPECT_EQ(result, ERR_OK);
2270     result = handler.OnAuthorize(true);
2271     EXPECT_EQ(result, ERR_OK);
2272     result = handler.OnAuthorize(false);
2273     EXPECT_EQ(result, ERR_OK);
2274 }
2275 
2276 /**
2277  * @tc.name: ServerMsgHandlerTest_OnMoveMouse_002
2278  * @tc.desc: Test the function OnMoveMouse
2279  * @tc.type: FUNC
2280  * @tc.require:
2281  */
2282 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMoveMouse_002, TestSize.Level1)
2283 {
2284     CALL_TEST_DEBUG;
2285     ServerMsgHandler handler;
2286     int32_t offsetX = 0;
2287     int32_t offsetY = 0;
2288     std::shared_ptr<PointerEvent> pointerEvent_ = PointerEvent::Create();
2289     ASSERT_NE(pointerEvent_, nullptr);
2290     int32_t ret = handler.OnMoveMouse(offsetX, offsetY);
2291     EXPECT_EQ(ret, RET_OK);
2292 }
2293 
2294 /**
2295  * @tc.name: ServerMsgHandlerTest_OnAuthorize_004
2296  * @tc.desc: Test the function OnAuthorize
2297  * @tc.type: FUNC
2298  * @tc.require:
2299  */
2300 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAuthorize_004, TestSize.Level1)
2301 {
2302     CALL_TEST_DEBUG;
2303     ServerMsgHandler handler;
2304     handler.CurrentPID_ = 12345;
2305     handler.authorizationCollection_[12345] = AuthorizationStatus::UNAUTHORIZED;
2306     int32_t result = handler.OnAuthorize(false);
2307     EXPECT_EQ(result, ERR_OK);
2308     EXPECT_EQ(handler.authorizationCollection_[12345], AuthorizationStatus::UNAUTHORIZED);
2309 }
2310 
2311 /**
2312  * @tc.name: ServerMsgHandlerTest_OnMsgHandler_001
2313  * @tc.desc: Test if (callback == nullptr) branch success
2314  * @tc.type: FUNC
2315  * @tc.require:
2316  */
2317 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMsgHandler_001, TestSize.Level1)
2318 {
2319     CALL_TEST_DEBUG;
2320     ServerMsgHandler msgHandler;
2321     MsgHandler<int, int> handler;
2322     handler.callbacks_[0] = 1;
2323     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2324     MmiMessageId idMsg = MmiMessageId::INVALID;
2325     NetPacket pkt(idMsg);
2326     EXPECT_NO_FATAL_FAILURE(msgHandler.OnMsgHandler(sess, pkt));
2327 }
2328 
2329 /**
2330 @tc.name: ServerMsgHandlerTest_OnMsgHandler_002
2331 @tc.desc: Test if callback branch success
2332 @tc.type: FUNC
2333 @tc.require:
2334 */
2335 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMsgHandler_002, TestSize.Level1)
2336 {
2337     OHOS::MMI::ServerMsgHandler handler;
2338     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2339     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
__anon58fdef9f0202(SessionPtr sess, NetPacket &pkt) 2340     ServerMsgFun msgFunc = [](SessionPtr sess, NetPacket &pkt) {
2341         return 0;
2342     };
2343     ServerMsgHandler::MsgCallback msgCallback = {MmiMessageId::DISPLAY_INFO, msgFunc};
2344     handler.RegistrationEvent(msgCallback);
2345     EXPECT_NO_FATAL_FAILURE(handler.OnMsgHandler(sess, pkt));
2346 }
2347 
2348 /**
2349 @tc.name: ServerMsgHandlerTest_OnMsgHandler_003
2350 @tc.desc: Test if callback branch failed
2351 @tc.type: FUNC
2352 @tc.require:
2353 */
2354 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMsgHandler_003, TestSize.Level1)
2355 {
2356     OHOS::MMI::ServerMsgHandler handler;
2357     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2358     NetPacket pkt(MmiMessageId::ADD_INPUT_DEVICE_LISTENER);
__anon58fdef9f0302(SessionPtr sess, NetPacket &pkt) 2359     ServerMsgFun msgFunc = [](SessionPtr sess, NetPacket &pkt) {
2360         return -1;
2361     };
2362     ServerMsgHandler::MsgCallback msgCallback = {MmiMessageId::DISPLAY_INFO, msgFunc};
2363     handler.RegistrationEvent(msgCallback);
2364     EXPECT_NO_FATAL_FAILURE(handler.OnMsgHandler(sess, pkt));
2365 }
2366 
2367 /**
2368  * @tc.name: ServerMsgHandlerTest_OnSetFunctionKeyState_002
2369  * @tc.desc: Test the function OnSetFunctionKeyState
2370  * @tc.type: FUNC
2371  * @tc.require:
2372  */
2373 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSetFunctionKeyState_002, TestSize.Level1)
2374 {
2375     CALL_TEST_DEBUG;
2376     ServerMsgHandler handler;
2377     int32_t funcKey = 1;
2378     int32_t pid = 15;
2379     bool enable = true;
2380     INPUT_DEV_MGR->IsKeyboardDevice(nullptr);
2381     EXPECT_EQ(handler.OnSetFunctionKeyState(pid, funcKey, enable), ERR_NON_INPUT_APPLICATION);
2382 }
2383 
2384 /**
2385  * @tc.name: ServerMsgHandlerTest_IsNavigationWindowInjectEvent
2386  * @tc.desc: Test the function IsNavigationWindowInjectEvent
2387  * @tc.type: FUNC
2388  * @tc.require:
2389  */
2390 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_IsNavigationWindowInjectEvent, TestSize.Level1)
2391 {
2392     CALL_TEST_DEBUG;
2393     ServerMsgHandler handler;
2394     auto pointerEvent = PointerEvent::Create();
2395     pointerEvent->zOrder_ = 1;
2396     bool ret = false;
2397     ret = handler.IsNavigationWindowInjectEvent(pointerEvent);
2398     ASSERT_TRUE(ret);
2399 }
2400 
2401 /**
2402  * @tc.name: ServerMsgHandlerTest_OnRemoveGestureMonitor
2403  * @tc.desc: Test the function OnRemoveGestureMonitor
2404  * @tc.type: FUNC
2405  * @tc.require:
2406  */
2407 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveGestureMonitor, TestSize.Level1)
2408 {
2409     CALL_TEST_DEBUG;
2410     ServerMsgHandler handler;
2411     auto udsSe = std::make_shared<UDSSession>("mytest", 2, 3, 4, 5);
2412     InputHandlerType inputHandlerType = InputHandlerType::MONITOR;
2413     uint32_t eventType = HANDLE_EVENT_TYPE_KEY;
2414     uint32_t gestureType = TOUCH_GESTURE_TYPE_PINCH;
2415     uint32_t fingers = 3;
2416     InputHandler->eventMonitorHandler_ = std::make_shared<EventMonitorHandler>();
2417     int32_t ret = handler.OnRemoveGestureMonitor(udsSe, inputHandlerType, eventType, gestureType, fingers);
2418     ASSERT_NE(ret, RET_OK);
2419 }
2420 
2421 /**
2422  * @tc.name: ServerMsgHandlerTest_OnAddGestureMonitor
2423  * @tc.desc: Test the function OnAddGestureMonitor
2424  * @tc.type: FUNC
2425  * @tc.require:
2426  */
2427 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAddGestureMonitor, TestSize.Level1)
2428 {
2429     CALL_TEST_DEBUG;
2430     ServerMsgHandler handler;
2431     auto udsSe = std::make_shared<UDSSession>("mytest", 2, 3, 4, 5);
2432     InputHandlerType handlerType = InputHandlerType::MONITOR;
2433     uint32_t eventType = HANDLE_EVENT_TYPE_KEY;
2434     uint32_t gestureType = TOUCH_GESTURE_TYPE_PINCH;
2435     uint32_t fingers = 3;
2436     InputHandler->eventMonitorHandler_ = std::make_shared<EventMonitorHandler>();
2437     int32_t ret = handler.OnAddGestureMonitor(udsSe, handlerType, eventType, gestureType, fingers);
2438     ASSERT_NE(ret, RET_OK);
2439 
2440     handlerType = InputHandlerType::NONE;
2441     ret = handler.OnAddGestureMonitor(udsSe, handlerType, eventType, gestureType, fingers);
2442     ASSERT_EQ(ret, RET_OK);
2443 }
2444 
2445 /**
2446 @tc.name: ServerMsgHandlerTest_OnDisplayInfo_001
2447 @tc.desc: Test the function OnDisplayInfo
2448 @tc.type: FUNC
2449 @tc.require:
2450 */
2451 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_001, TestSize.Level1)
2452 {
2453     CALL_TEST_DEBUG;
2454     ServerMsgHandler handler;
2455     int32_t num = 1;
2456     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2457     sess->SetTokenType(TOKEN_HAP);
2458     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
2459     OLD::DisplayGroupInfo displayGroupInfo {
2460         .focusWindowId = 10,
2461         .currentUserId = 20,
2462     };
2463     pkt << displayGroupInfo.focusWindowId << displayGroupInfo.currentUserId << num;
2464     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_WRITE;
2465     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_ERR);
2466 }
2467 
2468 /**
2469 @tc.name: ServerMsgHandlerTest_OnDisplayInfo_002
2470 @tc.desc: Test the function OnDisplayInfo
2471 @tc.type: FUNC
2472 @tc.require:
2473 */
2474 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_002, TestSize.Level1)
2475 {
2476     CALL_TEST_DEBUG;
2477     ServerMsgHandler handler;
2478     int32_t num = 1;
2479     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2480     sess->SetTokenType(TOKEN_NATIVE);
2481     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
2482     OLD::DisplayGroupInfo displayGroupInfo {
2483         .focusWindowId = 10,
2484         .currentUserId = 20,
2485     };
2486     pkt << displayGroupInfo.focusWindowId << displayGroupInfo.currentUserId << num;
2487     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
2488     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_ERR);
2489 }
2490 
2491 /**
2492 @tc.name: ServerMsgHandlerTest_OnDisplayInfo_003
2493 @tc.desc: Test the function OnDisplayInfo
2494 @tc.type: FUNC
2495 @tc.require:
2496 */
2497 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_003, TestSize.Level1)
2498 {
2499     CALL_TEST_DEBUG;
2500     ServerMsgHandler handler;
2501     int32_t num = 1;
2502     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2503     sess->SetTokenType(TOKEN_SYSTEM_HAP);
2504     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
2505     OLD::DisplayGroupInfo displayGroupInfo {
2506         .focusWindowId = 10,
2507         .currentUserId = 20,
2508     };
2509     pkt << displayGroupInfo.focusWindowId << displayGroupInfo.currentUserId << num;
2510     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
2511     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_ERR);
2512 }
2513 
2514 /**
2515 @tc.name: ServerMsgHandlerTest_OnDisplayInfo_004
2516 @tc.desc: Test the function OnDisplayInfo
2517 @tc.type: FUNC
2518 @tc.require:
2519 */
2520 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_004, TestSize.Level1)
2521 {
2522     CALL_TEST_DEBUG;
2523     ServerMsgHandler handler;
2524     int32_t num = 1;
2525     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2526     sess->SetTokenType(TOKEN_SHELL);
2527     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
2528     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
2529     OLD::DisplayGroupInfo displayGroupInfo {
2530         .focusWindowId = 10,
2531         .currentUserId = 20,
2532     };
2533     pkt << displayGroupInfo.focusWindowId << displayGroupInfo.currentUserId << num;
2534     Rect rec = {1, 1, 1, 1};
2535     std::vector recVec = {rec, rec};
2536     std::vector<int32_t> pChangeAreas = {1, 1, 1};
2537     std::vector transform = {1.0, 1.0, 1.0};
2538     pkt << 1 << 1 << 1 << rec << recVec << recVec << 1 << 1 << WINDOW_UPDATE_ACTION::ADD << 1 << 1.0 << pChangeAreas
2539         << transform << 1 << 1 << 1 << 1 << false;
2540     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_ERR);
2541 }
2542 
2543 /**
2544  * @tc.name: ServerMsgHandlerTest_DealGesturePointers
2545  * @tc.desc: Test the function DealGesturePointers
2546  * @tc.type: FUNC
2547  * @tc.require:
2548  */
2549 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_DealGesturePointers, TestSize.Level1)
2550 {
2551     CALL_TEST_DEBUG;
2552     ServerMsgHandler handler;
2553     auto pointerEvent = PointerEvent::Create();
2554     ASSERT_NE(pointerEvent, nullptr);
2555     pointerEvent->SetId(1);
2556     pointerEvent->SetPointerId(10001);
2557     auto touchEvent = PointerEvent::Create();
2558     ASSERT_NE(touchEvent, nullptr);
2559     PointerEvent::PointerItem item;
2560     item.SetPointerId(10002);
2561     item.SetOriginPointerId(10002);
2562     item.SetPressed(true);
2563     touchEvent->AddPointerItem(item);
2564     ASSERT_NO_FATAL_FAILURE(handler.DealGesturePointers(pointerEvent));
2565 }
2566 
2567 /**
2568 @tc.name: ServerMsgHandlerTest_DealGesturePointers_001
2569 @tc.desc: Test the function DealGesturePointers
2570 @tc.type: FUNC
2571 @tc.require:
2572 */
2573 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_DealGesturePointers_001, TestSize.Level1)
2574 {
2575     CALL_TEST_DEBUG;
2576     ServerMsgHandler handler;
2577     auto pointerEvent = PointerEvent::Create();
2578     pointerEvent->SetId(1);
2579     pointerEvent->SetPointerId(10001);
2580     ASSERT_NO_FATAL_FAILURE(handler.DealGesturePointers(pointerEvent));
2581 }
2582 
2583 /**
2584 @tc.name: ServerMsgHandlerTest_ScreenFactor_001
2585 @tc.desc: Test the function ScreenFactor
2586 @tc.type: FUNC
2587 @tc.require:
2588 */
2589 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ScreenFactor_001, TestSize.Level1)
2590 {
2591     CALL_TEST_DEBUG;
2592     ServerMsgHandler handler;
2593     int32_t diagonalInch = 0;
2594     EXPECT_EQ(handler.ScreenFactor(diagonalInch), FACTOR_0);
2595     diagonalInch = 5;
2596     EXPECT_EQ(handler.ScreenFactor(diagonalInch), FACTOR_8);
2597     diagonalInch = 10;
2598     EXPECT_EQ(handler.ScreenFactor(diagonalInch), FACTOR_18);
2599     diagonalInch = 20;
2600     EXPECT_EQ(handler.ScreenFactor(diagonalInch), FACTOR_27);
2601     diagonalInch = 30;
2602     EXPECT_EQ(handler.ScreenFactor(diagonalInch), FACTOR_55);
2603     diagonalInch = 55;
2604     EXPECT_EQ(handler.ScreenFactor(diagonalInch), FACTOR_MAX);
2605 }
2606 
2607 /**
2608 @tc.name: ServerMsgHandlerTest_UpdateTouchEvent_001
2609 @tc.desc: Test the function UpdateTouchEvent
2610 @tc.type: FUNC
2611 @tc.require:
2612 */
2613 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdateTouchEvent_001, TestSize.Level1)
2614 {
2615     CALL_TEST_DEBUG;
2616     ServerMsgHandler handler;
2617     auto pointerEvent = PointerEvent::Create();
2618     pointerEvent->SetId(1);
2619     pointerEvent->SetPointerId(10001);
2620     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
2621     pointerEvent->SetTargetWindowId(10);
2622     PointerEvent::PointerItem item;
2623     item.SetPointerId(10001);
2624     pointerEvent->AddPointerItem(item);
2625     int32_t action = PointerEvent::POINTER_ACTION_HOVER_ENTER;
2626     int32_t targetWindowId = 10;
2627     bool result = handler.UpdateTouchEvent(pointerEvent, action, targetWindowId);
2628     EXPECT_TRUE(result);
2629 }
2630 
2631 /**
2632 @tc.name: ServerMsgHandlerTest_UpdateTouchEvent_002
2633 @tc.desc: Test the function UpdateTouchEvent
2634 @tc.type: FUNC
2635 @tc.require:
2636 */
2637 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdateTouchEvent_002, TestSize.Level1)
2638 {
2639     CALL_TEST_DEBUG;
2640     ServerMsgHandler handler;
2641     auto pointerEvent = PointerEvent::Create();
2642     pointerEvent->SetId(1);
2643     pointerEvent->SetPointerId(10001);
2644     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
2645     pointerEvent->SetTargetWindowId(10);
2646     PointerEvent::PointerItem item;
2647     item.SetPointerId(10001);
2648     pointerEvent->AddPointerItem(item);
2649     int32_t action = PointerEvent::POINTER_ACTION_DOWN;
2650     int32_t targetWindowId = 10;
2651     bool result = handler.UpdateTouchEvent(pointerEvent, action, targetWindowId);
2652     EXPECT_TRUE(result);
2653 }
2654 
2655 /**
2656 @tc.name: ServerMsgHandlerTest_UpdateTouchEvent_003
2657 @tc.desc: Test the function UpdateTouchEvent
2658 @tc.type: FUNC
2659 @tc.require:
2660 */
2661 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdateTouchEvent_003, TestSize.Level1)
2662 {
2663     CALL_TEST_DEBUG;
2664     ServerMsgHandler handler;
2665     auto pointerEvent = PointerEvent::Create();
2666     pointerEvent->SetId(1);
2667     pointerEvent->SetPointerId(10001);
2668     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
2669     pointerEvent->SetTargetWindowId(-1);
2670     PointerEvent::PointerItem item;
2671     item.SetPointerId(10001);
2672     pointerEvent->AddPointerItem(item);
2673     int32_t action = PointerEvent::POINTER_ACTION_CANCEL;
2674     int32_t targetWindowId = -1;
2675     bool result = handler.UpdateTouchEvent(pointerEvent, action, targetWindowId);
2676     EXPECT_TRUE(result);
2677 }
2678 
2679 /**
2680 @tc.name: ServerMsgHandlerTest_UpdateTouchEvent_004
2681 @tc.desc: Test the function UpdateTouchEvent
2682 @tc.type: FUNC
2683 @tc.require:
2684 */
2685 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdateTouchEvent_004, TestSize.Level1)
2686 {
2687     CALL_TEST_DEBUG;
2688     ServerMsgHandler handler;
2689     auto pointerEvent = PointerEvent::Create();
2690     pointerEvent->SetId(1);
2691     pointerEvent->SetPointerId(10001);
2692     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL);
2693     pointerEvent->SetTargetWindowId(10);
2694     PointerEvent::PointerItem item;
2695     item.SetPointerId(10001);
2696     pointerEvent->AddPointerItem(item);
2697     int32_t action = PointerEvent::POINTER_ACTION_CANCEL;
2698     int32_t targetWindowId = 10;
2699     bool result = handler.UpdateTouchEvent(pointerEvent, action, targetWindowId);
2700     EXPECT_TRUE(result);
2701     pointerEvent->RemoveAllPointerItems();
2702     EXPECT_FALSE(handler.UpdateTouchEvent(pointerEvent, action, targetWindowId));
2703 }
2704 
2705 /**
2706 @tc.name: ServerMsgHandlerTest_SubscribeKeyMonitor_001
2707 @tc.desc: Test the function SubscribeKeyMonitor
2708 @tc.type: FUNC
2709 @tc.require:
2710 */
2711 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SubscribeKeyMonitor_001, TestSize.Level1)
2712 {
2713     CALL_TEST_DEBUG;
2714     ServerMsgHandler serverMsgHandler;
2715     int32_t session = 1;
2716     KeyMonitorOption keyOption;
2717     ASSERT_NO_FATAL_FAILURE(serverMsgHandler.SubscribeKeyMonitor(session, keyOption));
2718 }
2719 
2720 /**
2721 @tc.name: ServerMsgHandlerTest_UnsubscribeKeyMonitor
2722 @tc.desc: Test the function UnsubscribeKeyMonitor
2723 @tc.type: FUNC
2724 @tc.require:
2725 */
2726 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UnsubscribeKeyMonitor_001, TestSize.Level1)
2727 {
2728     CALL_TEST_DEBUG;
2729     ServerMsgHandler serverMsgHandler;
2730     int32_t session = 1;
2731     KeyMonitorOption keyOption;
2732     ASSERT_NO_FATAL_FAILURE(serverMsgHandler.UnsubscribeKeyMonitor(session, keyOption));
2733 }
2734 
2735 /**
2736  * @tc.name: ServerMsgHandlerTest_OnAuthorize_005
2737  * @tc.desc: Test the function OnAuthorize
2738  * @tc.type: FUNC
2739  * @tc.require:
2740  */
2741 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAuthorize_005, TestSize.Level1)
2742 {
2743     CALL_TEST_DEBUG;
2744     ServerMsgHandler handler;
2745     handler.CurrentPID_ = 12345;
2746     handler.authorizationCollection_[12345] = AuthorizationStatus::UNAUTHORIZED;
2747     int32_t result = handler.OnAuthorize(true);
2748     EXPECT_EQ(result, ERR_OK);
2749 }
2750 
2751 /**
2752  * @tc.name: ServerMsgHandlerTest_OnAuthorize_006
2753  * @tc.desc: Test the function OnAuthorize
2754  * @tc.type: FUNC
2755  * @tc.require:
2756  */
2757 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnAuthorize_006, TestSize.Level1)
2758 {
2759     CALL_TEST_DEBUG;
2760     ServerMsgHandler handler;
2761     handler.CurrentPID_ = 12345;
2762     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_SELECTION_AUTHORIZE;
2763     int32_t result = handler.OnAuthorize(false);
2764     EXPECT_EQ(result, ERR_OK);
2765 }
2766 
2767 /**
2768  * @tc.name: ServerMsgHandlerTest_OnCancelInjection_005
2769  * @tc.desc: Test the function OnCancelInjection
2770  * @tc.type: FUNC
2771  * @tc.require:
2772  */
2773 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnCancelInjection_005, TestSize.Level1)
2774 {
2775     CALL_TEST_DEBUG;
2776     ServerMsgHandler handler;
2777     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_AUTHORIZE;
2778     int callPid = 12345;
2779     int32_t ret = handler.OnCancelInjection(callPid);
2780     EXPECT_EQ(ret, COMMON_PERMISSION_CHECK_ERROR);
2781 }
2782 
2783 /**
2784  * @tc.name: ServerMsgHandlerTest_OnCancelInjection_006
2785  * @tc.desc: Test the function OnCancelInjection
2786  * @tc.type: FUNC
2787  * @tc.require:
2788  */
2789 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnCancelInjection_006, TestSize.Level1)
2790 {
2791     CALL_TEST_DEBUG;
2792     ServerMsgHandler handler;
2793     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_AUTHORIZE;
2794     int callPid = 0;
2795     ASSERT_NO_FATAL_FAILURE(handler.OnCancelInjection(callPid));
2796     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_SELECTION_AUTHORIZE;
2797     ASSERT_NO_FATAL_FAILURE(handler.OnCancelInjection(callPid));
2798 }
2799 
2800 /**
2801 @tc.name: ServerMsgHandlerTest_OnMsgHandler04
2802 @tc.desc: Test if callback branch failed
2803 @tc.type: FUNC
2804 @tc.require: nhj
2805 */
2806 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnMsgHandler04, TestSize.Level1)
2807 {
2808     OHOS::MMI::ServerMsgHandler handler;
2809     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
2810     NetPacket pkt(MmiMessageId::ADD_INPUT_DEVICE_LISTENER);
__anon58fdef9f0402(SessionPtr sess, NetPacket &pkt) 2811     ServerMsgFun msgFunc = [](SessionPtr sess, NetPacket &pkt) {
2812         return -2;
2813     };
2814     ServerMsgHandler::MsgCallback msgCallback = {MmiMessageId::DISPLAY_INFO, msgFunc};
2815     handler.RegistrationEvent(msgCallback);
2816     EXPECT_NO_FATAL_FAILURE(handler.OnMsgHandler(sess, pkt));
2817 }
2818 
2819 /**
2820  * @tc.name: ServerMsgHandlerTest_OnGetFunctionKeyState
2821  * @tc.desc: Test the function OnGetFunctionKeyState
2822  * @tc.type: FUNC
2823  * @tc.require:
2824  */
2825 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnGetFunctionKeyState, TestSize.Level1)
2826 {
2827     CALL_TEST_DEBUG;
2828     ServerMsgHandler handler;
2829     int32_t funcKey = MOUSE_ICON_SIZE;
2830     bool state = true;
2831     auto ret = handler.OnGetFunctionKeyState(funcKey, state);
2832     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
2833 }
2834 
2835 /**
2836  * @tc.name: ServerMsgHandlerTest_OnSetFunctionKeyState
2837  * @tc.desc: Test the function OnSetFunctionKeyState
2838  * @tc.type: FUNC
2839  * @tc.require:
2840  */
2841 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSetFunctionKeyState, TestSize.Level1)
2842 {
2843     CALL_TEST_DEBUG;
2844     ServerMsgHandler handler;
2845     int32_t funcKey = NUM_LOCK_FUNCTION_KEY;
2846     int32_t pid = 15;
2847     bool enable = false;
2848     auto ret = handler.OnSetFunctionKeyState(pid, funcKey, enable);
2849     EXPECT_EQ(ret, ERR_NON_INPUT_APPLICATION);
2850 }
2851 
2852 /**
2853  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEvent_005
2854  * @tc.desc: Test if (iter->second == AuthorizationStatus::UNAUTHORIZED) branch failed
2855  * @tc.type: FUNC
2856  * @tc.require:
2857  */
2858 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEvent_005, TestSize.Level1)
2859 {
2860     CALL_TEST_DEBUG;
2861     ServerMsgHandler msgHandler;
2862     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2863     ASSERT_NE(pointerEvent, nullptr);
2864     int32_t pid = 0;
2865     bool isNativeInject = true;
2866     pointerEvent->SetId(1);
2867     pointerEvent->eventType_ = 1;
2868     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
2869     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_UNKNOWN);
2870     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNKNOWN));
2871     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
2872     int32_t result =
2873         msgHandler.OnInjectPointerEvent(pointerEvent, pid, isNativeInject, false, PointerEvent::DISPLAY_COORDINATE);
2874     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
2875 }
2876 
2877 /**
2878  * @tc.name: ServerMsgHandlerTest_DealGesturePointers
2879  * @tc.desc: Test the function DealGesturePointers
2880  * @tc.type: FUNC
2881  * @tc.require:
2882  */
2883 HWTEST_F(ServerMsgHandlerTest, DealGesturePointers001, TestSize.Level1)
2884 {
2885     CALL_TEST_DEBUG;
2886     ServerMsgHandler handler;
2887     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2888     ASSERT_NE(pointerEvent, nullptr);
2889     pointerEvent->SetId(1);
2890     pointerEvent->eventType_ = 1;
2891     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
2892     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2893     handler.nativeTargetWindowIds_.insert(std::make_pair(pointerEvent->GetPointerId(), 10));
2894     auto touchEvent = PointerEvent::Create();
2895     ASSERT_NE(touchEvent, nullptr);
2896     PointerEvent::PointerItem item;
2897     item.SetPointerId(10002);
2898     item.SetOriginPointerId(10002);
2899     item.SetPressed(true);
2900     touchEvent->AddPointerItem(item);
2901     ASSERT_NO_FATAL_FAILURE(handler.DealGesturePointers(pointerEvent));
2902 }
2903 
2904 /**
2905  * @tc.name: ServerMsgHandlerTest_ScreenFactor
2906  * @tc.desc: Test the function ScreenFactor
2907  * @tc.type: FUNC
2908  * @tc.require:
2909  */
2910 HWTEST_F(ServerMsgHandlerTest, ScreenFactor, TestSize.Level1)
2911 {
2912     CALL_TEST_DEBUG;
2913     ServerMsgHandler handler;
2914     int32_t diagonalInch = -1;
2915     auto ret = handler.ScreenFactor(diagonalInch);
2916     EXPECT_EQ(ret, FACTOR_0);
2917     diagonalInch = 1;
2918     ret = handler.ScreenFactor(diagonalInch);
2919     EXPECT_EQ(ret, FACTOR_8);
2920     diagonalInch = 10;
2921     ret = handler.ScreenFactor(diagonalInch);
2922     EXPECT_EQ(ret, FACTOR_18);
2923     diagonalInch = 20;
2924     ret = handler.ScreenFactor(diagonalInch);
2925     EXPECT_EQ(ret, FACTOR_27);
2926     diagonalInch = 40;
2927     ret = handler.ScreenFactor(diagonalInch);
2928     EXPECT_EQ(ret, FACTOR_55);
2929     diagonalInch = 100;
2930     ret = handler.ScreenFactor(diagonalInch);
2931     EXPECT_EQ(ret, FACTOR_MAX);
2932 }
2933 
2934 /**
2935  * @tc.name: ServerMsgHandlerTest_OnInjectTouchPadEventExt
2936  * @tc.desc: Test OnInjectTouchPadEventExt
2937  * @tc.type: FUNC
2938  * @tc.require:
2939  */
2940 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectTouchPadEventExt, TestSize.Level1)
2941 {
2942     CALL_TEST_DEBUG;
2943     ServerMsgHandler msgHandler;
2944     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
2945     ASSERT_NE(pointerEvent, nullptr);
2946     int32_t pid = 0;
2947     bool isNativeInject = true;
2948     OHOS::MMI::TouchpadCDG touchpadCDG;
2949     touchpadCDG.frequency = 1;
2950     pointerEvent->SetId(1);
2951     pointerEvent->eventType_ = 1;
2952     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
2953     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
2954     msgHandler.authorizationCollection_.insert(std::make_pair(pid, AuthorizationStatus::UNKNOWN));
2955     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
2956     int32_t result = msgHandler.OnInjectTouchPadEventExt(pointerEvent, touchpadCDG, false);
2957     EXPECT_EQ(result, ERROR_NULL_POINTER);
2958 }
2959 
2960 /**
2961  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_006
2962  * @tc.desc: Test the function AccelerateMotion
2963  * @tc.type: FUNC
2964  * @tc.require:
2965  */
2966 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_006, TestSize.Level1)
2967 {
2968     CALL_TEST_DEBUG;
2969     ServerMsgHandler handler;
2970     auto pointerEvent = PointerEvent::Create();
2971     ASSERT_NE(pointerEvent, nullptr);
2972     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
2973     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2974     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
2975     int32_t pointerId = 1;
2976     PointerEvent::PointerItem item;
2977     item.SetPointerId(pointerId);
2978     pointerEvent->AddPointerItem(item);
2979     pointerEvent->SetPointerId(0);
2980     int32_t ret = handler.AccelerateMotion(pointerEvent);
2981     EXPECT_EQ(ret, RET_OK);
2982 }
2983 
2984 /**
2985  * @tc.name: ServerMsgHandlerTest_AccelerateMotion_008
2986  * @tc.desc: Test the function AccelerateMotion
2987  * @tc.type: FUNC
2988  * @tc.require:
2989  */
2990 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotion_008, TestSize.Level1)
2991 {
2992     CALL_TEST_DEBUG;
2993     ServerMsgHandler handler;
2994     auto pointerEvent = PointerEvent::Create();
2995     ASSERT_NE(pointerEvent, nullptr);
2996     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER);
2997     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
2998     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
2999     int32_t pointerId = 1;
3000     PointerEvent::PointerItem item;
3001     item.SetPointerId(pointerId);
3002     item.SetRawDx(1);
3003     item.SetRawDy(1);
3004     pointerEvent->AddPointerItem(item);
3005     pointerEvent->SetPointerId(1);
3006     int32_t ret = handler.AccelerateMotion(pointerEvent);
3007     EXPECT_EQ(ret, RET_OK);
3008 }
3009 
3010 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD)
3011 /**
3012 @tc.name: ServerMsgHandlerTest_AddInputEventFilter
3013 @tc.desc: Test the function AddInputEventFilter
3014 @tc.type: FUNC
3015 @tc.require:
3016 */
3017 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AddInputEventFilter, TestSize.Level1)
3018 {
3019     CALL_TEST_DEBUG;
3020     ServerMsgHandler handler;
3021     int32_t filterId = 1;
3022     int32_t priority = 1;
3023     uint32_t deviceTags = 1;
3024     int32_t clientPid = 1;
3025     EXPECT_EQ(handler.AddInputEventFilter({}, filterId, priority, deviceTags, clientPid), ERROR_NULL_POINTER);
3026     EXPECT_EQ(handler.RemoveInputEventFilter(clientPid, filterId), ERROR_NULL_POINTER);
3027 }
3028 #endif
3029 
3030 /**
3031  * @tc.name: ServerMsgHandlerTest_AccelerateMotionTouchpad
3032  * @tc.desc: Test the function AccelerateMotionTouchpad
3033  * @tc.type: FUNC
3034  * @tc.require:
3035  */
3036 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_AccelerateMotionTouchpad, TestSize.Level1)
3037 {
3038     CALL_TEST_DEBUG;
3039     ServerMsgHandler handler;
3040     auto pointerEvent = PointerEvent::Create();
3041     ASSERT_NE(pointerEvent, nullptr);
3042     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
3043     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
3044     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
3045     int32_t pointerId = 1;
3046     PointerEvent::PointerItem item;
3047     item.SetPointerId(pointerId);
3048     pointerEvent->AddPointerItem(item);
3049     pointerEvent->SetPointerId(0);
3050     DisplayInfo displayInfo;
3051     displayInfo.id = -1;
3052     OHOS::MMI::TouchpadCDG touchpadCDG;
3053     touchpadCDG.frequency = 1;
3054     int32_t ret = handler.AccelerateMotionTouchpad(pointerEvent, touchpadCDG);
3055     EXPECT_EQ(ret, RET_ERR);
3056 }
3057 
3058 /**
3059 @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_008
3060 @tc.desc: Test the function SaveTargetWindowId
3061 @tc.type: FUNC
3062 @tc.require:
3063 */
3064 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_008, TestSize.Level1)
3065 {
3066     CALL_TEST_DEBUG;
3067     ServerMsgHandler handler;
3068     auto pointerEvent = PointerEvent::Create();
3069     ASSERT_NE(pointerEvent, nullptr);
3070     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3071     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
3072     int32_t pointerId = 1;
3073     PointerEvent::PointerItem item;
3074     item.SetPointerId(pointerId);
3075     pointerEvent->AddPointerItem(item);
3076     pointerEvent->SetPointerId(0);
3077     int32_t ret = handler.SaveTargetWindowId(pointerEvent, true);
3078     EXPECT_EQ(ret, RET_OK);
3079     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_EXIT);
3080     ret = handler.SaveTargetWindowId(pointerEvent, true);
3081     EXPECT_EQ(ret, RET_OK);
3082 }
3083 
3084 /**
3085 @tc.name: ServerMsgHandlerTest_UpdateTouchEvent
3086 @tc.desc: Test the function UpdateTouchEvent
3087 @tc.type: FUNC
3088 @tc.require:
3089 */
3090 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdateTouchEvent, TestSize.Level1)
3091 {
3092     CALL_TEST_DEBUG;
3093     ServerMsgHandler handler;
3094     auto pointerEvent = PointerEvent::Create();
3095     ASSERT_NE(pointerEvent, nullptr);
3096     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3097     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
3098     int32_t action = PointerEvent::POINTER_ACTION_HOVER_ENTER;
3099     int32_t targetWindowId = -1;
3100     auto pointerIds = pointerEvent->GetPointerIds();
3101     EXPECT_TRUE(pointerIds.empty());
3102     auto ret = handler.UpdateTouchEvent(pointerEvent, action, targetWindowId);
3103     EXPECT_EQ(ret, false);
3104 }
3105 
3106 /**
3107 @tc.name: ServerMsgHandlerTest_UpdateTouchEvent
3108 @tc.desc: Test the function UpdateTouchEvent
3109 @tc.type: FUNC
3110 @tc.require:
3111 */
3112 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UpdateTouchEvent001, TestSize.Level1)
3113 {
3114     CALL_TEST_DEBUG;
3115     ServerMsgHandler handler;
3116     auto pointerEvent = PointerEvent::Create();
3117     ASSERT_NE(pointerEvent, nullptr);
3118     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3119     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP);
3120     int32_t action = PointerEvent::SOURCE_TYPE_TOUCHSCREEN;
3121     int32_t targetWindowId = -1;
3122     int32_t pointerId = 1;
3123     PointerEvent::PointerItem item;
3124     item.SetPointerId(pointerId);
3125     item.SetTargetWindowId(2);
3126     pointerEvent->AddPointerItem(item);
3127     pointerEvent->SetPointerId(1);
3128     auto pointerIds = pointerEvent->GetPointerIds();
3129     EXPECT_FALSE(pointerIds.empty());
3130     int32_t id = 1;
3131     EXPECT_TRUE(pointerEvent->GetPointerItem(id, item));
3132     auto ret = handler.UpdateTouchEvent(pointerEvent, action, targetWindowId);
3133     EXPECT_EQ(ret, true);
3134 }
3135 
3136 /**
3137  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandler_003
3138  * @tc.desc: Test the function OnRemoveInputHandler
3139  * @tc.type: FUNC
3140  * @tc.require:
3141  */
3142 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandler_003, TestSize.Level1)
3143 {
3144     CALL_TEST_DEBUG;
3145     ServerMsgHandler handler;
3146     InputHandlerType handlerType = InputHandlerType::NONE;
3147     HandleEventType eventType = 1;
3148     int32_t priority = 2;
3149     uint32_t deviceTags = 3;
3150     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
3151     int32_t ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
3152     EXPECT_EQ(ret, RET_OK);
3153 }
3154 
3155 /**
3156  * @tc.name: ServerMsgHandlerTest_SubscribeKeyMonitor
3157  * @tc.desc: Test the function SubscribeKeyMonitor
3158  * @tc.type: FUNC
3159  * @tc.require:
3160  */
3161 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SubscribeKeyMonitor002, TestSize.Level1)
3162 {
3163     CALL_TEST_DEBUG;
3164     ServerMsgHandler handler;
3165     OHOS::MMI::KeyMonitorOption keyOption;
3166     int32_t session {-1};
3167     int32_t ret = handler.SubscribeKeyMonitor(session, keyOption);
3168     EXPECT_EQ(ret, -CAPABILITY_NOT_SUPPORTED);
3169 }
3170 
3171 /**
3172  * @tc.name: ServerMsgHandlerTest_UnsubscribeKeyMonitor
3173  * @tc.desc: Test the function UnsubscribeKeyMonitor
3174  * @tc.type: FUNC
3175  * @tc.require:
3176  */
3177 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_UnsubscribeKeyMonitor002, TestSize.Level1)
3178 {
3179     CALL_TEST_DEBUG;
3180     ServerMsgHandler handler;
3181     OHOS::MMI::KeyMonitorOption keyOption;
3182     int32_t session {-1};
3183     int32_t ret = handler.UnsubscribeKeyMonitor(session, keyOption);
3184     EXPECT_EQ(ret, -CAPABILITY_NOT_SUPPORTED);
3185 }
3186 
3187 /**
3188  * @tc.name: ServerMsgHandlerTest_DealGesturePointers002
3189  * @tc.desc: Test the function DealGesturePointers
3190  * @tc.type: FUNC
3191  * @tc.require:
3192  */
3193 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_DealGesturePointers002, TestSize.Level1)
3194 {
3195     CALL_TEST_DEBUG;
3196     ServerMsgHandler handler;
3197     auto pointerEvent = PointerEvent::Create();
3198     ASSERT_NE(pointerEvent, nullptr);
3199     pointerEvent->SetId(1);
3200     pointerEvent->SetPointerId(10001);
3201     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_ACCESSIBILITY;
3202     ASSERT_NO_FATAL_FAILURE(handler.DealGesturePointers(pointerEvent));
3203     auto touchEvent = PointerEvent::Create();
3204     ASSERT_NE(touchEvent, nullptr);
3205     PointerEvent::PointerItem item;
3206     item.SetPointerId(10002);
3207     item.SetOriginPointerId(10002);
3208     item.SetPressed(true);
3209     touchEvent->AddPointerItem(item);
3210     ASSERT_NO_FATAL_FAILURE(handler.DealGesturePointers(pointerEvent));
3211 }
3212 
3213 /**
3214  * @tc.name: ServerMsgHandlerTest_OnSetFunctionKeyState003
3215  * @tc.desc: Test the function OnSetFunctionKeyState
3216  * @tc.type: FUNC
3217  * @tc.require:
3218  */
3219 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnSetFunctionKeyState003, TestSize.Level1)
3220 {
3221     CALL_TEST_DEBUG;
3222     ServerMsgHandler handler;
3223     AppExecFwk::RunningProcessInfo processInfo;
3224     processInfo.extensionType_ = AppExecFwk::ExtensionAbilityType::INPUTMETHOD;
3225     int32_t funcKey = 1;
3226     int32_t pid = 15;
3227     bool enable = true;
3228     INPUT_DEV_MGR->IsKeyboardDevice(nullptr);
3229     ASSERT_NO_FATAL_FAILURE(handler.OnSetFunctionKeyState(pid, funcKey, enable));
3230     enable = false;
3231     ASSERT_NO_FATAL_FAILURE(handler.OnSetFunctionKeyState(pid, funcKey, enable));
3232 }
3233 
3234 /**
3235  * @tc.name: ServerMsgHandlerTest_OnInjectPointerEventExt002
3236  * @tc.desc: Test OnInjectPointerEventExt
3237  * @tc.type: FUNC
3238  * @tc.require:
3239  */
3240 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnInjectPointerEventExt002, TestSize.Level1)
3241 {
3242     CALL_TEST_DEBUG;
3243     ServerMsgHandler msgHandler;
3244     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
3245     ASSERT_NE(pointerEvent, nullptr);
3246     InputHandler->eventNormalizeHandler_ = std::make_shared<EventNormalizeHandler>();
3247     pointerEvent->SetId(1);
3248     pointerEvent->eventType_ = 1;
3249     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
3250     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
3251     msgHandler.nativeTargetWindowIds_.insert(std::make_pair(pointerEvent->GetPointerId(), 10));
3252     ASSERT_NO_FATAL_FAILURE(msgHandler.OnInjectPointerEventExt(pointerEvent, true, PointerEvent::DISPLAY_COORDINATE));
3253 
3254     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE);
3255     pointerEvent->SetPointerId(1);
3256     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
3257     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT;
3258     ASSERT_NO_FATAL_FAILURE(msgHandler.OnInjectPointerEventExt(pointerEvent, true, PointerEvent::DISPLAY_COORDINATE));
3259 
3260     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK);
3261     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE);
3262     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NONE);
3263     ASSERT_NO_FATAL_FAILURE(msgHandler.OnInjectPointerEventExt(pointerEvent, true, PointerEvent::DISPLAY_COORDINATE));
3264 
3265     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHPAD);
3266     pointerEvent->bitwise_ = InputEvent::EVENT_FLAG_HIDE_POINTER;
3267     ASSERT_NO_FATAL_FAILURE(msgHandler.OnInjectPointerEventExt(pointerEvent, true, PointerEvent::DISPLAY_COORDINATE));
3268 }
3269 
3270 /**
3271 @tc.name: ServerMsgHandlerTest_FixTargetWindowId_008
3272 @tc.desc: Test FixTargetWindowId
3273 @tc.type: FUNC
3274 @tc.require:
3275 */
3276 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_008, TestSize.Level1)
3277 {
3278     CALL_TEST_DEBUG;
3279     ServerMsgHandler handler;
3280     handler.shellTargetWindowIds_.clear();
3281     handler.castTargetWindowIds_.clear();
3282     handler.accessTargetWindowIds_.clear();
3283     handler.nativeTargetWindowIds_.clear();
3284     auto pointerEvent = PointerEvent::Create();
3285     ASSERT_NE(pointerEvent, nullptr);
3286     pointerEvent->SetDeviceId(CAST_INPUT_DEVICEID);
3287     int32_t action = PointerEvent::POINTER_ACTION_DOWN;
3288     int32_t pointerId = -1;
3289     PointerEvent::PointerItem item;
3290     item.SetPointerId(pointerId);
3291     pointerEvent->AddPointerItem(item);
3292     pointerEvent->SetPointerId(-1);
3293     handler.shellTargetWindowIds_[0] = -1;
3294     pointerEvent->SetZOrder(1);
3295     ASSERT_NO_FATAL_FAILURE(handler.FixTargetWindowId(pointerEvent, action, true));
3296     handler.castTargetWindowIds_[0] = -1;
3297     ASSERT_NO_FATAL_FAILURE(handler.FixTargetWindowId(pointerEvent, action, true));
3298     pointerEvent->SetZOrder(-1);
3299     ASSERT_NO_FATAL_FAILURE(handler.FixTargetWindowId(pointerEvent, action, true));
3300     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY);
3301     ASSERT_NO_FATAL_FAILURE(handler.FixTargetWindowId(pointerEvent, action, true));
3302     handler.accessTargetWindowIds_[0] = -1;
3303     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_NO_INTERCEPT);
3304     ASSERT_NO_FATAL_FAILURE(handler.FixTargetWindowId(pointerEvent, action, true));
3305     handler.nativeTargetWindowIds_[0] = -1;
3306     ASSERT_NO_FATAL_FAILURE(handler.FixTargetWindowId(pointerEvent, action, true));
3307 }
3308 
3309 /**
3310 @tc.name: ServerMsgHandlerTest_ReadScreensInfo_001
3311 @tc.desc: Test ReadScreensInfo
3312 @tc.type: FUNC
3313 @tc.require:
3314 */
3315 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadScreensInfo_001, TestSize.Level1)
3316 {
3317     CALL_TEST_DEBUG;
3318     ServerMsgHandler handler;
3319     UserScreenInfo userScreenInfo;
3320     MmiMessageId idMsg = MmiMessageId::INVALID;
3321     NetPacket pkt(idMsg);
3322     uint32_t num = MAX_SCREEN_SIZE + 1;
3323     pkt << num;
3324     EXPECT_EQ(handler.ReadScreensInfo(pkt, userScreenInfo), RET_ERR);
3325 }
3326 
3327 /**
3328 @tc.name: ServerMsgHandlerTest_ReadScreensInfo_002
3329 @tc.desc: Test ReadScreensInfo
3330 @tc.type: FUNC
3331 @tc.require:
3332 */
3333 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadScreensInfo_002, TestSize.Level1)
3334 {
3335     CALL_TEST_DEBUG;
3336     ServerMsgHandler handler;
3337     UserScreenInfo userScreenInfo;
3338     MmiMessageId idMsg = MmiMessageId::INVALID;
3339     NetPacket pkt(idMsg);
3340     ScreenInfo info;
3341     uint32_t num = 1;
3342     pkt << num << info.id << info.uniqueId << info.screenType << info.width << info.height << info.physicalWidth
3343         << info.physicalHeight << info.tpDirection << info.dpi << info.ppi << info.rotation;
3344     EXPECT_EQ(handler.ReadScreensInfo(pkt, userScreenInfo), RET_OK);
3345 }
3346 
3347 /**
3348 @tc.name: ServerMsgHandlerTest_ReadScreensInfo_003
3349 @tc.desc: Test ReadScreensInfo
3350 @tc.type: FUNC
3351 @tc.require:
3352 */
3353 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadScreensInfo_003, TestSize.Level1)
3354 {
3355     CALL_TEST_DEBUG;
3356     ServerMsgHandler handler;
3357     UserScreenInfo userScreenInfo;
3358     MmiMessageId idMsg = MmiMessageId::INVALID;
3359     NetPacket pkt(idMsg);
3360     ScreenInfo info;
3361     uint32_t num = 1;
3362     pkt << num << info.id << info.uniqueId << info.screenType << info.width << info.height << info.physicalWidth
3363         << info.physicalHeight << info.tpDirection << info.dpi << info.ppi << info.rotation;
3364     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
3365     EXPECT_EQ(handler.ReadScreensInfo(pkt, userScreenInfo), RET_ERR);
3366 }
3367 
3368 /**
3369 @tc.name: ServerMsgHandlerTest_ReadDisplayGroupsInfo_001
3370 @tc.desc: Test ReadDisplayGroupsInfo
3371 @tc.type: FUNC
3372 @tc.require:
3373 */
3374 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadDisplayGroupsInfo_001, TestSize.Level1)
3375 {
3376     CALL_TEST_DEBUG;
3377     ServerMsgHandler handler;
3378     UserScreenInfo userScreenInfo;
3379     MmiMessageId idMsg = MmiMessageId::INVALID;
3380     NetPacket pkt(idMsg);
3381     uint32_t num = MAX_SCREEN_SIZE + 1;
3382     pkt << num;
3383     EXPECT_EQ(handler.ReadDisplayGroupsInfo(pkt, userScreenInfo), RET_ERR);
3384 }
3385 
3386 /**
3387 @tc.name: ServerMsgHandlerTest_ReadDisplayGroupsInfo_002
3388 @tc.desc: Test ReadDisplayGroupsInfo
3389 @tc.type: FUNC
3390 @tc.require:
3391 */
3392 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadDisplayGroupsInfo_002, TestSize.Level1)
3393 {
3394     CALL_TEST_DEBUG;
3395     ServerMsgHandler handler;
3396     UserScreenInfo userScreenInfo;
3397     MmiMessageId idMsg = MmiMessageId::INVALID;
3398     NetPacket pkt(idMsg);
3399     DisplayGroupInfo info;
3400     uint32_t num = 1;
3401     pkt << num << info.id << info.name << info.type << info.mainDisplayId << info.focusWindowId;
3402     EXPECT_EQ(handler.ReadDisplayGroupsInfo(pkt, userScreenInfo), RET_OK);
3403 }
3404 
3405 /**
3406 @tc.name: ServerMsgHandlerTest_ReadDisplayGroupsInfo_003
3407 @tc.desc: Test ReadDisplayGroupsInfo
3408 @tc.type: FUNC
3409 @tc.require:
3410 */
3411 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadDisplayGroupsInfo_003, TestSize.Level1)
3412 {
3413     CALL_TEST_DEBUG;
3414     ServerMsgHandler handler;
3415     UserScreenInfo userScreenInfo;
3416     MmiMessageId idMsg = MmiMessageId::INVALID;
3417     NetPacket pkt(idMsg);
3418     DisplayGroupInfo info;
3419     uint32_t num = 1;
3420     pkt << num << info.id << info.name << info.type << info.mainDisplayId << info.focusWindowId;
3421     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
3422     EXPECT_EQ(handler.ReadDisplayGroupsInfo(pkt, userScreenInfo), RET_OK);
3423 }
3424 
3425 /**
3426 @tc.name: ServerMsgHandlerTest_ReadDisplaysInfo_001
3427 @tc.desc: Test ReadDisplaysInfo
3428 @tc.type: FUNC
3429 @tc.require:
3430 */
3431 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadDisplaysInfo_001, TestSize.Level1)
3432 {
3433     CALL_TEST_DEBUG;
3434     ServerMsgHandler handler;
3435     DisplayGroupInfo displayGroupInfo;
3436     MmiMessageId idMsg = MmiMessageId::INVALID;
3437     NetPacket pkt(idMsg);
3438     uint32_t num = MAX_SCREEN_SIZE + 1;
3439     pkt << num;
3440     EXPECT_EQ(handler.ReadDisplaysInfo(pkt, displayGroupInfo), RET_ERR);
3441 }
3442 
3443 /**
3444 @tc.name: ServerMsgHandlerTest_ReadDisplaysInfo_002
3445 @tc.desc: Test ReadDisplaysInfo
3446 @tc.type: FUNC
3447 @tc.require:
3448 */
3449 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadDisplaysInfo_002, TestSize.Level1)
3450 {
3451     CALL_TEST_DEBUG;
3452     ServerMsgHandler handler;
3453     DisplayGroupInfo displayGroupInfo;
3454     MmiMessageId idMsg = MmiMessageId::INVALID;
3455     NetPacket pkt(idMsg);
3456     DisplayInfo info;
3457     uint32_t num = 1;
3458     pkt << num << info.id << info.x << info.y << info.width << info.height << info.dpi << info.name << info.direction
3459         << info.displayDirection << info.displayMode << info.transform << info.scalePercent << info.expandHeight
3460         << info.isCurrentOffScreenRendering << info.displaySourceMode << info.oneHandX << info.oneHandY
3461         << info.screenArea << info.rsId << info.offsetX << info.offsetY << info.pointerActiveWidth
3462         << info.pointerActiveHeight;
3463     ;
3464     EXPECT_EQ(handler.ReadDisplaysInfo(pkt, displayGroupInfo), RET_OK);
3465 }
3466 
3467 /**
3468 @tc.name: ServerMsgHandlerTest_ReadWindowsInfo_001
3469 @tc.desc: Test ReadWindowsInfo
3470 @tc.type: FUNC
3471 @tc.require:
3472 */
3473 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadWindowsInfo_001, TestSize.Level1)
3474 {
3475     CALL_TEST_DEBUG;
3476     ServerMsgHandler handler;
3477     DisplayGroupInfo displayGroupInfo;
3478     OLD::DisplayGroupInfo oldDisplayGroupInfo {
3479         .focusWindowId = 10,
3480         .currentUserId = 20,
3481     };
3482     MmiMessageId idMsg = MmiMessageId::INVALID;
3483     NetPacket pkt(idMsg);
3484     uint32_t num = MAX_SCREEN_SIZE + 1;
3485     pkt << num;
3486     EXPECT_EQ(handler.ReadWindowsInfo(pkt, displayGroupInfo, oldDisplayGroupInfo), RET_ERR);
3487 }
3488 
3489 /**
3490 @tc.name: ServerMsgHandlerTest_ReadWindowsInfo_002
3491 @tc.desc: Test ReadWindowsInfo
3492 @tc.type: FUNC
3493 @tc.require:
3494 */
3495 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadWindowsInfo_002, TestSize.Level1)
3496 {
3497     CALL_TEST_DEBUG;
3498     ServerMsgHandler handler;
3499     DisplayGroupInfo displayGroupInfo;
3500     OLD::DisplayGroupInfo oldDisplayGroupInfo {
3501         .focusWindowId = 10,
3502         .currentUserId = 20,
3503     };
3504     MmiMessageId idMsg = MmiMessageId::INVALID;
3505     NetPacket pkt(idMsg);
3506     WindowInfo info;
3507     uint32_t num = 1;
3508     int32_t byteCount = 0;
3509     pkt << num << info.id << info.pid << info.uid << info.area << info.defaultHotAreas << info.pointerHotAreas
3510         << info.agentWindowId << info.flags << info.action << info.displayId << info.groupId << info.zOrder
3511         << info.pointerChangeAreas << info.transform << info.windowInputType << info.privacyMode << info.windowType
3512         << info.isSkipSelfWhenShowOnVirtualScreen << info.windowNameType << byteCount;
3513     EXPECT_EQ(handler.ReadWindowsInfo(pkt, displayGroupInfo, oldDisplayGroupInfo), RET_ERR);
3514 }
3515 
3516 /**
3517 @tc.name: ServerMsgHandlerTest_ReadWindowsInfo_003
3518 @tc.desc: Test ReadWindowsInfo
3519 @tc.type: FUNC
3520 @tc.require:
3521 */
3522 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ReadWindowsInfo_003, TestSize.Level1)
3523 {
3524     CALL_TEST_DEBUG;
3525     ServerMsgHandler handler;
3526     DisplayGroupInfo displayGroupInfo;
3527     OLD::DisplayGroupInfo oldDisplayGroupInfo {
3528         .focusWindowId = 10,
3529         .currentUserId = 20,
3530     };
3531     MmiMessageId idMsg = MmiMessageId::INVALID;
3532     NetPacket pkt(idMsg);
3533     WindowInfo info;
3534     uint32_t num = 1;
3535     int32_t byteCount = 0;
3536     pkt << num << info.id << info.pid << info.uid << info.area << info.defaultHotAreas << info.pointerHotAreas
3537         << info.agentWindowId << info.flags << info.action << info.displayId << info.groupId << info.zOrder
3538         << info.pointerChangeAreas << info.transform << info.windowInputType << info.privacyMode << info.windowType
3539         << info.isSkipSelfWhenShowOnVirtualScreen << info.windowNameType << byteCount;
3540     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_READ;
3541     EXPECT_EQ(handler.ReadWindowsInfo(pkt, displayGroupInfo, oldDisplayGroupInfo), RET_OK);
3542 }
3543 
3544 /**
3545  * @tc.name: ServerMsgHandlerTest_TestChangeToOld_001
3546  * @tc.desc: Test ChangeToOld
3547  * @tc.type: FUNC
3548  * @tc.require:
3549  */
3550 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_TestChangeToOld_001, TestSize.Level1)
3551 {
3552     CALL_TEST_DEBUG;
3553     UserScreenInfo userScreenInfo;
3554     userScreenInfo.userId = 0;
3555     DisplayGroupInfo group;
3556     group.id = 1;
3557     group.name = "MainGroup";
3558     group.type = GroupType::GROUP_DEFAULT;
3559     group.mainDisplayId = 2;
3560     group.focusWindowId = 123;
3561     group.windowsInfo.push_back(WindowInfo());
3562     group.displaysInfo.push_back(DisplayInfo());
3563     DisplayInfo display;
3564     display.width = 1920;
3565     display.height = 1080;
3566     group.displaysInfo.push_back(display);
3567     WindowInfo window;
3568     window.groupId = 0;
3569     window.id = 123;
3570     group.windowsInfo.push_back(window);
3571     userScreenInfo.displayGroups.push_back(group);
3572     userScreenInfo.screens.push_back(ScreenInfo());
3573     ServerMsgHandler handler;
3574     EXPECT_EQ(handler.ChangeToOld(userScreenInfo), false);
3575 }
3576 
3577 /**
3578  * @tc.name: ServerMsgHandlerTest_TestChangeToOld_002
3579  * @tc.desc: Test ChangeToOld
3580  * @tc.type: FUNC
3581  * @tc.require:
3582  */
3583 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_TestChangeToOld_002, TestSize.Level1)
3584 {
3585     CALL_TEST_DEBUG;
3586     size_t num {1};
3587     std::vector<DisplayInfo> displaysInfos;
3588     DisplayInfo display;
3589     display.width = 1920;
3590     display.height = 1080;
3591     display.direction = DIRECTION0;
3592     display.screenArea.id = 1;
3593     display.screenArea.area.width = 100;
3594     display.screenArea.area.height = 100;
3595     displaysInfos.push_back(display);
3596     std::vector<ScreenInfo> screens;
3597     ScreenInfo screenInfo;
3598     screenInfo.id = 1;
3599     screens.push_back(screenInfo);
3600     ServerMsgHandler handler;
3601     ASSERT_NO_FATAL_FAILURE(handler.ChangeToOld(num, displaysInfos, screens));
3602     display.direction = DIRECTION90;
3603     displaysInfos = {display};
3604     ASSERT_NO_FATAL_FAILURE(handler.ChangeToOld(num, displaysInfos, screens));
3605 }
3606 
3607 /**
3608  * @tc.name: ServerMsgHandlerTest_TestPrintf
3609  * @tc.desc: Test Printf
3610  * @tc.type: FUNC
3611  * @tc.require:
3612  */
3613 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_TestPrintf, TestSize.Level1)
3614 {
3615     CALL_TEST_DEBUG;
3616     UserScreenInfo userScreenInfo;
3617     userScreenInfo.userId = 0;
3618     DisplayGroupInfo group;
3619     group.id = 1;
3620     group.name = "MainGroup";
3621     group.type = GroupType::GROUP_DEFAULT;
3622     group.mainDisplayId = 2;
3623     group.focusWindowId = 123;
3624     group.windowsInfo.push_back(WindowInfo());
3625     group.displaysInfo.push_back(DisplayInfo());
3626     DisplayInfo display;
3627     display.width = 1920;
3628     display.height = 1080;
3629     display.transform = {0, 0, 0, 0};
3630     group.displaysInfo.push_back(display);
3631     WindowInfo window;
3632     window.groupId = 0;
3633     window.id = 123;
3634     group.windowsInfo.push_back(window);
3635     userScreenInfo.displayGroups.push_back(group);
3636     userScreenInfo.screens.push_back(ScreenInfo());
3637     ServerMsgHandler handler;
3638     ASSERT_NO_FATAL_FAILURE(handler.Printf(userScreenInfo));
3639 }
3640 
3641 /**
3642  * @tc.name: ServerMsgHandlerTest_TestChangeToOld_003
3643  * @tc.desc: Test ChangeToOld
3644  * @tc.type: FUNC
3645  * @tc.require:
3646  */
3647 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_TestChangeToOld_003, TestSize.Level1)
3648 {
3649     CALL_TEST_DEBUG;
3650     UserScreenInfo userScreenInfo;
3651     userScreenInfo.userId = 0;
3652     DisplayGroupInfo group;
3653     group.id = 1;
3654     group.name = "MainGroup";
3655     group.type = GroupType::GROUP_DEFAULT;
3656     group.mainDisplayId = 2;
3657     group.focusWindowId = 123;
3658     group.windowsInfo.push_back(WindowInfo());
3659     group.displaysInfo.push_back(DisplayInfo());
3660     DisplayInfo display;
3661     display.width = 1920;
3662     display.height = 1080;
3663     group.displaysInfo.push_back(display);
3664     WindowInfo window;
3665     window.groupId = 0;
3666     window.id = 123;
3667     group.windowsInfo.push_back(window);
3668     userScreenInfo.displayGroups.push_back(group);
3669     userScreenInfo.screens.push_back(ScreenInfo());
3670     ServerMsgHandler handler;
3671     OLD::DisplayGroupInfo oldInfo;
3672     handler.oldDisplayGroupInfos_.push_back(oldInfo);
3673     EXPECT_EQ(handler.ChangeToOld(userScreenInfo), true);
3674 }
3675 
3676 /**
3677 @tc.name: ServerMsgHandlerTest_ChangeToOld_001
3678 @tc.desc: Test ChangeToOld
3679 @tc.type: FUNC
3680 @tc.require:
3681 */
3682 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ChangeToOld_001, TestSize.Level1)
3683 {
3684     CALL_TEST_DEBUG;
3685 
3686     DisplayInfo displayInfo;
3687     displayInfo.id = 1;
3688     displayInfo.x = 0;
3689     displayInfo.y = 0;
3690     displayInfo.width = 100;
3691     displayInfo.height = 200;
3692     displayInfo.dpi = 300;
3693     displayInfo.name = "TestDisplay";
3694     displayInfo.direction = Direction::DIRECTION0;
3695     displayInfo.displayDirection = Direction::DIRECTION0;
3696     displayInfo.displayMode = DisplayMode::FULL;
3697     displayInfo.transform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
3698     displayInfo.scalePercent = 100;
3699     displayInfo.expandHeight = 0;
3700     displayInfo.isCurrentOffScreenRendering = false;
3701     displayInfo.displaySourceMode = DisplaySourceMode::SCREEN_MAIN;
3702     displayInfo.oneHandX = 0;
3703     displayInfo.oneHandY = 0;
3704     displayInfo.screenArea.id = 1;
3705     displayInfo.screenArea.area = {0, 0, 100, 200};
3706     displayInfo.rsId = 1;
3707     displayInfo.offsetX = 0;
3708     displayInfo.offsetY = 0;
3709     displayInfo.pointerActiveWidth = 0;
3710     displayInfo.pointerActiveHeight = 0;
3711 
3712     ScreenInfo screenInfo;
3713     screenInfo.id = 1;
3714     screenInfo.uniqueId = "TestScreen";
3715     screenInfo.screenType = ScreenType::REAL;
3716     screenInfo.width = 100;
3717     screenInfo.height = 200;
3718     screenInfo.physicalWidth = 100;
3719     screenInfo.physicalHeight = 200;
3720 
3721     std::vector<DisplayInfo> displaysInfo = {displayInfo};
3722     std::vector<ScreenInfo> screens = {screenInfo};
3723 
3724     ServerMsgHandler handler;
3725     ASSERT_NO_FATAL_FAILURE(handler.ChangeToOld(1, displaysInfo, screens));
3726 }
3727 
3728 /**
3729 @tc.name: ServerMsgHandlerTest_ChangeToOld_002
3730 @tc.desc: Test ChangeToOld
3731 @tc.type: FUNC
3732 @tc.require:
3733 */
3734 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ChangeToOld_002, TestSize.Level1)
3735 {
3736     CALL_TEST_DEBUG;
3737 
3738     UserScreenInfo userScreenInfo;
3739     userScreenInfo.userId = 0;
3740 
3741     DisplayGroupInfo displayGroupInfo1;
3742     displayGroupInfo1.id = 0;
3743     displayGroupInfo1.type = GroupType::GROUP_DEFAULT;
3744     displayGroupInfo1.mainDisplayId = 0;
3745     displayGroupInfo1.focusWindowId = GLOBAL_WINDOW_ID;
3746 
3747     DisplayGroupInfo displayGroupInfo2;
3748     displayGroupInfo2.id = 1;
3749     displayGroupInfo2.type = GroupType::GROUP_SPECIAL;
3750     displayGroupInfo2.mainDisplayId = 1;
3751     displayGroupInfo2.focusWindowId = GLOBAL_WINDOW_ID;
3752 
3753     userScreenInfo.displayGroups = {displayGroupInfo1, displayGroupInfo2};
3754 
3755     ServerMsgHandler handler;
3756     EXPECT_FALSE(handler.ChangeToOld(userScreenInfo));
3757 }
3758 
3759 /**
3760 @tc.name: ServerMsgHandlerTest_ChangeToOld_003
3761 @tc.desc: Test ChangeToOld
3762 @tc.type: FUNC
3763 @tc.require:
3764 */
3765 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ChangeToOld_003, TestSize.Level1)
3766 {
3767     CALL_TEST_DEBUG;
3768 
3769     UserScreenInfo userScreenInfo;
3770     userScreenInfo.userId = 0;
3771 
3772     DisplayGroupInfo displayGroupInfo;
3773     displayGroupInfo.id = 0;
3774     displayGroupInfo.type = GroupType::GROUP_DEFAULT;
3775     displayGroupInfo.mainDisplayId = 0;
3776     displayGroupInfo.focusWindowId = GLOBAL_WINDOW_ID;
3777 
3778     userScreenInfo.displayGroups = {displayGroupInfo, displayGroupInfo};
3779 
3780     ServerMsgHandler handler;
3781     EXPECT_FALSE(handler.ChangeToOld(userScreenInfo));
3782 }
3783 
3784 /**
3785 @tc.name: ServerMsgHandlerTest_ChangeToOld_004
3786 @tc.desc: Test ChangeToOld
3787 @tc.type: FUNC
3788 @tc.require:
3789 */
3790 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ChangeToOld_004, TestSize.Level1)
3791 {
3792     CALL_TEST_DEBUG;
3793 
3794     UserScreenInfo userScreenInfo;
3795     userScreenInfo.userId = 0;
3796     userScreenInfo.displayGroups.clear();
3797 
3798     ServerMsgHandler handler;
3799     EXPECT_TRUE(handler.ChangeToOld(userScreenInfo));
3800 }
3801 
3802 /**
3803 @tc.name: ServerMsgHandlerTest_ChangeToOld_005
3804 @tc.desc: Test ChangeToOld
3805 @tc.type: FUNC
3806 @tc.require:
3807 */
3808 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ChangeToOld_005, TestSize.Level1)
3809 {
3810     CALL_TEST_DEBUG;
3811 
3812     UserScreenInfo userScreenInfo;
3813     userScreenInfo.userId = 0;
3814 
3815     DisplayGroupInfo displayGroupInfo1;
3816     displayGroupInfo1.id = 0;
3817     displayGroupInfo1.type = GroupType::GROUP_DEFAULT;
3818     displayGroupInfo1.mainDisplayId = 0;
3819     displayGroupInfo1.focusWindowId = GLOBAL_WINDOW_ID;
3820 
3821     DisplayGroupInfo displayGroupInfo2;
3822     displayGroupInfo2.id = 1;
3823     displayGroupInfo2.type = GroupType::GROUP_SPECIAL;
3824     displayGroupInfo2.mainDisplayId = 1;
3825     displayGroupInfo2.focusWindowId = GLOBAL_WINDOW_ID;
3826 
3827     DisplayGroupInfo displayGroupInfo3;
3828     displayGroupInfo3.id = 2;
3829     displayGroupInfo3.type = GroupType::GROUP_DEFAULT;
3830     displayGroupInfo3.mainDisplayId = 2;
3831     displayGroupInfo3.focusWindowId = GLOBAL_WINDOW_ID;
3832 
3833     userScreenInfo.displayGroups = {displayGroupInfo1, displayGroupInfo2, displayGroupInfo3};
3834 
3835     ServerMsgHandler handler;
3836     EXPECT_FALSE(handler.ChangeToOld(userScreenInfo));
3837 }
3838 
3839 /**
3840 @tc.name: ServerMsgHandlerTest_ChangeToOld_006
3841 @tc.desc: Test ChangeToOld
3842 @tc.type: FUNC
3843 @tc.require:
3844 */
3845 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ChangeToOld_006, TestSize.Level1)
3846 {
3847     CALL_TEST_DEBUG;
3848 
3849     UserScreenInfo userScreenInfo;
3850     userScreenInfo.userId = 0;
3851 
3852     DisplayGroupInfo displayGroupInfo;
3853     displayGroupInfo.id = 0;
3854     displayGroupInfo.type = GroupType::GROUP_DEFAULT;
3855     displayGroupInfo.mainDisplayId = 0;
3856     displayGroupInfo.focusWindowId = GLOBAL_WINDOW_ID;
3857 
3858     userScreenInfo.displayGroups = {displayGroupInfo};
3859     ServerMsgHandler handler;
3860     EXPECT_FALSE(handler.ChangeToOld(userScreenInfo));
3861 }
3862 
3863 /**
3864 @tc.name: ServerMsgHandlerTest_OnDisplayInfo_005
3865 @tc.desc: Test the function OnDisplayInfo
3866 @tc.type: FUNC
3867 @tc.require:
3868 */
3869 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_005, TestSize.Level1)
3870 {
3871     CALL_TEST_DEBUG;
3872     ServerMsgHandler handler;
3873     int32_t num = 1;
3874     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
3875     sess->SetTokenType(TOKEN_SHELL);
3876     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
3877     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
3878     ScreenInfo info;
3879     pkt << num;
3880     pkt << info.id << info.uniqueId << info.screenType << info.width << info.height << info.physicalWidth
3881         << info.physicalHeight << info.tpDirection << info.dpi << info.ppi << info.rotation;
3882     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_ERR);
3883 }
3884 
3885 /**
3886 @tc.name: ServerMsgHandlerTest_OnDisplayInfo_006
3887 @tc.desc: Test the function OnDisplayInfo
3888 @tc.type: FUNC
3889 @tc.require:
3890 */
3891 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_006, TestSize.Level1)
3892 {
3893     CALL_TEST_DEBUG;
3894     ServerMsgHandler handler;
3895     int32_t num = 1;
3896     int32_t num2 = 10;
3897     int32_t num3 = 0;
3898     bool ret = false;
3899     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
3900     sess->SetTokenType(TOKEN_SHELL);
3901     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
3902     pkt.rwErrorStatus_ = CircleStreamBuffer::ErrorStatus::ERROR_STATUS_OK;
3903     {
3904         ScreenInfo info;
3905         pkt << num2 << num << info.id << info.uniqueId << info.screenType << info.width << info.height
3906             << info.physicalWidth << info.physicalHeight << info.tpDirection << info.dpi << info.ppi << info.rotation;
3907     }
3908     {
3909         DisplayGroupInfo info;
3910         pkt << num << info.id << info.name << info.type << info.mainDisplayId << info.focusWindowId;
3911     }
3912     {
3913         DisplayInfo info;
3914         pkt << num << info.id << info.x << info.y << info.width << info.height << info.dpi << info.name
3915             << info.direction << info.displayDirection << info.displayMode << info.transform << info.scalePercent
3916             << info.expandHeight << info.isCurrentOffScreenRendering << info.displaySourceMode << info.oneHandX
3917             << info.oneHandY << info.screenArea << info.rsId << info.offsetX << info.offsetY<< info.pointerActiveWidth
3918             << info.pointerActiveHeight;
3919     }
3920     {
3921         WindowInfo info;
3922         pkt << num << info.id << info.pid << info.uid << info.area << info.defaultHotAreas << info.pointerHotAreas
3923             << info.agentWindowId << info.flags << info.action << info.displayId << info.groupId << info.zOrder
3924             << info.pointerChangeAreas << info.transform << info.windowInputType << info.privacyMode << info.windowType
3925             << info.isSkipSelfWhenShowOnVirtualScreen << info.windowNameType << num3;
3926     }
3927     {
3928         WindowInfo extensionInfo;
3929         pkt << num << extensionInfo.id << extensionInfo.pid << extensionInfo.uid << extensionInfo.area
3930             << extensionInfo.defaultHotAreas << extensionInfo.pointerHotAreas << extensionInfo.agentWindowId
3931             << extensionInfo.flags << extensionInfo.action << extensionInfo.displayId << extensionInfo.groupId
3932             << extensionInfo.zOrder << extensionInfo.pointerChangeAreas << extensionInfo.transform
3933             << extensionInfo.windowInputType << extensionInfo.privacyMode << extensionInfo.windowType
3934             << extensionInfo.privacyUIFlag << extensionInfo.rectChangeBySystem
3935             << extensionInfo.isSkipSelfWhenShowOnVirtualScreen << extensionInfo.windowNameType;
3936     }
3937     pkt << ret;
3938     EXPECT_EQ(handler.OnDisplayInfo(sess, pkt), RET_OK);
3939 }
3940 
3941 /**
3942 @tc.name: ServerMsgHandlerTest_NativeInjectCheck
3943 @tc.desc: Test the function NativeInjectCheck
3944 @tc.type: FUNC
3945 @tc.require:
3946 */
3947 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_NativeInjectCheck, TestSize.Level1)
3948 {
3949     CALL_TEST_DEBUG;
3950     ServerMsgHandler handler;
3951     handler.InitInjectNoticeSource();
3952     int32_t pid = -1;
3953     auto result = handler.NativeInjectCheck(pid);
3954     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
3955     pid = 0;
3956     result = handler.NativeInjectCheck(pid);
3957     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
3958 }
3959 
3960 /**
3961 @tc.name: ServerMsgHandlerTest_NativeInjectCheck001
3962 @tc.desc: Test the function NativeInjectCheck
3963 @tc.type: FUNC
3964 @tc.require:
3965 */
3966 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_NativeInjectCheck001, TestSize.Level1)
3967 {
3968     CALL_TEST_DEBUG;
3969     ServerMsgHandler handler;
3970     int32_t pid = 1234;
3971     auto isPC = handler.IsPC();
3972     if (!isPC) {
3973         auto result = handler.NativeInjectCheck(pid);
3974         EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
3975     }
3976 }
3977 
3978 /**
3979 @tc.name: ServerMsgHandlerTest_NativeInjectCheck002
3980 @tc.desc: Test the function NativeInjectCheck
3981 @tc.type: FUNC
3982 @tc.require:
3983 */
3984 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_NativeInjectCheck002, TestSize.Level1)
3985 {
3986     CALL_TEST_DEBUG;
3987     ServerMsgHandler handler;
3988     int32_t pid = 1234;
3989     auto isPC = handler.IsPC();
3990     EXPECT_EQ(isPC, false);
3991     DISPLAY_MONITOR->SetScreenLocked(true);
3992     auto result = handler.NativeInjectCheck(pid);
3993     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
3994 }
3995 
3996 /**
3997 @tc.name: ServerMsgHandlerTest_NativeInjectCheck003
3998 @tc.desc: Test the function NativeInjectCheck
3999 @tc.type: FUNC
4000 @tc.require:
4001 */
4002 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_NativeInjectCheck003, TestSize.Level1)
4003 {
4004     CALL_TEST_DEBUG;
4005     ServerMsgHandler handler;
4006     int32_t pid = 1234;
4007     auto isPC = handler.IsPC();
4008     EXPECT_EQ(isPC, false);
4009     DISPLAY_MONITOR->SetScreenLocked(false);
4010     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
4011     auto result = handler.NativeInjectCheck(pid);
4012     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
4013     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_AUTHORIZE;
4014     result = handler.NativeInjectCheck(pid);
4015     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
4016 }
4017 
4018 /**
4019  * @tc.name: ServerMsgHandlerTest_CloseInjectNotice_002
4020  * @tc.desc: Test CloseInjectNotice
4021  * @tc.type: FUNC
4022  * @tc.require:
4023  */
4024 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_CloseInjectNotice_002, TestSize.Level1)
4025 {
4026     CALL_TEST_DEBUG;
4027     ServerMsgHandler handler;
4028     handler.InitInjectNoticeSource();
4029     int32_t pid = 0;
4030     bool result = handler.CloseInjectNotice(pid);
4031     ASSERT_FALSE(result);
4032 }
4033 
4034 /**
4035  * @tc.name: ServerMsgHandlerTest_CloseInjectNotice_003
4036  * @tc.desc: Test the function CloseInjectNotice
4037  * @tc.require:
4038  */
4039 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_CloseInjectNotice_003, TestSize.Level1)
4040 {
4041     CALL_TEST_DEBUG;
4042     ServerMsgHandler handler;
4043     InjectNoticeManager manager;
4044     handler.InitInjectNoticeSource();
4045     int32_t pid = 1234;
4046     handler.injectNotice_ = nullptr;
4047     bool ret = handler.InitInjectNoticeSource();
4048     handler.injectNotice_->isStartSrv_ = true;
4049     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
4050     EXPECT_NE(nullptr, manager.connectionCallback_);
4051     auto connection = handler.injectNotice_->GetConnection();
4052     connection->isConnected_ = false;
4053     ret = handler.CloseInjectNotice(pid);
4054     EXPECT_FALSE(ret);
4055 }
4056 
4057 /**
4058  * @tc.name: ServerMsgHandlerTest_InitInjectNoticeSource_004
4059  * @tc.desc: Test the function InitInjectNoticeSource
4060  * @tc.type: FUNC
4061  * @tc.require:
4062  */
4063 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_InitInjectNoticeSource_004, TestSize.Level1)
4064 {
4065     CALL_TEST_DEBUG;
4066     ServerMsgHandler handler;
4067     InjectNoticeManager manager;
4068     bool ret = handler.InitInjectNoticeSource();
4069     handler.injectNotice_ = std::make_shared<InjectNoticeManager>();
4070     manager.isStartSrv_ = false;
4071     ret = handler.InitInjectNoticeSource();
4072     EXPECT_FALSE(ret);
4073     manager.isStartSrv_ = true;
4074     ret = handler.InitInjectNoticeSource();
4075     EXPECT_FALSE(ret);
4076     manager.connectionCallback_ = new (std::nothrow) InjectNoticeManager::InjectNoticeConnection;
4077     manager.connectionCallback_->isConnected_ = false;
4078     ret = handler.InitInjectNoticeSource();
4079     EXPECT_FALSE(ret);
4080     manager.connectionCallback_->isConnected_ = true;
4081     ret = handler.InitInjectNoticeSource();
4082     EXPECT_FALSE(ret);
4083 }
4084 
4085 /**
4086  * @tc.name: ServerMsgHandlerTest_QueryAuthorizedStatus001
4087  * @tc.desc: Test the function QueryAuthorizedStatus
4088  * @tc.type: FUNC
4089  * @tc.require:
4090  */
4091 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_QueryAuthorizedStatus001, TestSize.Level1)
4092 {
4093     CALL_TEST_DEBUG;
4094     ServerMsgHandler handler;
4095     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_SELECTION_AUTHORIZE;
4096     int32_t callingPid = 1;
4097     int32_t status = 1;
4098     int32_t result = handler.QueryAuthorizedStatus(callingPid, status);
4099     EXPECT_EQ(result, ERR_OK);
4100 }
4101 
4102 /**
4103  * @tc.name: ServerMsgHandlerTest_RequestInjection_002
4104  * @tc.desc: Test the function RequestInjection
4105  * @tc.type: FUNC
4106  * @tc.require:
4107  */
4108 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_RequestInjection_002, TestSize.Level1)
4109 {
4110     CALL_TEST_DEBUG;
4111     ServerMsgHandler handler;
4112     int32_t callingPid = 1;
4113     int32_t status = 1;
4114     int32_t reqId = 1;
4115     auto isPC = handler.IsPC();
4116     if (!isPC) {
4117         auto result = handler.RequestInjection(callingPid, status, reqId);
4118         EXPECT_EQ(result, ERROR_DEVICE_NOT_SUPPORTED);
4119         return;
4120     }
4121     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_AUTHORIZE;
4122     handler.OnCancelInjection(callingPid);
4123     auto result = handler.OnAuthorize(false);
4124     EXPECT_EQ(result, ERR_OK);
4125     result = handler.RequestInjection(callingPid, status, reqId);
4126     EXPECT_EQ(result, ERR_OK);
4127     result = handler.OnAuthorize(true);
4128     EXPECT_EQ(result, ERR_OK);
4129 }
4130 
4131 /**
4132 @tc.name: ServerMsgHandlerTest_ChangeToOld_007
4133 @tc.desc: Test ChangeToOld
4134 @tc.type: FUNC
4135 @tc.require:
4136 */
4137 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_ChangeToOld_007, TestSize.Level1)
4138 {
4139     CALL_TEST_DEBUG;
4140     UserScreenInfo userScreenInfo;
4141     userScreenInfo.userId = 0;
4142 
4143     DisplayGroupInfo displayGroupInfo1;
4144     displayGroupInfo1.id = 0;
4145     displayGroupInfo1.type = GroupType::GROUP_DEFAULT;
4146     displayGroupInfo1.mainDisplayId = 0;
4147     displayGroupInfo1.focusWindowId = GLOBAL_WINDOW_ID;
4148 
4149     DisplayGroupInfo displayGroupInfo2;
4150     displayGroupInfo2.id = 1;
4151     displayGroupInfo2.type = GroupType::GROUP_SPECIAL;
4152     displayGroupInfo2.mainDisplayId = 1;
4153     displayGroupInfo2.focusWindowId = GLOBAL_WINDOW_ID;
4154 
4155     DisplayGroupInfo displayGroupInfo3;
4156     displayGroupInfo3.id = 2;
4157     displayGroupInfo3.type = GroupType::GROUP_DEFAULT;
4158     displayGroupInfo3.mainDisplayId = 2;
4159     displayGroupInfo3.focusWindowId = GLOBAL_WINDOW_ID;
4160 
4161     DisplayGroupInfo displayGroupInfo4;
4162     displayGroupInfo3.id = 3;
4163     displayGroupInfo3.type = GroupType::GROUP_SPECIAL;
4164     displayGroupInfo3.mainDisplayId = 3;
4165     displayGroupInfo3.focusWindowId = DEFAULT_GROUP_ID;
4166 
4167     userScreenInfo.displayGroups = {displayGroupInfo1, displayGroupInfo2, displayGroupInfo3, displayGroupInfo4};
4168 
4169     ServerMsgHandler handler;
4170     EXPECT_FALSE(handler.ChangeToOld(userScreenInfo));
4171 }
4172 
4173 /**
4174  * @tc.name: ServerMsgHandlerTest_TestChangeToOld_008
4175  * @tc.desc: Test ChangeToOld
4176  * @tc.type: FUNC
4177  * @tc.require:
4178  */
4179 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_TestChangeToOld_008, TestSize.Level1)
4180 {
4181     CALL_TEST_DEBUG;
4182     size_t num {1};
4183     std::vector<DisplayInfo> displaysInfos;
4184     DisplayInfo display;
4185     display.width = 1920;
4186     display.height = 1080;
4187     display.direction = DIRECTION180;
4188     display.screenArea.id = 2;
4189     display.screenArea.area.width = 0;
4190     display.screenArea.area.height = 0;
4191     displaysInfos.push_back(display);
4192     std::vector<ScreenInfo> screens;
4193     ScreenInfo screenInfo;
4194     screenInfo.id = 1;
4195     screens.push_back(screenInfo);
4196     ServerMsgHandler handler;
4197     ASSERT_NO_FATAL_FAILURE(handler.ChangeToOld(num, displaysInfos, screens));
4198     display.direction = DIRECTION90;
4199     displaysInfos = {display};
4200     ASSERT_NO_FATAL_FAILURE(handler.ChangeToOld(num, displaysInfos, screens));
4201     display.direction = DIRECTION270;
4202     displaysInfos = {display};
4203     ASSERT_NO_FATAL_FAILURE(handler.ChangeToOld(num, displaysInfos, screens));
4204 }
4205 
4206 /**
4207 @tc.name: ServerMsgHandlerTest_OnWindowGroupInfo_005
4208 @tc.desc: Test the function OnWindowGroupInfo
4209 @tc.type: FUNC
4210 @tc.require:
4211 */
4212 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnWindowGroupInfo_005, TestSize.Level1)
4213 {
4214     CALL_TEST_DEBUG;
4215     ServerMsgHandler handler;
4216     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
4217     sess->SetTokenType(TOKEN_INVALID);
4218     int32_t p1 = 112;
4219     std::string p2 = "test111";
4220     NetPacket pkt(MmiMessageId::INVALID);
4221     pkt << p1 << p2;
4222     EXPECT_FALSE(pkt.ChkRWError());
4223 
4224     int32_t r1 = 0;
4225     std::string r2;
4226     pkt >> r1 >> r2;
4227     EXPECT_FALSE(pkt.ChkRWError());
4228     int32_t r3;
4229     pkt >> r3;
4230     EXPECT_TRUE(pkt.ChkRWError());
4231 
4232     Rect rec = {1, 1, 1, 1};
4233     std::vector recVec = {rec, rec};
4234     std::vector<int32_t> pChangeAreas = {1, 1, 1};
4235     std::vector transform = {1.0, 1.0, 1.0};
4236 
4237     int32_t ret = handler.OnWindowGroupInfo(sess, pkt);
4238     EXPECT_EQ(ret, RET_ERR);
4239 }
4240 
4241 /**
4242  * @tc.name: ServerMsgHandlerTest_OnGetFunctionKeyState_003
4243  * @tc.desc: Test the function OnGetFunctionKeyState
4244  * @tc.type: FUNC
4245  * @tc.require:
4246  */
4247 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnGetFunctionKeyState_003, TestSize.Level1)
4248 {
4249     CALL_TEST_DEBUG;
4250     ServerMsgHandler handler;
4251     int32_t funcKey = CAPS_LOCK_FUNCTION_KEY;
4252     bool state = true;
4253     AppExecFwk::RunningProcessInfo processInfo;
4254     processInfo.extensionType_ = AppExecFwk::ExtensionAbilityType::INPUTMETHOD;
4255     int32_t pid = 15;
4256     bool enable = true;
4257     AUTHORIZE_HELPER->state_ = AuthorizeState::STATE_UNAUTHORIZE;
4258     auto result = handler.NativeInjectCheck(pid);
4259     EXPECT_EQ(result, COMMON_PERMISSION_CHECK_ERROR);
4260     int32_t ret = handler.OnGetFunctionKeyState(funcKey, state);
4261     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
4262     ASSERT_NO_FATAL_FAILURE(handler.OnSetFunctionKeyState(pid, funcKey, enable));
4263     funcKey = 0;
4264     enable = false;
4265     ret = handler.OnGetFunctionKeyState(funcKey, state);
4266     ASSERT_NO_FATAL_FAILURE(handler.OnSetFunctionKeyState(pid, funcKey, enable));
4267     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
4268     state = false;
4269     funcKey = 30;
4270     ret = handler.OnGetFunctionKeyState(funcKey, state);
4271     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
4272     funcKey = 10;
4273     state = false;
4274     ret = handler.OnGetFunctionKeyState(funcKey, state);
4275     EXPECT_EQ(ret, ERR_DEVICE_NOT_EXIST);
4276 }
4277 
4278 /**
4279 @tc.name: ServerMsgHandlerTest_SaveTargetWindowId_009
4280 @tc.desc: Test the function SaveTargetWindowId
4281 @tc.type: FUNC
4282 @tc.require:
4283 */
4284 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_SaveTargetWindowId_009, TestSize.Level1)
4285 {
4286     CALL_TEST_DEBUG;
4287     ServerMsgHandler handler;
4288     auto pointer = PointerEvent::Create();
4289     ASSERT_NE(pointer, nullptr);
4290     pointer->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
4291     pointer->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN);
4292     int32_t id = 100;
4293     PointerEvent::PointerItem item;
4294     item.SetPointerId(id);
4295     pointer->AddPointerItem(item);
4296     pointer->SetPointerId(0);
4297     pointer->SetZOrder(-1);
4298     int32_t ret = handler.SaveTargetWindowId(pointer, false);
4299     EXPECT_EQ(ret, RET_ERR);
4300     pointer->SetDeviceId(111);
4301     pointer->SetZOrder(1);
4302     pointer->SetPointerAction(PointerEvent::POINTER_ACTION_HOVER_ENTER);
4303     ret = handler.SaveTargetWindowId(pointer, false);
4304     EXPECT_EQ(ret, RET_ERR);
4305     pointer->SetDeviceId(-1);
4306     pointer->SetZOrder(-1);
4307     ret = handler.SaveTargetWindowId(pointer, false);
4308     EXPECT_EQ(ret, RET_ERR);
4309     ret = handler.SaveTargetWindowId(pointer, false);
4310     EXPECT_EQ(ret, RET_ERR);
4311 }
4312 
4313 /**
4314 @tc.name: ServerMsgHandlerTest_FixTargetWindowId_009
4315 @tc.desc: Test FixTargetWindowId
4316 @tc.type: FUNC
4317 @tc.require:
4318 */
4319 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId_009, TestSize.Level1)
4320 {
4321     CALL_TEST_DEBUG;
4322     ServerMsgHandler handler;
4323     handler.shellTargetWindowIds_.clear();
4324     handler.castTargetWindowIds_.clear();
4325     handler.accessTargetWindowIds_.clear();
4326     handler.nativeTargetWindowIds_.clear();
4327     auto pointerEvent = PointerEvent::Create();
4328     ASSERT_NE(pointerEvent, nullptr);
4329     int32_t action = PointerEvent::POINTER_INITIAL_VALUE;
4330     std::vector<int32_t> pointerIds {pointerEvent->GetPointerIds()};
4331     int32_t pointerId = 1;
4332     PointerEvent::PointerItem item;
4333     item.SetPointerId(pointerId);
4334     pointerEvent->AddPointerItem(item);
4335     pointerEvent->SetDeviceId(111);
4336     pointerEvent->SetZOrder(1);
4337     bool result = handler.FixTargetWindowId(pointerEvent, action, false);
4338     ASSERT_FALSE(result);
4339     handler.shellTargetWindowIds_[0] = 0;
4340     action = PointerEvent::POINTER_ACTION_UNKNOWN;
4341     pointerEvent->SetDeviceId(CAST_INPUT_DEVICEID);
4342     pointerEvent->SetZOrder(-1);
4343     result = handler.FixTargetWindowId(pointerEvent, action, false);
4344     ASSERT_FALSE(result);
4345     handler.shellTargetWindowIds_[0] = 1;
4346     action = PointerEvent::POINTER_ACTION_CANCEL;
4347     pointerEvent->SetZOrder(0);
4348     result = handler.FixTargetWindowId(pointerEvent, action, false);
4349     ASSERT_FALSE(result);
4350     pointerEvent->pointers_.clear();
4351     action = PointerEvent::POINTER_ACTION_DOWN;
4352     pointerEvent->SetZOrder(1);
4353     result = handler.FixTargetWindowId(pointerEvent, action, false);
4354     ASSERT_FALSE(result);
4355 }
4356 
4357 /**
4358  * @tc.name: ServerMsgHandlerTest_DealGesturePointers
4359  * @tc.desc: Test the function DealGesturePointers
4360  * @tc.type: FUNC
4361  * @tc.require:
4362  */
4363 HWTEST_F(ServerMsgHandlerTest, DealGesturePointers003, TestSize.Level1)
4364 {
4365     CALL_TEST_DEBUG;
4366     ServerMsgHandler handler;
4367     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4368     ASSERT_NE(pointerEvent, nullptr);
4369     pointerEvent->SetId(1);
4370     pointerEvent->eventType_ = 1;
4371     pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN);
4372     pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
4373     handler.nativeTargetWindowIds_.insert(std::make_pair(pointerEvent->GetPointerId(), 10));
4374     std::list<PointerEvent::PointerItem> pointers_;
4375     PointerEvent::PointerItem item1;
4376     item1.SetPointerId(1);
4377     PointerEvent::PointerItem item2;
4378     item2.SetPointerId(2);
4379     pointers_.push_back(item1);
4380     pointers_.push_back(item2);
4381     pointerEvent->AddPointerItem(item1);
4382     pointerEvent->AddPointerItem(item2);
4383     bool ret = pointerEvent->GetPointerItem(pointerEvent->pointerId_, item2);
4384     EXPECT_FALSE(ret);
4385     ASSERT_NO_FATAL_FAILURE(handler.DealGesturePointers(pointerEvent));
4386 }
4387 
4388 /**
4389 @tc.name: ServerMsgHandlerTest_FixTargetWindowId_01
4390 @tc.desc: Test FixTargetWindowId
4391 @tc.type: FUNC
4392 @tc.require:
4393 */
4394 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId01, TestSize.Level1)
4395 {
4396     CALL_TEST_DEBUG;
4397     ServerMsgHandler handler;
4398     handler.shellTargetWindowIds_.clear();
4399     std::shared_ptr<PointerEvent> pointerEvent = nullptr;
4400     std::map<int32_t, int32_t> targetWindowIdMap = {
4401         {PointerEvent::SOURCE_TYPE_MOUSE, PointerEvent::SOURCE_TYPE_TOUCHSCREEN},
4402         {PointerEvent::POINTER_ACTION_BUTTON_DOWN, PointerEvent::POINTER_ACTION_DOWN},
4403         {PointerEvent::MOUSE_BUTTON_LEFT, PointerEvent::POINTER_INITIAL_VALUE}
4404     };
4405     bool bNeedResetPointerId = false;
4406     int32_t diffPointerId = 0;
4407     int32_t result = handler.FixTargetWindowId(pointerEvent, targetWindowIdMap, bNeedResetPointerId, diffPointerId);
4408     EXPECT_EQ(result, RET_ERR);
4409 }
4410 
4411 /**
4412 @tc.name: ServerMsgHandlerTest_FixTargetWindowId_02
4413 @tc.desc: Test FixTargetWindowId
4414 @tc.type: FUNC
4415 @tc.require:
4416 */
4417 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_FixTargetWindowId02, TestSize.Level1)
4418 {
4419     CALL_TEST_DEBUG;
4420     ServerMsgHandler handler;
4421     handler.shellTargetWindowIds_.clear();
4422     std::shared_ptr<PointerEvent> pointerEvent = PointerEvent::Create();
4423     ASSERT_NE(pointerEvent, nullptr);
4424 
4425     pointerEvent->SetPointerId(999);
4426     std::map<int32_t, int32_t> targetWindowIdMap;
4427     bool bNeedResetPointerId = true;
4428     int32_t diffPointerId = 0;
4429     int32_t result = handler.FixTargetWindowId(pointerEvent, targetWindowIdMap, bNeedResetPointerId, diffPointerId);
4430     EXPECT_EQ(result, RET_ERR);
4431 
4432     PointerEvent::PointerItem item;
4433     item.SetPointerId(1);
4434     pointerEvent->AddPointerItem(item);
4435     pointerEvent->SetPointerId(1);
4436     bNeedResetPointerId = true;
4437     diffPointerId = -5;
4438     result = handler.FixTargetWindowId(pointerEvent, targetWindowIdMap, bNeedResetPointerId, diffPointerId);
4439     EXPECT_EQ(result, RET_ERR);
4440 }
4441 
4442 /**
4443  * @tc.name: ServerMsgHandlerTest_OnDisplayInfo_08
4444  * @tc.desc: Test the function OnDisplayInfo_08
4445  * @tc.type: FUNC
4446  * @tc.require:
4447  */
4448 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_08, TestSize.Level1)
4449 {
4450     CALL_TEST_DEBUG;
4451     ServerMsgHandler handler;
4452     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
4453     sess->SetTokenType(TokenType::TOKEN_NATIVE);
4454     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
4455     int32_t userId = 0;
4456     pkt << userId;
4457     uint32_t screenNum = 1;
4458     pkt << screenNum;
4459     ScreenInfo screenInfo;
4460     pkt << screenInfo.id << screenInfo.uniqueId << screenInfo.screenType << screenInfo.width << screenInfo.height
4461         << screenInfo.physicalWidth << screenInfo.physicalHeight << screenInfo.tpDirection << screenInfo.dpi
4462         << screenInfo.ppi << screenInfo.rotation;
4463     uint32_t groupNum = 1;
4464     pkt << groupNum;
4465     DisplayGroupInfo groupInfo;
4466     pkt << groupInfo.id << groupInfo.name << groupInfo.type << groupInfo.mainDisplayId << groupInfo.focusWindowId;
4467     uint32_t displayNum = 1;
4468     pkt << displayNum;
4469     DisplayInfo displayInfo;
4470     pkt << displayInfo.id << displayInfo.x << displayInfo.y << displayInfo.width << displayInfo.height
4471         << displayInfo.dpi << displayInfo.name << displayInfo.direction << displayInfo.displayDirection
4472         << displayInfo.displayMode << displayInfo.transform << displayInfo.scalePercent << displayInfo.expandHeight
4473         << displayInfo.isCurrentOffScreenRendering << displayInfo.displaySourceMode << displayInfo.oneHandX
4474         << displayInfo.oneHandY << displayInfo.screenArea << displayInfo.rsId << displayInfo.offsetX
4475         << displayInfo.offsetY << displayInfo.pointerActiveWidth << displayInfo.pointerActiveHeight;
4476     uint32_t windowNum = 1;
4477     pkt << windowNum;
4478     WindowInfo windowInfo;
4479     int32_t byteCount = 0;
4480     pkt << windowInfo.id << windowInfo.pid << windowInfo.uid << windowInfo.area << windowInfo.defaultHotAreas
4481         << windowInfo.pointerHotAreas << windowInfo.agentWindowId << windowInfo.flags << windowInfo.action
4482         << windowInfo.displayId << windowInfo.groupId << windowInfo.zOrder << windowInfo.pointerChangeAreas
4483         << windowInfo.transform << windowInfo.windowInputType << windowInfo.privacyMode << windowInfo.windowType
4484         << windowInfo.isSkipSelfWhenShowOnVirtualScreen << windowInfo.windowNameType << byteCount;
4485     int32_t result = handler.OnDisplayInfo(sess, pkt);
4486     EXPECT_EQ(result, RET_ERR);
4487 }
4488 
4489 /**
4490  * @tc.name: ServerMsgHandlerTest_OnDisplayInfo_09
4491  * @tc.desc: Test the function OnDisplayInfo_09
4492  * @tc.type: FUNC
4493  * @tc.require:
4494  */
4495 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnDisplayInfo_09, TestSize.Level1)
4496 {
4497     CALL_TEST_DEBUG;
4498     ServerMsgHandler handler;
4499     SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
4500     sess->SetTokenType(TokenType::TOKEN_HAP);
4501     NetPacket pkt(MmiMessageId::DISPLAY_INFO);
4502     int32_t result = handler.OnDisplayInfo(sess, pkt);
4503     EXPECT_EQ(result, RET_ERR);
4504 }
4505 
4506 /**
4507  * @tc.name: ServerMsgHandlerTest_OnRemoveInputHandler_002
4508  * @tc.desc: Test the function OnRemoveInputHandler
4509  * @tc.type: FUNC
4510  * @tc.require:
4511  */
4512 HWTEST_F(ServerMsgHandlerTest, ServerMsgHandlerTest_OnRemoveInputHandler_002, TestSize.Level1)
4513 {
4514     CALL_TEST_DEBUG;
4515     ServerMsgHandler handler;
4516     SessionPtr sess = nullptr;
4517     InputHandlerType handlerType = InputHandlerType::INTERCEPTOR;
4518     HandleEventType eventType = 1;
4519     int32_t priority = 1;
4520     uint32_t deviceTags = 0x01;
4521     EXPECT_EQ(
4522         handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags), ERROR_NULL_POINTER);
4523     sess = std::make_shared<UDSSession>(PROGRAM_NAME, g_moduleType, g_writeFd, UID_ROOT, g_pid);
4524     handlerType = InputHandlerType::NONE;
4525     priority = 2;
4526     deviceTags = 3;
4527     auto ret = handler.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags);
4528     EXPECT_EQ(ret, RET_OK);
4529     ret = handler.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags);
4530     EXPECT_EQ(ret, RET_OK);
4531 }
4532 } // namespace MMI
4533 } // namespace OHOS
4534