1 /*
2 * Copyright (c) 2022 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 std::string deviceId = "deviceId_test";
62 dInputHandler.FindDevicesInfoByType(inputTypes, datas);
63 dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas);
64 dInputHandler.Query();
65 dInputHandler.StartInputMonitorDeviceThread(deviceId);
66
67 InputDevice inputDevice;
68 dInputHandler.mEventBuffer[0].type = DeviceType::DEVICE_ADDED;
69 dInputHandler.mEventBuffer[0].deviceInfo = inputDevice;
70 dInputHandler.NotifyHardWare(0);
71 dInputHandler.mEventBuffer[1].type = DeviceType::DEVICE_REMOVED;
72 dInputHandler.mEventBuffer[1].deviceInfo = inputDevice;
73 dInputHandler.NotifyHardWare(1);
74 dInputHandler.mEventBuffer[2].type = DeviceType::FINISHED_DEVICE_SCAN;
75 dInputHandler.mEventBuffer[2].deviceInfo = inputDevice;
76 dInputHandler.NotifyHardWare(2);
77 std::map<std::string, std::string> ret = dInputHandler.QueryExtraInfo();
78 EXPECT_EQ(0, ret.size());
79 dInputHandler.inputHub_ = std::make_unique<InputHub>();
80 dInputHandler.StartInputMonitorDeviceThread(deviceId);
81 }
82 } // namespace DistributedInput
83 } // namespace DistributedHardware
84 } // namespace OHOS