Description:add ut

Match-id-824bbc46f87c667fb1f8f9a2be692a0786ba8715
This commit is contained in:
xxxx
2022-12-05 21:15:52 +08:00
parent 473bef7f3c
commit ae06289559
8 changed files with 263 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
group("test") {
testonly = true
deps = [ "inputhandlertest:inputhandlertest" ]
}
@@ -0,0 +1,82 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import(
"//foundation/distributedhardware/distributed_input/distributedinput.gni")
module_out_path = "distributed_input/input_handler"
group("inputhandlertest") {
testonly = true
deps = [ ":distributed_input_handler_test" ]
}
## HandlerTest distributed_input_handler_test {{{
ohos_unittest("distributed_input_handler_test") {
module_out_path = module_out_path
include_dirs = [
"${common_path}/include",
"//commonlibrary/c_utils/base/include",
"//utils/system/safwk/native/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"${service_common}/include",
"${frameworks_path}/include",
"${utils_path}/include",
"//third_party/json/include",
"${fwk_interfaces_path}/include",
"${fwk_interfaces_path}/include/ipc",
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
"//foundation/distributedhardware/distributed_input/inputdevicehandler/include",
]
sources = [
"${common_path}/include/input_hub.cpp",
"//foundation/distributedhardware/distributed_input/inputdevicehandler/src/distributed_input_handler.cpp",
"distributed_input_handler_test.cpp",
]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Dprivate=public",
"-Dprotected=public",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"distributedinpututtest\"",
"LOG_DOMAIN=0xD004100",
]
deps = [
"${fwk_utils_path}:distributedhardwareutils",
"${utils_path}:libdinput_utils",
"//third_party/openssl:libcrypto_static",
]
external_deps = [
"c_utils:utils",
"dsoftbus:softbus_client",
]
cflags_cc = [ "-DHILOG_ENABLE" ]
}
## UnitTest distributed_input_handler_test }}}
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "distributed_input_handler_test.h"
#include "system_ability_definition.h"
#include "dinput_errcode.h"
#include "distributed_input_handler.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
void DInputHandlerTest::SetUp()
{
}
void DInputHandlerTest::TearDown()
{
}
void DInputHandlerTest::SetUpTestCase()
{
}
void DInputHandlerTest::TearDownTestCase()
{
}
HWTEST_F(DInputHandlerTest, QueryExtraInfo_001, testing::ext::TestSize.Level1)
{
DistributedInputHandler dInputHandler;
uint32_t inputTypes = static_cast<uint32_t>(DInputDeviceType::ALL);
std::map<int32_t, std::string> datas;
std::vector<std::string> dhidsVec;
dInputHandler.FindDevicesInfoByType(inputTypes, datas);
dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas);
std::map<std::string, std::string> ret = dInputHandler.QueryExtraInfo();
EXPECT_EQ(0, ret.size());
}
HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Level1)
{
DistributedInputHandler dInputHandler;
dInputHandler.inputHub_ = nullptr;
uint32_t inputTypes = static_cast<uint32_t>(DInputDeviceType::ALL);
std::map<int32_t, std::string> datas;
std::vector<std::string> dhidsVec;
std::string deviceId = "deviceId_test";
dInputHandler.FindDevicesInfoByType(inputTypes, datas);
dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas);
dInputHandler.Query();
dInputHandler.StartInputMonitorDeviceThread(deviceId);
InputDevice inputDevice;
dInputHandler.mEventBuffer[0].type = DeviceType::DEVICE_ADDED;
dInputHandler.mEventBuffer[0].deviceInfo = inputDevice;
dInputHandler.NotifyHardWare(0);
dInputHandler.mEventBuffer[1].type = DeviceType::DEVICE_REMOVED;
dInputHandler.mEventBuffer[1].deviceInfo = inputDevice;
dInputHandler.NotifyHardWare(1);
dInputHandler.mEventBuffer[2].type = DeviceType::FINISHED_DEVICE_SCAN;
dInputHandler.mEventBuffer[2].deviceInfo = inputDevice;
dInputHandler.NotifyHardWare(2);
std::map<std::string, std::string> ret = dInputHandler.QueryExtraInfo();
EXPECT_EQ(0, ret.size());
dInputHandler.inputHub_ = std::make_unique<InputHub>();
dInputHandler.StartInputMonitorDeviceThread(deviceId);
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef DISRIBUTED_INPUT_HANDLER_TEST_H
#define DISRIBUTED_INPUT_HANDLER_TEST_H
#include <functional>
#include <iostream>
#include <refbase.h>
#include <thread>
#include <gtest/gtest.h>
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "constants_dinput.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class DInputHandlerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISRIBUTED_INPUT_HANDLER_TEST_H