1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "define_multimodal.h"
19 #include "input_manager.h"
20
21 #undef MMI_LOG_TAG
22 #define MMI_LOG_TAG "InputManagerAncoTest"
23
24 namespace OHOS {
25 namespace MMI {
26 using namespace testing::ext;
27
28 class InputManagerAncoTest : public testing::Test {
29 public:
SetUpTestCase(void)30 static void SetUpTestCase(void) {}
TearDownTestCase(void)31 static void TearDownTestCase(void) {}
32 };
33
34 class AncoMonitor final : public IAncoConsumer {
35 public:
36 AncoMonitor() = default;
37 ~AncoMonitor() override = default;
38
39 int32_t SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent) override;
40 int32_t SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent) override;
41 int32_t UpdateWindowInfo(std::shared_ptr<AncoWindows> windows) override;
42 int32_t SyncKnuckleStatus(bool isKnuckleEnable) override;
43 int32_t UpdateOneHandData(const AncoOneHandData &oneHandData) override;
44 };
45
SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)46 int32_t AncoMonitor::SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
47 {
48 std::cout << "No:" << pointerEvent->GetId() << ",S:" << pointerEvent->GetSourceType()
49 << ",A:" << pointerEvent->GetPointerAction() << std::endl;
50 return RET_OK;
51 }
52
SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)53 int32_t AncoMonitor::SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)
54 {
55 std::cout << "No:" << keyEvent->GetId() << ",K:" << keyEvent->GetKeyCode()
56 << ",A:" << keyEvent->GetKeyAction() << std::endl;
57 return RET_OK;
58 }
59
UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)60 int32_t AncoMonitor::UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)
61 {
62 return RET_OK;
63 }
64
SyncKnuckleStatus(bool isKnuckleEnable)65 int32_t AncoMonitor::SyncKnuckleStatus(bool isKnuckleEnable)
66 {
67 return RET_OK;
68 }
69
UpdateOneHandData(const AncoOneHandData & oneHandData)70 int32_t AncoMonitor::UpdateOneHandData(const AncoOneHandData &oneHandData)
71 {
72 return RET_OK;
73 }
74
75 /**
76 * @tc.name: InputManagerAncoTest_SyncPointerEvent_001
77 * @tc.desc: Verify key event
78 * @tc.type: FUNC
79 * @tc.require:
80 */
81 HWTEST_F(InputManagerAncoTest, InputManagerAncoTest_SyncPointerEvent_001, TestSize.Level1)
82 {
83 CALL_TEST_DEBUG;
84 auto monitor = std::make_shared<AncoMonitor>();
85 ASSERT_EQ(InputManager::GetInstance()->AncoAddConsumer(monitor), RET_OK);
86 std::this_thread::sleep_for(std::chrono::minutes(1));
87 ASSERT_EQ(InputManager::GetInstance()->AncoRemoveConsumer(monitor), RET_OK);
88 }
89 } // namespace MMI
90 } // namespace OHOS
91