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