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 <gmock/gmock.h>
18
19 #include <cstdio>
20
21 #include "crown_transform_processor.h"
22 #include "general_crown.h"
23 #include "i_input_windows_manager.h"
24 #include "input_device_manager.h"
25 #include "input_event_handler.h"
26 #include "libinput.h"
27 #include "libinput_mock.h"
28 #include "libinput_wrapper.h"
29 #include "mmi_log.h"
30 #include "window_info.h"
31
32 #undef MMI_LOG_TAG
33 #define MMI_LOG_TAG "CrownTransformProcessorExTest"
34
35 namespace OHOS {
36 namespace MMI {
37 namespace {
38 using namespace testing;
39 using namespace testing::ext;
40 }
41 class CrownTransformProcessorExTest : public testing::Test {
42 public:
43 static void SetUpTestCase(void);
44 static void TearDownTestCase(void);
45 void SetUp();
46 void TearDown();
47 };
48
SetUpTestCase(void)49 void CrownTransformProcessorExTest::SetUpTestCase(void)
50 {
51 }
52
TearDownTestCase(void)53 void CrownTransformProcessorExTest::TearDownTestCase(void)
54 {
55 }
56
SetUp()57 void CrownTransformProcessorExTest::SetUp()
58 {
59 }
60
TearDown()61 void CrownTransformProcessorExTest::TearDown()
62 {
63 }
64
65 /**
66 * @tc.name: CrownTransformProcessorExTest_IsCrownEvent_001
67 * @tc.desc: Test GetPointerEvent
68 * @tc.type: FUNC
69 * @tc.require:
70 */
71 HWTEST_F(CrownTransformProcessorExTest, CrownTransformProcessorExTest_IsCrownEvent_001, TestSize.Level1)
72 {
73 CALL_TEST_DEBUG;
74 libinput_event event {};
75 libinput_device device {};
76 libinput_event_pointer pointer {};
77 NiceMock<LibinputInterfaceMock> libinputMock;
78 EXPECT_CALL(libinputMock, GetDevice).WillRepeatedly(Return(&device));
79 EXPECT_CALL(libinputMock, DeviceGetName).WillRepeatedly(Return(const_cast<char*>("rotary_crown")));
80 bool result = CROWN_EVENT_HDR->IsCrownEvent(&event);
81 ASSERT_FALSE(result);
82 EXPECT_CALL(libinputMock, DeviceGetName).WillRepeatedly(Return(const_cast<char*>("Virtual Crown")));
83 result = CROWN_EVENT_HDR->IsCrownEvent(&event);
84 ASSERT_FALSE(result);
85 EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_AXIS));
86 EXPECT_CALL(libinputMock, LibinputGetPointerEvent).WillRepeatedly(Return(&pointer));
87 EXPECT_CALL(libinputMock, GetAxisSource).WillRepeatedly(Return(LIBINPUT_POINTER_AXIS_SOURCE_FINGER));
88 result = CROWN_EVENT_HDR->IsCrownEvent(&event);
89 ASSERT_FALSE(result);
90 EXPECT_CALL(libinputMock, GetAxisSource).WillRepeatedly(Return(LIBINPUT_POINTER_AXIS_SOURCE_WHEEL));
91 result = CROWN_EVENT_HDR->IsCrownEvent(&event);
92 ASSERT_TRUE(result);
93 EXPECT_CALL(libinputMock, GetEventType).WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_MOTION));
94 result = CROWN_EVENT_HDR->IsCrownEvent(&event);
95 ASSERT_FALSE(result);
96 EXPECT_CALL(libinputMock, DeviceGetName).WillRepeatedly(Return(const_cast<char*>("ut_good")));
97 result = CROWN_EVENT_HDR->IsCrownEvent(&event);
98 ASSERT_FALSE(result);
99 }
100 } // namespace MMI
101 } // namespace OHOS