1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include <fstream>
17c29fa5a6Sopenharmony_ci#include <list>
18c29fa5a6Sopenharmony_ci
19c29fa5a6Sopenharmony_ci#include <gtest/gtest.h>
20c29fa5a6Sopenharmony_ci
21c29fa5a6Sopenharmony_ci#include "key_option.h"
22c29fa5a6Sopenharmony_ci#include "key_subscriber_handler.h"
23c29fa5a6Sopenharmony_ci#include "call_manager_client.h"
24c29fa5a6Sopenharmony_ci#include "common_event_data.h"
25c29fa5a6Sopenharmony_ci#include "common_event_manager.h"
26c29fa5a6Sopenharmony_ci#include "common_event_support.h"
27c29fa5a6Sopenharmony_ci#include "device_event_monitor.h"
28c29fa5a6Sopenharmony_ci#include "input_event_handler.h"
29c29fa5a6Sopenharmony_ci#include "key_event.h"
30c29fa5a6Sopenharmony_ci#include "mmi_log.h"
31c29fa5a6Sopenharmony_ci#include "nap_process.h"
32c29fa5a6Sopenharmony_ci#include "switch_subscriber_handler.h"
33c29fa5a6Sopenharmony_ci#include "uds_server.h"
34c29fa5a6Sopenharmony_ci#include "want.h"
35c29fa5a6Sopenharmony_ci#include "event_log_helper.h"
36c29fa5a6Sopenharmony_ci
37c29fa5a6Sopenharmony_ci#undef MMI_LOG_TAG
38c29fa5a6Sopenharmony_ci#define MMI_LOG_TAG "KeyCommandHandlerTest"
39c29fa5a6Sopenharmony_ci
40c29fa5a6Sopenharmony_cinamespace OHOS {
41c29fa5a6Sopenharmony_cinamespace MMI {
42c29fa5a6Sopenharmony_cinamespace {
43c29fa5a6Sopenharmony_ciusing namespace testing::ext;
44c29fa5a6Sopenharmony_ciconst std::string PROGRAM_NAME = "uds_session_test";
45c29fa5a6Sopenharmony_ciconstexpr int32_t MODULE_TYPE = 1;
46c29fa5a6Sopenharmony_ciconstexpr int32_t UDS_FD = 1;
47c29fa5a6Sopenharmony_ciconstexpr int32_t UDS_UID = 100;
48c29fa5a6Sopenharmony_ciconstexpr int32_t UDS_PID = 100;
49c29fa5a6Sopenharmony_ciconstexpr int32_t REMOVE_OBSERVER { -2 };
50c29fa5a6Sopenharmony_ciconstexpr int32_t UNOBSERVED { -1 };
51c29fa5a6Sopenharmony_ciconstexpr int32_t ACTIVE_EVENT { 2 };
52c29fa5a6Sopenharmony_ci} // namespace
53c29fa5a6Sopenharmony_ci
54c29fa5a6Sopenharmony_ciclass KeySubscriberHandlerTest : public testing::Test {
55c29fa5a6Sopenharmony_cipublic:
56c29fa5a6Sopenharmony_ci    static void SetUpTestCase(void) {}
57c29fa5a6Sopenharmony_ci    static void TearDownTestCase(void) {}
58c29fa5a6Sopenharmony_ci};
59c29fa5a6Sopenharmony_ci
60c29fa5a6Sopenharmony_ci/**
61c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleCallEnded_001
62c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleCallEnded
63c29fa5a6Sopenharmony_ci * @tc.type: FUNC
64c29fa5a6Sopenharmony_ci * @tc.require:
65c29fa5a6Sopenharmony_ci */
66c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleCallEnded_001, TestSize.Level1)
67c29fa5a6Sopenharmony_ci{
68c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
69c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
70c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
71c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
72c29fa5a6Sopenharmony_ci    handler.callBahaviorState_ = true;
73c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
74c29fa5a6Sopenharmony_ci    keyEvent->keyAction_ = KeyEvent::KEY_ACTION_DOWN;
75c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_ALERTING;
76c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
77c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_ANSWERED;
78c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
79c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_ACTIVE;
80c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
81c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_DIALING;
82c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
83c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_WAITING;
84c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
85c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
86c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
87c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_IDLE;
88c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
89c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_DISCONNECTING;
90c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
91c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_DISCONNECTED;
92c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
93c29fa5a6Sopenharmony_ci}
94c29fa5a6Sopenharmony_ci
95c29fa5a6Sopenharmony_ci/**
96c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleCallEnded_002
97c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleCallEnded
98c29fa5a6Sopenharmony_ci * @tc.type: FUNC
99c29fa5a6Sopenharmony_ci * @tc.require:
100c29fa5a6Sopenharmony_ci */
101c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleCallEnded_002, TestSize.Level1)
102c29fa5a6Sopenharmony_ci{
103c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
104c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
105c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
106c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
107c29fa5a6Sopenharmony_ci    handler.callBahaviorState_ = false;
108c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
109c29fa5a6Sopenharmony_ci}
110c29fa5a6Sopenharmony_ci
111c29fa5a6Sopenharmony_ci/**
112c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleCallEnded_003
113c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleCallEnded
114c29fa5a6Sopenharmony_ci * @tc.type: FUNC
115c29fa5a6Sopenharmony_ci * @tc.require:
116c29fa5a6Sopenharmony_ci */
117c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleCallEnded_003, TestSize.Level1)
118c29fa5a6Sopenharmony_ci{
119c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
120c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
121c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
122c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
123c29fa5a6Sopenharmony_ci    handler.callBahaviorState_ = true;
124c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_UP;
125c29fa5a6Sopenharmony_ci    keyEvent->keyAction_ = KeyEvent::KEY_ACTION_UP;
126c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleCallEnded(keyEvent));
127c29fa5a6Sopenharmony_ci}
128c29fa5a6Sopenharmony_ci
129c29fa5a6Sopenharmony_ci/**
130c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HangUpCallProcess_001
131c29fa5a6Sopenharmony_ci * @tc.desc: Test HangUpCallProcess
132c29fa5a6Sopenharmony_ci * @tc.type: FUNC
133c29fa5a6Sopenharmony_ci * @tc.require:
134c29fa5a6Sopenharmony_ci */
135c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HangUpCallProcess_001, TestSize.Level1)
136c29fa5a6Sopenharmony_ci{
137c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
138c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
139c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr = nullptr;
140c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.HangUpCallProcess());
141c29fa5a6Sopenharmony_ci}
142c29fa5a6Sopenharmony_ci
143c29fa5a6Sopenharmony_ci/**
144c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HangUpCallProcess_002
145c29fa5a6Sopenharmony_ci * @tc.desc: Test HangUpCallProcess
146c29fa5a6Sopenharmony_ci * @tc.type: FUNC
147c29fa5a6Sopenharmony_ci * @tc.require:
148c29fa5a6Sopenharmony_ci */
149c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HangUpCallProcess_002, TestSize.Level1)
150c29fa5a6Sopenharmony_ci{
151c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
152c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
153c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr;
154c29fa5a6Sopenharmony_ci    callManagerClientPtr = std::make_shared<OHOS::Telephony::CallManagerClient>();
155c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
156c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.HangUpCallProcess());
157c29fa5a6Sopenharmony_ci}
158c29fa5a6Sopenharmony_ci
159c29fa5a6Sopenharmony_ci/**
160c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RejectCallProcess_001
161c29fa5a6Sopenharmony_ci * @tc.desc: Test RejectCallProcess
162c29fa5a6Sopenharmony_ci * @tc.type: FUNC
163c29fa5a6Sopenharmony_ci * @tc.require:
164c29fa5a6Sopenharmony_ci */
165c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RejectCallProcess_001, TestSize.Level1)
166c29fa5a6Sopenharmony_ci{
167c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
168c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
169c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr = nullptr;
170c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.RejectCallProcess());
171c29fa5a6Sopenharmony_ci}
172c29fa5a6Sopenharmony_ci
173c29fa5a6Sopenharmony_ci/**
174c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RejectCallProcess_002
175c29fa5a6Sopenharmony_ci * @tc.desc: Test RejectCallProcess
176c29fa5a6Sopenharmony_ci * @tc.type: FUNC
177c29fa5a6Sopenharmony_ci * @tc.require:
178c29fa5a6Sopenharmony_ci */
179c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RejectCallProcess_002, TestSize.Level1)
180c29fa5a6Sopenharmony_ci{
181c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
182c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
183c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr;
184c29fa5a6Sopenharmony_ci    callManagerClientPtr = std::make_shared<OHOS::Telephony::CallManagerClient>();
185c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
186c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.RejectCallProcess());
187c29fa5a6Sopenharmony_ci}
188c29fa5a6Sopenharmony_ci
189c29fa5a6Sopenharmony_ci/**
190c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyEvent_001
191c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleKeyEvent
192c29fa5a6Sopenharmony_ci * @tc.type: FUNC
193c29fa5a6Sopenharmony_ci * @tc.require:
194c29fa5a6Sopenharmony_ci */
195c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyEvent_001, TestSize.Level1)
196c29fa5a6Sopenharmony_ci{
197c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
198c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
199c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
200c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
201c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
202c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = false;
203c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_BRIGHTNESS_DOWN);
204c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_A);
205c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
206c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_B);
207c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
208c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
209c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
210c29fa5a6Sopenharmony_ci
211c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = true;
212c29fa5a6Sopenharmony_ci    handler.hasEventExecuting_ = true;
213c29fa5a6Sopenharmony_ci    handler.keyEvent_ = KeyEvent::Create();
214c29fa5a6Sopenharmony_ci    ASSERT_NE(handler.keyEvent_, nullptr);
215c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyCode(KeyEvent::KEYCODE_BRIGHTNESS_DOWN);
216c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyAction(KeyEvent::KEY_ACTION_UP);
217c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
218c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_A);
219c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
220c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_B);
221c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
222c29fa5a6Sopenharmony_ci    EXPECT_TRUE(handler.OnSubscribeKeyEvent(keyEvent));
223c29fa5a6Sopenharmony_ci    EXPECT_FALSE(EventLogHelper::IsBetaVersion());
224c29fa5a6Sopenharmony_ci    EXPECT_FALSE(keyEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE));
225c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.HandleKeyEvent(keyEvent));
226c29fa5a6Sopenharmony_ci}
227c29fa5a6Sopenharmony_ci
228c29fa5a6Sopenharmony_ci/**
229c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_DumpSubscriber_001
230c29fa5a6Sopenharmony_ci * @tc.desc: Test DumpSubscriber
231c29fa5a6Sopenharmony_ci * @tc.type: FUNC
232c29fa5a6Sopenharmony_ci * @tc.require:
233c29fa5a6Sopenharmony_ci */
234c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_DumpSubscriber_001, TestSize.Level1)
235c29fa5a6Sopenharmony_ci{
236c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
237c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
238c29fa5a6Sopenharmony_ci    int32_t fd = 1;
239c29fa5a6Sopenharmony_ci    SessionPtr sess;
240c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
241c29fa5a6Sopenharmony_ci    keyOption->preKeys_.insert(10);
242c29fa5a6Sopenharmony_ci    keyOption->preKeys_.insert(20);
243c29fa5a6Sopenharmony_ci    keyOption->preKeys_.insert(30);
244c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
245c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.DumpSubscriber(fd, subscriber));
246c29fa5a6Sopenharmony_ci}
247c29fa5a6Sopenharmony_ci
248c29fa5a6Sopenharmony_ci/**
249c29fa5a6Sopenharmony_ci * @tc.name: InputWindowsManagerTest_UnsubscribeKeyEvent_001
250c29fa5a6Sopenharmony_ci * @tc.desc: Test UnsubscribeKeyEvent
251c29fa5a6Sopenharmony_ci * @tc.type: FUNC
252c29fa5a6Sopenharmony_ci * @tc.require:
253c29fa5a6Sopenharmony_ci */
254c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, InputWindowsManagerTest_UnsubscribeKeyEvent_001, TestSize.Level1)
255c29fa5a6Sopenharmony_ci{
256c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
257c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
258c29fa5a6Sopenharmony_ci    auto keyEvent = KeyEvent::Create();
259c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
260c29fa5a6Sopenharmony_ci    keySubscriberHandler.HandleKeyEvent(keyEvent);
261c29fa5a6Sopenharmony_ci    auto pointerEvent = PointerEvent::Create();
262c29fa5a6Sopenharmony_ci    keySubscriberHandler.HandlePointerEvent(pointerEvent);
263c29fa5a6Sopenharmony_ci    keySubscriberHandler.HandleTouchEvent(pointerEvent);
264c29fa5a6Sopenharmony_ci    keySubscriberHandler.RemoveSubscriberKeyUpTimer(1);
265c29fa5a6Sopenharmony_ci    std::vector<std::string> args = {};
266c29fa5a6Sopenharmony_ci    keySubscriberHandler.Dump(1, args);
267c29fa5a6Sopenharmony_ci    UDSServer udsServer;
268c29fa5a6Sopenharmony_ci    SessionPtr sess = udsServer.GetSessionByPid(1);
269c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = nullptr;
270c29fa5a6Sopenharmony_ci    ASSERT_EQ(keySubscriberHandler.SubscribeKeyEvent(sess, -1, keyOption), -1);
271c29fa5a6Sopenharmony_ci    SessionPtr sessPtr = nullptr;
272c29fa5a6Sopenharmony_ci    ASSERT_NE(keySubscriberHandler.UnsubscribeKeyEvent(sessPtr, -1), 0);
273c29fa5a6Sopenharmony_ci    ASSERT_NE(keySubscriberHandler.UnsubscribeKeyEvent(sess, 1), 0);
274c29fa5a6Sopenharmony_ci}
275c29fa5a6Sopenharmony_ci
276c29fa5a6Sopenharmony_ci/**
277c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEnableCombineKey_001
278c29fa5a6Sopenharmony_ci * @tc.desc: Test IsEnableCombineKey
279c29fa5a6Sopenharmony_ci * @tc.type: FUNC
280c29fa5a6Sopenharmony_ci * @tc.require:
281c29fa5a6Sopenharmony_ci */
282c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEnableCombineKey_001, TestSize.Level1)
283c29fa5a6Sopenharmony_ci{
284c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
285c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
286c29fa5a6Sopenharmony_ci    keySubscriberHandler.EnableCombineKey(false);
287c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
288c29fa5a6Sopenharmony_ci    CHKPV(keyEvent);
289c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
290c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
291c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
292c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
293c29fa5a6Sopenharmony_ci    keySubscriberHandler.HandleKeyEvent(keyEvent);
294c29fa5a6Sopenharmony_ci    ASSERT_EQ(keySubscriberHandler.EnableCombineKey(true), RET_OK);
295c29fa5a6Sopenharmony_ci}
296c29fa5a6Sopenharmony_ci
297c29fa5a6Sopenharmony_ci/**
298c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEnableCombineKey_002
299c29fa5a6Sopenharmony_ci * @tc.desc: Test IsEnableCombineKey
300c29fa5a6Sopenharmony_ci * @tc.type: FUNC
301c29fa5a6Sopenharmony_ci * @tc.require:
302c29fa5a6Sopenharmony_ci */
303c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEnableCombineKey_002, TestSize.Level1)
304c29fa5a6Sopenharmony_ci{
305c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
306c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
307c29fa5a6Sopenharmony_ci    keySubscriberHandler.EnableCombineKey(false);
308c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
309c29fa5a6Sopenharmony_ci    CHKPV(keyEvent);
310c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item1;
311c29fa5a6Sopenharmony_ci    item1.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
312c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item1);
313c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item2;
314c29fa5a6Sopenharmony_ci    item2.SetKeyCode(KeyEvent::KEYCODE_L);
315c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item2);
316c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
317c29fa5a6Sopenharmony_ci    ASSERT_EQ(keySubscriberHandler.EnableCombineKey(true), RET_OK);
318c29fa5a6Sopenharmony_ci}
319c29fa5a6Sopenharmony_ci
320c29fa5a6Sopenharmony_ci/**
321c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_EnableCombineKey_001
322c29fa5a6Sopenharmony_ci * @tc.desc: Test enable combineKey
323c29fa5a6Sopenharmony_ci * @tc.type: FUNC
324c29fa5a6Sopenharmony_ci * @tc.require:
325c29fa5a6Sopenharmony_ci */
326c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_EnableCombineKey_001, TestSize.Level1)
327c29fa5a6Sopenharmony_ci{
328c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
329c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
330c29fa5a6Sopenharmony_ci    ASSERT_EQ(keySubscriberHandler.EnableCombineKey(true), RET_OK);
331c29fa5a6Sopenharmony_ci}
332c29fa5a6Sopenharmony_ci
333c29fa5a6Sopenharmony_ci/**
334c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_SubscribeKeyEvent_001
335c29fa5a6Sopenharmony_ci * @tc.desc: Test subscribe keyEvent
336c29fa5a6Sopenharmony_ci * @tc.type: FUNC
337c29fa5a6Sopenharmony_ci * @tc.require:
338c29fa5a6Sopenharmony_ci */
339c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_SubscribeKeyEvent_001, TestSize.Level1)
340c29fa5a6Sopenharmony_ci{
341c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
342c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
343c29fa5a6Sopenharmony_ci    SessionPtr sess;
344c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
345c29fa5a6Sopenharmony_ci    int32_t ret = handler.SubscribeKeyEvent(sess, -1, keyOption);
346c29fa5a6Sopenharmony_ci    ASSERT_EQ(ret, RET_ERR);
347c29fa5a6Sopenharmony_ci    ret = handler.SubscribeKeyEvent(nullptr, 1, keyOption);
348c29fa5a6Sopenharmony_ci    ASSERT_NE(ret, RET_OK);
349c29fa5a6Sopenharmony_ci    ret = handler.SubscribeKeyEvent(sess, 1, keyOption);
350c29fa5a6Sopenharmony_ci    ASSERT_NE(ret, RET_OK);
351c29fa5a6Sopenharmony_ci}
352c29fa5a6Sopenharmony_ci
353c29fa5a6Sopenharmony_ci/**
354c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveSubscriber_001
355c29fa5a6Sopenharmony_ci * @tc.desc: Test remove subscriber
356c29fa5a6Sopenharmony_ci * @tc.type: FUNC
357c29fa5a6Sopenharmony_ci * @tc.require:
358c29fa5a6Sopenharmony_ci */
359c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveSubscriber_001, TestSize.Level1)
360c29fa5a6Sopenharmony_ci{
361c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
362c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
363c29fa5a6Sopenharmony_ci    SessionPtr sess;
364c29fa5a6Sopenharmony_ci    int32_t ret = handler.RemoveSubscriber(sess, 1, true);
365c29fa5a6Sopenharmony_ci    ASSERT_EQ(ret, RET_ERR);
366c29fa5a6Sopenharmony_ci    ret = handler.RemoveSubscriber(nullptr, 1, true);
367c29fa5a6Sopenharmony_ci    ASSERT_EQ(ret, RET_ERR);
368c29fa5a6Sopenharmony_ci}
369c29fa5a6Sopenharmony_ci
370c29fa5a6Sopenharmony_ci/**
371c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEqualKeyOption_001
372c29fa5a6Sopenharmony_ci * @tc.desc: Test is equal keyOption
373c29fa5a6Sopenharmony_ci * @tc.type: FUNC
374c29fa5a6Sopenharmony_ci * @tc.require:
375c29fa5a6Sopenharmony_ci */
376c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEqualKeyOption_001, TestSize.Level1)
377c29fa5a6Sopenharmony_ci{
378c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
379c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
380c29fa5a6Sopenharmony_ci    auto newOption = std::make_shared<KeyOption>();
381c29fa5a6Sopenharmony_ci    auto oldOption = std::make_shared<KeyOption>();
382c29fa5a6Sopenharmony_ci    newOption->SetPreKeys({1, 2, 3});
383c29fa5a6Sopenharmony_ci    oldOption->SetPreKeys({4, 5, 6});
384c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
385c29fa5a6Sopenharmony_ci    newOption->SetFinalKey(1);
386c29fa5a6Sopenharmony_ci    oldOption->SetFinalKey(2);
387c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
388c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyDown(true);
389c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDown(false);
390c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
391c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyDownDuration(100);
392c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDownDuration(200);
393c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
394c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyUpDelay(100);
395c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyUpDelay(200);
396c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
397c29fa5a6Sopenharmony_ci    newOption->SetPreKeys({1, 2, 3});
398c29fa5a6Sopenharmony_ci    oldOption->SetPreKeys({1, 2, 3});
399c29fa5a6Sopenharmony_ci    newOption->SetFinalKey(1);
400c29fa5a6Sopenharmony_ci    oldOption->SetFinalKey(1);
401c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyDown(true);
402c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDown(true);
403c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyDownDuration(100);
404c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDownDuration(100);
405c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyUpDelay(100);
406c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyUpDelay(100);
407c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEqualKeyOption(newOption, oldOption));
408c29fa5a6Sopenharmony_ci}
409c29fa5a6Sopenharmony_ci
410c29fa5a6Sopenharmony_ci/**
411c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsPreKeysMatch_001
412c29fa5a6Sopenharmony_ci * @tc.desc: Test is preKeys match
413c29fa5a6Sopenharmony_ci * @tc.type: FUNC
414c29fa5a6Sopenharmony_ci * @tc.require:
415c29fa5a6Sopenharmony_ci */
416c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsPreKeysMatch_001, TestSize.Level1)
417c29fa5a6Sopenharmony_ci{
418c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
419c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
420c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys;
421c29fa5a6Sopenharmony_ci    std::vector<int32_t> pressedKeys = {1, 2, 3};
422c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsPreKeysMatch(preKeys, pressedKeys));
423c29fa5a6Sopenharmony_ci    preKeys = {1, 2, 3};
424c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsPreKeysMatch(preKeys, pressedKeys));
425c29fa5a6Sopenharmony_ci    pressedKeys = {1, 2, 3, 4};
426c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsPreKeysMatch(preKeys, pressedKeys));
427c29fa5a6Sopenharmony_ci    pressedKeys = {1, 2, 3};
428c29fa5a6Sopenharmony_ci    preKeys = {1, 2, 3, 4};
429c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsPreKeysMatch(preKeys, pressedKeys));
430c29fa5a6Sopenharmony_ci}
431c29fa5a6Sopenharmony_ci
432c29fa5a6Sopenharmony_ci/**
433c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEqualPreKeys_001
434c29fa5a6Sopenharmony_ci * @tc.desc: Test is equal preKeys
435c29fa5a6Sopenharmony_ci * @tc.type: FUNC
436c29fa5a6Sopenharmony_ci * @tc.require:
437c29fa5a6Sopenharmony_ci */
438c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEqualPreKeys_001, TestSize.Level1)
439c29fa5a6Sopenharmony_ci{
440c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
441c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
442c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys = {1, 2, 3};
443c29fa5a6Sopenharmony_ci    std::set<int32_t> pressedKeys = {4, 5, 6};
444c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualPreKeys(preKeys, pressedKeys));
445c29fa5a6Sopenharmony_ci    pressedKeys = {1, 2, 3};
446c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEqualPreKeys(preKeys, pressedKeys));
447c29fa5a6Sopenharmony_ci    pressedKeys = {1, 2};
448c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualPreKeys(preKeys, pressedKeys));
449c29fa5a6Sopenharmony_ci}
450c29fa5a6Sopenharmony_ci
451c29fa5a6Sopenharmony_ci/**
452c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsMatchForegroundPid_001
453c29fa5a6Sopenharmony_ci * @tc.desc: Test is match foreground pid
454c29fa5a6Sopenharmony_ci * @tc.type: FUNC
455c29fa5a6Sopenharmony_ci * @tc.require:
456c29fa5a6Sopenharmony_ci */
457c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsMatchForegroundPid_001, TestSize.Level1)
458c29fa5a6Sopenharmony_ci{
459c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
460c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
461c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subs;
462c29fa5a6Sopenharmony_ci    std::set<int32_t> foregroundPids = {1, 2, 3};
463c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsMatchForegroundPid(subs, foregroundPids));
464c29fa5a6Sopenharmony_ci}
465c29fa5a6Sopenharmony_ci
466c29fa5a6Sopenharmony_ci/**
467c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyDownSubscriber_001
468c29fa5a6Sopenharmony_ci * @tc.desc: Test notify key down subscriber
469c29fa5a6Sopenharmony_ci * @tc.type: FUNC
470c29fa5a6Sopenharmony_ci * @tc.require:
471c29fa5a6Sopenharmony_ci */
472c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyDownSubscriber_001, TestSize.Level1)
473c29fa5a6Sopenharmony_ci{
474c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
475c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
476c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
477c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
478c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
479c29fa5a6Sopenharmony_ci    bool handled = false;
480c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyDownSubscriber(keyEvent, keyOption, subscribers, handled));
481c29fa5a6Sopenharmony_ci    keyEvent = nullptr;
482c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyDownSubscriber(keyEvent, keyOption, subscribers, handled));
483c29fa5a6Sopenharmony_ci}
484c29fa5a6Sopenharmony_ci
485c29fa5a6Sopenharmony_ci/**
486c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyDownRightNow_001
487c29fa5a6Sopenharmony_ci * @tc.desc: Test notify key down right now
488c29fa5a6Sopenharmony_ci * @tc.type: FUNC
489c29fa5a6Sopenharmony_ci * @tc.require:
490c29fa5a6Sopenharmony_ci */
491c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyDownRightNow_001, TestSize.Level1)
492c29fa5a6Sopenharmony_ci{
493c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
494c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
495c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
496c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
497c29fa5a6Sopenharmony_ci    bool handled = false;
498c29fa5a6Sopenharmony_ci    handler.NotifyKeyDownRightNow(keyEvent, subscribers, true, handled);
499c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handled);
500c29fa5a6Sopenharmony_ci}
501c29fa5a6Sopenharmony_ci
502c29fa5a6Sopenharmony_ci/**
503c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyDownDelay_001
504c29fa5a6Sopenharmony_ci * @tc.desc: Test notify key down delay
505c29fa5a6Sopenharmony_ci * @tc.type: FUNC
506c29fa5a6Sopenharmony_ci * @tc.require:
507c29fa5a6Sopenharmony_ci */
508c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyDownDelay_001, TestSize.Level1)
509c29fa5a6Sopenharmony_ci{
510c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
511c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
512c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
513c29fa5a6Sopenharmony_ci    CHKPV(keyEvent);
514c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
515c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
516c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
517c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
518c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
519c29fa5a6Sopenharmony_ci    bool handled = false;
520c29fa5a6Sopenharmony_ci    handler.NotifyKeyDownDelay(keyEvent, subscribers, handled);
521c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handled);
522c29fa5a6Sopenharmony_ci}
523c29fa5a6Sopenharmony_ci
524c29fa5a6Sopenharmony_ci/**
525c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_InitSessionDeleteCallback_001
526c29fa5a6Sopenharmony_ci * @tc.desc: Test init session delete callback
527c29fa5a6Sopenharmony_ci * @tc.type: FUNC
528c29fa5a6Sopenharmony_ci * @tc.require:
529c29fa5a6Sopenharmony_ci */
530c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_InitSessionDeleteCallback_001, TestSize.Level1)
531c29fa5a6Sopenharmony_ci{
532c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
533c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
534c29fa5a6Sopenharmony_ci    handler.callbackInitialized_ = true;
535c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.InitSessionDeleteCallback());
536c29fa5a6Sopenharmony_ci    handler.callbackInitialized_ = false;
537c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.InitSessionDeleteCallback());
538c29fa5a6Sopenharmony_ci}
539c29fa5a6Sopenharmony_ci
540c29fa5a6Sopenharmony_ci/**
541c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyDown_001
542c29fa5a6Sopenharmony_ci * @tc.desc: Test handle key down
543c29fa5a6Sopenharmony_ci * @tc.type: FUNC
544c29fa5a6Sopenharmony_ci * @tc.require:
545c29fa5a6Sopenharmony_ci */
546c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyDown_001, TestSize.Level1)
547c29fa5a6Sopenharmony_ci{
548c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
549c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
550c29fa5a6Sopenharmony_ci    auto result = handler.HandleKeyDown(nullptr);
551c29fa5a6Sopenharmony_ci    ASSERT_FALSE(result);
552c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
553c29fa5a6Sopenharmony_ci    CHKPV(keyEvent);
554c29fa5a6Sopenharmony_ci    result = handler.HandleKeyDown(keyEvent);
555c29fa5a6Sopenharmony_ci    ASSERT_FALSE(result);
556c29fa5a6Sopenharmony_ci}
557c29fa5a6Sopenharmony_ci
558c29fa5a6Sopenharmony_ci/**
559c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveKeyCode_001
560c29fa5a6Sopenharmony_ci * @tc.desc: Test remove key code
561c29fa5a6Sopenharmony_ci * @tc.type: FUNC
562c29fa5a6Sopenharmony_ci * @tc.require:
563c29fa5a6Sopenharmony_ci */
564c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveKeyCode_001, TestSize.Level1)
565c29fa5a6Sopenharmony_ci{
566c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
567c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
568c29fa5a6Sopenharmony_ci    std::vector<int32_t> keyCodes;
569c29fa5a6Sopenharmony_ci    handler.RemoveKeyCode(1, keyCodes);
570c29fa5a6Sopenharmony_ci    ASSERT_TRUE(keyCodes.empty());
571c29fa5a6Sopenharmony_ci    keyCodes = {2, 3, 4};
572c29fa5a6Sopenharmony_ci    handler.RemoveKeyCode(1, keyCodes);
573c29fa5a6Sopenharmony_ci    ASSERT_EQ(keyCodes, (std::vector<int32_t>{2, 3, 4}));
574c29fa5a6Sopenharmony_ci    keyCodes = {1, 2, 3};
575c29fa5a6Sopenharmony_ci    ASSERT_EQ(keyCodes, (std::vector<int32_t>{1, 2, 3}));
576c29fa5a6Sopenharmony_ci}
577c29fa5a6Sopenharmony_ci
578c29fa5a6Sopenharmony_ci/**
579c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_AddSubscriber_001
580c29fa5a6Sopenharmony_ci * @tc.desc: Test add subscriber
581c29fa5a6Sopenharmony_ci * @tc.type: FUNC
582c29fa5a6Sopenharmony_ci * @tc.require:
583c29fa5a6Sopenharmony_ci */
584c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_AddSubscriber_001, TestSize.Level1)
585c29fa5a6Sopenharmony_ci{
586c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
587c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
588c29fa5a6Sopenharmony_ci    SessionPtr sess;
589c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
590c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
591c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> option = std::make_shared<KeyOption>();
592c29fa5a6Sopenharmony_ci    handler.AddSubscriber(subscriber, option, true);
593c29fa5a6Sopenharmony_ci    auto it = handler.subscriberMap_.find(option);
594c29fa5a6Sopenharmony_ci    ASSERT_NE(it->second.front(), subscriber);
595c29fa5a6Sopenharmony_ci    auto newSubscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
596c29fa5a6Sopenharmony_ci    handler.AddSubscriber(newSubscriber, option, true);
597c29fa5a6Sopenharmony_ci    ASSERT_NE(it->second.back(), newSubscriber);
598c29fa5a6Sopenharmony_ci}
599c29fa5a6Sopenharmony_ci
600c29fa5a6Sopenharmony_ci/**
601c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsFunctionKey_001
602c29fa5a6Sopenharmony_ci * @tc.desc: Test is function key
603c29fa5a6Sopenharmony_ci * @tc.type: FUNC
604c29fa5a6Sopenharmony_ci * @tc.require:
605c29fa5a6Sopenharmony_ci */
606c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsFunctionKey_001, TestSize.Level1)
607c29fa5a6Sopenharmony_ci{
608c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
609c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
610c29fa5a6Sopenharmony_ci    auto keyEvent = std::make_shared<KeyEvent>(KeyEvent::KEYCODE_BRIGHTNESS_DOWN);
611c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
612c29fa5a6Sopenharmony_ci    keyEvent = std::make_shared<KeyEvent>(KeyEvent::KEYCODE_BRIGHTNESS_UP);
613c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
614c29fa5a6Sopenharmony_ci    keyEvent = std::make_shared<KeyEvent>(KeyEvent::KEYCODE_MUTE);
615c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
616c29fa5a6Sopenharmony_ci    keyEvent = std::make_shared<KeyEvent>(KeyEvent::KEYCODE_SWITCHVIDEOMODE);
617c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
618c29fa5a6Sopenharmony_ci    keyEvent = std::make_shared<KeyEvent>(KeyEvent::KEYCODE_WLAN);
619c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
620c29fa5a6Sopenharmony_ci    keyEvent = std::make_shared<KeyEvent>(KeyEvent::KEYCODE_CONFIG);
621c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
622c29fa5a6Sopenharmony_ci    keyEvent = std::make_shared<KeyEvent>(KeyEvent::KEYCODE_A);
623c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
624c29fa5a6Sopenharmony_ci}
625c29fa5a6Sopenharmony_ci
626c29fa5a6Sopenharmony_ci/**
627c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_CloneKeyEvent_001
628c29fa5a6Sopenharmony_ci * @tc.desc: Test clone key event
629c29fa5a6Sopenharmony_ci * @tc.type: FUNC
630c29fa5a6Sopenharmony_ci * @tc.require:
631c29fa5a6Sopenharmony_ci */
632c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_CloneKeyEvent_001, TestSize.Level1)
633c29fa5a6Sopenharmony_ci{
634c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
635c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
636c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
637c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
638c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.CloneKeyEvent(keyEvent));
639c29fa5a6Sopenharmony_ci    handler.keyEvent_ = nullptr;
640c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.CloneKeyEvent(keyEvent));
641c29fa5a6Sopenharmony_ci}
642c29fa5a6Sopenharmony_ci
643c29fa5a6Sopenharmony_ci/**
644c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyUpSubscriber_001
645c29fa5a6Sopenharmony_ci * @tc.desc: Test notify key up subscriber
646c29fa5a6Sopenharmony_ci * @tc.type: FUNC
647c29fa5a6Sopenharmony_ci * @tc.require:
648c29fa5a6Sopenharmony_ci */
649c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyUpSubscriber_001, TestSize.Level1)
650c29fa5a6Sopenharmony_ci{
651c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
652c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
653c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
654c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
655c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
656c29fa5a6Sopenharmony_ci    bool handled = false;
657c29fa5a6Sopenharmony_ci    handler.NotifyKeyUpSubscriber(keyEvent, subscribers, handled);
658c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handled);
659c29fa5a6Sopenharmony_ci    handler.isForegroundExits_ = false;
660c29fa5a6Sopenharmony_ci    handler.NotifyKeyUpSubscriber(keyEvent, subscribers, handled);
661c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handled);
662c29fa5a6Sopenharmony_ci    handler.isForegroundExits_ = true;
663c29fa5a6Sopenharmony_ci    handler.foregroundPids_.clear();
664c29fa5a6Sopenharmony_ci    handler.NotifyKeyUpSubscriber(keyEvent, subscribers, handled);
665c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handled);
666c29fa5a6Sopenharmony_ci}
667c29fa5a6Sopenharmony_ci
668c29fa5a6Sopenharmony_ci/**
669c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEnableCombineKeySwipe_001
670c29fa5a6Sopenharmony_ci * @tc.desc: Test is enable combine key swipe
671c29fa5a6Sopenharmony_ci * @tc.type: FUNC
672c29fa5a6Sopenharmony_ci * @tc.require:
673c29fa5a6Sopenharmony_ci */
674c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEnableCombineKeySwipe_001, TestSize.Level1)
675c29fa5a6Sopenharmony_ci{
676c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
677c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
678c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
679c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
680c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
681c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
682c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
683c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_CTRL_LEFT);
684c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKeySwipe(keyEvent));
685c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
686c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
687c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
688c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKeySwipe(keyEvent));
689c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_DPAD_RIGHT);
690c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
691c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_DPAD_RIGHT);
692c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKeySwipe(keyEvent));
693c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_CTRL_RIGHT);
694c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
695c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_CTRL_RIGHT);
696c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKeySwipe(keyEvent));
697c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_A);
698c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
699c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_A);
700c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKeySwipe(keyEvent));
701c29fa5a6Sopenharmony_ci}
702c29fa5a6Sopenharmony_ci
703c29fa5a6Sopenharmony_ci/**
704c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSubscribeKeyEvent_001
705c29fa5a6Sopenharmony_ci * @tc.desc: Test on subscribe key event
706c29fa5a6Sopenharmony_ci * @tc.type: FUNC
707c29fa5a6Sopenharmony_ci * @tc.require:
708c29fa5a6Sopenharmony_ci */
709c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSubscribeKeyEvent_001, TestSize.Level1)
710c29fa5a6Sopenharmony_ci{
711c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
712c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
713c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
714c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
715c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
716c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
717c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
718c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
719c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
720c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
721c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_CANCEL);
722c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
723c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
724c29fa5a6Sopenharmony_ci    handler.OnSubscribeKeyEvent(keyEvent);
725c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
726c29fa5a6Sopenharmony_ci}
727c29fa5a6Sopenharmony_ci
728c29fa5a6Sopenharmony_ci/**
729c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSessionDelete_001
730c29fa5a6Sopenharmony_ci * @tc.desc: Test onSession delete
731c29fa5a6Sopenharmony_ci * @tc.type: FUNC
732c29fa5a6Sopenharmony_ci * @tc.require:
733c29fa5a6Sopenharmony_ci */
734c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSessionDelete_001, TestSize.Level1)
735c29fa5a6Sopenharmony_ci{
736c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
737c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
738c29fa5a6Sopenharmony_ci    UDSServer udsServer;
739c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
740c29fa5a6Sopenharmony_ci    SessionPtr sess = udsServer.GetSessionByPid(1);
741c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>>subscriberMap_;
742c29fa5a6Sopenharmony_ci    auto newSubscriber1 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
743c29fa5a6Sopenharmony_ci    auto newSubscriber2 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(2, sess, keyOption);
744c29fa5a6Sopenharmony_ci    auto newSubscriber3 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(3, sess, keyOption);
745c29fa5a6Sopenharmony_ci    subscriberMap_.push_back(newSubscriber1);
746c29fa5a6Sopenharmony_ci    subscriberMap_.push_back(newSubscriber2);
747c29fa5a6Sopenharmony_ci    subscriberMap_.push_back(newSubscriber3);
748c29fa5a6Sopenharmony_ci    handler.OnSessionDelete(sess);
749c29fa5a6Sopenharmony_ci    for (auto& sub : subscriberMap_) {
750c29fa5a6Sopenharmony_ci        ASSERT_EQ(sub->sess_, nullptr);
751c29fa5a6Sopenharmony_ci    }
752c29fa5a6Sopenharmony_ci}
753c29fa5a6Sopenharmony_ci
754c29fa5a6Sopenharmony_ci/**
755c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_ClearSubscriberTimer_001
756c29fa5a6Sopenharmony_ci * @tc.desc: Test clear subscriber timer
757c29fa5a6Sopenharmony_ci * @tc.type: FUNC
758c29fa5a6Sopenharmony_ci * @tc.require:
759c29fa5a6Sopenharmony_ci */
760c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_ClearSubscriberTimer_001, TestSize.Level1)
761c29fa5a6Sopenharmony_ci{
762c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
763c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
764c29fa5a6Sopenharmony_ci    SessionPtr sess;
765c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
766c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
767c29fa5a6Sopenharmony_ci    auto subscriber1 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
768c29fa5a6Sopenharmony_ci    auto subscriber2 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(2, sess, keyOption);
769c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber1);
770c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber2);
771c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.ClearSubscriberTimer(subscribers));
772c29fa5a6Sopenharmony_ci}
773c29fa5a6Sopenharmony_ci
774c29fa5a6Sopenharmony_ci/**
775c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnTimer_001
776c29fa5a6Sopenharmony_ci * @tc.desc: Test OnTimer
777c29fa5a6Sopenharmony_ci * @tc.type: FUNC
778c29fa5a6Sopenharmony_ci * @tc.require:
779c29fa5a6Sopenharmony_ci */
780c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnTimer_001, TestSize.Level1)
781c29fa5a6Sopenharmony_ci{
782c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
783c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
784c29fa5a6Sopenharmony_ci    SessionPtr sess;
785c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
786c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
787c29fa5a6Sopenharmony_ci    subscriber->keyEvent_.reset();
788c29fa5a6Sopenharmony_ci    handler.OnTimer(subscriber);
789c29fa5a6Sopenharmony_ci    ASSERT_EQ(subscriber->keyEvent_, nullptr);
790c29fa5a6Sopenharmony_ci}
791c29fa5a6Sopenharmony_ci
792c29fa5a6Sopenharmony_ci/**
793c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_SubscriberNotifyNap_001
794c29fa5a6Sopenharmony_ci * @tc.desc: Test SubscriberNotifyNap
795c29fa5a6Sopenharmony_ci * @tc.type: FUNC
796c29fa5a6Sopenharmony_ci * @tc.require:
797c29fa5a6Sopenharmony_ci */
798c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_SubscriberNotifyNap_001, TestSize.Level1)
799c29fa5a6Sopenharmony_ci{
800c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
801c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
802c29fa5a6Sopenharmony_ci    SessionPtr sess;
803c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
804c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
805c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.SubscriberNotifyNap(subscriber));
806c29fa5a6Sopenharmony_ci}
807c29fa5a6Sopenharmony_ci
808c29fa5a6Sopenharmony_ci/**
809c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyUp_001
810c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleKeyUp
811c29fa5a6Sopenharmony_ci * @tc.type: FUNC
812c29fa5a6Sopenharmony_ci * @tc.require:
813c29fa5a6Sopenharmony_ci */
814c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyUp_001, TestSize.Level1)
815c29fa5a6Sopenharmony_ci{
816c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
817c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
818c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
819c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
820c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
821c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
822c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
823c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
824c29fa5a6Sopenharmony_ci    bool handled = handler.HandleKeyUp(keyEvent);
825c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handled);
826c29fa5a6Sopenharmony_ci}
827c29fa5a6Sopenharmony_ci
828c29fa5a6Sopenharmony_ci/**
829c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifySubscriber_001
830c29fa5a6Sopenharmony_ci * @tc.desc: Test NotifySubscriber
831c29fa5a6Sopenharmony_ci * @tc.type: FUNC
832c29fa5a6Sopenharmony_ci * @tc.require:
833c29fa5a6Sopenharmony_ci */
834c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifySubscriber_001, TestSize.Level1)
835c29fa5a6Sopenharmony_ci{
836c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
837c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
838c29fa5a6Sopenharmony_ci    SessionPtr sess;
839c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
840c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
841c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
842c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
843c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
844c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
845c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
846c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
847c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
848c29fa5a6Sopenharmony_ci}
849c29fa5a6Sopenharmony_ci
850c29fa5a6Sopenharmony_ci/**
851c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyCancel_001
852c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleKeyCancel
853c29fa5a6Sopenharmony_ci * @tc.type: FUNC
854c29fa5a6Sopenharmony_ci * @tc.require:
855c29fa5a6Sopenharmony_ci */
856c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyCancel_001, TestSize.Level1)
857c29fa5a6Sopenharmony_ci{
858c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
859c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
860c29fa5a6Sopenharmony_ci    UDSServer udsServer;
861c29fa5a6Sopenharmony_ci    SessionPtr sess = udsServer.GetSessionByPid(1);
862c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
863c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
864c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
865c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>>subscriberMap_;
866c29fa5a6Sopenharmony_ci    auto newSubscriber1 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
867c29fa5a6Sopenharmony_ci    auto newSubscriber2 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(2, sess, keyOption);
868c29fa5a6Sopenharmony_ci    subscriberMap_.push_back(newSubscriber1);
869c29fa5a6Sopenharmony_ci    subscriberMap_.push_back(newSubscriber2);
870c29fa5a6Sopenharmony_ci    EXPECT_FALSE(handler.HandleKeyCancel(keyEvent));
871c29fa5a6Sopenharmony_ci}
872c29fa5a6Sopenharmony_ci
873c29fa5a6Sopenharmony_ci/**
874c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_PrintKeyOption_001
875c29fa5a6Sopenharmony_ci * @tc.desc: Test PrintKeyOption
876c29fa5a6Sopenharmony_ci * @tc.type: FUNC
877c29fa5a6Sopenharmony_ci * @tc.require:
878c29fa5a6Sopenharmony_ci */
879c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_PrintKeyOption_001, TestSize.Level1)
880c29fa5a6Sopenharmony_ci{
881c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
882c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
883c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
884c29fa5a6Sopenharmony_ci    keyOption->SetFinalKey(1);
885c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyDown(true);
886c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyDownDuration(1000);
887c29fa5a6Sopenharmony_ci    keyOption->SetPreKeys({1, 2, 3});
888c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.PrintKeyOption(keyOption));
889c29fa5a6Sopenharmony_ci}
890c29fa5a6Sopenharmony_ci
891c29fa5a6Sopenharmony_ci/**
892c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyUpWithDelay_002
893c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleKeyUpWithDelay
894c29fa5a6Sopenharmony_ci * @tc.type: FUNC
895c29fa5a6Sopenharmony_ci * @tc.require:
896c29fa5a6Sopenharmony_ci */
897c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyUpWithDelay_002, TestSize.Level1)
898c29fa5a6Sopenharmony_ci{
899c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
900c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
901c29fa5a6Sopenharmony_ci    SessionPtr sess;
902c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
903c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
904c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
905c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
906c29fa5a6Sopenharmony_ci
907c29fa5a6Sopenharmony_ci    subscriber->keyOption_->finalKeyUpDelay_ = -2;
908c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.HandleKeyUpWithDelay(keyEvent, subscriber));
909c29fa5a6Sopenharmony_ci}
910c29fa5a6Sopenharmony_ci
911c29fa5a6Sopenharmony_ci/**
912c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_001
913c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
914c29fa5a6Sopenharmony_ci * @tc.type: FUNC
915c29fa5a6Sopenharmony_ci * @tc.require:
916c29fa5a6Sopenharmony_ci */
917c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_001, TestSize.Level1)
918c29fa5a6Sopenharmony_ci{
919c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
920c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
921c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
922c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
923c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
924c29fa5a6Sopenharmony_ci    data.SetWant(want);
925c29fa5a6Sopenharmony_ci    int callState = 0;
926c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
927c29fa5a6Sopenharmony_ci
928c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
929c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
930c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
931c29fa5a6Sopenharmony_ci}
932c29fa5a6Sopenharmony_ci
933c29fa5a6Sopenharmony_ci/**
934c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_002
935c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
936c29fa5a6Sopenharmony_ci * @tc.type: FUNC
937c29fa5a6Sopenharmony_ci * @tc.require:
938c29fa5a6Sopenharmony_ci */
939c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_002, TestSize.Level1)
940c29fa5a6Sopenharmony_ci{
941c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
942c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
943c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
944c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_DISCONNECTED);
945c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
946c29fa5a6Sopenharmony_ci    data.SetWant(want);
947c29fa5a6Sopenharmony_ci    int callState = 0;
948c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
949c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
950c29fa5a6Sopenharmony_ci    data.SetWant(want);
951c29fa5a6Sopenharmony_ci    callState = 0;
952c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
953c29fa5a6Sopenharmony_ci
954c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
955c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
956c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
957c29fa5a6Sopenharmony_ci}
958c29fa5a6Sopenharmony_ci
959c29fa5a6Sopenharmony_ci/**
960c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_003
961c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
962c29fa5a6Sopenharmony_ci * @tc.type: FUNC
963c29fa5a6Sopenharmony_ci * @tc.require:
964c29fa5a6Sopenharmony_ci */
965c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_003, TestSize.Level1)
966c29fa5a6Sopenharmony_ci{
967c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
968c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
969c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
970c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_DISCONNECTED);
971c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
972c29fa5a6Sopenharmony_ci    data.SetWant(want);
973c29fa5a6Sopenharmony_ci    int callState = 0;
974c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
975c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
976c29fa5a6Sopenharmony_ci    data.SetWant(want);
977c29fa5a6Sopenharmony_ci    callState = 0;
978c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
979c29fa5a6Sopenharmony_ci
980c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
981c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
982c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
983c29fa5a6Sopenharmony_ci}
984c29fa5a6Sopenharmony_ci
985c29fa5a6Sopenharmony_ci/**
986c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_004
987c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
988c29fa5a6Sopenharmony_ci * @tc.type: FUNC
989c29fa5a6Sopenharmony_ci * @tc.require:
990c29fa5a6Sopenharmony_ci */
991c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_004, TestSize.Level1)
992c29fa5a6Sopenharmony_ci{
993c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
994c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
995c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
996c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_DISCONNECTED);
997c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
998c29fa5a6Sopenharmony_ci    data.SetWant(want);
999c29fa5a6Sopenharmony_ci    int callState = 0;
1000c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1001c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
1002c29fa5a6Sopenharmony_ci    data.SetWant(want);
1003c29fa5a6Sopenharmony_ci    callState = 0;
1004c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1005c29fa5a6Sopenharmony_ci
1006c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1007c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_F1);
1008c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1009c29fa5a6Sopenharmony_ci}
1010c29fa5a6Sopenharmony_ci
1011c29fa5a6Sopenharmony_ci/**
1012c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_005
1013c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1014c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1015c29fa5a6Sopenharmony_ci * @tc.require:
1016c29fa5a6Sopenharmony_ci */
1017c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_005, TestSize.Level1)
1018c29fa5a6Sopenharmony_ci{
1019c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1020c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1021c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
1022c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
1023c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
1024c29fa5a6Sopenharmony_ci    data.SetWant(want);
1025c29fa5a6Sopenharmony_ci    int callState = 0;
1026c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1027c29fa5a6Sopenharmony_ci
1028c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1029c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1030c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1031c29fa5a6Sopenharmony_ci}
1032c29fa5a6Sopenharmony_ci
1033c29fa5a6Sopenharmony_ci/**
1034c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_006
1035c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1036c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1037c29fa5a6Sopenharmony_ci * @tc.require:
1038c29fa5a6Sopenharmony_ci */
1039c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_006, TestSize.Level1)
1040c29fa5a6Sopenharmony_ci{
1041c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1042c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1043c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
1044c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_DISCONNECTED);
1045c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
1046c29fa5a6Sopenharmony_ci    data.SetWant(want);
1047c29fa5a6Sopenharmony_ci    int callState = 0;
1048c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1049c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
1050c29fa5a6Sopenharmony_ci    data.SetWant(want);
1051c29fa5a6Sopenharmony_ci    callState = 0;
1052c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1053c29fa5a6Sopenharmony_ci
1054c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1055c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
1056c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1057c29fa5a6Sopenharmony_ci}
1058c29fa5a6Sopenharmony_ci
1059c29fa5a6Sopenharmony_ci/**
1060c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_007
1061c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1062c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1063c29fa5a6Sopenharmony_ci * @tc.require:
1064c29fa5a6Sopenharmony_ci */
1065c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_007, TestSize.Level1)
1066c29fa5a6Sopenharmony_ci{
1067c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1068c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1069c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
1070c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_DISCONNECTED);
1071c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
1072c29fa5a6Sopenharmony_ci    data.SetWant(want);
1073c29fa5a6Sopenharmony_ci    int callState = 0;
1074c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1075c29fa5a6Sopenharmony_ci
1076c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1077c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1078c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1079c29fa5a6Sopenharmony_ci}
1080c29fa5a6Sopenharmony_ci
1081c29fa5a6Sopenharmony_ci/**
1082c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_008
1083c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1084c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1085c29fa5a6Sopenharmony_ci * @tc.require:
1086c29fa5a6Sopenharmony_ci */
1087c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_008, TestSize.Level1)
1088c29fa5a6Sopenharmony_ci{
1089c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1090c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1091c29fa5a6Sopenharmony_ci
1092c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1093c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
1094c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1095c29fa5a6Sopenharmony_ci}
1096c29fa5a6Sopenharmony_ci
1097c29fa5a6Sopenharmony_ci/**
1098c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_009
1099c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1100c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1101c29fa5a6Sopenharmony_ci * @tc.require:
1102c29fa5a6Sopenharmony_ci */
1103c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_009, TestSize.Level1)
1104c29fa5a6Sopenharmony_ci{
1105c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1106c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1107c29fa5a6Sopenharmony_ci
1108c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1109c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
1110c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1111c29fa5a6Sopenharmony_ci}
1112c29fa5a6Sopenharmony_ci
1113c29fa5a6Sopenharmony_ci/**
1114c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_SubscribeKeyEvent_002
1115c29fa5a6Sopenharmony_ci * @tc.desc: Test subscribe keyEvent
1116c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1117c29fa5a6Sopenharmony_ci * @tc.require:
1118c29fa5a6Sopenharmony_ci */
1119c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_SubscribeKeyEvent_002, TestSize.Level1)
1120c29fa5a6Sopenharmony_ci{
1121c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1122c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1123c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
1124c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1125c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1126c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys;
1127c29fa5a6Sopenharmony_ci    preKeys.insert(1);
1128c29fa5a6Sopenharmony_ci    keyOption->SetPreKeys(preKeys);
1129c29fa5a6Sopenharmony_ci    ASSERT_NE(handler.SubscribeKeyEvent(sess, subscribeId, keyOption), RET_OK);
1130c29fa5a6Sopenharmony_ci
1131c29fa5a6Sopenharmony_ci    preKeys.insert(2);
1132c29fa5a6Sopenharmony_ci    preKeys.insert(3);
1133c29fa5a6Sopenharmony_ci    preKeys.insert(4);
1134c29fa5a6Sopenharmony_ci    preKeys.insert(5);
1135c29fa5a6Sopenharmony_ci    preKeys.insert(6);
1136c29fa5a6Sopenharmony_ci    keyOption->SetPreKeys(preKeys);
1137c29fa5a6Sopenharmony_ci    ASSERT_NE(handler.SubscribeKeyEvent(sess, subscribeId, keyOption), RET_OK);
1138c29fa5a6Sopenharmony_ci}
1139c29fa5a6Sopenharmony_ci
1140c29fa5a6Sopenharmony_ci/**
1141c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEqualKeyOption
1142c29fa5a6Sopenharmony_ci * @tc.desc: Test Is Equal KeyOption
1143c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1144c29fa5a6Sopenharmony_ci * @tc.require:
1145c29fa5a6Sopenharmony_ci */
1146c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEqualKeyOption, TestSize.Level1)
1147c29fa5a6Sopenharmony_ci{
1148c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1149c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1150c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> newOption = std::make_shared<KeyOption>();
1151c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> oldOption = std::make_shared<KeyOption>();
1152c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys;
1153c29fa5a6Sopenharmony_ci    std::set<int32_t> pressedKeys;
1154c29fa5a6Sopenharmony_ci    preKeys.insert(1);
1155c29fa5a6Sopenharmony_ci    pressedKeys.insert(1);
1156c29fa5a6Sopenharmony_ci    newOption->SetPreKeys(preKeys);
1157c29fa5a6Sopenharmony_ci    oldOption->SetPreKeys(pressedKeys);
1158c29fa5a6Sopenharmony_ci    newOption->SetFinalKey(1);
1159c29fa5a6Sopenharmony_ci    oldOption->SetFinalKey(2);
1160c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
1161c29fa5a6Sopenharmony_ci
1162c29fa5a6Sopenharmony_ci    oldOption->SetFinalKey(1);
1163c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyDown(true);
1164c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDown(false);
1165c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
1166c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDown(true);
1167c29fa5a6Sopenharmony_ci
1168c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyDownDuration(100);
1169c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDownDuration(150);
1170c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
1171c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyDownDuration(100);
1172c29fa5a6Sopenharmony_ci
1173c29fa5a6Sopenharmony_ci    newOption->SetFinalKeyUpDelay(100);
1174c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyUpDelay(150);
1175c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEqualKeyOption(newOption, oldOption));
1176c29fa5a6Sopenharmony_ci    oldOption->SetFinalKeyUpDelay(100);
1177c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEqualKeyOption(newOption, oldOption));
1178c29fa5a6Sopenharmony_ci}
1179c29fa5a6Sopenharmony_ci
1180c29fa5a6Sopenharmony_ci/**
1181c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEnableCombineKey_003
1182c29fa5a6Sopenharmony_ci * @tc.desc: Test Is Enable CombineKey
1183c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1184c29fa5a6Sopenharmony_ci * @tc.require:
1185c29fa5a6Sopenharmony_ci */
1186c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEnableCombineKey_003, TestSize.Level1)
1187c29fa5a6Sopenharmony_ci{
1188c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1189c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1190c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1191c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1192c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = false;
1193c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_BRIGHTNESS_DOWN);
1194c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_A);
1195c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1196c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKey(keyEvent));
1197c29fa5a6Sopenharmony_ci
1198c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1199c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1200c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKey(keyEvent));
1201c29fa5a6Sopenharmony_ci
1202c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_B);
1203c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1204c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEnableCombineKey(keyEvent));
1205c29fa5a6Sopenharmony_ci
1206c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_DPAD_RIGHT);
1207c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEnableCombineKey(keyEvent));
1208c29fa5a6Sopenharmony_ci
1209c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
1210c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsEnableCombineKey(keyEvent));
1211c29fa5a6Sopenharmony_ci}
1212c29fa5a6Sopenharmony_ci
1213c29fa5a6Sopenharmony_ci/**
1214c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEnableCombineKey_004
1215c29fa5a6Sopenharmony_ci * @tc.desc: Test Is Enable CombineKey
1216c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1217c29fa5a6Sopenharmony_ci * @tc.require:
1218c29fa5a6Sopenharmony_ci */
1219c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEnableCombineKey_004, TestSize.Level1)
1220c29fa5a6Sopenharmony_ci{
1221c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1222c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1223c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1224c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1225c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1226c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = false;
1227c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
1228c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_L);
1229c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1230c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKey(keyEvent));
1231c29fa5a6Sopenharmony_ci}
1232c29fa5a6Sopenharmony_ci
1233c29fa5a6Sopenharmony_ci/**
1234c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEnableCombineKey_005
1235c29fa5a6Sopenharmony_ci * @tc.desc: Test Is Enable CombineKey
1236c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1237c29fa5a6Sopenharmony_ci * @tc.require:
1238c29fa5a6Sopenharmony_ci */
1239c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEnableCombineKey_005, TestSize.Level1)
1240c29fa5a6Sopenharmony_ci{
1241c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1242c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1243c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1244c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1245c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1246c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = false;
1247c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
1248c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_META_LEFT);
1249c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1250c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKey(keyEvent));
1251c29fa5a6Sopenharmony_ci}
1252c29fa5a6Sopenharmony_ci
1253c29fa5a6Sopenharmony_ci/**
1254c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsEnableCombineKey_006
1255c29fa5a6Sopenharmony_ci * @tc.desc: Test Is Enable CombineKey
1256c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1257c29fa5a6Sopenharmony_ci * @tc.require:
1258c29fa5a6Sopenharmony_ci */
1259c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsEnableCombineKey_006, TestSize.Level1)
1260c29fa5a6Sopenharmony_ci{
1261c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1262c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1263c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1264c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1265c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1266c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = false;
1267c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_L);
1268c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_META_RIGHT);
1269c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1270c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsEnableCombineKey(keyEvent));
1271c29fa5a6Sopenharmony_ci}
1272c29fa5a6Sopenharmony_ci
1273c29fa5a6Sopenharmony_ci/**
1274c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveSubscriber
1275c29fa5a6Sopenharmony_ci * @tc.desc: Test Remove Subscriber
1276c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1277c29fa5a6Sopenharmony_ci * @tc.require:
1278c29fa5a6Sopenharmony_ci */
1279c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveSubscriber, TestSize.Level1)
1280c29fa5a6Sopenharmony_ci{
1281c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1282c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1283c29fa5a6Sopenharmony_ci    int32_t subscribeId = 2;
1284c29fa5a6Sopenharmony_ci    int32_t id = 1;
1285c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1286c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1287c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1288c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1289c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1290c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1291c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscriberList));
1292c29fa5a6Sopenharmony_ci    ASSERT_EQ(handler.RemoveSubscriber(session, subscribeId, true), RET_ERR);
1293c29fa5a6Sopenharmony_ci    subscribeId = 1;
1294c29fa5a6Sopenharmony_ci    ASSERT_EQ(handler.RemoveSubscriber(session, subscribeId, true), RET_OK);
1295c29fa5a6Sopenharmony_ci}
1296c29fa5a6Sopenharmony_ci
1297c29fa5a6Sopenharmony_ci/**
1298c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsFunctionKey
1299c29fa5a6Sopenharmony_ci * @tc.desc: Test IsFunctionKey
1300c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1301c29fa5a6Sopenharmony_ci * @tc.require:
1302c29fa5a6Sopenharmony_ci */
1303c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsFunctionKey, TestSize.Level1)
1304c29fa5a6Sopenharmony_ci{
1305c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1306c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1307c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1308c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1309c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_BRIGHTNESS_UP);
1310c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsFunctionKey(keyEvent));
1311c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
1312c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsFunctionKey(keyEvent));
1313c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
1314c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsFunctionKey(keyEvent));
1315c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_MUTE);
1316c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsFunctionKey(keyEvent));
1317c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_MUTE);
1318c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsFunctionKey(keyEvent));
1319c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_SWITCHVIDEOMODE);
1320c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsFunctionKey(keyEvent));
1321c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_WLAN);
1322c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
1323c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_CONFIG);
1324c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsFunctionKey(keyEvent));
1325c29fa5a6Sopenharmony_ci}
1326c29fa5a6Sopenharmony_ci
1327c29fa5a6Sopenharmony_ci/**
1328c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSubscribeKeyEvent
1329c29fa5a6Sopenharmony_ci * @tc.desc: Test OnSubscribeKeyEvent
1330c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1331c29fa5a6Sopenharmony_ci * @tc.require:
1332c29fa5a6Sopenharmony_ci */
1333c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSubscribeKeyEvent, TestSize.Level1)
1334c29fa5a6Sopenharmony_ci{
1335c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1336c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1337c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1338c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1339c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1340c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = false;
1341c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_BRIGHTNESS_DOWN);
1342c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_A);
1343c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1344c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_B);
1345c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1346c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
1347c29fa5a6Sopenharmony_ci
1348c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = true;
1349c29fa5a6Sopenharmony_ci    handler.hasEventExecuting_ = true;
1350c29fa5a6Sopenharmony_ci    handler.keyEvent_ = KeyEvent::Create();
1351c29fa5a6Sopenharmony_ci    ASSERT_NE(handler.keyEvent_, nullptr);
1352c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyCode(KeyEvent::KEYCODE_BRIGHTNESS_DOWN);
1353c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1354c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1355c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_A);
1356c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
1357c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_B);
1358c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
1359c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.OnSubscribeKeyEvent(keyEvent));
1360c29fa5a6Sopenharmony_ci
1361c29fa5a6Sopenharmony_ci    handler.hasEventExecuting_ = false;
1362c29fa5a6Sopenharmony_ci    handler.needSkipPowerKeyUp_ = true;
1363c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1364c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.OnSubscribeKeyEvent(keyEvent));
1365c29fa5a6Sopenharmony_ci
1366c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UNKNOWN);
1367c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
1368c29fa5a6Sopenharmony_ci}
1369c29fa5a6Sopenharmony_ci
1370c29fa5a6Sopenharmony_ci/**
1371c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSessionDelete
1372c29fa5a6Sopenharmony_ci * @tc.desc: Test OnSessionDelete
1373c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1374c29fa5a6Sopenharmony_ci * @tc.require:
1375c29fa5a6Sopenharmony_ci */
1376c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSessionDelete, TestSize.Level1)
1377c29fa5a6Sopenharmony_ci{
1378c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1379c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1380c29fa5a6Sopenharmony_ci    int32_t id = 1;
1381c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1382c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1383c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1384c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1385c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1386c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1387c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscriberList));
1388c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1389c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.OnSessionDelete(sess));
1390c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.OnSessionDelete(session));
1391c29fa5a6Sopenharmony_ci}
1392c29fa5a6Sopenharmony_ci
1393c29fa5a6Sopenharmony_ci/**
1394c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsPreKeysMatch
1395c29fa5a6Sopenharmony_ci * @tc.desc: Test IsPreKeysMatch
1396c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1397c29fa5a6Sopenharmony_ci * @tc.require:
1398c29fa5a6Sopenharmony_ci */
1399c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsPreKeysMatch, TestSize.Level1)
1400c29fa5a6Sopenharmony_ci{
1401c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1402c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1403c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys;
1404c29fa5a6Sopenharmony_ci    std::vector<int32_t> pressedKeys;
1405c29fa5a6Sopenharmony_ci    preKeys.insert(KeyEvent::KEYCODE_A);
1406c29fa5a6Sopenharmony_ci    pressedKeys.push_back(KeyEvent::KEYCODE_B);
1407c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsPreKeysMatch(preKeys, pressedKeys));
1408c29fa5a6Sopenharmony_ci    preKeys.clear();
1409c29fa5a6Sopenharmony_ci    pressedKeys.clear();
1410c29fa5a6Sopenharmony_ci    preKeys.insert(KeyEvent::KEYCODE_C);
1411c29fa5a6Sopenharmony_ci    pressedKeys.push_back(KeyEvent::KEYCODE_C);
1412c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsPreKeysMatch(preKeys, pressedKeys));
1413c29fa5a6Sopenharmony_ci}
1414c29fa5a6Sopenharmony_ci
1415c29fa5a6Sopenharmony_ci/**
1416c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsMatchForegroundPid
1417c29fa5a6Sopenharmony_ci * @tc.desc: Test Is Match Foreground Pid
1418c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1419c29fa5a6Sopenharmony_ci * @tc.require:
1420c29fa5a6Sopenharmony_ci */
1421c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsMatchForegroundPid, TestSize.Level1)
1422c29fa5a6Sopenharmony_ci{
1423c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1424c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1425c29fa5a6Sopenharmony_ci    int32_t id = 1;
1426c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1427c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1428c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1429c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1430c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1431c29fa5a6Sopenharmony_ci    std::set<int32_t> foregroundPids;
1432c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1433c29fa5a6Sopenharmony_ci    foregroundPids.insert(1);
1434c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsMatchForegroundPid(subscriberList, foregroundPids));
1435c29fa5a6Sopenharmony_ci
1436c29fa5a6Sopenharmony_ci    foregroundPids.insert(100);
1437c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsMatchForegroundPid(subscriberList, foregroundPids));
1438c29fa5a6Sopenharmony_ci}
1439c29fa5a6Sopenharmony_ci
1440c29fa5a6Sopenharmony_ci/**
1441c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyDownSubscriber
1442c29fa5a6Sopenharmony_ci * @tc.desc: Test Notify Key Down Subscriber
1443c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1444c29fa5a6Sopenharmony_ci * @tc.require:
1445c29fa5a6Sopenharmony_ci */
1446c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyDownSubscriber, TestSize.Level1)
1447c29fa5a6Sopenharmony_ci{
1448c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1449c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1450c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1451c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1452c29fa5a6Sopenharmony_ci    int32_t id = 1;
1453c29fa5a6Sopenharmony_ci    bool handled = false;
1454c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1455c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1456c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1457c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1458c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1459c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1460c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyDownDuration(100);
1461c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyDownSubscriber(keyEvent, keyOption, subscriberList, handled));
1462c29fa5a6Sopenharmony_ci}
1463c29fa5a6Sopenharmony_ci
1464c29fa5a6Sopenharmony_ci/**
1465c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyDownRightNow
1466c29fa5a6Sopenharmony_ci * @tc.desc: Test Notify Key Down Right Now
1467c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1468c29fa5a6Sopenharmony_ci * @tc.require:
1469c29fa5a6Sopenharmony_ci */
1470c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyDownRightNow, TestSize.Level1)
1471c29fa5a6Sopenharmony_ci{
1472c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1473c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1474c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1475c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1476c29fa5a6Sopenharmony_ci    int32_t id = 1;
1477c29fa5a6Sopenharmony_ci    bool handled = false;
1478c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1479c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1480c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1481c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1482c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1483c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1484c29fa5a6Sopenharmony_ci    handler.isForegroundExits_ = true;
1485c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyDownRightNow(keyEvent, subscriberList, true, handled));
1486c29fa5a6Sopenharmony_ci
1487c29fa5a6Sopenharmony_ci    handler.isForegroundExits_ = false;
1488c29fa5a6Sopenharmony_ci    handler.foregroundPids_.insert(UDS_PID);
1489c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1490c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyDownRightNow(keyEvent, subscriberList, true, handled));
1491c29fa5a6Sopenharmony_ci}
1492c29fa5a6Sopenharmony_ci
1493c29fa5a6Sopenharmony_ci/**
1494c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyDownDelay
1495c29fa5a6Sopenharmony_ci * @tc.desc: Test Notify KeyDown Delay
1496c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1497c29fa5a6Sopenharmony_ci * @tc.require:
1498c29fa5a6Sopenharmony_ci */
1499c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyDownDelay, TestSize.Level1)
1500c29fa5a6Sopenharmony_ci{
1501c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1502c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1503c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1504c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1505c29fa5a6Sopenharmony_ci    int32_t id = 1;
1506c29fa5a6Sopenharmony_ci    bool handled = false;
1507c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1508c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1509c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1510c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1511c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1512c29fa5a6Sopenharmony_ci    subscriber->timerId_ = 1;
1513c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1514c29fa5a6Sopenharmony_ci    handler.isForegroundExits_ = true;
1515c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyDownDelay(keyEvent, subscriberList, handled));
1516c29fa5a6Sopenharmony_ci
1517c29fa5a6Sopenharmony_ci    handler.isForegroundExits_ = false;
1518c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1519c29fa5a6Sopenharmony_ci    handler.foregroundPids_.insert(UDS_PID);
1520c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyDownDelay(keyEvent, subscriberList, handled));
1521c29fa5a6Sopenharmony_ci}
1522c29fa5a6Sopenharmony_ci
1523c29fa5a6Sopenharmony_ci/**
1524c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifyKeyUpSubscriber
1525c29fa5a6Sopenharmony_ci * @tc.desc: Test Notify KeyUp Subscriber
1526c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1527c29fa5a6Sopenharmony_ci * @tc.require:
1528c29fa5a6Sopenharmony_ci */
1529c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifyKeyUpSubscriber, TestSize.Level1)
1530c29fa5a6Sopenharmony_ci{
1531c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1532c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1533c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1534c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1535c29fa5a6Sopenharmony_ci    int32_t id = 1;
1536c29fa5a6Sopenharmony_ci    bool handled = false;
1537c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1538c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1539c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1540c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1541c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1542c29fa5a6Sopenharmony_ci    subscriber->timerId_ = 1;
1543c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyUpDelay(1000);
1544c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1545c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyUpSubscriber(keyEvent, subscriberList, handled));
1546c29fa5a6Sopenharmony_ci    handler.isForegroundExits_ = true;
1547c29fa5a6Sopenharmony_ci    handler.foregroundPids_.insert(UDS_PID);
1548c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyUpSubscriber(keyEvent, subscriberList, handled));
1549c29fa5a6Sopenharmony_ci    handler.foregroundPids_.erase(UDS_PID);
1550c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifyKeyUpSubscriber(keyEvent, subscriberList, handled));
1551c29fa5a6Sopenharmony_ci}
1552c29fa5a6Sopenharmony_ci
1553c29fa5a6Sopenharmony_ci/**
1554c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsKeyEventSubscribed
1555c29fa5a6Sopenharmony_ci * @tc.desc: Test IsKeyEventSubscribed
1556c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1557c29fa5a6Sopenharmony_ci * @tc.require:
1558c29fa5a6Sopenharmony_ci */
1559c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsKeyEventSubscribed, TestSize.Level1)
1560c29fa5a6Sopenharmony_ci{
1561c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1562c29fa5a6Sopenharmony_ci    int32_t id = 1;
1563c29fa5a6Sopenharmony_ci    int32_t keyCode = KeyEvent::KEYCODE_ALT_LEFT;
1564c29fa5a6Sopenharmony_ci    int32_t trrigerType = KeyEvent::KEY_ACTION_DOWN;
1565c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1566c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1567c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyDown(false);
1568c29fa5a6Sopenharmony_ci    keyOption->SetFinalKey(KeyEvent::KEYCODE_CTRL_LEFT);
1569c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1570c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1571c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> subscriberList;
1572c29fa5a6Sopenharmony_ci    subscriberList.push_back(subscriber);
1573c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscriberList));
1574c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsKeyEventSubscribed(keyCode, trrigerType));
1575c29fa5a6Sopenharmony_ci
1576c29fa5a6Sopenharmony_ci    for (auto &iter : handler.subscriberMap_) {
1577c29fa5a6Sopenharmony_ci        iter.first->SetFinalKeyDown(true);
1578c29fa5a6Sopenharmony_ci    }
1579c29fa5a6Sopenharmony_ci    keyCode = KeyEvent::KEYCODE_CTRL_LEFT;
1580c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.IsKeyEventSubscribed(keyCode, trrigerType));
1581c29fa5a6Sopenharmony_ci}
1582c29fa5a6Sopenharmony_ci
1583c29fa5a6Sopenharmony_ci/**
1584c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveKeyCode
1585c29fa5a6Sopenharmony_ci * @tc.desc: Test RemoveKeyCode
1586c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1587c29fa5a6Sopenharmony_ci * @tc.require:
1588c29fa5a6Sopenharmony_ci */
1589c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveKeyCode, TestSize.Level1)
1590c29fa5a6Sopenharmony_ci{
1591c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1592c29fa5a6Sopenharmony_ci    int32_t keyCode = KeyEvent::KEYCODE_A;
1593c29fa5a6Sopenharmony_ci    std::vector<int32_t> keyCodes { KeyEvent::KEYCODE_A, KeyEvent::KEYCODE_B };
1594c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.RemoveKeyCode(keyCode, keyCodes));
1595c29fa5a6Sopenharmony_ci    keyCode = KeyEvent::KEYCODE_C;
1596c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.RemoveKeyCode(keyCode, keyCodes));
1597c29fa5a6Sopenharmony_ci}
1598c29fa5a6Sopenharmony_ci
1599c29fa5a6Sopenharmony_ci/**
1600c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_IsRepeatedKeyEvent
1601c29fa5a6Sopenharmony_ci * @tc.desc: Test IsRepeatedKeyEvent
1602c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1603c29fa5a6Sopenharmony_ci * @tc.require:
1604c29fa5a6Sopenharmony_ci */
1605c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_IsRepeatedKeyEvent, TestSize.Level1)
1606c29fa5a6Sopenharmony_ci{
1607c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1608c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1609c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1610c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsRepeatedKeyEvent(keyEvent));
1611c29fa5a6Sopenharmony_ci    handler.keyEvent_ = KeyEvent::Create();
1612c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1613c29fa5a6Sopenharmony_ci    handler.hasEventExecuting_ = true;
1614c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyCode(KeyEvent::KEYCODE_A);
1615c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_B);
1616c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsRepeatedKeyEvent(keyEvent));
1617c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_A);
1618c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1619c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1620c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsRepeatedKeyEvent(keyEvent));
1621c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
1622c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1623c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_A);
1624c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
1625c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsRepeatedKeyEvent(keyEvent));
1626c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_B);
1627c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1628c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsRepeatedKeyEvent(keyEvent));
1629c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_B);
1630c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
1631c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_D);
1632c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1633c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.IsRepeatedKeyEvent(keyEvent));
1634c29fa5a6Sopenharmony_ci}
1635c29fa5a6Sopenharmony_ci
1636c29fa5a6Sopenharmony_ci/**
1637c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_010
1638c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation HandleRingMute
1639c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1640c29fa5a6Sopenharmony_ci * @tc.require:
1641c29fa5a6Sopenharmony_ci */
1642c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_010, TestSize.Level1)
1643c29fa5a6Sopenharmony_ci{
1644c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1645c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1646c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1647c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1648c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN);
1649c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
1650c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
1651c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
1652c29fa5a6Sopenharmony_ci    data.SetWant(want);
1653c29fa5a6Sopenharmony_ci    int32_t callState = 0;
1654c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1655c29fa5a6Sopenharmony_ci    DeviceEventMonitor monitor;
1656c29fa5a6Sopenharmony_ci    monitor.hasHandleRingMute_ = false;
1657c29fa5a6Sopenharmony_ci    bool ret = handler.HandleRingMute(keyEvent);
1658c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1659c29fa5a6Sopenharmony_ci    monitor.hasHandleRingMute_ = true;
1660c29fa5a6Sopenharmony_ci    ret = handler.HandleRingMute(keyEvent);
1661c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1662c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1663c29fa5a6Sopenharmony_ci    ret = handler.HandleRingMute(keyEvent);
1664c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1665c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_ALERTING);
1666c29fa5a6Sopenharmony_ci    data.SetWant(want);
1667c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1668c29fa5a6Sopenharmony_ci    ret = handler.HandleRingMute(keyEvent);
1669c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1670c29fa5a6Sopenharmony_ci}
1671c29fa5a6Sopenharmony_ci
1672c29fa5a6Sopenharmony_ci/**
1673c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSubscribeKeyEvent_002
1674c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation OnSubscribeKeyEvent
1675c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1676c29fa5a6Sopenharmony_ci * @tc.require:
1677c29fa5a6Sopenharmony_ci */
1678c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSubscribeKeyEvent_002, TestSize.Level1)
1679c29fa5a6Sopenharmony_ci{
1680c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1681c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1682c29fa5a6Sopenharmony_ci    OHOS::EventFwk::Want want;
1683c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_DISCONNECTED);
1684c29fa5a6Sopenharmony_ci    OHOS::EventFwk::CommonEventData data;
1685c29fa5a6Sopenharmony_ci    data.SetWant(want);
1686c29fa5a6Sopenharmony_ci    int callState = 0;
1687c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1688c29fa5a6Sopenharmony_ci    want.SetParam("state", StateType::CALL_STATUS_INCOMING);
1689c29fa5a6Sopenharmony_ci    data.SetWant(want);
1690c29fa5a6Sopenharmony_ci    callState = 0;
1691c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->SetCallState(data, callState);
1692c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1693c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_UP);
1694c29fa5a6Sopenharmony_ci    bool ret = handler.OnSubscribeKeyEvent(keyEvent);
1695c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1696c29fa5a6Sopenharmony_ci}
1697c29fa5a6Sopenharmony_ci
1698c29fa5a6Sopenharmony_ci/**
1699c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSubscribeKeyEvent_003
1700c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation OnSubscribeKeyEvent
1701c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1702c29fa5a6Sopenharmony_ci * @tc.require:
1703c29fa5a6Sopenharmony_ci */
1704c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSubscribeKeyEvent_003, TestSize.Level1)
1705c29fa5a6Sopenharmony_ci{
1706c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1707c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1708c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1709c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1710c29fa5a6Sopenharmony_ci    handler.needSkipPowerKeyUp_ = true;
1711c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1712c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
1713c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1714c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1715c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_UP);
1716c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.OnSubscribeKeyEvent(keyEvent));
1717c29fa5a6Sopenharmony_ci}
1718c29fa5a6Sopenharmony_ci
1719c29fa5a6Sopenharmony_ci/**
1720c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifySubscriber_002
1721c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation NotifySubscriber
1722c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1723c29fa5a6Sopenharmony_ci * @tc.require:
1724c29fa5a6Sopenharmony_ci */
1725c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifySubscriber_002, TestSize.Level1)
1726c29fa5a6Sopenharmony_ci{
1727c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1728c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1729c29fa5a6Sopenharmony_ci    SessionPtr sess;
1730c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
1731c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1732c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1733c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1734c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1735c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
1736c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1737c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_CAMERA);
1738c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
1739c29fa5a6Sopenharmony_ci}
1740c29fa5a6Sopenharmony_ci
1741c29fa5a6Sopenharmony_ci/**
1742c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_AddTimer_001
1743c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation AddTimer
1744c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1745c29fa5a6Sopenharmony_ci * @tc.require:
1746c29fa5a6Sopenharmony_ci */
1747c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_AddTimer_001, TestSize.Level1)
1748c29fa5a6Sopenharmony_ci{
1749c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1750c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1751c29fa5a6Sopenharmony_ci    int32_t id = 1;
1752c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
1753c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
1754c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
1755c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(id, session, keyOption);
1756c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1757c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1758c29fa5a6Sopenharmony_ci    subscriber->timerId_ = 1;
1759c29fa5a6Sopenharmony_ci    bool ret = handler.AddTimer(subscriber, keyEvent);
1760c29fa5a6Sopenharmony_ci    ASSERT_TRUE(ret);
1761c29fa5a6Sopenharmony_ci    subscriber->timerId_ = -1;
1762c29fa5a6Sopenharmony_ci    keyOption->isFinalKeyDown_ = true;
1763c29fa5a6Sopenharmony_ci    ret = handler.AddTimer(subscriber, keyEvent);
1764c29fa5a6Sopenharmony_ci    ASSERT_TRUE(ret);
1765c29fa5a6Sopenharmony_ci    keyOption->isFinalKeyDown_ = false;
1766c29fa5a6Sopenharmony_ci    ret = handler.AddTimer(subscriber, keyEvent);
1767c29fa5a6Sopenharmony_ci    ASSERT_TRUE(ret);
1768c29fa5a6Sopenharmony_ci}
1769c29fa5a6Sopenharmony_ci
1770c29fa5a6Sopenharmony_ci/**
1771c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyDown_002
1772c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation HandleKeyDown
1773c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1774c29fa5a6Sopenharmony_ci * @tc.require:
1775c29fa5a6Sopenharmony_ci */
1776c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyDown_002, TestSize.Level1)
1777c29fa5a6Sopenharmony_ci{
1778c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1779c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1780c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1781c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1782c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
1783c29fa5a6Sopenharmony_ci    keyOption->isFinalKeyDown_ = false;
1784c29fa5a6Sopenharmony_ci    SessionPtr sess;
1785c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1786c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
1787c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1788c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1789c29fa5a6Sopenharmony_ci    bool ret = handler.HandleKeyDown(keyEvent);
1790c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1791c29fa5a6Sopenharmony_ci    keyOption->isFinalKeyDown_ = true;
1792c29fa5a6Sopenharmony_ci    keyOption->finalKey_ = true;
1793c29fa5a6Sopenharmony_ci    subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1794c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1795c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1796c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
1797c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
1798c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
1799c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1800c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyDown(keyEvent);
1801c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1802c29fa5a6Sopenharmony_ci    keyOption->finalKey_ = false;
1803c29fa5a6Sopenharmony_ci    std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1804c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1805c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1806c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyDown(keyEvent);
1807c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1808c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_CAMERA);
1809c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyDown(keyEvent);
1810c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1811c29fa5a6Sopenharmony_ci}
1812c29fa5a6Sopenharmony_ci
1813c29fa5a6Sopenharmony_ci/**
1814c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyUp_002
1815c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation HandleKeyUp
1816c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1817c29fa5a6Sopenharmony_ci * @tc.require:
1818c29fa5a6Sopenharmony_ci */
1819c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyUp_002, TestSize.Level1)
1820c29fa5a6Sopenharmony_ci{
1821c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
1822c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1823c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1824c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1825c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
1826c29fa5a6Sopenharmony_ci    keyOption->isFinalKeyDown_ = true;
1827c29fa5a6Sopenharmony_ci    SessionPtr sess;
1828c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1829c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
1830c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1831c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1832c29fa5a6Sopenharmony_ci    bool ret = handler.HandleKeyUp(keyEvent);
1833c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1834c29fa5a6Sopenharmony_ci    keyOption->isFinalKeyDown_ = false;
1835c29fa5a6Sopenharmony_ci    keyOption->finalKey_ = -1;
1836c29fa5a6Sopenharmony_ci    subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1837c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1838c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1839c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyUp(keyEvent);
1840c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1841c29fa5a6Sopenharmony_ci    keyOption->finalKey_ = 0;
1842c29fa5a6Sopenharmony_ci    subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1843c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1844c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1845c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyUp(keyEvent);
1846c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1847c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys;
1848c29fa5a6Sopenharmony_ci    std::vector<int32_t> pressedKeys = {1, 2, 3};
1849c29fa5a6Sopenharmony_ci    subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1850c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1851c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1852c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyUp(keyEvent);
1853c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1854c29fa5a6Sopenharmony_ci    pressedKeys = {1, 2, 3};
1855c29fa5a6Sopenharmony_ci    preKeys = {1, 2, 3, 4};
1856c29fa5a6Sopenharmony_ci    subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
1857c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
1858c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
1859c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyUp(keyEvent);
1860c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1861c29fa5a6Sopenharmony_ci}
1862c29fa5a6Sopenharmony_ci
1863c29fa5a6Sopenharmony_ci/**
1864c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_01
1865c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation HandleRingMute
1866c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1867c29fa5a6Sopenharmony_ci * @tc.require:
1868c29fa5a6Sopenharmony_ci */
1869c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_01, TestSize.Level1)
1870c29fa5a6Sopenharmony_ci{
1871c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1872c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
1873c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1874c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1875c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
1876c29fa5a6Sopenharmony_ci    DeviceEventMonitor monitor;
1877c29fa5a6Sopenharmony_ci    monitor.callState_ = StateType::CALL_STATUS_INCOMING;
1878c29fa5a6Sopenharmony_ci    bool ret = handler.HandleRingMute(keyEvent);
1879c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1880c29fa5a6Sopenharmony_ci    handler.HandleRingMute(keyEvent);
1881c29fa5a6Sopenharmony_ci    monitor.hasHandleRingMute_ = false;
1882c29fa5a6Sopenharmony_ci    ret = handler.HandleRingMute(keyEvent);
1883c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1884c29fa5a6Sopenharmony_ci    monitor.hasHandleRingMute_ = true;
1885c29fa5a6Sopenharmony_ci    ret = handler.HandleRingMute(keyEvent);
1886c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1887c29fa5a6Sopenharmony_ci    monitor.callState_ = StateType::CALL_STATUS_DIALING;
1888c29fa5a6Sopenharmony_ci    ret = handler.HandleRingMute(keyEvent);
1889c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
1890c29fa5a6Sopenharmony_ci}
1891c29fa5a6Sopenharmony_ci
1892c29fa5a6Sopenharmony_ci/**
1893c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_02
1894c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1895c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1896c29fa5a6Sopenharmony_ci * @tc.require:
1897c29fa5a6Sopenharmony_ci */
1898c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_02, TestSize.Level1)
1899c29fa5a6Sopenharmony_ci{
1900c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1901c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1902c29fa5a6Sopenharmony_ci
1903c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1904c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1905c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
1906c29fa5a6Sopenharmony_ci
1907c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
1908c29fa5a6Sopenharmony_ci    auto callManagerClientPtr = DelayedSingleton<OHOS::Telephony::CallManagerClient>::GetInstance();
1909c29fa5a6Sopenharmony_ci    callManagerClientPtr = nullptr;
1910c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1911c29fa5a6Sopenharmony_ci}
1912c29fa5a6Sopenharmony_ci
1913c29fa5a6Sopenharmony_ci/**
1914c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_03
1915c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1916c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1917c29fa5a6Sopenharmony_ci * @tc.require:
1918c29fa5a6Sopenharmony_ci */
1919c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_03, TestSize.Level1)
1920c29fa5a6Sopenharmony_ci{
1921c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1922c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1923c29fa5a6Sopenharmony_ci
1924c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1925c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1926c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
1927c29fa5a6Sopenharmony_ci
1928c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
1929c29fa5a6Sopenharmony_ci    auto callManagerClientPtr = DelayedSingleton<OHOS::Telephony::CallManagerClient>::GetInstance();
1930c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
1931c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = false;
1932c29fa5a6Sopenharmony_ci    auto ret = callManagerClientPtr->MuteRinger();
1933c29fa5a6Sopenharmony_ci    EXPECT_NE(ret, ERR_OK);
1934c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1935c29fa5a6Sopenharmony_ci}
1936c29fa5a6Sopenharmony_ci
1937c29fa5a6Sopenharmony_ci/**
1938c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_04
1939c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1940c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1941c29fa5a6Sopenharmony_ci * @tc.require:
1942c29fa5a6Sopenharmony_ci */
1943c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_04, TestSize.Level1)
1944c29fa5a6Sopenharmony_ci{
1945c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1946c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1947c29fa5a6Sopenharmony_ci
1948c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1949c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1950c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
1951c29fa5a6Sopenharmony_ci
1952c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
1953c29fa5a6Sopenharmony_ci    auto callManagerClientPtr = DelayedSingleton<OHOS::Telephony::CallManagerClient>::GetInstance();
1954c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
1955c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = false;
1956c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
1957c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1958c29fa5a6Sopenharmony_ci}
1959c29fa5a6Sopenharmony_ci
1960c29fa5a6Sopenharmony_ci/**
1961c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_05
1962c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1963c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1964c29fa5a6Sopenharmony_ci * @tc.require:
1965c29fa5a6Sopenharmony_ci */
1966c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_05, TestSize.Level1)
1967c29fa5a6Sopenharmony_ci{
1968c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1969c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1970c29fa5a6Sopenharmony_ci
1971c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1972c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1973c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
1974c29fa5a6Sopenharmony_ci
1975c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
1976c29fa5a6Sopenharmony_ci    auto callManagerClientPtr = DelayedSingleton<OHOS::Telephony::CallManagerClient>::GetInstance();
1977c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
1978c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = false;
1979c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_CALL;
1980c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
1981c29fa5a6Sopenharmony_ci}
1982c29fa5a6Sopenharmony_ci
1983c29fa5a6Sopenharmony_ci/**
1984c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_06
1985c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
1986c29fa5a6Sopenharmony_ci * @tc.type: FUNC
1987c29fa5a6Sopenharmony_ci * @tc.require:
1988c29fa5a6Sopenharmony_ci */
1989c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_06, TestSize.Level1)
1990c29fa5a6Sopenharmony_ci{
1991c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
1992c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
1993c29fa5a6Sopenharmony_ci
1994c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
1995c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
1996c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_UP;
1997c29fa5a6Sopenharmony_ci
1998c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
1999c29fa5a6Sopenharmony_ci    auto callManagerClientPtr = DelayedSingleton<OHOS::Telephony::CallManagerClient>::GetInstance();
2000c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
2001c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = true;
2002c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
2003c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
2004c29fa5a6Sopenharmony_ci}
2005c29fa5a6Sopenharmony_ci
2006c29fa5a6Sopenharmony_ci/**
2007c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_07
2008c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
2009c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2010c29fa5a6Sopenharmony_ci * @tc.require:
2011c29fa5a6Sopenharmony_ci */
2012c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_07, TestSize.Level1)
2013c29fa5a6Sopenharmony_ci{
2014c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2015c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
2016c29fa5a6Sopenharmony_ci
2017c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2018c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2019c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_UP;
2020c29fa5a6Sopenharmony_ci
2021c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
2022c29fa5a6Sopenharmony_ci    auto callManagerClientPtr = DelayedSingleton<OHOS::Telephony::CallManagerClient>::GetInstance();
2023c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
2024c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = true;
2025c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_CAMERA;
2026c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
2027c29fa5a6Sopenharmony_ci}
2028c29fa5a6Sopenharmony_ci
2029c29fa5a6Sopenharmony_ci/**
2030c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_08
2031c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
2032c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2033c29fa5a6Sopenharmony_ci * @tc.require:
2034c29fa5a6Sopenharmony_ci */
2035c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_08, TestSize.Level1)
2036c29fa5a6Sopenharmony_ci{
2037c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2038c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
2039c29fa5a6Sopenharmony_ci
2040c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2041c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2042c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
2043c29fa5a6Sopenharmony_ci
2044c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
2045c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr = nullptr;
2046c29fa5a6Sopenharmony_ci    ASSERT_TRUE(keySubscriberHandler.HandleRingMute(keyEvent));
2047c29fa5a6Sopenharmony_ci}
2048c29fa5a6Sopenharmony_ci
2049c29fa5a6Sopenharmony_ci/**
2050c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_09
2051c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
2052c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2053c29fa5a6Sopenharmony_ci * @tc.require:
2054c29fa5a6Sopenharmony_ci */
2055c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_09, TestSize.Level1)
2056c29fa5a6Sopenharmony_ci{
2057c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2058c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
2059c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2060c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2061c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
2062c29fa5a6Sopenharmony_ci
2063c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
2064c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr;
2065c29fa5a6Sopenharmony_ci    callManagerClientPtr = std::make_shared<OHOS::Telephony::CallManagerClient>();
2066c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
2067c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = false;
2068c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
2069c29fa5a6Sopenharmony_ci}
2070c29fa5a6Sopenharmony_ci
2071c29fa5a6Sopenharmony_ci/**
2072c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_10
2073c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
2074c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2075c29fa5a6Sopenharmony_ci * @tc.require:
2076c29fa5a6Sopenharmony_ci */
2077c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_10, TestSize.Level1)
2078c29fa5a6Sopenharmony_ci{
2079c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2080c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
2081c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2082c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2083c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
2084c29fa5a6Sopenharmony_ci
2085c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
2086c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr;
2087c29fa5a6Sopenharmony_ci    callManagerClientPtr = std::make_shared<OHOS::Telephony::CallManagerClient>();
2088c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
2089c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = true;
2090c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_UP;
2091c29fa5a6Sopenharmony_ci    ASSERT_TRUE(keySubscriberHandler.HandleRingMute(keyEvent));
2092c29fa5a6Sopenharmony_ci}
2093c29fa5a6Sopenharmony_ci
2094c29fa5a6Sopenharmony_ci/**
2095c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleRingMute_11
2096c29fa5a6Sopenharmony_ci * @tc.desc: Test ring mute
2097c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2098c29fa5a6Sopenharmony_ci * @tc.require:
2099c29fa5a6Sopenharmony_ci */
2100c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleRingMute_11, TestSize.Level1)
2101c29fa5a6Sopenharmony_ci{
2102c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2103c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
2104c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2105c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2106c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_DOWN;
2107c29fa5a6Sopenharmony_ci
2108c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->callState_ = StateType::CALL_STATUS_INCOMING;
2109c29fa5a6Sopenharmony_ci    std::shared_ptr<OHOS::Telephony::CallManagerClient> callManagerClientPtr;
2110c29fa5a6Sopenharmony_ci    callManagerClientPtr = std::make_shared<OHOS::Telephony::CallManagerClient>();
2111c29fa5a6Sopenharmony_ci    EXPECT_NE(callManagerClientPtr, nullptr);
2112c29fa5a6Sopenharmony_ci    DEVICE_MONITOR->hasHandleRingMute_ = true;
2113c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
2114c29fa5a6Sopenharmony_ci    ASSERT_FALSE(keySubscriberHandler.HandleRingMute(keyEvent));
2115c29fa5a6Sopenharmony_ci}
2116c29fa5a6Sopenharmony_ci
2117c29fa5a6Sopenharmony_ci/**
2118c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_AddKeyGestureSubscriber_01
2119c29fa5a6Sopenharmony_ci * @tc.desc: Test AddKeyGestureSubscriber
2120c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2121c29fa5a6Sopenharmony_ci * @tc.require:
2122c29fa5a6Sopenharmony_ci */
2123c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_AddKeyGestureSubscriber_01, TestSize.Level1)
2124c29fa5a6Sopenharmony_ci{
2125c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2126c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2127c29fa5a6Sopenharmony_ci    SessionPtr sess;
2128c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2129c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2130c29fa5a6Sopenharmony_ci    subscriber->timerId_ = -1;
2131c29fa5a6Sopenharmony_ci    int32_t ret = handler.AddKeyGestureSubscriber(subscriber, keyOption);
2132c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, RET_ERR);
2133c29fa5a6Sopenharmony_ci}
2134c29fa5a6Sopenharmony_ci
2135c29fa5a6Sopenharmony_ci/**
2136c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_AddKeyGestureSubscriber_02
2137c29fa5a6Sopenharmony_ci * @tc.desc: Test AddKeyGestureSubscriber
2138c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2139c29fa5a6Sopenharmony_ci * @tc.require:
2140c29fa5a6Sopenharmony_ci */
2141c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_AddKeyGestureSubscriber_02, TestSize.Level1)
2142c29fa5a6Sopenharmony_ci{
2143c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2144c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2145c29fa5a6Sopenharmony_ci    SessionPtr sess;
2146c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2147c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(3, sess, keyOption);
2148c29fa5a6Sopenharmony_ci    subscriber->timerId_ = 1;
2149c29fa5a6Sopenharmony_ci
2150c29fa5a6Sopenharmony_ci    auto keyOption1 = std::make_shared<KeyOption>();
2151c29fa5a6Sopenharmony_ci    keyOption1->SetFinalKey(1);
2152c29fa5a6Sopenharmony_ci    keyOption1->SetFinalKeyDown(true);
2153c29fa5a6Sopenharmony_ci    auto keyOption2 = std::make_shared<KeyOption>();
2154c29fa5a6Sopenharmony_ci    keyOption2->SetFinalKey(1);
2155c29fa5a6Sopenharmony_ci    keyOption2->SetFinalKeyDown(true);
2156c29fa5a6Sopenharmony_ci
2157c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
2158c29fa5a6Sopenharmony_ci    auto subscriber1 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2159c29fa5a6Sopenharmony_ci    auto subscriber2 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(2, sess, keyOption);
2160c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber1);
2161c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber2);
2162c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert({keyOption2, subscribers});
2163c29fa5a6Sopenharmony_ci
2164c29fa5a6Sopenharmony_ci    for (auto &iter : handler.keyGestures_) {
2165c29fa5a6Sopenharmony_ci        EXPECT_TRUE(handler.IsEqualKeyOption(keyOption1, iter.first));
2166c29fa5a6Sopenharmony_ci    }
2167c29fa5a6Sopenharmony_ci    int32_t ret = handler.AddKeyGestureSubscriber(subscriber, keyOption1);
2168c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, RET_ERR);
2169c29fa5a6Sopenharmony_ci}
2170c29fa5a6Sopenharmony_ci
2171c29fa5a6Sopenharmony_ci/**
2172c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_AddKeyGestureSubscriber_03
2173c29fa5a6Sopenharmony_ci * @tc.desc: Test AddKeyGestureSubscriber
2174c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2175c29fa5a6Sopenharmony_ci * @tc.require:
2176c29fa5a6Sopenharmony_ci */
2177c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_AddKeyGestureSubscriber_03, TestSize.Level1)
2178c29fa5a6Sopenharmony_ci{
2179c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2180c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2181c29fa5a6Sopenharmony_ci    SessionPtr sess;
2182c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2183c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(3, sess, keyOption);
2184c29fa5a6Sopenharmony_ci    subscriber->timerId_ = 2;
2185c29fa5a6Sopenharmony_ci
2186c29fa5a6Sopenharmony_ci    auto keyOption1 = std::make_shared<KeyOption>();
2187c29fa5a6Sopenharmony_ci    keyOption1->SetFinalKey(2);
2188c29fa5a6Sopenharmony_ci    keyOption1->SetFinalKeyDown(true);
2189c29fa5a6Sopenharmony_ci    auto keyOption2 = std::make_shared<KeyOption>();
2190c29fa5a6Sopenharmony_ci    keyOption2->SetFinalKey(1);
2191c29fa5a6Sopenharmony_ci    keyOption2->SetFinalKeyDown(false);
2192c29fa5a6Sopenharmony_ci
2193c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
2194c29fa5a6Sopenharmony_ci    auto subscriber1 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2195c29fa5a6Sopenharmony_ci    auto subscriber2 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(2, sess, keyOption);
2196c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber1);
2197c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber2);
2198c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert({keyOption2, subscribers});
2199c29fa5a6Sopenharmony_ci
2200c29fa5a6Sopenharmony_ci    for (auto &iter : handler.keyGestures_) {
2201c29fa5a6Sopenharmony_ci        EXPECT_FALSE(handler.IsEqualKeyOption(keyOption1, iter.first));
2202c29fa5a6Sopenharmony_ci    }
2203c29fa5a6Sopenharmony_ci    int32_t ret = handler.AddKeyGestureSubscriber(subscriber, keyOption1);
2204c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, RET_ERR);
2205c29fa5a6Sopenharmony_ci}
2206c29fa5a6Sopenharmony_ci
2207c29fa5a6Sopenharmony_ci/**
2208c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveKeyGestureSubscriber_01
2209c29fa5a6Sopenharmony_ci * @tc.desc: Test RemoveKeyGestureSubscriber
2210c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2211c29fa5a6Sopenharmony_ci * @tc.require:
2212c29fa5a6Sopenharmony_ci */
2213c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveKeyGestureSubscriber_01, TestSize.Level1)
2214c29fa5a6Sopenharmony_ci{
2215c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2216c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2217c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2218c29fa5a6Sopenharmony_ci    EXPECT_NE(sess, nullptr);
2219c29fa5a6Sopenharmony_ci
2220c29fa5a6Sopenharmony_ci    auto keyOption1 = std::make_shared<KeyOption>();
2221c29fa5a6Sopenharmony_ci    keyOption1->SetFinalKey(2);
2222c29fa5a6Sopenharmony_ci    keyOption1->SetFinalKeyDown(true);
2223c29fa5a6Sopenharmony_ci    auto keyOption2 = std::make_shared<KeyOption>();
2224c29fa5a6Sopenharmony_ci    keyOption2->SetFinalKey(1);
2225c29fa5a6Sopenharmony_ci    keyOption2->SetFinalKeyDown(false);
2226c29fa5a6Sopenharmony_ci
2227c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
2228c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2229c29fa5a6Sopenharmony_ci    auto subscriber1 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2230c29fa5a6Sopenharmony_ci    auto subscriber2 = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(2, sess, keyOption);
2231c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber1);
2232c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber2);
2233c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert({keyOption2, subscribers});
2234c29fa5a6Sopenharmony_ci
2235c29fa5a6Sopenharmony_ci    int32_t subscribeId = 3;
2236c29fa5a6Sopenharmony_ci    for (auto &iter : handler.keyGestures_) {
2237c29fa5a6Sopenharmony_ci        for (auto innerIter = iter.second.begin(); innerIter != iter.second.end(); ++innerIter) {
2238c29fa5a6Sopenharmony_ci        auto subscriber = *innerIter;
2239c29fa5a6Sopenharmony_ci        EXPECT_TRUE(subscriber->id_ != subscribeId);
2240c29fa5a6Sopenharmony_ci        EXPECT_FALSE(subscriber->sess_ != sess);
2241c29fa5a6Sopenharmony_ci    }
2242c29fa5a6Sopenharmony_ci    int32_t ret = handler.RemoveKeyGestureSubscriber(sess, subscribeId);
2243c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, RET_ERR);
2244c29fa5a6Sopenharmony_ci    }
2245c29fa5a6Sopenharmony_ci}
2246c29fa5a6Sopenharmony_ci
2247c29fa5a6Sopenharmony_ci/**
2248c29fa5a6Sopenharmony_ci * @tc.name: InputWindowsManagerTest_UnsubscribeKeyEvent_01
2249c29fa5a6Sopenharmony_ci * @tc.desc: Test UnsubscribeKeyEvent
2250c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2251c29fa5a6Sopenharmony_ci * @tc.require:
2252c29fa5a6Sopenharmony_ci */
2253c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, InputWindowsManagerTest_UnsubscribeKeyEvent_01, TestSize.Level1)
2254c29fa5a6Sopenharmony_ci{
2255c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2256c29fa5a6Sopenharmony_ci    KeySubscriberHandler keySubscriberHandler;
2257c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2258c29fa5a6Sopenharmony_ci    EXPECT_NE(sess, nullptr);
2259c29fa5a6Sopenharmony_ci    int32_t subscribeId = 2;
2260c29fa5a6Sopenharmony_ci    int32_t ret1 = keySubscriberHandler.RemoveSubscriber(sess, subscribeId, true);
2261c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret1, RET_ERR);
2262c29fa5a6Sopenharmony_ci    int32_t ret2 = keySubscriberHandler.UnsubscribeKeyEvent(sess, subscribeId);
2263c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret2, RET_ERR);
2264c29fa5a6Sopenharmony_ci}
2265c29fa5a6Sopenharmony_ci
2266c29fa5a6Sopenharmony_ci/**
2267c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifySubscriber_01
2268c29fa5a6Sopenharmony_ci * @tc.desc: Test NotifySubscriber
2269c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2270c29fa5a6Sopenharmony_ci * @tc.require:
2271c29fa5a6Sopenharmony_ci */
2272c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifySubscriber_01, TestSize.Level1)
2273c29fa5a6Sopenharmony_ci{
2274c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2275c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2276c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2277c29fa5a6Sopenharmony_ci    EXPECT_NE(sess, nullptr);
2278c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2279c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2280c29fa5a6Sopenharmony_ci    EXPECT_NE(keyEvent, nullptr);
2281c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2282c29fa5a6Sopenharmony_ci    EXPECT_NE(subscriber, nullptr);
2283c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
2284c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
2285c29fa5a6Sopenharmony_ci}
2286c29fa5a6Sopenharmony_ci
2287c29fa5a6Sopenharmony_ci/**
2288c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifySubscriber_02
2289c29fa5a6Sopenharmony_ci * @tc.desc: Test NotifySubscriber
2290c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2291c29fa5a6Sopenharmony_ci * @tc.require:
2292c29fa5a6Sopenharmony_ci */
2293c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifySubscriber_02, TestSize.Level1)
2294c29fa5a6Sopenharmony_ci{
2295c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2296c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2297c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2298c29fa5a6Sopenharmony_ci    EXPECT_NE(sess, nullptr);
2299c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2300c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2301c29fa5a6Sopenharmony_ci    EXPECT_NE(keyEvent, nullptr);
2302c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2303c29fa5a6Sopenharmony_ci    EXPECT_NE(subscriber, nullptr);
2304c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_VOLUME_UP;
2305c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
2306c29fa5a6Sopenharmony_ci}
2307c29fa5a6Sopenharmony_ci
2308c29fa5a6Sopenharmony_ci/**
2309c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSubscribeKeyEvent_004
2310c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation OnSubscribeKeyEvent
2311c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2312c29fa5a6Sopenharmony_ci * @tc.require:
2313c29fa5a6Sopenharmony_ci */
2314c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSubscribeKeyEvent_004, TestSize.Level1)
2315c29fa5a6Sopenharmony_ci{
2316c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
2317c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2318c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
2319c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2320c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2321c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = false;
2322c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEY_ACTION_UP);
2323c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_O);
2324c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
2325c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_P);
2326c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
2327c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
2328c29fa5a6Sopenharmony_ci    handler.enableCombineKey_ = true;
2329c29fa5a6Sopenharmony_ci    handler.hasEventExecuting_ = true;
2330c29fa5a6Sopenharmony_ci    handler.keyEvent_ = KeyEvent::Create();
2331c29fa5a6Sopenharmony_ci    ASSERT_NE(handler.keyEvent_, nullptr);
2332c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyCode(KeyEvent::KEY_ACTION_UP);
2333c29fa5a6Sopenharmony_ci    handler.keyEvent_->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2334c29fa5a6Sopenharmony_ci    keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN);
2335c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_O);
2336c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
2337c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_P);
2338c29fa5a6Sopenharmony_ci    handler.keyEvent_->AddKeyItem(item);
2339c29fa5a6Sopenharmony_ci    ASSERT_TRUE(handler.OnSubscribeKeyEvent(keyEvent));
2340c29fa5a6Sopenharmony_ci    handler.hasEventExecuting_ = false;
2341c29fa5a6Sopenharmony_ci    handler.needSkipPowerKeyUp_ = true;
2342c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEY_ACTION_CANCEL);
2343c29fa5a6Sopenharmony_ci    ASSERT_FALSE(handler.OnSubscribeKeyEvent(keyEvent));
2344c29fa5a6Sopenharmony_ci}
2345c29fa5a6Sopenharmony_ci
2346c29fa5a6Sopenharmony_ci/**
2347c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifySubscriber_003
2348c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation NotifySubscriber
2349c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2350c29fa5a6Sopenharmony_ci * @tc.require:
2351c29fa5a6Sopenharmony_ci */
2352c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifySubscriber_003, TestSize.Level1)
2353c29fa5a6Sopenharmony_ci{
2354c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2355c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2356c29fa5a6Sopenharmony_ci    SessionPtr sess;
2357c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2358c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2359c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2360c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2361c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
2362c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_POWER);
2363c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
2364c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_POWER);
2365c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
2366c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_CAMERA);
2367c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
2368c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_CAMERA);
2369c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
2370c29fa5a6Sopenharmony_ci}
2371c29fa5a6Sopenharmony_ci
2372c29fa5a6Sopenharmony_ci/**
2373c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifySubscriber_004
2374c29fa5a6Sopenharmony_ci * @tc.desc: Test NotifySubscriber
2375c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2376c29fa5a6Sopenharmony_ci * @tc.require:
2377c29fa5a6Sopenharmony_ci */
2378c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifySubscriber_004, TestSize.Level1)
2379c29fa5a6Sopenharmony_ci{
2380c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2381c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2382c29fa5a6Sopenharmony_ci    SessionPtr sess;
2383c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2384c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2385c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2386c29fa5a6Sopenharmony_ci
2387c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2388c29fa5a6Sopenharmony_ci    ASSERT_NE(subscriber, nullptr);
2389c29fa5a6Sopenharmony_ci
2390c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_POWER;
2391c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
2392c29fa5a6Sopenharmony_ci}
2393c29fa5a6Sopenharmony_ci
2394c29fa5a6Sopenharmony_ci/**
2395c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_NotifySubscriber_005
2396c29fa5a6Sopenharmony_ci * @tc.desc: Test NotifySubscriber
2397c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2398c29fa5a6Sopenharmony_ci * @tc.require:
2399c29fa5a6Sopenharmony_ci */
2400c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_NotifySubscriber_005, TestSize.Level1)
2401c29fa5a6Sopenharmony_ci{
2402c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2403c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2404c29fa5a6Sopenharmony_ci    SessionPtr sess;
2405c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2406c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2407c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2408c29fa5a6Sopenharmony_ci
2409c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2410c29fa5a6Sopenharmony_ci    ASSERT_NE(subscriber, nullptr);
2411c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = KeyEvent::KEYCODE_CAMERA;
2412c29fa5a6Sopenharmony_ci    EXPECT_FALSE(EventLogHelper::IsBetaVersion());
2413c29fa5a6Sopenharmony_ci    EXPECT_FALSE(keyEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE));
2414c29fa5a6Sopenharmony_ci
2415c29fa5a6Sopenharmony_ci    NetPacket pkt(MmiMessageId::ON_SUBSCRIBE_KEY);
2416c29fa5a6Sopenharmony_ci    EXPECT_FALSE(pkt.ChkRWError());
2417c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.NotifySubscriber(keyEvent, subscriber));
2418c29fa5a6Sopenharmony_ci}
2419c29fa5a6Sopenharmony_ci
2420c29fa5a6Sopenharmony_ci/**
2421c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyDown_003
2422c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation HandleKeyDown
2423c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2424c29fa5a6Sopenharmony_ci * @tc.require:
2425c29fa5a6Sopenharmony_ci */
2426c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyDown_003, TestSize.Level1)
2427c29fa5a6Sopenharmony_ci{
2428c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
2429c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2430c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = KeyEvent::Create();
2431c29fa5a6Sopenharmony_ci    ASSERT_NE(keyEvent, nullptr);
2432c29fa5a6Sopenharmony_ci    auto keyOption = std::make_shared<KeyOption>();
2433c29fa5a6Sopenharmony_ci    keyOption->isFinalKeyDown_ = true;
2434c29fa5a6Sopenharmony_ci    keyEvent->keyCode_ = 1;
2435c29fa5a6Sopenharmony_ci    SessionPtr sess;
2436c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2437c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<OHOS::MMI::KeySubscriberHandler::Subscriber>> subscribers;
2438c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
2439c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
2440c29fa5a6Sopenharmony_ci    keyOption->finalKey_ = 5;
2441c29fa5a6Sopenharmony_ci    bool ret = handler.HandleKeyDown(keyEvent);
2442c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
2443c29fa5a6Sopenharmony_ci    keyOption->finalKey_ = 1;
2444c29fa5a6Sopenharmony_ci    subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2445c29fa5a6Sopenharmony_ci    subscribers.push_back(subscriber);
2446c29fa5a6Sopenharmony_ci    handler.subscriberMap_.insert(std::make_pair(keyOption, subscribers));
2447c29fa5a6Sopenharmony_ci    KeyEvent::KeyItem item;
2448c29fa5a6Sopenharmony_ci    item.SetKeyCode(KeyEvent::KEYCODE_CAMERA);
2449c29fa5a6Sopenharmony_ci    keyEvent->AddKeyItem(item);
2450c29fa5a6Sopenharmony_ci    keyEvent->SetKeyCode(KeyEvent::KEYCODE_CAMERA);
2451c29fa5a6Sopenharmony_ci    ret = handler.HandleKeyDown(keyEvent);
2452c29fa5a6Sopenharmony_ci    ASSERT_FALSE(ret);
2453c29fa5a6Sopenharmony_ci}
2454c29fa5a6Sopenharmony_ci
2455c29fa5a6Sopenharmony_ci/**
2456c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_SubscriberNotifyNap_002
2457c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation SubscriberNotifyNap
2458c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2459c29fa5a6Sopenharmony_ci * @tc.require:
2460c29fa5a6Sopenharmony_ci */
2461c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_SubscriberNotifyNap_002, TestSize.Level1)
2462c29fa5a6Sopenharmony_ci{
2463c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2464c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2465c29fa5a6Sopenharmony_ci    SessionPtr sess;
2466c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2467c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2468c29fa5a6Sopenharmony_ci    NapProcess napProcess;
2469c29fa5a6Sopenharmony_ci    napProcess.napClientPid_ = REMOVE_OBSERVER;
2470c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.SubscriberNotifyNap(subscriber));
2471c29fa5a6Sopenharmony_ci    napProcess.napClientPid_ = UNOBSERVED;
2472c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.SubscriberNotifyNap(subscriber));
2473c29fa5a6Sopenharmony_ci    napProcess.napClientPid_ = 10;
2474c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.SubscriberNotifyNap(subscriber));
2475c29fa5a6Sopenharmony_ci}
2476c29fa5a6Sopenharmony_ci
2477c29fa5a6Sopenharmony_ci/**
2478c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_SubscriberNotifyNap_003
2479c29fa5a6Sopenharmony_ci * @tc.desc: Test the funcation SubscriberNotifyNap
2480c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2481c29fa5a6Sopenharmony_ci * @tc.require:
2482c29fa5a6Sopenharmony_ci */
2483c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_SubscriberNotifyNap_003, TestSize.Level1)
2484c29fa5a6Sopenharmony_ci{
2485c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2486c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2487c29fa5a6Sopenharmony_ci    SessionPtr sess;
2488c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption;
2489c29fa5a6Sopenharmony_ci    auto subscriber = std::make_shared<OHOS::MMI::KeySubscriberHandler::Subscriber>(1, sess, keyOption);
2490c29fa5a6Sopenharmony_ci    ASSERT_NE(subscriber, nullptr);
2491c29fa5a6Sopenharmony_ci
2492c29fa5a6Sopenharmony_ci    NapProcess napProcess;
2493c29fa5a6Sopenharmony_ci    napProcess.napClientPid_ = ACTIVE_EVENT;
2494c29fa5a6Sopenharmony_ci    OHOS::MMI::NapProcess::NapStatusData napData;
2495c29fa5a6Sopenharmony_ci    napData.pid = 2;
2496c29fa5a6Sopenharmony_ci    napData.uid = 3;
2497c29fa5a6Sopenharmony_ci    napData.bundleName = "programName";
2498c29fa5a6Sopenharmony_ci    EXPECT_FALSE(napProcess.IsNeedNotify(napData));
2499c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(handler.SubscriberNotifyNap(subscriber));
2500c29fa5a6Sopenharmony_ci}
2501c29fa5a6Sopenharmony_ci
2502c29fa5a6Sopenharmony_ci/**
2503c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_SubscribeKeyEvent_003
2504c29fa5a6Sopenharmony_ci * @tc.desc: Test subscribe keyEvent
2505c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2506c29fa5a6Sopenharmony_ci * @tc.require:
2507c29fa5a6Sopenharmony_ci */
2508c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_SubscribeKeyEvent_003, TestSize.Level1)
2509c29fa5a6Sopenharmony_ci{
2510c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2511c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2512c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2513c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2514c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2515c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys = { 2017, 2018, 2019, 2072, 2046 };
2516c29fa5a6Sopenharmony_ci    keyOption->SetPreKeys(preKeys);
2517c29fa5a6Sopenharmony_ci    EXPECT_EQ(handler.SubscribeKeyEvent(sess, subscribeId, keyOption), RET_ERR);
2518c29fa5a6Sopenharmony_ci}
2519c29fa5a6Sopenharmony_ci
2520c29fa5a6Sopenharmony_ci/**
2521c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_SubscribeKeyEvent_004
2522c29fa5a6Sopenharmony_ci * @tc.desc: Test subscribe keyEvent
2523c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2524c29fa5a6Sopenharmony_ci * @tc.require:
2525c29fa5a6Sopenharmony_ci */
2526c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_SubscribeKeyEvent_004, TestSize.Level1)
2527c29fa5a6Sopenharmony_ci{
2528c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2529c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2530c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2531c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2532c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2533c29fa5a6Sopenharmony_ci    keyOption->SetFinalKey(2072);
2534c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyDown(true);
2535c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyDownDuration(100);
2536c29fa5a6Sopenharmony_ci    EXPECT_NE(handler.SubscribeKeyEvent(sess, subscribeId, keyOption), RET_OK);
2537c29fa5a6Sopenharmony_ci}
2538c29fa5a6Sopenharmony_ci
2539c29fa5a6Sopenharmony_ci/**
2540c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_AddKeyGestureSubscriber_003
2541c29fa5a6Sopenharmony_ci * @tc.desc: Test AddKeyGestureSubscriber
2542c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2543c29fa5a6Sopenharmony_ci * @tc.require:
2544c29fa5a6Sopenharmony_ci */
2545c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_AddKeyGestureSubscriber_003, TestSize.Level1)
2546c29fa5a6Sopenharmony_ci{
2547c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2548c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2549c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2550c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2551c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2552c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2553c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2554c29fa5a6Sopenharmony_ci    subscriber->timerId_ = -1;
2555c29fa5a6Sopenharmony_ci    EXPECT_EQ(handler.AddKeyGestureSubscriber(subscriber, keyOption), RET_ERR);
2556c29fa5a6Sopenharmony_ci}
2557c29fa5a6Sopenharmony_ci
2558c29fa5a6Sopenharmony_ci/**
2559c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveKeyGestureSubscriber
2560c29fa5a6Sopenharmony_ci * @tc.desc: Test RemoveKeyGestureSubscriber
2561c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2562c29fa5a6Sopenharmony_ci * @tc.require:
2563c29fa5a6Sopenharmony_ci */
2564c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveKeyGestureSubscriber, TestSize.Level1)
2565c29fa5a6Sopenharmony_ci{
2566c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2567c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2568c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2569c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2570c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2571c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2572c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2573c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> listSub;
2574c29fa5a6Sopenharmony_ci    listSub.push_back(subscriber);
2575c29fa5a6Sopenharmony_ci    subscribeId = 2;
2576c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert(std::make_pair(keyOption, listSub));
2577c29fa5a6Sopenharmony_ci    EXPECT_EQ(handler.RemoveKeyGestureSubscriber(sess, subscribeId), RET_ERR);
2578c29fa5a6Sopenharmony_ci}
2579c29fa5a6Sopenharmony_ci
2580c29fa5a6Sopenharmony_ci/**
2581c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveKeyGestureSubscriber_001
2582c29fa5a6Sopenharmony_ci * @tc.desc: Test RemoveKeyGestureSubscriber
2583c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2584c29fa5a6Sopenharmony_ci * @tc.require:
2585c29fa5a6Sopenharmony_ci */
2586c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveKeyGestureSubscriber_001, TestSize.Level1)
2587c29fa5a6Sopenharmony_ci{
2588c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2589c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2590c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2591c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2592c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2593c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2594c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2595c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> listSub;
2596c29fa5a6Sopenharmony_ci    listSub.push_back(subscriber);
2597c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2598c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert(std::make_pair(keyOption, listSub));
2599c29fa5a6Sopenharmony_ci    EXPECT_EQ(handler.RemoveKeyGestureSubscriber(session, subscribeId), RET_ERR);
2600c29fa5a6Sopenharmony_ci}
2601c29fa5a6Sopenharmony_ci
2602c29fa5a6Sopenharmony_ci/**
2603c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_RemoveKeyGestureSubscriber_002
2604c29fa5a6Sopenharmony_ci * @tc.desc: Test RemoveKeyGestureSubscriber
2605c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2606c29fa5a6Sopenharmony_ci * @tc.require:
2607c29fa5a6Sopenharmony_ci */
2608c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_RemoveKeyGestureSubscriber_002, TestSize.Level1)
2609c29fa5a6Sopenharmony_ci{
2610c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2611c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2612c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2613c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2614c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2615c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2616c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2617c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> listSub;
2618c29fa5a6Sopenharmony_ci    listSub.push_back(subscriber);
2619c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert(std::make_pair(keyOption, listSub));
2620c29fa5a6Sopenharmony_ci    EXPECT_EQ(handler.RemoveKeyGestureSubscriber(sess, subscribeId), RET_OK);
2621c29fa5a6Sopenharmony_ci}
2622c29fa5a6Sopenharmony_ci
2623c29fa5a6Sopenharmony_ci/**
2624c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSessionDelete_002
2625c29fa5a6Sopenharmony_ci * @tc.desc: Test OnSessionDelete
2626c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2627c29fa5a6Sopenharmony_ci * @tc.require:
2628c29fa5a6Sopenharmony_ci */
2629c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSessionDelete_002, TestSize.Level1)
2630c29fa5a6Sopenharmony_ci{
2631c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2632c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2633c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2634c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2635c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2636c29fa5a6Sopenharmony_ci
2637c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2638c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2639c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> listSub;
2640c29fa5a6Sopenharmony_ci    listSub.push_back(subscriber);
2641c29fa5a6Sopenharmony_ci
2642c29fa5a6Sopenharmony_ci    SessionPtr session = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2643c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> keySubscriber =
2644c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, session, keyOption);
2645c29fa5a6Sopenharmony_ci    listSub.push_back(keySubscriber);
2646c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert(std::make_pair(keyOption, listSub));
2647c29fa5a6Sopenharmony_ci    EXPECT_NO_FATAL_FAILURE(handler.OnSessionDelete(session));
2648c29fa5a6Sopenharmony_ci}
2649c29fa5a6Sopenharmony_ci
2650c29fa5a6Sopenharmony_ci/**
2651c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_OnSessionDelete_003
2652c29fa5a6Sopenharmony_ci * @tc.desc: Test OnSessionDelete
2653c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2654c29fa5a6Sopenharmony_ci * @tc.require:
2655c29fa5a6Sopenharmony_ci */
2656c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_OnSessionDelete_003, TestSize.Level1)
2657c29fa5a6Sopenharmony_ci{
2658c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2659c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2660c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2661c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2662c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2663c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2664c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2665c29fa5a6Sopenharmony_ci    std::list<std::shared_ptr<KeySubscriberHandler::Subscriber>> listSub;
2666c29fa5a6Sopenharmony_ci    handler.keyGestures_.insert(std::make_pair(keyOption, listSub));
2667c29fa5a6Sopenharmony_ci    EXPECT_NO_FATAL_FAILURE(handler.OnSessionDelete(sess));
2668c29fa5a6Sopenharmony_ci}
2669c29fa5a6Sopenharmony_ci
2670c29fa5a6Sopenharmony_ci/**
2671c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyUpWithDelay_03
2672c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleKeyUpWithDelay
2673c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2674c29fa5a6Sopenharmony_ci * @tc.require:
2675c29fa5a6Sopenharmony_ci */
2676c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyUpWithDelay_03, TestSize.Level1)
2677c29fa5a6Sopenharmony_ci{
2678c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2679c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2680c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2681c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2682c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2683c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyUpDelay(-1);
2684c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2685c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2686c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = nullptr;
2687c29fa5a6Sopenharmony_ci    EXPECT_NO_FATAL_FAILURE(handler.HandleKeyUpWithDelay(keyEvent, subscriber));
2688c29fa5a6Sopenharmony_ci}
2689c29fa5a6Sopenharmony_ci
2690c29fa5a6Sopenharmony_ci/**
2691c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_HandleKeyUpWithDelay_04
2692c29fa5a6Sopenharmony_ci * @tc.desc: Test HandleKeyUpWithDelay
2693c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2694c29fa5a6Sopenharmony_ci * @tc.require:
2695c29fa5a6Sopenharmony_ci */
2696c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_HandleKeyUpWithDelay_04, TestSize.Level1)
2697c29fa5a6Sopenharmony_ci{
2698c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2699c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2700c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2701c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2702c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2703c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyUpDelay(100);
2704c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2705c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2706c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent = nullptr;
2707c29fa5a6Sopenharmony_ci    EXPECT_NO_FATAL_FAILURE(handler.HandleKeyUpWithDelay(keyEvent, subscriber));
2708c29fa5a6Sopenharmony_ci}
2709c29fa5a6Sopenharmony_ci
2710c29fa5a6Sopenharmony_ci/**
2711c29fa5a6Sopenharmony_ci * @tc.name: KeySubscriberHandlerTest_DumpSubscriber
2712c29fa5a6Sopenharmony_ci * @tc.desc: Test DumpSubscriber
2713c29fa5a6Sopenharmony_ci * @tc.type: FUNC
2714c29fa5a6Sopenharmony_ci * @tc.require:
2715c29fa5a6Sopenharmony_ci */
2716c29fa5a6Sopenharmony_ciHWTEST_F(KeySubscriberHandlerTest, KeySubscriberHandlerTest_DumpSubscriber, TestSize.Level1)
2717c29fa5a6Sopenharmony_ci{
2718c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
2719c29fa5a6Sopenharmony_ci    KeySubscriberHandler handler;
2720c29fa5a6Sopenharmony_ci    int32_t subscribeId = 1;
2721c29fa5a6Sopenharmony_ci    SessionPtr sess = std::make_shared<UDSSession>(PROGRAM_NAME, MODULE_TYPE, UDS_FD, UDS_UID, UDS_PID);
2722c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> keyOption = std::make_shared<KeyOption>();
2723c29fa5a6Sopenharmony_ci    keyOption->SetFinalKeyUpDelay(100);
2724c29fa5a6Sopenharmony_ci    std::shared_ptr<KeySubscriberHandler::Subscriber> subscriber =
2725c29fa5a6Sopenharmony_ci        std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, keyOption);
2726c29fa5a6Sopenharmony_ci    int32_t fd = 100;
2727c29fa5a6Sopenharmony_ci    EXPECT_NO_FATAL_FAILURE(handler.DumpSubscriber(fd, subscriber));
2728c29fa5a6Sopenharmony_ci
2729c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyOption> option = std::make_shared<KeyOption>();
2730c29fa5a6Sopenharmony_ci    std::set<int32_t> preKeys = { 2020, 2021 };
2731c29fa5a6Sopenharmony_ci    option->SetPreKeys(preKeys);
2732c29fa5a6Sopenharmony_ci    subscriber = std::make_shared<KeySubscriberHandler::Subscriber>(subscribeId, sess, option);
2733c29fa5a6Sopenharmony_ci    EXPECT_NO_FATAL_FAILURE(handler.DumpSubscriber(fd, subscriber));
2734c29fa5a6Sopenharmony_ci}
2735c29fa5a6Sopenharmony_ci} // namespace MMI
2736c29fa5a6Sopenharmony_ci} // namespace OHOS
2737