1 /*
2  * Copyright (c) 2022-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 "distributed_input_handler_test.h"
17 
18 #include "system_ability_definition.h"
19 
20 #include "dinput_errcode.h"
21 #include "distributed_input_handler.h"
22 
23 namespace OHOS {
24 namespace DistributedHardware {
25 namespace DistributedInput {
SetUp()26 void DInputHandlerTest::SetUp()
27 {
28 }
29 
TearDown()30 void DInputHandlerTest::TearDown()
31 {
32 }
33 
SetUpTestCase()34 void DInputHandlerTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void DInputHandlerTest::TearDownTestCase()
39 {
40 }
41 
42 HWTEST_F(DInputHandlerTest, QueryExtraInfo_001, testing::ext::TestSize.Level1)
43 {
44     DistributedInputHandler dInputHandler;
45     uint32_t inputTypes = static_cast<uint32_t>(DInputDeviceType::ALL);
46     std::map<int32_t, std::string> datas;
47     std::vector<std::string> dhidsVec;
48     dInputHandler.FindDevicesInfoByType(inputTypes, datas);
49     dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas);
50     std::map<std::string, std::string> ret = dInputHandler.QueryExtraInfo();
51     EXPECT_EQ(0, ret.size());
52 }
53 
54 HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Level1)
55 {
56     DistributedInputHandler dInputHandler;
57     dInputHandler.inputHub_ = nullptr;
58     uint32_t inputTypes = static_cast<uint32_t>(DInputDeviceType::ALL);
59     std::map<int32_t, std::string> datas;
60     std::vector<std::string> dhidsVec;
61     dInputHandler.FindDevicesInfoByType(inputTypes, datas);
62     dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas);
63     dInputHandler.Query();
64     dInputHandler.StartInputMonitorDeviceThread();
65 
66     InputDevice inputDevice;
67     dInputHandler.mEventBuffer_[0].type = DeviceType::DEVICE_ADDED;
68     dInputHandler.mEventBuffer_[0].deviceInfo = inputDevice;
69     dInputHandler.NotifyHardWare(0);
70     dInputHandler.mEventBuffer_[1].type = DeviceType::DEVICE_REMOVED;
71     dInputHandler.mEventBuffer_[1].deviceInfo = inputDevice;
72     dInputHandler.NotifyHardWare(1);
73     dInputHandler.mEventBuffer_[2].type = DeviceType::FINISHED_DEVICE_SCAN;
74     dInputHandler.mEventBuffer_[2].deviceInfo = inputDevice;
75     dInputHandler.NotifyHardWare(2);
76     std::map<std::string, std::string> ret = dInputHandler.QueryExtraInfo();
77     EXPECT_EQ(0, ret.size());
78     dInputHandler.inputHub_ = std::make_unique<InputHub>(true);
79     dInputHandler.StartInputMonitorDeviceThread();
80 }
81 } // namespace DistributedInput
82 } // namespace DistributedHardware
83 } // namespace OHOS