1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 18 #include <fstream> 19 20 #include "key_subscriber_handler.h" 21 #include "switch_subscriber_handler.h" 22 #include "mmi_log.h" 23 #include "uds_server.h" 24 25 namespace OHOS { 26 namespace MMI { 27 namespace { 28 using namespace testing::ext; 29 } // namespace 30 31 class KeySubscriberHandlerTest : public testing::Test { 32 public: SetUpTestCase(void)33 static void SetUpTestCase(void) {} TearDownTestCase(void)34 static void TearDownTestCase(void) {} 35 }; 36 37 /** 38 * @tc.name: InputWindowsManagerTest_UnsubscribeKeyEvent_001 39 * @tc.desc: Test UnsubscribeKeyEvent 40 * @tc.type: FUNC 41 * @tc.require: 42 */ 43 HWTEST_F(KeySubscriberHandlerTest, InputWindowsManagerTest_UnsubscribeKeyEvent_001, TestSize.Level1) 44 { 45 KeySubscriberHandler keySubscriberHandler; 46 auto keyEvent = KeyEvent::Create(); 47 keySubscriberHandler.HandleKeyEvent(keyEvent); 48 auto pointerEvent = PointerEvent::Create(); 49 keySubscriberHandler.HandlePointerEvent(pointerEvent); 50 keySubscriberHandler.HandleTouchEvent(pointerEvent); 51 keySubscriberHandler.RemoveSubscriberKeyUpTimer(1); 52 std::vector<std::string> args = {}; 53 keySubscriberHandler.Dump(1, args); 54 55 UDSServer udsServer; 56 SessionPtr sess = udsServer.GetSessionByPid(1); 57 std::shared_ptr<KeyOption> keyOption = nullptr; 58 ASSERT_EQ(keySubscriberHandler.SubscribeKeyEvent(sess, -1, keyOption), -1); 59 SessionPtr sessPtr = nullptr; 60 ASSERT_EQ(keySubscriberHandler.UnsubscribeKeyEvent(sessPtr, -1), -1); 61 ASSERT_EQ(keySubscriberHandler.UnsubscribeKeyEvent(sess, 1), -1); 62 } 63 } // namespace MMI 64 } // namespace OHOS 65