Description:fix ut

Match-id-9de3c6bbe0b92f2ac2e3065c0ce70c11d7476025
This commit is contained in:
xxxx
2022-05-24 19:42:55 +08:00
parent 081bf1ec11
commit bee83d222a
14 changed files with 303 additions and 113 deletions
+4 -1
View File
@@ -41,11 +41,14 @@ ohos_unittest("distributed_input_sink_handler_test") {
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"//third_party/json/include",
]
sources = [
"//foundation/distributedhardware/distributedinput/sinkhandler/src/distributed_input_sink_handler.cpp",
"//foundation/distributedhardware/distributedinput/sinkhandler/src/load_d_input_sink_callback.cpp",
"distributed_input_sinkhandler_test.cpp",
"//foundation/distributedhardware/distributedinput/sinkhandler/test/unittest/mock/mock_distributed_input_client.cpp",
]
cflags = [
@@ -67,7 +70,7 @@ ohos_unittest("distributed_input_sink_handler_test") {
"//utils/native/base:utils",
"${fwk_utils_path}:distributedhardwareutils",
"${innerkits_path}:libdinput_sdk",
"${services_sink_path}/sinkmanager:libdinput_sink",
"${services_source_path}/sourcemanager:libdinput_source",
]
external_deps = [
@@ -0,0 +1,172 @@
/*
* Copyright (c) 2021 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_client.h"
#include "constants_dinput.h"
#include "white_list_util.h"
#include "nlohmann/json.hpp"
#include "distributed_hardware_log.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
DistributedInputClient &DistributedInputClient::GetInstance()
{
static DistributedInputClient instance;
return instance;
}
void DistributedInputClient::RegisterDInputCb::OnResult(
const std::string& devId, const std::string& dhId, const int32_t& status)
{
for (std::vector<DHardWareFwkRegistInfo>::iterator iter =
DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin();
iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end();
iter++) {
if (iter->devId == devId && iter->dhId == dhId) {
iter->callback->OnRegisterResult(devId, dhId, status, "");
DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter);
return;
}
}
}
void DistributedInputClient::UnregisterDInputCb::OnResult(
const std::string& devId, const std::string& dhId, const int32_t& status)
{
for (std::vector<DHardWareFwkUnRegistInfo>::iterator iter =
DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin();
iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end();
iter++) {
if (iter->devId == devId && iter->dhId == dhId) {
iter->callback->OnUnregisterResult(devId, dhId, status, "");
DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter);
return;
}
}
}
void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status, const uint32_t& inputTypes)
{
if (DInputServerType::SOURCE_SERVER_TYPE == static_cast<DInputServerType>(status)) {
DistributedInputClient::GetInstance().serverType = DInputServerType::SOURCE_SERVER_TYPE;
DistributedInputClient::GetInstance().inputTypes = inputTypes;
} else if (DInputServerType::SINK_SERVER_TYPE == static_cast<DInputServerType>(status)) {
DistributedInputClient::GetInstance().serverType = DInputServerType::SINK_SERVER_TYPE;
DistributedInputClient::GetInstance().inputTypes = inputTypes;
} else {
DistributedInputClient::GetInstance().serverType = DInputServerType::NULL_SERVER_TYPE;
DistributedInputClient::GetInstance().inputTypes = INPUT_TYPE_NULL;
}
}
void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson)
{
nlohmann::json inputData = nlohmann::json::parse(strJson);
int jsonSize = inputData.size();
DHLOGI("AddWhiteListInfosCb OnResult json size:%d.\n", jsonSize);
TYPE_WHITE_LIST_VEC vecWhiteList = inputData;
WhiteListUtil::GetInstance().SyncWhiteList(deviceId, vecWhiteList);
}
void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& deviceId)
{
WhiteListUtil::GetInstance().ClearWhiteList(deviceId);
}
int32_t DistributedInputClient::InitSource()
{
return SUCCESS;
}
int32_t DistributedInputClient::InitSink()
{
return SUCCESS;
}
int32_t DistributedInputClient::ReleaseSource()
{
return SUCCESS;
}
int32_t DistributedInputClient::ReleaseSink()
{
return SUCCESS;
}
int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& devId, const std::string& dhId,
const std::string& parameters, const std::shared_ptr<RegisterCallback>& callback)
{
return SUCCESS;
}
int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId,
const std::shared_ptr<UnregisterCallback>& callback)
{
return SUCCESS;
}
int32_t DistributedInputClient::PrepareRemoteInput(
const std::string& deviceId, sptr<IPrepareDInputCallback> callback)
{
return SUCCESS;
}
int32_t DistributedInputClient::UnprepareRemoteInput(
const std::string& deviceId, sptr<IUnprepareDInputCallback> callback)
{
return SUCCESS;
}
int32_t DistributedInputClient::StartRemoteInput(
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStartDInputCallback> callback)
{
return SUCCESS;
}
int32_t DistributedInputClient::StopRemoteInput(
const std::string& deviceId, const uint32_t& inputTypes, sptr<IStopDInputCallback> callback)
{
return SUCCESS;
}
bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event)
{
return true;
}
DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType)
{
return serverType;
}
bool DistributedInputClient::GetDInputSourceProxy()
{
return true;
}
bool DistributedInputClient::GetDInputSinkProxy()
{
return true;
}
bool DistributedInputClient::IsJsonData(std::string strData) const
{
return true;
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS