1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "gtest/gtest.h" 17 #include "keys_input_device.h" 18 19 #include <thread> 20 #include "updater_event.h" 21 22 using namespace testing::ext; 23 using namespace Updater; 24 25 namespace UpdaterUt { 26 enum KeyUpDownEvent { 27 EVENT_KEY_UP_VALUE, 28 EVENT_KEY_DOWN_VALUE 29 }; 30 31 class KeysInputDeviceUnitTest : public testing::Test { 32 public: SetUpTestCase(void)33 static void SetUpTestCase(void) {} TearDownTestCase(void)34 static void TearDownTestCase(void) {} SetUp()35 void SetUp() override {} TearDown()36 void TearDown() override {} 37 }; 38 39 HWTEST_F(KeysInputDeviceUnitTest, test_keys_input_read, TestSize.Level0) 40 { 41 OHOS::DeviceData data; 42 EXPECT_FALSE(KeysInputDevice::GetInstance().Read(data)); 43 } 44 45 HWTEST_F(KeysInputDeviceUnitTest, test_handle_key_event, TestSize.Level0) 46 { 47 input_event ev = {.type = EV_KEY + 1}; 48 uint32_t type = 0; 49 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 50 ev.type = EV_KEY; 51 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 52 ev.code = KEY_MAX +1; 53 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 54 ev.value = EVENT_KEY_UP_VALUE; 55 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 56 ev.code = BTN_TOUCH; 57 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 58 ev.code = BTN_TOOL_FINGER; 59 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 60 ev.code = BTN_MOUSE; 61 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 62 ev.code = BTN_LEFT; 63 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 64 ev.code = BTN_MIDDLE; 65 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 66 ev.code = BTN_RIGHT; 67 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 68 ev.code = KEY_VOLUMEDOWN; 69 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 70 ev.code = KEY_VOLUMEUP; 71 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 72 ev.code = KEY_POWER; 73 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 74 ev.value = EVENT_KEY_DOWN_VALUE; 75 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 76 ev.code = KEY_HOMEPAGE; 77 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 78 KeysInputDevice::GetInstance().SetLongPressType(LONG_PRESS_POWER_ONLY_TYPE); 79 EXPECT_EQ(KeysInputDevice::GetInstance().HandleKeyEvent(ev, type), 0); 80 } 81 }