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 };
44
SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)45 int32_t AncoMonitor::SyncInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
46 {
47 std::cout << "No:" << pointerEvent->GetId() << ",S:" << pointerEvent->GetSourceType()
48 << ",A:" << pointerEvent->GetPointerAction() << std::endl;
49 return RET_OK;
50 }
51
SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)52 int32_t AncoMonitor::SyncInputEvent(std::shared_ptr<KeyEvent> keyEvent)
53 {
54 std::cout << "No:" << keyEvent->GetId() << ",K:" << keyEvent->GetKeyCode()
55 << ",A:" << keyEvent->GetKeyAction() << std::endl;
56 return RET_OK;
57 }
58
UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)59 int32_t AncoMonitor::UpdateWindowInfo(std::shared_ptr<AncoWindows> windows)
60 {
61 return RET_OK;
62 }
63
SyncKnuckleStatus(bool isKnuckleEnable)64 int32_t AncoMonitor::SyncKnuckleStatus(bool isKnuckleEnable)
65 {
66 return RET_OK;
67 }
68
69 /**
70 * @tc.name: InputManagerAncoTest_SyncPointerEvent_001
71 * @tc.desc: Verify key event
72 * @tc.type: FUNC
73 * @tc.require:
74 */
75 HWTEST_F(InputManagerAncoTest, InputManagerAncoTest_SyncPointerEvent_001, TestSize.Level1)
76 {
77 CALL_TEST_DEBUG;
78 auto monitor = std::make_shared<AncoMonitor>();
79 ASSERT_EQ(InputManager::GetInstance()->AncoAddConsumer(monitor), RET_OK);
80 std::this_thread::sleep_for(std::chrono::minutes(1));
81 ASSERT_EQ(InputManager::GetInstance()->AncoRemoveConsumer(monitor), RET_OK);
82 }
83 } // namespace MMI
84 } // namespace OHOS
85