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