• 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 <vector>
17 
18 #include <gtest/gtest.h>
19 
20 #include "key_shortcut_manager.h"
21 #include "mmi_log.h"
22 
23 #undef MMI_LOG_DOMAIN
24 #define MMI_LOG_DOMAIN MMI_LOG_HANDLER
25 #undef MMI_LOG_TAG
26 #define MMI_LOG_TAG "KeyShortcutManagerTest"
27 
28 namespace OHOS {
29 namespace MMI {
30 namespace {
31 constexpr int32_t NO_LONG_PRESS { 0 };
32 constexpr int32_t DEFAULT_LONG_PRESS_TIME { 100 }; // 100ms
33 constexpr int32_t TWICE_LONG_PRESS_TIME { DEFAULT_LONG_PRESS_TIME + DEFAULT_LONG_PRESS_TIME };
34 constexpr int32_t BASE_SHORTCUT_ID { 1 };
35 constexpr int32_t DEFAULT_SAMPLING_PERIOD { 8 }; // 8ms
36 }
37 
38 using namespace testing;
39 using namespace testing::ext;
40 
41 class KeyShortcutManagerTest : public testing::Test {
42 public:
SetUpTestCase(void)43     static void SetUpTestCase(void) {}
TearDownTestCase(void)44     static void TearDownTestCase(void) {}
45 
46     std::shared_ptr<KeyEvent> TriggerSystemKey01();
47     std::shared_ptr<KeyEvent> TriggerSystemKey02();
48     std::shared_ptr<KeyEvent> TriggerSystemKey03();
49     std::shared_ptr<KeyEvent> TriggerSystemKey04();
50     std::shared_ptr<KeyEvent> TriggerSystemKey05();
51     std::shared_ptr<KeyEvent> TriggerSystemKey06();
52     std::shared_ptr<KeyEvent> TriggerSystemKey07();
53     std::shared_ptr<KeyEvent> TriggerGlobalKey01();
54     std::shared_ptr<KeyEvent> TriggerGlobalKey0101();
55     std::shared_ptr<KeyEvent> ResetAllTriggering();
56 };
57 
58 /**
59  * @tc.name: KeyShortcutManagerTest_SystemKey_01
60  * @tc.desc: We can register system shortcut key that consist of modifiers only.
61  * @tc.type: FUNC
62  * @tc.require:
63  */
64 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_01, TestSize.Level1)
65 {
66     CALL_TEST_DEBUG;
67     KeyShortcutManager::SystemShortcutKey sysKey {
68         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_RIGHT },
69         .finalKey = KeyShortcutManager::SHORTCUT_PURE_MODIFIERS,
70     };
71     KeyShortcutManager shortcutMgr;
72     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
73     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
74 }
75 
76 /**
77  * @tc.name: KeyShortcutManagerTest_SystemKey_02
78  * @tc.desc: We can register system shortcut key that consist of modifiers and
79  *           single non-modifier key, with the non-modifier key as final key.
80  * @tc.type: FUNC
81  * @tc.require:
82  */
83 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_02, TestSize.Level1)
84 {
85     CALL_TEST_DEBUG;
86     KeyShortcutManager::SystemShortcutKey sysKey {
87         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_RIGHT },
88         .finalKey = KeyEvent::KEYCODE_S,
89     };
90     KeyShortcutManager shortcutMgr;
91     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
92     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
93 }
94 
95 /**
96  * @tc.name: KeyShortcutManagerTest_SystemKey_03
97  * @tc.desc: We can register system shortcut key that consist of modifiers and
98  *           single non-modifier key, with the non-modifier key as final key.
99  * @tc.type: FUNC
100  * @tc.require:
101  */
102 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_03, TestSize.Level1)
103 {
104     CALL_TEST_DEBUG;
105     KeyShortcutManager::SystemShortcutKey sysKey {
106         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT },
107         .finalKey = KeyEvent::KEYCODE_BACKSLASH,
108     };
109     KeyShortcutManager shortcutMgr;
110     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
111     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
112 }
113 
114 /**
115  * @tc.name: KeyShortcutManagerTest_SystemKey_04
116  * @tc.desc: We can register system shortcut key that consist of modifiers and
117  *           single non-modifier key, with the non-modifier key as final key.
118  * @tc.type: FUNC
119  * @tc.require:
120  */
121 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_04, TestSize.Level1)
122 {
123     CALL_TEST_DEBUG;
124     KeyShortcutManager::SystemShortcutKey sysKey {
125         .finalKey = KeyEvent::KEYCODE_A,
126     };
127     KeyShortcutManager shortcutMgr;
128     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
129     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
130 }
131 
132 /**
133  * @tc.name: KeyShortcutManagerTest_SystemKey_05
134  * @tc.desc: Only 'LOGO' can be single-key shortcut.
135  * @tc.type: FUNC
136  * @tc.require:
137  */
138 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_05, TestSize.Level1)
139 {
140     CALL_TEST_DEBUG;
141     KeyShortcutManager::SystemShortcutKey sysKey {
142         .modifiers = { KeyEvent::KEYCODE_META_LEFT },
143         .finalKey = KeyShortcutManager::SHORTCUT_PURE_MODIFIERS,
144     };
145     KeyShortcutManager shortcutMgr;
146     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
147     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
148 }
149 
150 /**
151  * @tc.name: KeyShortcutManagerTest_SystemKey_06
152  * @tc.desc: Only 'LOGO' can be single-key shortcut.
153  * @tc.type: FUNC
154  * @tc.require:
155  */
156 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_06, TestSize.Level1)
157 {
158     CALL_TEST_DEBUG;
159     KeyShortcutManager::SystemShortcutKey sysKey {
160         .modifiers = { KeyEvent::KEYCODE_SHIFT_LEFT },
161         .finalKey = KeyShortcutManager::SHORTCUT_PURE_MODIFIERS,
162     };
163     KeyShortcutManager shortcutMgr;
164     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
165     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
166 }
167 
168 /**
169  * @tc.name: KeyShortcutManagerTest_SystemKey_07
170  * @tc.desc: Can not register reserved system key.
171  * @tc.type: FUNC
172  * @tc.require:
173  */
174 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_07, TestSize.Level1)
175 {
176     CALL_TEST_DEBUG;
177     KeyShortcutManager::SystemShortcutKey sysKey {
178         .modifiers = { KeyEvent::KEYCODE_META_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
179         .finalKey = KeyEvent::KEYCODE_S,
180     };
181     KeyShortcutManager shortcutMgr;
182     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
183     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
184 }
185 
186 /**
187  * @tc.name: KeyShortcutManagerTest_SystemKey_08
188  * @tc.desc: System key support DOWN and UP trigger.
189  * @tc.type: FUNC
190  * @tc.require:
191  */
192 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_08, TestSize.Level1)
193 {
194     CALL_TEST_DEBUG;
195     KeyShortcutManager::SystemShortcutKey sysKey {
196         .modifiers = { KeyEvent::KEYCODE_META_LEFT },
197         .finalKey = KeyEvent::KEYCODE_D,
198         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_UP,
199     };
200     KeyShortcutManager shortcutMgr;
201     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
202     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
203 }
204 
205 /**
206  * @tc.name: KeyShortcutManagerTest_SystemKey_09
207  * @tc.desc: System key support long press.
208  * @tc.type: FUNC
209  * @tc.require:
210  */
211 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_SystemKey_09, TestSize.Level1)
212 {
213     CALL_TEST_DEBUG;
214     KeyShortcutManager::SystemShortcutKey sysKey {
215         .modifiers = { KeyEvent::KEYCODE_META_LEFT },
216         .finalKey = KeyEvent::KEYCODE_D,
217         .longPressTime = DEFAULT_LONG_PRESS_TIME,
218         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_UP,
219     };
220     KeyShortcutManager shortcutMgr;
221     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
222     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
223 }
224 
225 /**
226  * @tc.name: KeyShortcutManagerTest_GlobalKey_01
227  * @tc.desc: Global shortcut key that consist of modifiers and single non-modifier key,
228  *           with the non-modifier key as final key.
229  * @tc.type: FUNC
230  * @tc.require:
231  */
232 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GlobalKey_01, TestSize.Level1)
233 {
234     CALL_TEST_DEBUG;
235     KeyShortcutManager::HotKey globalKey {
236         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
237         .finalKey = KeyEvent::KEYCODE_M,
238     };
239     KeyShortcutManager shortcutMgr;
240     int32_t shortcutId = shortcutMgr.RegisterHotKey(globalKey);
241     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
242 }
243 
244 /**
245  * @tc.name: KeyShortcutManagerTest_GlobalKey_02
246  * @tc.desc: Global shortcut key that consist of modifiers and single non-modifier key,
247  *           with the non-modifier key as final key.
248  * @tc.type: FUNC
249  * @tc.require:
250  */
251 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GlobalKey_02, TestSize.Level1)
252 {
253     CALL_TEST_DEBUG;
254     KeyShortcutManager::HotKey globalKey {
255         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
256         .finalKey = KeyShortcutManager::SHORTCUT_PURE_MODIFIERS,
257     };
258     KeyShortcutManager shortcutMgr;
259     int32_t shortcutId = shortcutMgr.RegisterHotKey(globalKey);
260     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
261 }
262 
263 /**
264  * @tc.name: KeyShortcutManagerTest_GlobalKey_03
265  * @tc.desc: Global shortcut key that consist of modifiers and single non-modifier key,
266  *           with the non-modifier key as final key.
267  * @tc.type: FUNC
268  * @tc.require:
269  */
270 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GlobalKey_03, TestSize.Level1)
271 {
272     CALL_TEST_DEBUG;
273     KeyShortcutManager::HotKey globalKey {
274         .finalKey = KeyEvent::KEYCODE_M,
275     };
276     KeyShortcutManager shortcutMgr;
277     int32_t shortcutId = shortcutMgr.RegisterHotKey(globalKey);
278     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
279 }
280 
281 /**
282  * @tc.name: KeyShortcutManagerTest_GlobalKey_04
283  * @tc.desc: 'LOGO' can not be modifier of Global shortcut key.
284  * @tc.type: FUNC
285  * @tc.require:
286  */
287 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GlobalKey_04, TestSize.Level1)
288 {
289     CALL_TEST_DEBUG;
290     KeyShortcutManager::HotKey globalKey {
291         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_META_LEFT },
292         .finalKey = KeyEvent::KEYCODE_M,
293     };
294     KeyShortcutManager shortcutMgr;
295     int32_t shortcutId = shortcutMgr.RegisterHotKey(globalKey);
296     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
297 }
298 
299 /**
300  * @tc.name: KeyShortcutManagerTest_GlobalKey_05
301  * @tc.desc: We can not register registered system key as global shortcut key.
302  * @tc.type: FUNC
303  * @tc.require:
304  */
305 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GlobalKey_05, TestSize.Level1)
306 {
307     CALL_TEST_DEBUG;
308     KeyShortcutManager::SystemShortcutKey sysKey {
309         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
310         .finalKey = KeyEvent::KEYCODE_M,
311     };
312     KeyShortcutManager shortcutMgr;
313     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
314     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
315 
316     KeyShortcutManager::HotKey globalKey {
317         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
318         .finalKey = KeyEvent::KEYCODE_M,
319     };
320     shortcutId = shortcutMgr.RegisterHotKey(globalKey);
321     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
322 }
323 
324 /**
325  * @tc.name: KeyShortcutManagerTest_GlobalKey_06
326  * @tc.desc: We can not register reserved system key as global shortcut key.
327  * @tc.type: FUNC
328  * @tc.require:
329  */
330 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GlobalKey_06, TestSize.Level1)
331 {
332     CALL_TEST_DEBUG;
333     KeyShortcutManager::HotKey globalKey {
334         .modifiers = { KeyEvent::KEYCODE_META_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
335         .finalKey = KeyEvent::KEYCODE_S,
336     };
337     KeyShortcutManager shortcutMgr;
338     int32_t shortcutId = shortcutMgr.RegisterHotKey(globalKey);
339     EXPECT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
340 }
341 
342 /**
343  * @tc.name: KeyShortcutManagerTest_GlobalKey_07
344  * @tc.desc: We can register a global shortcut key only once.
345  * @tc.type: FUNC
346  * @tc.require:
347  */
348 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GlobalKey_07, TestSize.Level1)
349 {
350     CALL_TEST_DEBUG;
351     KeyShortcutManager shortcutMgr;
352     KeyShortcutManager::HotKey globalKey {
353         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
354         .finalKey = KeyEvent::KEYCODE_M,
355     };
356     int32_t shortcutId = shortcutMgr.RegisterHotKey(globalKey);
357     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
358     shortcutId = shortcutMgr.RegisterHotKey(globalKey);
359     EXPECT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
360 }
361 
TriggerSystemKey01()362 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerSystemKey01()
363 {
364     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
365     CHKPP(keyEvent);
366     int64_t now = GetSysClockTime();
367     KeyEvent::KeyItem keyItem {};
368     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
369     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD));
370     keyItem.SetPressed(true);
371     keyEvent->AddKeyItem(keyItem);
372 
373     keyItem.SetKeyCode(KeyEvent::KEYCODE_SHIFT_LEFT);
374     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
375     keyEvent->AddKeyItem(keyItem);
376 
377     keyItem.SetKeyCode(KeyEvent::KEYCODE_S);
378     keyItem.SetDownTime(now);
379     keyEvent->AddKeyItem(keyItem);
380 
381     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
382     keyEvent->SetKeyCode(KeyEvent::KEYCODE_S);
383     keyEvent->SetActionTime(now);
384     return keyEvent;
385 }
386 
387 /**
388  * @tc.name: KeyShortcutManagerTest_TriggerSystemKey_01
389  * @tc.desc: Trigger system key immediately.
390  * @tc.type: FUNC
391  * @tc.require:
392  */
393 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerSystemKey_01, TestSize.Level1)
394 {
395     CALL_TEST_DEBUG;
396     bool triggered = false;
397     KeyShortcutManager::SystemShortcutKey sysKey {
398         .modifiers = { KeyEvent::KEYCODE_SHIFT_LEFT },
399         .finalKey = KeyEvent::KEYCODE_S,
400         .longPressTime = NO_LONG_PRESS,
401         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0202() 402         .callback = [&triggered](std::shared_ptr<KeyEvent> keyEvent) {
403             triggered = true;
404         },
405     };
406     KeyShortcutManager shortcutMgr;
407     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
408     ASSERT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
409 
410     auto keyEvent = TriggerSystemKey01();
411     ASSERT_TRUE(keyEvent != nullptr);
412     EXPECT_FALSE(shortcutMgr.HandleEvent(keyEvent));
413     EXPECT_FALSE(triggered);
414 }
415 
TriggerSystemKey02()416 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerSystemKey02()
417 {
418     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
419     CHKPP(keyEvent);
420     int64_t now = GetSysClockTime();
421     KeyEvent::KeyItem keyItem {};
422     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
423     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD));
424     keyItem.SetPressed(true);
425     keyEvent->AddKeyItem(keyItem);
426 
427     keyItem.SetKeyCode(KeyEvent::KEYCODE_SHIFT_LEFT);
428     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
429     keyEvent->AddKeyItem(keyItem);
430 
431     keyItem.SetKeyCode(KeyEvent::KEYCODE_S);
432     keyItem.SetDownTime(now);
433     keyEvent->AddKeyItem(keyItem);
434 
435     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
436     keyEvent->SetKeyCode(KeyEvent::KEYCODE_S);
437     keyEvent->SetActionTime(now);
438     return keyEvent;
439 }
440 
441 /**
442  * @tc.name: KeyShortcutManagerTest_TriggerSystemKey_02
443  * @tc.desc: Trigger system key immediately.
444  * @tc.type: FUNC
445  * @tc.require:
446  */
447 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerSystemKey_02, TestSize.Level1)
448 {
449     CALL_TEST_DEBUG;
450     bool triggered = false;
451     KeyShortcutManager::SystemShortcutKey sysKey {
452         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT },
453         .finalKey = KeyEvent::KEYCODE_S,
454         .longPressTime = NO_LONG_PRESS,
455         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0302() 456         .callback = [&triggered](std::shared_ptr<KeyEvent> keyEvent) {
457             triggered = true;
458         },
459     };
460     KeyShortcutManager shortcutMgr;
461     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
462     ASSERT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
463 
464     auto keyEvent = TriggerSystemKey02();
465     ASSERT_TRUE(keyEvent != nullptr);
466     EXPECT_FALSE(shortcutMgr.HandleEvent(keyEvent));
467     EXPECT_FALSE(triggered);
468 }
469 
TriggerSystemKey03()470 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerSystemKey03()
471 {
472     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
473     CHKPP(keyEvent);
474     int64_t now = GetSysClockTime();
475     KeyEvent::KeyItem keyItem {};
476     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
477     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
478     keyItem.SetPressed(true);
479     keyEvent->AddKeyItem(keyItem);
480 
481     keyItem.SetKeyCode(KeyEvent::KEYCODE_S);
482     keyItem.SetDownTime(now);
483     keyEvent->AddKeyItem(keyItem);
484 
485     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
486     keyEvent->SetKeyCode(KeyEvent::KEYCODE_S);
487     keyEvent->SetActionTime(now);
488     return keyEvent;
489 }
490 
491 /**
492  * @tc.name: KeyShortcutManagerTest_TriggerSystemKey_03
493  * @tc.desc: Long press system key.
494  * @tc.type: FUNC
495  * @tc.require:
496  */
497 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerSystemKey_03, TestSize.Level1)
498 {
499     CALL_TEST_DEBUG;
500     std::mutex mutex;
501     std::condition_variable condVar;
502     int32_t keyCode = KeyEvent::KEYCODE_UNKNOWN;
503     KeyShortcutManager::SystemShortcutKey sysKey {
504         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT },
505         .finalKey = KeyEvent::KEYCODE_S,
506         .longPressTime = DEFAULT_LONG_PRESS_TIME,
507         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0402() 508         .callback = [&](std::shared_ptr<KeyEvent> keyEvent) {
509             std::unique_lock<std::mutex> lock(mutex);
510             keyCode = keyEvent->GetKeyCode();
511             condVar.notify_all();
512         },
513     };
514     std::unique_lock<std::mutex> lock(mutex);
515     KeyShortcutManager shortcutMgr;
516     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
517     ASSERT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
518 
519     auto keyEvent = TriggerSystemKey03();
520     ASSERT_TRUE(keyEvent != nullptr);
521     EXPECT_FALSE(shortcutMgr.HandleEvent(keyEvent));
522     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
523     bool cvRet = condVar.wait_for(lock, std::chrono::milliseconds(TWICE_LONG_PRESS_TIME),
__anon7774e7bc0502() 524         [&keyCode]() {
525             return (keyCode != KeyEvent::KEYCODE_UNKNOWN);
526         });
527     EXPECT_FALSE(cvRet);
528     EXPECT_NE(keyCode, KeyEvent::KEYCODE_S);
529 }
530 
TriggerSystemKey04()531 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerSystemKey04()
532 {
533     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
534     CHKPP(keyEvent);
535     int64_t now = GetSysClockTime();
536     KeyEvent::KeyItem keyItem {};
537     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
538     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD));
539     keyItem.SetPressed(true);
540     keyEvent->AddKeyItem(keyItem);
541 
542     keyItem.SetKeyCode(KeyEvent::KEYCODE_S);
543     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
544     keyEvent->AddKeyItem(keyItem);
545 
546     keyItem.SetKeyCode(KeyEvent::KEYCODE_A);
547     keyItem.SetDownTime(now);
548     keyEvent->AddKeyItem(keyItem);
549 
550     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
551     keyEvent->SetKeyCode(KeyEvent::KEYCODE_A);
552     keyEvent->SetActionTime(now);
553     return keyEvent;
554 }
555 
556 /**
557  * @tc.name: KeyShortcutManagerTest_TriggerSystemKey_04
558  * @tc.desc: Reset pending shortcut when press down another key.
559  * @tc.type: FUNC
560  * @tc.require:
561  */
562 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerSystemKey_04, TestSize.Level1)
563 {
564     CALL_TEST_DEBUG;
565     std::mutex mutex;
566     std::condition_variable condVar;
567     int32_t keyCode = KeyEvent::KEYCODE_UNKNOWN;
568     KeyShortcutManager::SystemShortcutKey sysKey {
569         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT },
570         .finalKey = KeyEvent::KEYCODE_S,
571         .longPressTime = DEFAULT_LONG_PRESS_TIME,
572         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0602() 573         .callback = [&](std::shared_ptr<KeyEvent> keyEvent) {
574             std::unique_lock<std::mutex> lock(mutex);
575             keyCode = keyEvent->GetKeyCode();
576             condVar.notify_all();
577         },
578     };
579     std::unique_lock<std::mutex> lock(mutex);
580     KeyShortcutManager shortcutMgr;
581     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
582     ASSERT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
583 
584     auto keyEvent = TriggerSystemKey03();
585     ASSERT_TRUE(keyEvent != nullptr);
586     EXPECT_FALSE(shortcutMgr.HandleEvent(keyEvent));
587     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
588 
589     keyEvent = TriggerSystemKey04();
590     ASSERT_TRUE(keyEvent != nullptr);
591     EXPECT_FALSE(shortcutMgr.HandleEvent(keyEvent));
592     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
593 
594     bool cvRet = condVar.wait_for(lock, std::chrono::milliseconds(TWICE_LONG_PRESS_TIME),
__anon7774e7bc0702() 595         [&keyCode]() {
596             return (keyCode != KeyEvent::KEYCODE_UNKNOWN);
597         });
598     EXPECT_FALSE(cvRet);
599     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
600 }
601 
TriggerSystemKey05()602 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerSystemKey05()
603 {
604     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
605     CHKPP(keyEvent);
606     int64_t now = GetSysClockTime();
607     KeyEvent::KeyItem keyItem {};
608     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
609     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD));
610     keyItem.SetPressed(false);
611     keyEvent->AddKeyItem(keyItem);
612 
613     keyItem.SetKeyCode(KeyEvent::KEYCODE_S);
614     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
615     keyItem.SetPressed(true);
616     keyEvent->AddKeyItem(keyItem);
617 
618     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
619     keyEvent->SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
620     keyEvent->SetActionTime(now);
621     return keyEvent;
622 }
623 
624 /**
625  * @tc.name: KeyShortcutManagerTest_TriggerSystemKey_05
626  * @tc.desc: Reset pending shortcut when lift up dedicated key(s) before running shortcut.
627  * @tc.type: FUNC
628  * @tc.require:
629  */
630 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerSystemKey_05, TestSize.Level1)
631 {
632     CALL_TEST_DEBUG;
633     std::mutex mutex;
634     std::condition_variable condVar;
635     int32_t keyCode = KeyEvent::KEYCODE_UNKNOWN;
636     KeyShortcutManager::SystemShortcutKey sysKey {
637         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT },
638         .finalKey = KeyEvent::KEYCODE_S,
639         .longPressTime = DEFAULT_LONG_PRESS_TIME,
640         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0802() 641         .callback = [&](std::shared_ptr<KeyEvent> keyEvent) {
642             std::unique_lock<std::mutex> lock(mutex);
643             keyCode = keyEvent->GetKeyCode();
644             condVar.notify_all();
645         },
646     };
647     std::unique_lock<std::mutex> lock(mutex);
648     KeyShortcutManager shortcutMgr;
649     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
650     ASSERT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
651 
652     auto keyEvent = TriggerSystemKey03();
653     ASSERT_TRUE(keyEvent != nullptr);
654     EXPECT_FALSE(shortcutMgr.HandleEvent(keyEvent));
655     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
656 
657     keyEvent = TriggerSystemKey05();
658     ASSERT_TRUE(keyEvent != nullptr);
659     EXPECT_FALSE(shortcutMgr.HandleEvent(keyEvent));
660     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
661 
662     bool cvRet = condVar.wait_for(lock, std::chrono::milliseconds(TWICE_LONG_PRESS_TIME),
__anon7774e7bc0902() 663         [&keyCode]() {
664             return (keyCode != KeyEvent::KEYCODE_UNKNOWN);
665         });
666     EXPECT_FALSE(cvRet);
667     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
668 }
669 
TriggerSystemKey06()670 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerSystemKey06()
671 {
672     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
673     CHKPP(keyEvent);
674     int64_t now = GetSysClockTime();
675     KeyEvent::KeyItem keyItem {};
676     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
677     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_LONG_PRESS_TIME));
678     keyItem.SetPressed(true);
679     keyEvent->AddKeyItem(keyItem);
680 
681     keyItem.SetKeyCode(KeyEvent::KEYCODE_S);
682     keyItem.SetDownTime(now - MS2US(DEFAULT_LONG_PRESS_TIME));
683     keyItem.SetPressed(false);
684     keyEvent->AddKeyItem(keyItem);
685 
686     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
687     keyEvent->SetKeyCode(KeyEvent::KEYCODE_S);
688     keyEvent->SetActionTime(now);
689     return keyEvent;
690 }
691 
692 /**
693  * @tc.name: KeyShortcutManagerTest_TriggerSystemKey_06
694  * @tc.desc: Trigger key-up-trigger system key.
695  * @tc.type: FUNC
696  * @tc.require:
697  */
698 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerSystemKey_06, TestSize.Level1)
699 {
700     CALL_TEST_DEBUG;
701     bool triggered = false;
702     KeyShortcutManager::SystemShortcutKey sysKey {
703         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT },
704         .finalKey = KeyEvent::KEYCODE_S,
705         .longPressTime = DEFAULT_LONG_PRESS_TIME,
706         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_UP,
__anon7774e7bc0a02() 707         .callback = [&triggered](std::shared_ptr<KeyEvent> keyEvent) {
708             triggered = true;
709         },
710     };
711     KeyShortcutManager shortcutMgr;
712     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
713     ASSERT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
714 
715     auto keyEvent = TriggerSystemKey06();
716     ASSERT_TRUE(keyEvent != nullptr);
717     ASSERT_FALSE(shortcutMgr.HandleEvent(keyEvent));
718     ASSERT_FALSE(triggered);
719 }
720 
TriggerSystemKey07()721 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerSystemKey07()
722 {
723     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
724     CHKPP(keyEvent);
725     int64_t now = GetSysClockTime();
726     KeyEvent::KeyItem keyItem {};
727     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
728     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
729     keyItem.SetPressed(true);
730     keyEvent->AddKeyItem(keyItem);
731 
732     keyItem.SetKeyCode(KeyEvent::KEYCODE_SHIFT_RIGHT);
733     keyItem.SetDownTime(now);
734     keyEvent->AddKeyItem(keyItem);
735 
736     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
737     keyEvent->SetKeyCode(KeyEvent::KEYCODE_SHIFT_RIGHT);
738     keyEvent->SetActionTime(now);
739     return keyEvent;
740 }
741 
742 /**
743  * @tc.name: KeyShortcutManagerTest_TriggerSystemKey_07
744  * @tc.desc: Trigger pure-modifiers system key.
745  * @tc.type: FUNC
746  * @tc.require:
747  */
748 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerSystemKey_07, TestSize.Level1)
749 {
750     CALL_TEST_DEBUG;
751     int32_t keyCode = KeyEvent::KEYCODE_UNKNOWN;
752     KeyShortcutManager::SystemShortcutKey sysKey {
753         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
754         .finalKey = KeyShortcutManager::SHORTCUT_PURE_MODIFIERS,
755         .longPressTime = NO_LONG_PRESS,
756         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0b02() 757         .callback = [&keyCode](std::shared_ptr<KeyEvent> keyEvent) {
758             keyCode = keyEvent->GetKeyCode();
759         },
760     };
761     KeyShortcutManager shortcutMgr;
762     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
763     ASSERT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
764 
765     auto keyEvent = TriggerSystemKey07();
766     ASSERT_TRUE(keyEvent != nullptr);
767     EXPECT_TRUE(shortcutMgr.HandleEvent(keyEvent));
768     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_SHIFT_RIGHT);
769 }
770 
TriggerGlobalKey01()771 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerGlobalKey01()
772 {
773     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
774     CHKPP(keyEvent);
775     int64_t now = GetSysClockTime();
776     KeyEvent::KeyItem keyItem {};
777     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
778     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD));
779     keyItem.SetPressed(true);
780     keyEvent->AddKeyItem(keyItem);
781 
782     keyItem.SetKeyCode(KeyEvent::KEYCODE_SHIFT_LEFT);
783     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
784     keyEvent->AddKeyItem(keyItem);
785 
786     keyItem.SetKeyCode(KeyEvent::KEYCODE_A);
787     keyItem.SetDownTime(now);
788     keyEvent->AddKeyItem(keyItem);
789 
790     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
791     keyEvent->SetKeyCode(KeyEvent::KEYCODE_A);
792     keyEvent->SetActionTime(now);
793     return keyEvent;
794 }
795 
TriggerGlobalKey0101()796 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::TriggerGlobalKey0101()
797 {
798     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
799     CHKPP(keyEvent);
800     int64_t now = GetSysClockTime();
801     KeyEvent::KeyItem keyItem {};
802     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
803     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD));
804     keyItem.SetPressed(true);
805     keyEvent->AddKeyItem(keyItem);
806 
807     keyItem.SetKeyCode(KeyEvent::KEYCODE_SHIFT_LEFT);
808     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD + DEFAULT_SAMPLING_PERIOD));
809     keyEvent->AddKeyItem(keyItem);
810 
811     keyItem.SetKeyCode(KeyEvent::KEYCODE_A);
812     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
813     keyEvent->AddKeyItem(keyItem);
814 
815     keyItem.SetKeyCode(KeyEvent::KEYCODE_D);
816     keyItem.SetDownTime(now);
817     keyEvent->AddKeyItem(keyItem);
818 
819     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
820     keyEvent->SetKeyCode(KeyEvent::KEYCODE_D);
821     keyEvent->SetActionTime(now);
822     return keyEvent;
823 }
824 
825 /**
826  * @tc.name: KeyShortcutManagerTest_TriggerGlobalKey_01
827  * @tc.desc: Trigger key-up-trigger system key.
828  * @tc.type: FUNC
829  * @tc.require:
830  */
831 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerGlobalKey_01, TestSize.Level1)
832 {
833     CALL_TEST_DEBUG;
834     int32_t keyCode1 = KeyEvent::KEYCODE_UNKNOWN;
835     KeyShortcutManager::HotKey globalKey1 {
836         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
837         .finalKey = KeyEvent::KEYCODE_A,
__anon7774e7bc0c02() 838         .callback = [&keyCode1](std::shared_ptr<KeyEvent> keyEvent) {
839             keyCode1 = keyEvent->GetKeyCode();
840         },
841     };
842     KeyShortcutManager shortcutMgr;
843     int32_t shortcutId = shortcutMgr.RegisterHotKey(globalKey1);
844     ASSERT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
845 
846     int32_t keyCode2 = KeyEvent::KEYCODE_UNKNOWN;
847     KeyShortcutManager::HotKey globalKey2 {
848         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_RIGHT },
849         .finalKey = KeyEvent::KEYCODE_D,
__anon7774e7bc0d02() 850         .callback = [&keyCode2](std::shared_ptr<KeyEvent> keyEvent) {
851             keyCode2 = keyEvent->GetKeyCode();
852         },
853     };
854     shortcutId = shortcutMgr.RegisterHotKey(globalKey2);
855     ASSERT_TRUE(shortcutId >= BASE_SHORTCUT_ID);
856 
857     auto keyEvent1 = TriggerGlobalKey01();
858     ASSERT_TRUE(keyEvent1 != nullptr);
859     EXPECT_TRUE(shortcutMgr.HandleEvent(keyEvent1));
860     EXPECT_EQ(keyCode1, KeyEvent::KEYCODE_A);
861     EXPECT_EQ(keyCode2, KeyEvent::KEYCODE_UNKNOWN);
862 
863     auto keyEvent2 = TriggerGlobalKey0101();
864     ASSERT_TRUE(keyEvent2 != nullptr);
865     EXPECT_TRUE(shortcutMgr.HandleEvent(keyEvent2));
866     EXPECT_EQ(keyCode2, KeyEvent::KEYCODE_D);
867 }
868 
ResetAllTriggering()869 std::shared_ptr<KeyEvent> KeyShortcutManagerTest::ResetAllTriggering()
870 {
871     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
872     CHKPP(keyEvent);
873     int64_t now = GetSysClockTime();
874     KeyEvent::KeyItem keyItem {};
875     keyItem.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
876     keyItem.SetDownTime(now - MS2US(DEFAULT_SAMPLING_PERIOD));
877     keyItem.SetPressed(true);
878     keyEvent->AddKeyItem(keyItem);
879 
880     keyItem.SetKeyCode(KeyEvent::KEYCODE_S);
881     keyItem.SetDownTime(now);
882     keyEvent->AddKeyItem(keyItem);
883 
884     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
885     keyEvent->SetKeyCode(KeyEvent::KEYCODE_S);
886     keyEvent->SetActionTime(now);
887     return keyEvent;
888 }
889 
890 /**
891  * @tc.name: KeyShortcutManagerTest_ResetAllTriggering_01
892  * @tc.desc: Trigger key-up-trigger system key.
893  * @tc.type: FUNC
894  * @tc.require:
895  */
896 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ResetAllTriggering_01, TestSize.Level1)
897 {
898     int32_t keyCode = KeyEvent::KEYCODE_UNKNOWN;
899     KeyShortcutManager::SystemShortcutKey sysKey {
900         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT },
901         .finalKey = KeyEvent::KEYCODE_S,
902         .longPressTime = DEFAULT_LONG_PRESS_TIME,
903         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0e02() 904         .callback = [&keyCode](std::shared_ptr<KeyEvent> keyEvent) {
905             keyCode = keyEvent->GetKeyCode();
906         },
907     };
908     KeyShortcutManager shortcutMgr;
909     int32_t shortcutId = shortcutMgr.RegisterSystemKey(sysKey);
910     ASSERT_FALSE(shortcutId >= BASE_SHORTCUT_ID);
911 
912     auto keyEvent = ResetAllTriggering();
913     ASSERT_TRUE(keyEvent != nullptr);
914     ASSERT_FALSE(shortcutMgr.HandleEvent(keyEvent));
915     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
916     shortcutMgr.ResetAll();
917     std::this_thread::sleep_for(std::chrono::milliseconds(TWICE_LONG_PRESS_TIME));
918     EXPECT_EQ(keyCode, KeyEvent::KEYCODE_UNKNOWN);
919 }
920 
921 /**
922  * @tc.name: KeyShortcutManagerTest_GetInstance_01
923  * @tc.desc: Test the funcation GetInstance
924  * @tc.type: FUNC
925  * @tc.require:
926  */
927 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GetInstance_01, TestSize.Level1)
928 {
929     CALL_TEST_DEBUG;
930     KeyShortcutManager shortcutMgr;
931     shortcutMgr.instance_ = nullptr;
932     EXPECT_NO_FATAL_FAILURE(shortcutMgr.GetInstance());
933     shortcutMgr.instance_ = std::make_shared<KeyShortcutManager>();
934     ASSERT_TRUE(shortcutMgr.instance_ != nullptr);
935     EXPECT_NO_FATAL_FAILURE(shortcutMgr.GetInstance());
936 }
937 
938 /**
939  * @tc.name: KeyShortcutManagerTest_UnregisterHotKey_01
940  * @tc.desc: Test the funcation UnregisterHotKey
941  * @tc.type: FUNC
942  * @tc.require:
943  */
944 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_UnregisterHotKey_01, TestSize.Level1)
945 {
946     CALL_TEST_DEBUG;
947     bool triggered = false;
948     KeyShortcutManager::KeyShortcut keyShortcut {
949         .modifiers = KeyEvent::KEYCODE_META_LEFT,
950         .finalKey = KeyEvent::KEYCODE_T,
951         .longPressTime = DEFAULT_LONG_PRESS_TIME,
952         .triggerType = KeyShortcutManager::SHORTCUT_TRIGGER_TYPE_DOWN,
__anon7774e7bc0f02() 953         .callback = [&triggered](std::shared_ptr<KeyEvent> keyEvent) {
954             triggered = true;
955         },
956     };
957     KeyShortcutManager shortcutMgr;
958     int32_t shortcutId = 100;
959     shortcutMgr.shortcuts_[100] = keyShortcut;
960     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UnregisterHotKey(shortcutId));
961     shortcutId = 66;
962     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UnregisterHotKey(shortcutId));
963 }
964 
965 /**
966  * @tc.name: KeyShortcutManagerTest_UpdateShortcutConsumed_01
967  * @tc.desc: Test the funcation UpdateShortcutConsumed
968  * @tc.type: FUNC
969  * @tc.require:
970  */
971 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_UpdateShortcutConsumed_01, TestSize.Level1)
972 {
973     CALL_TEST_DEBUG;
974     KeyShortcutManager shortcutMgr;
975     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
976     ASSERT_NE(keyEvent, nullptr);
977     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
978     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UpdateShortcutConsumed(keyEvent));
979     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
980     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UpdateShortcutConsumed(keyEvent));
981     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UNKNOWN);
982     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UpdateShortcutConsumed(keyEvent));
983 }
984 
985 /**
986  * @tc.name: KeyShortcutManagerTest_MarkShortcutConsumed_01
987  * @tc.desc: Test the funcation MarkShortcutConsumed(ShortcutKey)
988  * @tc.type: FUNC
989  * @tc.require:
990  */
991 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_MarkShortcutConsumed_01, TestSize.Level1)
992 {
993     CALL_TEST_DEBUG;
994     KeyShortcutManager shortcutMgr;
995     ShortcutKey shortcut;
996     shortcut.preKeys = {1, 2, 3};
997     shortcut.businessId = "businessId";
998     shortcut.statusConfig = "statusConfig";
999     shortcut.statusConfigValue = true;
1000     shortcut.finalKey = 1;
1001     shortcut.keyDownDuration = 2;
1002     shortcut.triggerType = KeyEvent::KEY_ACTION_DOWN;
1003     shortcut.timerId = 1;
1004     EXPECT_NO_FATAL_FAILURE(shortcutMgr.MarkShortcutConsumed(shortcut));
1005     shortcut.triggerType = KeyEvent::KEY_ACTION_CANCEL;
1006     EXPECT_NO_FATAL_FAILURE(shortcutMgr.MarkShortcutConsumed(shortcut));
1007     shortcut.triggerType = KeyEvent::KEY_ACTION_UP;
1008     EXPECT_NO_FATAL_FAILURE(shortcutMgr.MarkShortcutConsumed(shortcut));
1009 }
1010 
1011 /**
1012  * @tc.name: KeyShortcutManagerTest_MarkShortcutConsumed_001
1013  * @tc.desc: Test the funcation MarkShortcutConsumed(KeyOption)
1014  * @tc.type: FUNC
1015  * @tc.require:
1016  */
1017 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_MarkShortcutConsumed_001, TestSize.Level1)
1018 {
1019     CALL_TEST_DEBUG;
1020     KeyShortcutManager shortcutMgr;
1021     KeyOption shortcut;
1022     std::set<int32_t> preKeys = {1, 2, 3, 4, 5};
1023     shortcut.SetPreKeys(preKeys);
1024     shortcut.SetFinalKeyDown(true);
1025     EXPECT_NO_FATAL_FAILURE(shortcutMgr.MarkShortcutConsumed(shortcut));
1026     shortcut.SetFinalKeyDown(false);
1027     EXPECT_NO_FATAL_FAILURE(shortcutMgr.MarkShortcutConsumed(shortcut));
1028 }
1029 
1030 /**
1031  * @tc.name: KeyShortcutManagerTest_ResetTriggering_01
1032  * @tc.desc: Test the funcation ResetTriggering
1033  * @tc.type: FUNC
1034  * @tc.require:
1035  */
1036 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ResetTriggering_01, TestSize.Level1)
1037 {
1038     CALL_TEST_DEBUG;
1039     KeyShortcutManager shortcutMgr;
1040     int32_t shortcutId = 1;
1041     shortcutMgr.triggering_[1] = 1;
1042     EXPECT_NO_FATAL_FAILURE(shortcutMgr.ResetTriggering(shortcutId));
1043     shortcutId = 10;
1044     EXPECT_NO_FATAL_FAILURE(shortcutMgr.ResetTriggering(shortcutId));
1045 }
1046 
1047 /**
1048  * @tc.name: KeyShortcutManagerTest_HandleEvent_001
1049  * @tc.desc: Test the funcation HandleEvent
1050  * @tc.type: FUNC
1051  * @tc.require:
1052  */
1053 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleEvent_001, TestSize.Level1)
1054 {
1055     CALL_TEST_DEBUG;
1056     KeyShortcutManager shortcutMgr;
1057     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1058     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
1059     bool ret = shortcutMgr.HandleEvent(keyEvent);
1060     ASSERT_EQ(ret, false);
1061     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UNKNOWN);
1062     ret = shortcutMgr.HandleEvent(keyEvent);
1063     ASSERT_EQ(ret, false);
1064 }
1065 
1066 /**
1067  * @tc.name: KeyShortcutManagerTest_WillResetOnKeyDown_001
1068  * @tc.desc: Test the funcation WillResetOnKeyDown
1069  * @tc.type: FUNC
1070  * @tc.require:
1071  */
1072 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_WillResetOnKeyDown_001, TestSize.Level1)
1073 {
1074     CALL_TEST_DEBUG;
1075     KeyShortcutManager shortcutMgr;
1076     int32_t keyCode = 1;
1077     KeyShortcutManager::KeyShortcut shortcut;
1078     shortcut.finalKey = 1;
1079     bool ret = shortcutMgr.WillResetOnKeyDown(keyCode, shortcut);
1080     ASSERT_EQ(ret, false);
1081     keyCode = 3;
1082     ret = shortcutMgr.WillResetOnKeyDown(keyCode, shortcut);
1083     ASSERT_EQ(ret, true);
1084 }
1085 
1086 /**
1087  * @tc.name: KeyShortcutManagerTest_WillResetOnKeyUp_001
1088  * @tc.desc: Test the funcation WillResetOnKeyUp
1089  * @tc.type: FUNC
1090  * @tc.require:
1091  */
1092 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_WillResetOnKeyUp_001, TestSize.Level1)
1093 {
1094     CALL_TEST_DEBUG;
1095     KeyShortcutManager shortcutMgr;
1096     int32_t keyCode = 1;
1097     KeyShortcutManager::KeyShortcut shortcut;
1098     shortcut.finalKey = 1;
1099     bool ret = shortcutMgr.WillResetOnKeyUp(keyCode, shortcut);
1100     ASSERT_EQ(ret, true);
1101     keyCode = 3;
1102     ret = shortcutMgr.WillResetOnKeyUp(keyCode, shortcut);
1103     ASSERT_EQ(ret, false);
1104 }
1105 
myCallback(std::shared_ptr<KeyEvent> event)1106 void myCallback(std::shared_ptr<KeyEvent> event)
1107 {
1108     std::cout << "Callback triggered!" << std::endl;
1109 }
1110 
1111 /**
1112  * @tc.name: KeyShortcutManagerTest_TriggerUp_001
1113  * @tc.desc: Test the funcation TriggerUp
1114  * @tc.type: FUNC
1115  * @tc.require:
1116  */
1117 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerUp_001, TestSize.Level1)
1118 {
1119     CALL_TEST_DEBUG;
1120     KeyShortcutManager shortcutMgr;
1121     int32_t shortcutId = 1;
1122     KeyShortcutManager::KeyShortcut shortcut;
1123     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1124     shortcut.longPressTime = -1;
1125     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1126     shortcut.callback = myCallback;
1127     shortcut.callback(keyEvent);
1128     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1129 }
1130 
1131 /**
1132  * @tc.name: KeyShortcutManagerTest_TriggerUp_002
1133  * @tc.desc: Test the funcation TriggerUp
1134  * @tc.type: FUNC
1135  * @tc.require:
1136  */
1137 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerUp_002, TestSize.Level1)
1138 {
1139     CALL_TEST_DEBUG;
1140     KeyShortcutManager shortcutMgr;
1141     int32_t shortcutId = 1;
1142     KeyShortcutManager::KeyShortcut shortcut;
1143     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1144     shortcut.longPressTime = 1000;
1145     KeyEvent::KeyItem item;
1146     item.SetKeyCode(-1);
1147     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1148     item.SetKeyCode(5);
1149     keyEvent->SetActionTime(3);
1150     item.SetDownTime(1);
1151     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1152 }
1153 
1154 /**
1155  * @tc.name: KeyShortcutManagerTest_RunShortcut_001
1156  * @tc.desc: Test the funcation RunShortcut
1157  * @tc.type: FUNC
1158  * @tc.require:
1159  */
1160 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_RunShortcut_001, TestSize.Level1)
1161 {
1162     CALL_TEST_DEBUG;
1163     KeyShortcutManager shortcutMgr;
1164     int32_t shortcutId = 1;
1165     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1166     EXPECT_NO_FATAL_FAILURE(shortcutMgr.RunShortcut(keyEvent, shortcutId));
1167 }
1168 
1169 /**
1170  * @tc.name: KeyShortcutManagerTest_RunShortcut_002
1171  * @tc.desc: Test the funcation RunShortcut
1172  * @tc.type: FUNC
1173  * @tc.require:
1174  */
1175 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_RunShortcut_002, TestSize.Level1)
1176 {
1177     CALL_TEST_DEBUG;
1178     KeyShortcutManager shortcutMgr;
1179     int32_t shortcutId = 1;
1180     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1181     KeyShortcutManager::KeyShortcut key1;
1182     shortcutMgr.shortcuts_[1] = key1;
1183     EXPECT_NO_FATAL_FAILURE(shortcutMgr.RunShortcut(keyEvent, shortcutId));
1184 }
1185 
1186 /**
1187  * @tc.name: KeyShortcutManagerTest_TriggerDown_002
1188  * @tc.desc: Test the funcation TriggerDown
1189  * @tc.type: FUNC
1190  * @tc.require:
1191  */
1192 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerDown_002, TestSize.Level1)
1193 {
1194     CALL_TEST_DEBUG;
1195     KeyShortcutManager shortcutMgr;
1196     int32_t shortcutId = 1;
1197     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1198     KeyShortcutManager::KeyShortcut shortcut;
1199     shortcut.longPressTime = -1;
1200     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerDown(keyEvent, shortcutId, shortcut));
1201     shortcut.callback = myCallback;
1202     shortcut.callback(keyEvent);
1203     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerDown(keyEvent, shortcutId, shortcut));
1204     shortcut.longPressTime = 2;
1205     shortcutMgr.triggering_[1] = 100;
1206     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerDown(keyEvent, shortcutId, shortcut));
1207 }
1208 
1209 /**
1210  * @tc.name: KeyShortcutManagerTest_HandleKeyUp_001
1211  * @tc.desc: Test the funcation HandleKeyUp
1212  * @tc.type: FUNC
1213  * @tc.require:
1214  */
1215 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleKeyUp_001, TestSize.Level1)
1216 {
1217     CALL_TEST_DEBUG;
1218     KeyShortcutManager shortcutMgr;
1219     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1220     KeyShortcutManager::KeyShortcut shortcut;
1221     shortcut.modifiers = 0x1;
1222     shortcut.finalKey = 0x2;
1223     shortcut.longPressTime = 500;
1224     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_DOWN;
1225     shortcut.session = 1;
1226     shortcut.callback = myCallback;
1227     shortcut.callback(keyEvent);
1228     shortcutMgr.shortcuts_[1] = shortcut;
1229     bool ret = shortcutMgr.HandleKeyUp(keyEvent);
1230     EXPECT_EQ(ret, false);
1231 }
1232 
1233 /**
1234  * @tc.name: KeyShortcutManagerTest_HandleKeyUp_002
1235  * @tc.desc: Test the funcation HandleKeyUp
1236  * @tc.type: FUNC
1237  * @tc.require:
1238  */
1239 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleKeyUp_002, TestSize.Level1)
1240 {
1241     CALL_TEST_DEBUG;
1242     KeyShortcutManager shortcutMgr;
1243     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1244     KeyShortcutManager::KeyShortcut shortcut;
1245     shortcut.modifiers = 0x1;
1246     shortcut.finalKey = 0x2;
1247     shortcut.longPressTime = 500;
1248     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1249     shortcut.session = 1;
1250     shortcut.callback = myCallback;
1251     shortcut.callback(keyEvent);
1252     shortcutMgr.shortcuts_[1] = shortcut;
1253     bool ret = shortcutMgr.HandleKeyUp(keyEvent);
1254     EXPECT_EQ(ret, false);
1255     shortcut.finalKey = KeyShortcutManager::SHORTCUT_PURE_MODIFIERS;
1256     shortcutMgr.shortcuts_[1] = shortcut;
1257     keyEvent->SetKeyCode(2046);
1258     ret = shortcutMgr.HandleKeyUp(keyEvent);
1259     EXPECT_EQ(ret, true);
1260 }
1261 
1262 /**
1263  * @tc.name: KeyShortcutManagerTest_UnregisterSystemKey_001
1264  * @tc.desc: Test the funcation UnregisterSystemKey
1265  * @tc.type: FUNC
1266  * @tc.require:
1267  */
1268 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_UnregisterSystemKey_001, TestSize.Level1)
1269 {
1270     CALL_TEST_DEBUG;
1271     KeyShortcutManager shortcutMgr;
1272     KeyShortcutManager::KeyShortcut shortcut;
1273     shortcut.modifiers = 0x1;
1274     shortcut.finalKey = 0x2;
1275     shortcut.longPressTime = 500;
1276     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1277     shortcut.session = 1;
1278     shortcutMgr.shortcuts_[1] = shortcut;
1279     int32_t shortcutId = 1;
1280     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UnregisterSystemKey(shortcutId));
1281 }
1282 
1283 /**
1284  * @tc.name: KeyShortcutManagerTest_UnregisterHotKey_002
1285  * @tc.desc: Test the funcation UnregisterHotKey
1286  * @tc.type: FUNC
1287  * @tc.require:
1288  */
1289 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_UnregisterHotKey_002, TestSize.Level1)
1290 {
1291     CALL_TEST_DEBUG;
1292     KeyShortcutManager shortcutMgr;
1293     KeyShortcutManager::KeyShortcut shortcut;
1294     shortcut.modifiers = 0x1;
1295     shortcut.finalKey = 0x2;
1296     shortcut.longPressTime = 500;
1297     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1298     shortcut.session = 1;
1299     shortcutMgr.shortcuts_[1] = shortcut;
1300     int32_t shortcutId = 1;
1301     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UnregisterHotKey(shortcutId));
1302     shortcutId = 5;
1303     EXPECT_NO_FATAL_FAILURE(shortcutMgr.UnregisterHotKey(shortcutId));
1304 }
1305 
1306 /**
1307  * @tc.name: KeyShortcutManagerTest_HandleEvent_002
1308  * @tc.desc: Test the funcation HandleEvent
1309  * @tc.type: FUNC
1310  * @tc.require:
1311  */
1312 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleEvent_002, TestSize.Level1)
1313 {
1314     CALL_TEST_DEBUG;
1315     KeyShortcutManager shortcutMgr;
1316     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1317     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1318     bool ret = shortcutMgr.HandleEvent(keyEvent);
1319     ASSERT_EQ(ret, false);
1320     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1321     ret = shortcutMgr.HandleEvent(keyEvent);
1322     ASSERT_EQ(ret, false);
1323     keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
1324     ret = shortcutMgr.HandleEvent(keyEvent);
1325     ASSERT_EQ(ret, false);
1326     keyEvent->SetKeyAction(KeyEvent::INTENTION_LEFT);
1327     ret = shortcutMgr.HandleEvent(keyEvent);
1328     ASSERT_EQ(ret, false);
1329 }
1330 
1331 /**
1332  * @tc.name: KeyShortcutManagerTest_FormatPressedKeys_001
1333  * @tc.desc: Test the funcation FormatPressedKeys
1334  * @tc.type: FUNC
1335  * @tc.require:
1336  */
1337 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_FormatPressedKeys_001, TestSize.Level1)
1338 {
1339     CALL_TEST_DEBUG;
1340     KeyShortcutManager shortcutMgr;
1341     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1342     int64_t downTime = 2;
1343     KeyEvent::KeyItem kitDown;
1344     kitDown.SetKeyCode(KeyEvent::KEYCODE_UNKNOWN);
1345     kitDown.SetPressed(true);
1346     kitDown.SetDownTime(downTime);
1347     keyEvent->AddPressedKeyItems(kitDown);
1348     std::string ret = shortcutMgr.FormatPressedKeys(keyEvent);
1349     ASSERT_EQ(ret, "-1");
1350 }
1351 
1352 /**
1353  * @tc.name: KeyShortcutManagerTest_CheckGlobalKey_001
1354  * @tc.desc: Test the funcation CheckGlobalKey
1355  * @tc.type: FUNC
1356  * @tc.require:
1357  */
1358 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_CheckGlobalKey_001, TestSize.Level1)
1359 {
1360     CALL_TEST_DEBUG;
1361     KeyShortcutManager shortcutMgr;
1362     KeyShortcutManager::HotKey globalKey {
1363         .modifiers = { KeyEvent::KEYCODE_CTRL_LEFT, KeyEvent::KEYCODE_SHIFT_LEFT },
1364         .finalKey = KeyEvent::KEYCODE_M,
1365     };
1366     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1367     KeyShortcutManager::KeyShortcut shortcut;
1368     shortcut.modifiers = 0x1;
1369     shortcut.finalKey = 0x2;
1370     shortcut.longPressTime = 500;
1371     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_DOWN;
1372     shortcut.session = 1;
1373     shortcut.callback = myCallback;
1374     shortcut.callback(keyEvent);
1375     bool ret = shortcutMgr.CheckGlobalKey(globalKey, shortcut);
1376     ASSERT_TRUE(ret);
1377 }
1378 
1379 /**
1380  * @tc.name: KeyShortcutManagerTest_GetForegroundPids_001
1381  * @tc.desc: Test the funcation GetForegroundPids
1382  * @tc.type: FUNC
1383  * @tc.require:
1384  */
1385 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GetForegroundPids_001, TestSize.Level1)
1386 {
1387     CALL_TEST_DEBUG;
1388     KeyShortcutManager shortcutMgr;
1389     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1390     KeyShortcutManager::KeyShortcut shortcut;
1391     shortcut.modifiers = 0x1;
1392     shortcut.finalKey = 0x2;
1393     shortcut.longPressTime = 500;
1394     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_DOWN;
1395     shortcut.session = 1;
1396     shortcut.callback = myCallback;
1397     shortcut.callback(keyEvent);
1398     shortcutMgr.shortcuts_[1] = shortcut;
1399     std::set<int32_t> ret = shortcutMgr.GetForegroundPids();
1400     std::set<int> mySet;
1401     ASSERT_EQ(ret, mySet);
1402 }
1403 
1404 /**
1405  * @tc.name: KeyShortcutManagerTest_HandleKeyDown_001
1406  * @tc.desc: Test the funcation HandleKeyDown
1407  * @tc.type: FUNC
1408  * @tc.require:
1409  */
1410 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleKeyDown_001, TestSize.Level1)
1411 {
1412     CALL_TEST_DEBUG;
1413     KeyShortcutManager shortcutMgr;
1414     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1415     KeyShortcutManager::KeyShortcut shortcut;
1416     shortcut.modifiers = 0x1;
1417     shortcut.finalKey = 0x2;
1418     shortcut.longPressTime = 500;
1419     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_DOWN;
1420     shortcut.session = 1;
1421     shortcut.callback = myCallback;
1422     shortcut.callback(keyEvent);
1423     shortcutMgr.shortcuts_[1] = shortcut;
1424     bool ret = shortcutMgr.HandleKeyDown(keyEvent);
1425     EXPECT_EQ(ret, false);
1426 }
1427 
1428 /**
1429  * @tc.name: KeyShortcutManagerTest_HandleKeyDown_002
1430  * @tc.desc: Test the funcation HandleKeyDown
1431  * @tc.type: FUNC
1432  * @tc.require:
1433  */
1434 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleKeyDown_002, TestSize.Level1)
1435 {
1436     CALL_TEST_DEBUG;
1437     KeyShortcutManager shortcutMgr;
1438     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1439     KeyShortcutManager::KeyShortcut shortcut;
1440     shortcut.modifiers = 0x1;
1441     shortcut.finalKey = 0x2;
1442     shortcut.longPressTime = 500;
1443     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1444     shortcut.session = 1;
1445     shortcut.callback = myCallback;
1446     shortcut.callback(keyEvent);
1447     shortcutMgr.shortcuts_[1] = shortcut;
1448     bool ret = shortcutMgr.HandleKeyDown(keyEvent);
1449     EXPECT_EQ(ret, false);
1450     shortcut.finalKey = KeyShortcutManager::SHORTCUT_PURE_MODIFIERS;
1451     shortcutMgr.shortcuts_[1] = shortcut;
1452     keyEvent->SetKeyCode(2046);
1453     ret = shortcutMgr.HandleKeyDown(keyEvent);
1454     EXPECT_FALSE(ret);
1455 }
1456 
1457 /**
1458  * @tc.name: KeyShortcutManagerTest_HandleKeyUp_003
1459  * @tc.desc: Test the funcation HandleKeyUp
1460  * @tc.type: FUNC
1461  * @tc.require:
1462  */
1463 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleKeyUp_003, TestSize.Level1)
1464 {
1465     CALL_TEST_DEBUG;
1466     KeyShortcutManager shortcutMgr;
1467     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1468     KeyShortcutManager::KeyShortcut shortcut;
1469     shortcut.modifiers = 0x1;
1470     shortcut.finalKey = 0x2;
1471     shortcut.longPressTime = 500;
1472     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1473     shortcut.session = 1;
1474     shortcut.callback = myCallback;
1475     shortcut.callback(keyEvent);
1476     shortcutMgr.shortcuts_[1] = shortcut;
1477     bool ret = shortcutMgr.HandleKeyUp(keyEvent);
1478     ASSERT_FALSE(ret);
1479     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_DOWN;
1480     shortcutMgr.shortcuts_[1] = shortcut;
1481     ret = shortcutMgr.HandleKeyUp(keyEvent);
1482     ASSERT_FALSE(ret);
1483 }
1484 
1485 /**
1486  * @tc.name: KeyShortcutManagerTest_CheckPureModifiers_001
1487  * @tc.desc: Test the funcation CheckPureModifiers
1488  * @tc.type: FUNC
1489  * @tc.require:
1490  */
1491 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_CheckPureModifiers_001, TestSize.Level1)
1492 {
1493     CALL_TEST_DEBUG;
1494     KeyShortcutManager shortcutMgr;
1495     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1496     KeyShortcutManager::KeyShortcut shortcut;
1497     shortcut.modifiers = 0x1;
1498     shortcut.finalKey = 0x2;
1499     shortcut.longPressTime = 500;
1500     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1501     shortcut.session = 1;
1502     shortcut.callback = myCallback;
1503     shortcut.callback(keyEvent);
1504     bool ret = shortcutMgr.CheckPureModifiers(keyEvent, shortcut);
1505     ASSERT_FALSE(ret);
1506     keyEvent->SetKeyCode(2045);
1507     int64_t downTime = 2;
1508     KeyEvent::KeyItem kitDown;
1509     kitDown.SetKeyCode(KeyEvent::KEYCODE_UNKNOWN);
1510     kitDown.SetPressed(true);
1511     kitDown.SetDownTime(downTime);
1512     keyEvent->AddPressedKeyItems(kitDown);
1513     ret = shortcutMgr.CheckPureModifiers(keyEvent, shortcut);
1514     ASSERT_TRUE(ret);
1515 }
1516 
1517 /**
1518  * @tc.name: KeyShortcutManagerTest_CheckModifiers_001
1519  * @tc.desc: Test the funcation CheckModifiers
1520  * @tc.type: FUNC
1521  * @tc.require:
1522  */
1523 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_CheckModifiers_001, TestSize.Level1)
1524 {
1525     CALL_TEST_DEBUG;
1526     KeyShortcutManager shortcutMgr;
1527     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1528     KeyShortcutManager::KeyShortcut shortcut;
1529     shortcut.modifiers = 0x1;
1530     shortcut.finalKey = 0x2;
1531     shortcut.longPressTime = 500;
1532     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1533     shortcut.session = 1;
1534     shortcut.callback = myCallback;
1535     shortcut.callback(keyEvent);
1536     bool ret = shortcutMgr.CheckModifiers(keyEvent, shortcut);
1537     ASSERT_FALSE(ret);
1538     keyEvent->SetKeyCode(2045);
1539     int64_t downTime = 2;
1540     KeyEvent::KeyItem kitDown;
1541     kitDown.SetKeyCode(KeyEvent::KEYCODE_UNKNOWN);
1542     kitDown.SetPressed(true);
1543     kitDown.SetDownTime(downTime);
1544     keyEvent->AddPressedKeyItems(kitDown);
1545     ret = shortcutMgr.CheckModifiers(keyEvent, shortcut);
1546     ASSERT_FALSE(ret);
1547 }
1548 
1549 /**
1550  * @tc.name: KeyShortcutManagerTest_TriggerDown_001
1551  * @tc.desc: Test the funcation TriggerDown
1552  * @tc.type: FUNC
1553  * @tc.require:
1554  */
1555 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerDown_001, TestSize.Level1)
1556 {
1557     CALL_TEST_DEBUG;
1558     KeyShortcutManager shortcutMgr;
1559     int32_t shortcutId = 1;
1560     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1561     KeyShortcutManager::KeyShortcut shortcut;
1562     shortcut.modifiers = 0x1;
1563     shortcut.finalKey = 0x2;
1564     shortcut.longPressTime = -5;
1565     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1566     shortcut.session = 1;
1567     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerDown(keyEvent, shortcutId, shortcut));
1568     shortcut.callback = myCallback;
1569     shortcut.callback(keyEvent);
1570     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerDown(keyEvent, shortcutId, shortcut));
1571 }
1572 
1573 /**
1574  * @tc.name: KeyShortcutManagerTest_RunShortcut_003
1575  * @tc.desc: Test the funcation RunShortcut
1576  * @tc.type: FUNC
1577  * @tc.require:
1578  */
1579 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_RunShortcut_003, TestSize.Level1)
1580 {
1581     CALL_TEST_DEBUG;
1582     KeyShortcutManager shortcutMgr;
1583     int32_t shortcutId = 1;
1584     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1585     EXPECT_NO_FATAL_FAILURE(shortcutMgr.RunShortcut(keyEvent, shortcutId));
1586     KeyShortcutManager::KeyShortcut shortcut;
1587     shortcut.modifiers = 0x1;
1588     shortcut.finalKey = 0x2;
1589     shortcut.longPressTime = 500;
1590     shortcut.triggerType = KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP;
1591     shortcut.session = 1;
1592     shortcutMgr.shortcuts_[1] = shortcut;
1593     EXPECT_NO_FATAL_FAILURE(shortcutMgr.RunShortcut(keyEvent, shortcutId));
1594     shortcut.callback = myCallback;
1595     shortcut.callback(keyEvent);
1596     EXPECT_NO_FATAL_FAILURE(shortcutMgr.RunShortcut(keyEvent, shortcutId));
1597 }
1598 
1599 /**
1600  * @tc.name: KeyShortcutManagerTest_TriggerUp_003
1601  * @tc.desc: Test the funcation TriggerUp
1602  * @tc.type: FUNC
1603  * @tc.require:
1604  */
1605 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_TriggerUp_003, TestSize.Level1)
1606 {
1607     CALL_TEST_DEBUG;
1608     KeyShortcutManager shortcutMgr;
1609     int32_t shortcutId = 1;
1610     KeyShortcutManager::KeyShortcut shortcut;
1611     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1612     shortcut.longPressTime = 1000;
1613     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1614     KeyEvent::KeyItem item;
1615     item.SetKeyCode(5);
1616     keyEvent->SetActionTime(3);
1617     item.SetDownTime(1);
1618     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1619     keyEvent->SetActionTime(1003);
1620     item.SetDownTime(1);
1621     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1622     shortcut.longPressTime = -10;
1623     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1624     shortcut.callback = myCallback;
1625     shortcut.callback(keyEvent);
1626     EXPECT_NO_FATAL_FAILURE(shortcutMgr.TriggerUp(keyEvent, shortcutId, shortcut));
1627 }
1628 
1629 /**
1630  * @tc.name: KeyShortcutManagerTest_ReadHotkey_001
1631  * @tc.desc: Test the funcation ReadHotkey
1632  * @tc.type: FUNC
1633  * @tc.require:
1634  */
1635 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadHotkey_001, TestSize.Level1)
1636 {
1637     CALL_TEST_DEBUG;
1638     KeyShortcutManager shortcutMgr;
1639     cJSON *jsonHotkey = cJSON_CreateString("not an object");
1640     int32_t ret = shortcutMgr.ReadHotkey(jsonHotkey) ;
1641     EXPECT_EQ(ret, RET_ERR);
1642     cJSON_Delete(jsonHotkey);
1643 }
1644 
1645 /**
1646  * @tc.name: KeyShortcutManagerTest_ReadHotkey_002
1647  * @tc.desc: Test the funcation ReadHotkey
1648  * @tc.type: FUNC
1649  * @tc.require:
1650  */
1651 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadHotkey_002, TestSize.Level1)
1652 {
1653     CALL_TEST_DEBUG;
1654     KeyShortcutManager shortcutMgr;
1655     cJSON *jsonHotkey = cJSON_CreateObject();
1656     int32_t ret = shortcutMgr.ReadHotkey(jsonHotkey) ;
1657     EXPECT_EQ(ret, RET_ERR);
1658     cJSON_Delete(jsonHotkey);
1659 }
1660 
1661 /**
1662  * @tc.name: KeyShortcutManagerTest_ReadHotkey_003
1663  * @tc.desc: Test the funcation ReadHotkey
1664  * @tc.type: FUNC
1665  * @tc.require:
1666  */
1667 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadHotkey_003, TestSize.Level1)
1668 {
1669     CALL_TEST_DEBUG;
1670     KeyShortcutManager shortcutMgr;
1671     cJSON *jsonHotkey = cJSON_CreateObject();
1672     cJSON_AddItemToObject(jsonHotkey, "businessId", cJSON_CreateNumber(123));
1673     int32_t ret = shortcutMgr.ReadHotkey(jsonHotkey) ;
1674     EXPECT_EQ(ret, RET_ERR);
1675     cJSON_Delete(jsonHotkey);
1676 }
1677 
1678 /**
1679  * @tc.name: KeyShortcutManagerTest_ReadHotkey_004
1680  * @tc.desc: Test the funcation ReadHotkey
1681  * @tc.type: FUNC
1682  * @tc.require:
1683  */
1684 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadHotkey_004, TestSize.Level1)
1685 {
1686     CALL_TEST_DEBUG;
1687     KeyShortcutManager shortcutMgr;
1688     cJSON *jsonHotkey = cJSON_CreateObject();
1689     cJSON* preKey = cJSON_CreateArray();
1690     for (int i = 0; i < 5; ++i) {
1691         cJSON_AddItemToArray(preKey, cJSON_CreateNumber(i));
1692     }
1693     cJSON_AddItemToObject(jsonHotkey, "preKey", preKey);
1694     int32_t ret = shortcutMgr.ReadHotkey(jsonHotkey) ;
1695     EXPECT_EQ(ret, RET_ERR);
1696     cJSON_Delete(jsonHotkey);
1697 }
1698 
1699 /**
1700  * @tc.name: KeyShortcutManagerTest_ReadHotkey_005
1701  * @tc.desc: Test the funcation ReadHotkey
1702  * @tc.type: FUNC
1703  * @tc.require:
1704  */
1705 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadHotkey_005, TestSize.Level1)
1706 {
1707     CALL_TEST_DEBUG;
1708     KeyShortcutManager shortcutMgr;
1709     cJSON *jsonHotkey = cJSON_CreateObject();
1710     cJSON* preKey = cJSON_CreateArray();
1711     for (int i = 0; i < 5; ++i) {
1712         cJSON_AddItemToArray(preKey, cJSON_CreateNumber(i));
1713     }
1714     cJSON_AddItemToObject(jsonHotkey, "preKey", preKey);
1715     cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1));
1716     int32_t ret = shortcutMgr.ReadHotkey(jsonHotkey) ;
1717     EXPECT_EQ(ret, RET_ERR);
1718     cJSON_Delete(jsonHotkey);
1719 }
1720 
1721 /**
1722  * @tc.name: KeyShortcutManagerTest_ReadSystemKey_001
1723  * @tc.desc: Test the funcation ReadSystemKey
1724  * @tc.type: FUNC
1725  * @tc.require:
1726  */
1727 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadSystemKey_001, TestSize.Level1)
1728 {
1729     CALL_TEST_DEBUG;
1730     KeyShortcutManager shortcutMgr;
1731     cJSON *jsonSysKey = cJSON_CreateString("not an object");
1732     int32_t ret = shortcutMgr.ReadSystemKey(jsonSysKey) ;
1733     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1734     cJSON_Delete(jsonSysKey);
1735 }
1736 
1737 /**
1738  * @tc.name: KeyShortcutManagerTest_ReadSystemKey_002
1739  * @tc.desc: Test the funcation ReadSystemKey
1740  * @tc.type: FUNC
1741  * @tc.require:
1742  */
1743 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadSystemKey_002, TestSize.Level1)
1744 {
1745     CALL_TEST_DEBUG;
1746     KeyShortcutManager shortcutMgr;
1747     cJSON *jsonSysKey = cJSON_CreateObject();
1748     int32_t ret = shortcutMgr.ReadSystemKey(jsonSysKey) ;
1749     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1750     cJSON_Delete(jsonSysKey);
1751 }
1752 
1753 /**
1754  * @tc.name: KeyShortcutManagerTest_ReadSystemKey_003
1755  * @tc.desc: Test the funcation ReadSystemKey
1756  * @tc.type: FUNC
1757  * @tc.require:
1758  */
1759 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadSystemKey_003, TestSize.Level1)
1760 {
1761     CALL_TEST_DEBUG;
1762     KeyShortcutManager shortcutMgr;
1763     cJSON *jsonSysKey = cJSON_CreateObject();
1764     cJSON* preKey = cJSON_CreateArray();
1765     cJSON_AddItemToObject(jsonSysKey, "preKey", preKey);
1766     int32_t ret = shortcutMgr.ReadSystemKey(jsonSysKey) ;
1767     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1768     cJSON_Delete(jsonSysKey);
1769 }
1770 
1771 /**
1772  * @tc.name: KeyShortcutManagerTest_ReadExceptionalSystemKey_001
1773  * @tc.desc: Test the funcation ReadExceptionalSystemKey
1774  * @tc.type: FUNC
1775  * @tc.require:
1776  */
1777 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadExceptionalSystemKey_001, TestSize.Level1)
1778 {
1779     CALL_TEST_DEBUG;
1780     KeyShortcutManager shortcutMgr;
1781     cJSON *jsonSysKey = cJSON_CreateString("not an object");
1782     int32_t ret = shortcutMgr.ReadExceptionalSystemKey(jsonSysKey) ;
1783     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1784     cJSON_Delete(jsonSysKey);
1785 }
1786 
1787 /**
1788  * @tc.name: KeyShortcutManagerTest_ReadExceptionalSystemKey_002
1789  * @tc.desc: Test the funcation ReadExceptionalSystemKey
1790  * @tc.type: FUNC
1791  * @tc.require:
1792  */
1793 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadExceptionalSystemKey_002, TestSize.Level1)
1794 {
1795     CALL_TEST_DEBUG;
1796     KeyShortcutManager shortcutMgr;
1797     cJSON *jsonSysKey = cJSON_CreateObject();
1798     int32_t ret = shortcutMgr.ReadExceptionalSystemKey(jsonSysKey) ;
1799     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1800     cJSON_Delete(jsonSysKey);
1801 }
1802 
1803 /**
1804  * @tc.name: KeyShortcutManagerTest_ReadExceptionalSystemKey_003
1805  * @tc.desc: Test the funcation ReadExceptionalSystemKey
1806  * @tc.type: FUNC
1807  * @tc.require:
1808  */
1809 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadExceptionalSystemKey_003, TestSize.Level1)
1810 {
1811     CALL_TEST_DEBUG;
1812     KeyShortcutManager shortcutMgr;
1813     cJSON *jsonSysKey = cJSON_CreateObject();
1814     cJSON* preKey = cJSON_CreateArray();
1815     cJSON_AddItemToObject(jsonSysKey, "preKey", preKey);
1816     int32_t ret = shortcutMgr.ReadExceptionalSystemKey(jsonSysKey) ;
1817     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1818     cJSON_Delete(jsonSysKey);
1819 }
1820 
1821 /**
1822  * @tc.name: KeyShortcutManagerTest_ReadExceptionalSystemKey_004
1823  * @tc.desc: Test the funcation ReadExceptionalSystemKey
1824  * @tc.type: FUNC
1825  * @tc.require:
1826  */
1827 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadExceptionalSystemKey_004, TestSize.Level1)
1828 {
1829     CALL_TEST_DEBUG;
1830     KeyShortcutManager shortcutMgr;
1831     cJSON *jsonSysKey = cJSON_CreateObject();
1832     cJSON* preKey = cJSON_CreateArray();
1833     for (int i = 0; i < 5; ++i) {
1834         cJSON_AddItemToArray(preKey, cJSON_CreateNumber(i));
1835     }
1836     cJSON_AddItemToObject(jsonSysKey, "preKey", preKey);
1837     cJSON_AddItemToArray(preKey, cJSON_CreateNumber(1));
1838     int32_t ret = shortcutMgr.ReadExceptionalSystemKey(jsonSysKey) ;
1839     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1840     cJSON_Delete(jsonSysKey);
1841 }
1842 
1843 /**
1844  * @tc.name: KeyShortcutManagerTest_ReadExceptionalSystemKey_005
1845  * @tc.desc: Test the funcation ReadExceptionalSystemKey
1846  * @tc.type: FUNC
1847  * @tc.require:
1848  */
1849 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadExceptionalSystemKey_005, TestSize.Level1)
1850 {
1851     CALL_TEST_DEBUG;
1852     KeyShortcutManager shortcutMgr;
1853     cJSON *jsonSysKey = cJSON_CreateObject();
1854     cJSON* preKey = cJSON_CreateArray();
1855     for (int i = 0; i < 5; ++i) {
1856         cJSON_AddItemToArray(preKey, cJSON_CreateNumber(i));
1857     }
1858     cJSON_AddItemToObject(jsonSysKey, "longPressTime", preKey);
1859     int32_t ret = shortcutMgr.ReadExceptionalSystemKey(jsonSysKey) ;
1860     EXPECT_EQ(ret, KEY_SHORTCUT_ERROR_CONFIG);
1861     cJSON_Delete(jsonSysKey);
1862 }
1863 
1864 /**
1865  * @tc.name: KeyShortcutManagerTest_IsReservedSystemKey
1866  * @tc.desc: Test the funcation IsReservedSystemKey
1867  * @tc.type: FUNC
1868  * @tc.require:
1869  */
1870 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_IsReservedSystemKey, TestSize.Level1)
1871 {
1872     CALL_TEST_DEBUG;
1873     KeyShortcutManager shortcutMgr;
1874     KeyShortcutManager::KeyShortcut shortcut;
1875     bool ret = shortcutMgr.IsReservedSystemKey(shortcut) ;
1876     ASSERT_FALSE(ret);
1877 }
1878 
1879 /**
1880  * @tc.name: KeyShortcutManagerTest_HaveRegisteredGlobalKey
1881  * @tc.desc: Test the funcation HaveRegisteredGlobalKey
1882  * @tc.type: FUNC
1883  * @tc.require:
1884  */
1885 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HaveRegisteredGlobalKey, TestSize.Level1)
1886 {
1887     CALL_TEST_DEBUG;
1888     KeyShortcutManager shortcutMgr;
1889     KeyShortcutManager::KeyShortcut shortcut;
1890     bool ret = shortcutMgr.HaveRegisteredGlobalKey(shortcut) ;
1891     ASSERT_FALSE(ret);
1892 }
1893 
1894 /**
1895  * @tc.name: KeyShortcutManagerTest_HandleKeyCancel
1896  * @tc.desc: Test the funcation HandleKeyCancel
1897  * @tc.type: FUNC
1898  * @tc.require:
1899  */
1900 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_HandleKeyCancel, TestSize.Level1)
1901 {
1902     CALL_TEST_DEBUG;
1903     KeyShortcutManager shortcutMgr;
1904     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1905     bool ret = shortcutMgr.HandleKeyCancel(keyEvent);
1906     ASSERT_FALSE(ret);
1907 }
1908 
1909 /**
1910  * @tc.name: KeyShortcutManagerTest_CheckCombination
1911  * @tc.desc: Test the funcation CheckCombination
1912  * @tc.type: FUNC
1913  * @tc.require:
1914  */
1915 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_CheckCombination, TestSize.Level1)
1916 {
1917     CALL_TEST_DEBUG;
1918     KeyShortcutManager shortcutMgr;
1919     std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1920     KeyShortcutManager::KeyShortcut shortcut;
1921     bool ret = shortcutMgr.CheckCombination(keyEvent, shortcut);
1922     ASSERT_FALSE(ret);
1923 }
1924 
1925 /**
1926  * @tc.name: KeyShortcutManagerTest_GetAllSystemHotkeys
1927  * @tc.desc: Test the funcation GetAllSystemHotkeys
1928  * @tc.type: FUNC
1929  * @tc.require:
1930  */
1931 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_GetAllSystemHotkeys, TestSize.Level1)
1932 {
1933     CALL_TEST_DEBUG;
1934     KeyShortcutManager shortcutMgr;
1935     std::vector<std::unique_ptr<KeyOption>> sysKeys;
1936     bool ret = shortcutMgr.GetAllSystemHotkeys(sysKeys);
1937     EXPECT_EQ(ret, RET_OK);
1938 }
1939 
1940 /**
1941  * @tc.name: KeyShortcutManagerTest_ReadExceptionalSystemKeys
1942  * @tc.desc: Test the funcation ReadExceptionalSystemKeys
1943  * @tc.type: FUNC
1944  * @tc.require:
1945  */
1946 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_ReadExceptionalSystemKeys, TestSize.Level1)
1947 {
1948     CALL_TEST_DEBUG;
1949     KeyShortcutManager shortcutMgr;
1950     const std::string cfgPath { "ExceptionalSystemKeys" };
1951     shortcutMgr.ReadExceptionalSystemKeys(cfgPath);
1952     EXPECT_EQ(cfgPath, "ExceptionalSystemKeys");
1953 }
1954 
1955 /**
1956  * @tc.name: KeyShortcutManagerTest_IsValid
1957  * @tc.desc: Test the funcation IsValid
1958  * @tc.type: FUNC
1959  * @tc.require:
1960  */
1961 HWTEST_F(KeyShortcutManagerTest, KeyShortcutManagerTest_IsValid, TestSize.Level1)
1962 {
1963     CALL_TEST_DEBUG;
1964     KeyShortcutManager shortcutMgr;
1965     KeyShortcutManager::ShortcutTriggerType triggerType {
1966         KeyShortcutManager::ShortcutTriggerType::SHORTCUT_TRIGGER_TYPE_UP };
1967     bool ret = shortcutMgr.IsValid(triggerType);
1968     EXPECT_TRUE(ret);
1969 }
1970 } // namespace MMI
1971 } // namespace OHOS
1972