• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define protected public
18 #include "MouseInputImpl.h"
19 
20 namespace {
21     double g_xPosition = 10;
22     double g_yPosition = 20;
23     int g_action = 0;
24     int g_xorFlag = 1;
25 
26     class MouseInputImplTest : public ::testing::Test {
27     public:
MouseInputImplTest()28         MouseInputImplTest() {}
~MouseInputImplTest()29         ~MouseInputImplTest() {}
30     protected:
SetUpTestCase()31         static void SetUpTestCase()
32         {
33             MouseInputImpl::GetInstance().SetMousePosition(g_xPosition, g_yPosition);
34             MouseInputImpl::GetInstance().SetMouseStatus(g_action);
35         }
36     };
37 
TEST_F(MouseInputImplTest,ReadTest)38     TEST_F(MouseInputImplTest, ReadTest)
39     {
40         OHOS::DeviceData data;
41         MouseInputImpl::GetInstance().Read(data);
42         EXPECT_EQ(data.point.x, g_xPosition);
43         EXPECT_EQ(data.point.y, g_yPosition);
44         int ret = g_action ^ g_xorFlag;
45         EXPECT_EQ(data.state, ret);
46     }
47 
TEST_F(MouseInputImplTest,SetMouseStatusTest)48     TEST_F(MouseInputImplTest, SetMouseStatusTest)
49     {
50         int status = 2;
51         MouseInputImpl::GetInstance().SetMouseStatus(status);
52         int ret = g_action ^ g_xorFlag;
53         EXPECT_EQ(MouseInputImpl::GetInstance().touchAction, ret);
54 
55         status = 1;
56         MouseInputImpl::GetInstance().SetMouseStatus(status);
57         EXPECT_EQ(MouseInputImpl::GetInstance().touchAction, 0);
58     }
59 }