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 <gtest/gtest.h>
17
18 #include "mmi_log.h"
19 #include "stylus_key_handler.h"
20
21
22 #undef MMI_LOG_TAG
23 #define MMI_LOG_TAG "StylusKeyHandlerTest"
24
25 namespace OHOS {
26 namespace MMI {
27 namespace {
28 using namespace testing::ext;
29 } // namespace
30 class StylusKeyHandlerTest : public testing::Test {
31 public:
SetUpTestCase(void)32 static void SetUpTestCase(void) {}
TearDownTestCase(void)33 static void TearDownTestCase(void) {}
34 std::shared_ptr<KeyEvent> SetupKeyEvent();
35 };
36
SetupKeyEvent()37 std::shared_ptr<KeyEvent> StylusKeyHandlerTest::SetupKeyEvent()
38 {
39 std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
40 CHKPP(keyEvent);
41 keyEvent->SetKeyCode(KeyEvent::KEYCODE_STYLUS_SCREEN);
42 return keyEvent;
43 }
44
45 /**
46 * @tc.name: StylusKeyHandlerTest_HandleStylusKey_001
47 * @tc.desc: Test HandleStylusKey
48 * @tc.type: FUNC
49 * @tc.require:
50 */
51 HWTEST_F(StylusKeyHandlerTest, StylusKeyHandlerTest_HandleStylusKey_001, TestSize.Level1)
52 {
53 CALL_TEST_DEBUG;
54 auto keyEvent = SetupKeyEvent();
55 ASSERT_TRUE(keyEvent != nullptr);
56 keyEvent->SetKeyCode(KeyEvent::UNKNOWN_FUNCTION_KEY);
57 STYLUS_HANDLER->isShortHandConfig_ = true;
58 auto result = STYLUS_HANDLER->HandleStylusKey(keyEvent);
59 ASSERT_FALSE(result);
60 }
61
62 /**
63 * @tc.name: StylusKeyHandlerTest_HandleStylusKey_002
64 * @tc.desc: Test HandleStylusKey
65 * @tc.type: FUNC
66 * @tc.require:
67 */
68 HWTEST_F(StylusKeyHandlerTest, StylusKeyHandlerTest_HandleStylusKey_002, TestSize.Level1)
69 {
70 CALL_TEST_DEBUG;
71 auto keyEvent = SetupKeyEvent();
72 ASSERT_TRUE(keyEvent != nullptr);
73 STYLUS_HANDLER->SetLastEventState(true);
74 STYLUS_HANDLER->isShortHandConfig_ = true;
75 STYLUS_HANDLER->stylusKey_.statusConfigValue = true;
76 STYLUS_HANDLER->IsLaunchAbility();
77 auto result = STYLUS_HANDLER->HandleStylusKey(keyEvent);
78 ASSERT_TRUE(result);
79 }
80
81 /**
82 * @tc.name: StylusKeyHandlerTest_HandleStylusKey_003
83 * @tc.desc: Test HandleStylusKey
84 * @tc.type: FUNC
85 * @tc.require:
86 */
87 HWTEST_F(StylusKeyHandlerTest, StylusKeyHandlerTest_HandleStylusKey_003, TestSize.Level1)
88 {
89 CALL_TEST_DEBUG;
90 auto keyEvent = SetupKeyEvent();
91 ASSERT_TRUE(keyEvent != nullptr);
92 STYLUS_HANDLER->isShortHandConfig_ = true;
93 auto result = STYLUS_HANDLER->HandleStylusKey(keyEvent);
94 ASSERT_FALSE(result);
95 }
96
97 /**
98 * @tc.name: StylusKeyHandlerTest_IsLaunchAbility_001
99 * @tc.desc: Test IsLaunchAbility
100 * @tc.type: FUNC
101 * @tc.require:
102 */
103 HWTEST_F(StylusKeyHandlerTest, StylusKeyHandlerTest_IsLaunchAbility_001, TestSize.Level1)
104 {
105 CALL_TEST_DEBUG;
106 STYLUS_HANDLER->SetLastEventState(false);
107 ASSERT_NO_FATAL_FAILURE(STYLUS_HANDLER->IsLaunchAbility());
108 }
109
110 /**
111 * @tc.name: StylusKeyHandlerTest_IsLaunchAbility_002
112 * @tc.desc: Test IsLaunchAbility
113 * @tc.type: FUNC
114 * @tc.require:
115 */
116 HWTEST_F(StylusKeyHandlerTest, StylusKeyHandlerTest_IsLaunchAbility_002, TestSize.Level1)
117 {
118 CALL_TEST_DEBUG;
119 STYLUS_HANDLER->SetLastEventState(true);
120 STYLUS_HANDLER->stylusKey_.statusConfigValue = true;
121 STYLUS_HANDLER->shortHandTarget_.statusConfigValue = true;
122 ASSERT_NO_FATAL_FAILURE(STYLUS_HANDLER->IsLaunchAbility());
123 }
124
125 /**
126 * @tc.name: StylusKeyHandlerTest_IsLaunchAbility_003
127 * @tc.desc: Test IsLaunchAbility
128 * @tc.type: FUNC
129 * @tc.require:
130 */
131 HWTEST_F(StylusKeyHandlerTest, StylusKeyHandlerTest_IsLaunchAbility_003, TestSize.Level1)
132 {
133 CALL_TEST_DEBUG;
134 STYLUS_HANDLER->SetLastEventState(true);
135 STYLUS_HANDLER->stylusKey_.statusConfigValue = true;
136 STYLUS_HANDLER->shortHandTarget_.statusConfigValue = false;
137 ASSERT_NO_FATAL_FAILURE(STYLUS_HANDLER->IsLaunchAbility());
138 }
139 } // namespace MMI
140 } // namespace OHOS