diff --git a/test/BUILD.gn b/test/BUILD.gn index 6411592..f86c930 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -15,7 +15,6 @@ group("test") { testonly = true deps = [ - "system:system", "fuzztest:fuzztest", ] } diff --git a/test/system/BUILD.gn b/test/system/BUILD.gn deleted file mode 100644 index f09c3e8..0000000 --- a/test/system/BUILD.gn +++ /dev/null @@ -1,98 +0,0 @@ -# Copyright (c) 2021-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/system" - -group("system") { - testonly = true - - deps = [ - ":distributed_input_test", - ] -} - -## UnitTest distributed_input_test {{{ -ohos_unittest("distributed_input_test") { - module_out_path = module_out_path - - include_dirs = [ - "include", - "${distributedinput_path}/interfaces/inner_kits/include", - "${distributedinput_path}/interfaces/inner_kits/src", - "${distributedinput_path}/interfaces/ipc/include", - "${distributedinput_path}/interfaces/ipc/src", - "${distributedinput_path}/services/source/sourcemanager/include", - "${distributedinput_path}/services/sink/sinkmanager/include", - "${distributedinput_path}/frameworks/include", - "${distributedinput_path}/sourcehandler/include", - "${distributedinput_path}/sinkhandler/include", - "${distributedinput_path}/inputdevicehandler/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${service_common}/include", - "${common_path}/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "//third_party/json/include", - ] - - sources = [ - "src/distributed_input_test.cpp", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedinpututtest\"", - "LOG_DOMAIN=0xD004100", - ] - - deps = [ - "${distributedinput_path}/interfaces/inner_kits:libdinput_sdk", - "${distributedinput_path}/services/source/sourcemanager:libdinput_source", - "${distributedinput_path}/services/source/inputinject:libdinput_inject", - "${distributedinput_path}/services/source/transport:libdinput_source_trans", - "${distributedinput_path}/services/sink/sinkmanager:libdinput_sink", - "${distributedinput_path}/services/sink/inputcollector:libdinput_collector", - "${distributedinput_path}/services/sink/transport:libdinput_sink_trans", - "${distributedinput_path}/sourcehandler:libdinput_source_handler", - "${distributedinput_path}/sinkhandler:libdinput_sink_handler", - "${distributedinput_path}/inputdevicehandler:libdinput_handler", - "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", - "//utils/native/base:utils", - "${fwk_utils_path}:distributedhardwareutils", - ] - - external_deps = [ - "dsoftbus_standard:softbus_client", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "hiviewdfx_hilog_native:libhilog", - "samgr_standard:samgr_proxy", - ] - - cflags_cc = [ "-DHILOG_ENABLE" ] -} - -## UnitTest distributed_input_test }}} \ No newline at end of file diff --git a/test/system/include/distributed_input_test.h b/test/system/include/distributed_input_test.h deleted file mode 100644 index 776127e..0000000 --- a/test/system/include/distributed_input_test.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2021-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_TEST_H -#define DISRIBUTED_INPUT_TEST_H - -#include -#include -#include - -#include -#include - -#include "constants_dinput.h" -#include "distributed_input_handler.h" -#include "distributed_input_kit.h" -#include "distributed_input_sink_handler.h" -#include "distributed_input_source_handler.h" -#include "i_distributed_sink_input.h" -#include "i_distributed_source_input.h" -#include "prepare_d_input_call_back_stub.h" -#include "unprepare_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class DistributedInputTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; - - void StartSourceSa(); - void StartSinkSa(); - void GetHardWhereInfo(); - void GetDeviceInfo(); - void RegisterDistributedHardware(); - void UnregisterDistributedHardware(); - void PrepareRemoteInput(); - void UnprepareRemoteInput(); - void StartRemoteInput(); - void StopRemoteInput(); - void IsStartDistributedInput(); - void IsNeedFilterOut(); - void StopSourceSa(); - void StopSinkSa(); - void Help(); - void SwitchCase(int32_t in); - - class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback { - public: - TestRegisterInputCallback() = default; - virtual ~TestRegisterInputCallback() = default; - virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) override; - }; - - class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback { - public: - TestUnregisterInputCallback() = default; - virtual ~TestUnregisterInputCallback() = default; - virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) override; - }; - - class TestPluginListener : public OHOS::DistributedHardware::PluginListener { - public: - TestPluginListener() = default; - virtual ~TestPluginListener() = default; - virtual void PluginHardware(const std::string &dhId, const std::string &attrs) override; - virtual void UnPluginHardware(const std::string &dhId) override; - }; - - class TestPrepareDInputCallback : - public OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { - public: - TestPrepareDInputCallback() = default; - virtual ~TestPrepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status); - }; - - class TestUnprepareDInputCallback : - public OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { - public: - TestUnprepareDInputCallback() = default; - virtual ~TestUnprepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status); - }; - - class TestStartDInputCallback : - public OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { - public: - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); - }; - - class TestStopDInputCallback : - public OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { - public: - TestStopDInputCallback() = default; - virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); - }; - - OHOS::DistributedHardware::EnableParam enableParam; - - std::shared_ptr registerCb = nullptr; - std::shared_ptr unregisterCb = nullptr; - std::shared_ptr pluginListener; - OHOS::sptr prepareCb; - OHOS::sptr unprepareCb; - OHOS::sptr startCb; - OHOS::sptr stopCb; -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISRIBUTED_INPUT_TEST_H diff --git a/test/system/src/distributed_input_test.cpp b/test/system/src/distributed_input_test.cpp deleted file mode 100644 index 84d42ed..0000000 --- a/test/system/src/distributed_input_test.cpp +++ /dev/null @@ -1,559 +0,0 @@ -/* - * Copyright (c) 2021-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_test.h" - -#include -#include - -#include - -#include "idistributed_hardware_source.h" -#include "ipc_skeleton.h" -#include "nlohmann/json.hpp" - -#include "softbus_bus_center.h" - -using namespace testing::ext; -using namespace OHOS::DistributedHardware::DistributedInput; -using namespace std; - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -namespace { - const int32_t TEST_START_SINK = 1; - const int32_t TEST_START_SOURCE = 2; - const int32_t TEST_GET_DEVICEINFO = 3; - const int32_t TEST_GET_HARDWAREINFO = 4; - const int32_t TEST_IS_START_INPUT = 5; - const int32_t TEST_IS_NEED_FILTEROUT = 6; - const int32_t TEST_STOP_SINK = 7; - const int32_t TEST_STOP_SOURCE = 8; - const int32_t TEST_HELP = 9; - const int32_t TEST_REGISTERHARDWARE = 11; - const int32_t TEST_PREPAREREMOTE = 12; - const int32_t TEST_STARTREMOTE = 13; - const int32_t TEST_STOPREMOTE = 14; - const int32_t TEST_UN_PREPAREREMOTE = 15; - const int32_t TEST_UN_REGISTERHARDWARE = 16; -} -void DistributedInputTest::SetUp() -{ -} - -void DistributedInputTest::TearDown() -{ -} - -void DistributedInputTest::SetUpTestCase() -{ -} - -void DistributedInputTest::TearDownTestCase() -{ -} - -void DistributedInputTest::TestPluginListener::PluginHardware( - const std::string &dhId, const std::string &attrs) -{ - std::cout << std::endl; - std::cout << "dhId::" << dhId < items = DistributedInputHandler::GetInstance().Query(); - int index = 0; - for (auto item : items) { - std::cout << "dhId :: " << std::endl; - std::cout << item.dhId << std::endl; - std::cout << "attrs:: " << std::endl; - index = 0; - while ((index = item.attrs.find(' ', index)) != string::npos) { - item.attrs.erase(index, 1); - } - std::cout << item.attrs << std::endl; - } - std::cout << "GetHardWhereInfo::end " << std::endl; -} - -void DistributedInputTest::GetDeviceInfo() -{ - std::cout << "GetDeviceInfo::start " << std::endl; - - NodeBasicInfo *info = NULL; - int32_t infoNum = 0; - GetAllNodeDeviceInfo("ohos.distributedhardware.devicemanager", &info, &infoNum); - std::cout << "DeviceInfo::" << std::endl; - for (int32_t i = 0; i < infoNum; i++) { - std::cout << "networkId::" << std::endl; - std::cout << info->networkId << std::endl; - std::cout << "deviceName::" << std::endl; - std::cout << info->deviceName << std::endl; - std::cout << std::endl; - info++; - } - std::cout << "GetDeviceInfo::end " << std::endl; -} - -void DistributedInputTest::IsStartDistributedInput() -{ - std::cout << "IsStartDistributedInput::start " << std::endl; - - uint32_t inputType = 0; - std::cout << "inputType::"; - std::cin >> inputType; - - DInputServerType type = DistributedInputKit::IsStartDistributedInput(inputType); - if (type == DInputServerType::SOURCE_SERVER_TYPE) { - std::cout << "The inputed type is using in source sa! " << std::endl; - } else if (type == DInputServerType::SINK_SERVER_TYPE) { - std::cout << "The inputed type is using in sink sa! " << std::endl; - } else { - std::cout << "No sa is using! " << std::endl; - } - - std::cout << "IsStartDistributedInput::end " << std::endl; -} - -void DistributedInputTest::IsNeedFilterOut() -{ - std::cout << "IsNeedFilterOut::start " << std::endl; - - string deviceId = ""; - int32_t pressedKey1 = 0; - int32_t pressedKey2 = 0; - int32_t keyCode = 0; - int32_t keyAction = 0; - BusinessEvent event; - - std::cout << "deviceId::"; - std::cin >> deviceId; - std::cout << "BusinessEvent::" << std::endl; - std::cout << "pressedKey1::"; - std::cin >> pressedKey1; - std::cout << "pressedKey2::"; - std::cin >> pressedKey2; - std::cout << "keyCode::"; - std::cin >> keyCode; - std::cout << "keyAction::"; - std::cin >> keyAction; - - event.pressedKeys.push_back(pressedKey1); - event.pressedKeys.push_back(pressedKey2); - event.keyCode = keyCode; - event.keyAction = keyAction; - - bool ret = DistributedInputKit::IsNeedFilterOut(deviceId, event); - if (ret == true) { - std::cout << " Result::true ! " << std::endl; - std::cout << " The businessEvent is not in the white list ! " << std::endl; - std::cout << " The businessEvent take effect at the source! " << std::endl; - } else { - std::cout << " Result::false ! " << std::endl; - std::cout << " The businessEvent is in the white list ! " << std::endl; - std::cout << " The businessEvent don`t take effect at the source! " << std::endl; - } - - std::cout << "IsNeedFilterOut::end " << std::endl; -} - -void DistributedInputTest::RegisterDistributedHardware() -{ - std::cout << "RegisterDistributedHardware::start " << std::endl; - - string rDevId = ""; - string rDhId = ""; - string attrs = ""; - - std::cout << "devId::"; - std::cin >> rDevId; - std::cout << "dhId::"; - std::cin >> rDhId; - std::cout << "params::"; - std::cin >> attrs; - - enableParam.version = "1.0"; - enableParam.attrs = attrs; - - registerCb = std::make_shared(); - int32_t ret = DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware( - rDevId, rDhId, enableParam, registerCb); - if (ret == SUCCESS) { - std::cout << "RegisterDistributedHardware is succese! " << std::endl; - } else { - std::cout << "RegisterDistributedHardware is fall! " << std::endl; - } - - std::cout << "RegisterDistributedHardware::end " << std::endl; -} - -void DistributedInputTest::PrepareRemoteInput() -{ - std::cout << "PrepareRemoteInput::start " << std::endl; - - string rDevId = ""; - - std::cout << "devId::"; - std::cin >> rDevId; - - prepareCb = new(std::nothrow) TestPrepareDInputCallback(); - int32_t ret = DistributedInputKit::PrepareRemoteInput(rDevId, prepareCb); - if (ret == SUCCESS) { - std::cout << "PrepareRemoteInput is succese! " << std::endl; - } else { - std::cout << "PrepareRemoteInput is fall! " << std::endl; - } - - std::cout << "PrepareRemoteInput::end " << std::endl; -} - -void DistributedInputTest::UnprepareRemoteInput() -{ - std::cout << "UnprepareRemoteInput::start " << std::endl; - - string rDevId = ""; - - std::cout << "devId::"; - std::cin >> rDevId; - - unprepareCb = new(std::nothrow) TestUnprepareDInputCallback(); - int32_t ret = DistributedInputKit::UnprepareRemoteInput(rDevId, unprepareCb); - if (ret == SUCCESS) { - std::cout << "UnprepareRemoteInput is succese! " << std::endl; - } else { - std::cout << "UnprepareRemoteInput is fall! " << std::endl; - } - std::cout << "UnprepareRemoteInput::end " << std::endl; -} - -void DistributedInputTest::StartRemoteInput() -{ - std::cout << "StartRemoteInput::start " << std::endl; - std::cout << "You can input 1 ~ 7" << std::endl; - std::cout << "1:mouse " << std::endl; - std::cout << "2:keyboard " << std::endl; - std::cout << "4:touch " << std::endl; - std::cout << "7:all " << std::endl; - - string rDevId = ""; - uint32_t rInputType = 0; - std::cout << "inputType::"; - std::cin >> rInputType; - std::cout << "devId::"; - std::cin >> rDevId; - - startCb = new(std::nothrow) TestStartDInputCallback(); - int32_t ret = DistributedInputKit::StartRemoteInput(rDevId, rInputType, startCb); - if (ret == SUCCESS) { - std::cout << "StartRemoteInput is succese! " << std::endl; - } else { - std::cout << "StartRemoteInput is fall! " << std::endl; - } - - std::cout << "StartRemoteInput::end " << std::endl; -} - -void DistributedInputTest::StopRemoteInput() -{ - std::cout << "StopRemoteInput::start " << std::endl; - std::cout << "You can input 1 ~ 7" << std::endl; - std::cout << "1:mouse " << std::endl; - std::cout << "2:keyboard " << std::endl; - std::cout << "4:touch " << std::endl; - std::cout << "7:all " << std::endl; - - string rDevId = ""; - uint32_t rInputType = 0; - - std::cout << "devId::"; - std::cin >> rDevId; - - std::cout << "inputType::"; - std::cin >> rInputType; - - stopCb = new(std::nothrow) TestStopDInputCallback(); - int32_t ret = DistributedInputKit::StopRemoteInput(rDevId, rInputType, stopCb); - if (ret == SUCCESS) { - std::cout << "StopRemoteInput is succese! " << std::endl; - } else { - std::cout << "StopRemoteInput is fall! " << std::endl; - } - - std::cout << "StopRemoteInput::end " << std::endl; -} - -void DistributedInputTest::UnregisterDistributedHardware() -{ - std::cout << "UnregisterDistributedHardware::start " << std::endl; - - string rDevId = ""; - string rDhId = ""; - string attrs = ""; - - std::cout << "devId::"; - std::cin >> rDevId; - std::cout << "dhId::"; - std::cin >> rDhId; - - unregisterCb = std::make_shared(); - int32_t ret = DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware( - rDevId, rDhId, unregisterCb); - if (ret == SUCCESS) { - std::cout << "UnregisterDistributedHardware is succese! " << std::endl; - } else { - std::cout << "UnregisterDistributedHardware is fall! " << std::endl; - } - - std::cout << "UnregisterDistributedHardware::end " << std::endl; -} - -void DistributedInputTest::StopSourceSa() -{ - std::cout << "StopSourceSa::start " << std::endl; - int ret = DistributedInputSourceHandler::GetInstance().ReleaseSource(); - if (ret == SUCCESS) { - std::cout << "StopSourceSa is succese! " << std::endl; - } else { - std::cout << "StopSourceSa is fall! " << std::endl; - } - - std::cout << "StopSourceSa::end " << std::endl; -} - -void DistributedInputTest::StopSinkSa() -{ - std::cout << "StopSinkSa::start " << std::endl; - int ret = DistributedInputSinkHandler::GetInstance().ReleaseSink(); - if (ret == SUCCESS) { - std::cout << "StopSinkSa is succese! " << std::endl; - } else { - std::cout << "StopSinkSa is fall! " << std::endl; - } - std::cout << "StopSinkSa::end " << std::endl; -} - -void DistributedInputTest::Help() -{ - std::cout << "************************************************************" << std::endl; - std::cout << "Welcome to the dinput source test demo!" << std::endl; - std::cout << "1 ::StartSinkSa " << std::endl; - std::cout << "2 ::StartSourceSa " << std::endl; - std::cout << "3 ::GetDeviceInfo " << std::endl; - std::cout << "4 ::GetHardWhereInfo " << std::endl; - std::cout << "5 ::IsStartDistributedInput " << std::endl; - std::cout << "6 ::IsNeedFilterOut " << std::endl; - std::cout << "7 ::StopSinkSa " << std::endl; - std::cout << "8 ::StopSourceSa " << std::endl; - std::cout << "9 ::Help " << std::endl; - std::cout << "0 ::Exit " << std::endl; - std::cout << "11::RegisterDistributedHardware " << std::endl; - std::cout << "12::PrepareRemoteInput " << std::endl; - std::cout << "13::StartRemoteInput " << std::endl; - std::cout << "14::StopRemoteInput " << std::endl; - std::cout << "15::UnprepareRemoteInput " << std::endl; - std::cout << "16::UnregisterDistributedHardware " << std::endl; - std::cout << "************************************************************" << std::endl; -} - -void DistributedInputTest::SwitchCase(int32_t in) -{ - switch (in) { - case TEST_START_SINK: - StartSinkSa(); - break; - case TEST_START_SOURCE: - StartSourceSa(); - break; - case TEST_GET_DEVICEINFO: - GetDeviceInfo(); - break; - case TEST_GET_HARDWAREINFO: - GetHardWhereInfo(); - break; - case TEST_IS_START_INPUT: - IsStartDistributedInput(); - break; - case TEST_IS_NEED_FILTEROUT: - IsNeedFilterOut(); - break; - case TEST_STOP_SINK: - StopSinkSa(); - break; - case TEST_STOP_SOURCE: - StopSourceSa(); - break; - case TEST_HELP: - Help(); - break; - case TEST_REGISTERHARDWARE: - RegisterDistributedHardware(); - break; - case TEST_PREPAREREMOTE: - PrepareRemoteInput(); - break; - case TEST_STARTREMOTE: - StartRemoteInput(); - break; - case TEST_STOPREMOTE: - StopRemoteInput(); - break; - case TEST_UN_PREPAREREMOTE: - UnprepareRemoteInput(); - break; - case TEST_UN_REGISTERHARDWARE: - UnregisterDistributedHardware(); - break; - default: - break; - } -} - -HWTEST_F(DistributedInputTest, SystemTest01, testing::ext::TestSize.Level0) -{ - Help(); - pluginListener = std::make_shared(); - DistributedInputHandler::GetInstance().RegisterPluginListener(pluginListener); - - int32_t in; - while (true) { - std::cout << std::endl; - std::cout << "Enter the case No : " << std::endl; - std::cin >> in; - if (in == 0) { - registerCb = nullptr; - unregisterCb = nullptr; - prepareCb = nullptr; - unprepareCb = nullptr; - startCb = nullptr; - stopCb = nullptr; - break; - } - SwitchCase(in); - } -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS