diff --git a/ext/decision/BUILD.gn b/ext/decision/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ac5e0a4a703d635fd76cdcb99ec1ce4c45b0edd1 --- /dev/null +++ b/ext/decision/BUILD.gn @@ -0,0 +1,59 @@ +# 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. + +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") +} else { + import("//build/ohos.gni") +} + +import("//foundation/distributedhardware/devicemanager/devicemanager.gni") + +if (defined(ohos_lite)) { +} else { + ohos_shared_library("devicemanagerext_decision") { + include_dirs = [ + "${ext_path}/decision/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + ] + + sources = [ "src/device_decision_adapter.cpp" ] + + deps = [ + "${services_path}:devicemanagerservice", + "${utils_path}:devicemanagerutils", + "//utils/native/base:utils", + ] + + external_deps = [ + #"device_decision_core:distributed_device_decision_client", + "hiviewdfx_hilog_native:libhilog", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerext\"", + "LOG_DOMAIN=0xD004100", + ] + + subsystem_name = "distributedhardware" + + part_name = "device_manager_base" + } +} diff --git a/ext/decision/include/device_decision_adapter.h b/ext/decision/include/device_decision_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..f234ecffaeae7e5e9c36102622fd3928759710d4 --- /dev/null +++ b/ext/decision/include/device_decision_adapter.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef OHOS_DM_ADAPTER_DEVICE_DECISION_H +#define OHOS_DM_ADAPTER_DEVICE_DECISION_H + +#include +#include +#include + +#include "decision_adapter.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceDecisionAdapter : public IDecisionAdapter { +public: + DeviceDecisionAdapter(); + ~DeviceDecisionAdapter(); + std::string GetName(); + std::string GetVersion(); + int32_t FilterDeviceList(std::vector &infoList, const std::string &filterOptions); + int32_t SortDeviceList(std::vector &infoList, const std::string &sortOptions); + void OnDecisionFilterResult(const char *result); +private: + std::vector infoListTemp_; + int32_t isWaiting; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_ADAPTER_DEVICE_DECISION_H diff --git a/ext/decision/src/device_decision_adapter.cpp b/ext/decision/src/device_decision_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..443882d7782b9b88c6ab4a9e691f624e0c10dbe4 --- /dev/null +++ b/ext/decision/src/device_decision_adapter.cpp @@ -0,0 +1,121 @@ +/* + * 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 "device_decision_adapter.h" +#include "dm_constants.h" +#include "dm_device_state_manager.h" +#include "dm_device_info_manager.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" +#include "dm_timer.h" + +namespace OHOS { +namespace DistributedHardware { +std::shared_ptr StartTimer = std::make_shared("decisionTimeoutTask"); +const static int32_t DECISION_TEST_CALLBACK_TIME = 1; + +static void TimeOut(void *data, DmTimer& timer) +{ + LOGI("DeviceDecisionAdapter time out "); + DeviceDecisionAdapter *decision = (DeviceDecisionAdapter *)data; + if (decision == nullptr) { + LOGE("time out error"); + return; + } + decision->OnDecisionFilterResult("result"); +} + +DeviceDecisionAdapter::DeviceDecisionAdapter() +{ + isWaiting = 0; +} + +DeviceDecisionAdapter::~DeviceDecisionAdapter() +{ + isWaiting = 0; +} + +std::string DeviceDecisionAdapter::GetName() +{ + std::string strName; + return strName; +} + +std::string DeviceDecisionAdapter::GetVersion() +{ + std::string strVersion; + return strVersion; +} + +int32_t DeviceDecisionAdapter::FilterDeviceList(std::vector &infoList, + const std::string &filterOptions) +{ + LOGI("DeviceDecisionAdapter::FilterDeviceList, ext=%s", filterOptions.c_str()); + /* std::string extra = filterOptions; + nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("extra jsonStr error"); + return DM_FAILED; + } + + if (!jsonObject.contains("FilterOptions")) { + LOGE("err FilterOptions json string"); + return DM_FAILED; + } + + std::string filterString = jsonObject["FilterOptions"]["filter"]; + LOGI("DeviceDecisionAdapter::FilterOptions = %s", filterString.c_str()); */ + isWaiting = 1; + //////////////////////////////////////////////////////////////////////////////////////////// + StartTimer->Start(DECISION_TEST_CALLBACK_TIME, TimeOut, (void *)this); + while (isWaiting == 1) { + LOGI("waiting for DS back"); + } + //////////////////////////////////////////////////////////////////////////////////////////// + return DM_OK; +} + +int32_t DeviceDecisionAdapter::SortDeviceList(std::vector &infoList, const std::string &sortOptions) +{ + std::string extra = sortOptions; + nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("extra jsonStr error"); + return DM_FAILED; + } + + if (!jsonObject.contains("FilterOptions")) { + LOGE("err FilterOptions json string"); + return DM_FAILED; + } + + int32_t sortType = jsonObject["FilterOptions"]["sortType"]; + LOGI("DeviceDecisionAdapter::sortType = %d", sortType); + return DM_OK; +} + +void DeviceDecisionAdapter::OnDecisionFilterResult(const char *result) +{ + LOGI("DeviceDecisionAdapter::OnResult"); + std::string resultString = std::string(result); + isWaiting = 0; // for test +} + +extern "C" IDecisionAdapter *CreateDeviceDecisionObject(void) +{ + return new DeviceDecisionAdapter; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9325d03ef428e43f7cc3753ec610c25ac8d08270..2b667317aa17efe523e637079654c5accf9de1f8 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -22,8 +22,10 @@ group("unittest") { ":UTTest_auth_message_processor", ":UTTest_auth_request_state", ":UTTest_auth_response_state", + ":UTTest_device_decision_adapter", ":UTTest_device_manager_service", ":UTTest_device_manager_service_listener", + ":UTTest_device_profile_adapter", ":UTTest_dm_auth_manager", ":UTTest_dm_device_info_manager", ":UTTest_dm_device_state_manager", @@ -34,6 +36,8 @@ group("unittest") { ":UTTest_ipc_server_client_proxy", ":UTTest_ipc_server_listener", ":UTTest_ipc_server_stub", + ":UTTest_multiple_user_connector", + ":UTTest_profile_connector", ":UTTest_softbus_connector", ":UTTest_softbus_session", ] @@ -193,6 +197,41 @@ ohos_unittest("UTTest_profile_connector") { ## UnitTest UTTest_profile_connector }}} +## UnitTest UTTest_device_profile_adapter {{{ +ohos_unittest("UTTest_device_profile_adapter") { + module_out_path = module_out_path + + sources = [ "UTTest_device_profile_adapter.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_device_decision_adapter }}} + +## UnitTest UTTest_device_decision_adapter {{{ +ohos_unittest("UTTest_device_decision_adapter") { + module_out_path = module_out_path + + sources = [ "UTTest_device_decision_adapter.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_device_decision_adapter }}} + +## UnitTest UTTest_multiple_user_connector }}} + +## UnitTest UTTest_multiple_user_connector {{{ +ohos_unittest("UTTest_multiple_user_connector") { + module_out_path = module_out_path + + sources = [ "UTTest_multiple_user_connector.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_multiple_user_connector }}} + ## UnitTest UTTest_device_manager_notify {{{ ohos_unittest("UTTest_device_manager_notify") { module_out_path = module_out_path @@ -328,7 +367,6 @@ ohos_unittest("UTTest_dm_discovery_manager") { } ## UnitTest UTTest_dm_discovery_manager }}} - ## Build device_manager_test_common.a {{{ config("device_manager_test_common_public_config") { include_dirs = [ @@ -370,6 +408,7 @@ config("device_manager_test_common_public_config") { "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", "//foundation/distributedhardware/devicemanager/ext/profile/include", "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/distributedhardware/devicemanager/ext/decision/include", "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", "//foundation/distributedhardware/devicemanager/ext/mini/common/include", "//base/security/deviceauth/interfaces/innerkits", @@ -404,6 +443,8 @@ ohos_static_library("device_manager_test_common") { "${services_path}:devicemanagerservice", "${utils_path}:devicemanagerutils", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/ext/decision:devicemanagerext_decision", + "//foundation/distributedhardware/devicemanager/ext/profile:devicemanagerext_profile", "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock", diff --git a/test/unittest/UTTest_device_decision_adapter.cpp b/test/unittest/UTTest_device_decision_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0031a2563ab6b3a413092857ce3e19d23d92724e --- /dev/null +++ b/test/unittest/UTTest_device_decision_adapter.cpp @@ -0,0 +1,89 @@ +/* + * 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 "UTTest_device_decision_adapter.h" +#include "dm_device_info.h" +#include "device_decision_adapter.h" +#include "dm_constants.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceDecisionAdapterTest::SetUp() +{ +} + +void DeviceDecisionAdapterTest::TearDown() +{ +} + +void DeviceDecisionAdapterTest::SetUpTestCase() +{ +} + +void DeviceDecisionAdapterTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: DmDeviceInfoManager_001 + * @tc.desc: Run FilterDeviceList. Its return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceDecisionAdapterTest, FilterDeviceList_001, testing::ext::TestSize.Level0) +{ + std::vector infoList; + std::string filterOptions = ""; + std::shared_ptr deviceDesicionAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceDesicionAdapter->FilterDeviceList(infoList, filterOptions); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: SortDeviceList_001 + * @tc.desc: Run SortDeviceList, Because needs Json, Its return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceDecisionAdapterTest, SortDeviceList_001, testing::ext::TestSize.Level0) +{ + std::vector infoList; + std::string sortOptions = ""; + std::shared_ptr deviceDesicionAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceDesicionAdapter->SortDeviceList(infoList, sortOptions); + ASSERT_EQ(ret, DM_FAILED); +} +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Callback for Module Decision, so. Its return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceDecisionAdapterTest, OnDecisionFilterResult_001, testing::ext::TestSize.Level0) +{ + const char result[] = "FilterResult"; + std::shared_ptr deviceDesicionAdapter = std::make_shared(); + + int32_t ret = DM_OK; + deviceDesicionAdapter->OnDecisionFilterResult(result); + ASSERT_EQ(ret, DM_OK); +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_device_decision_adapter.h b/test/unittest/UTTest_device_decision_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..52eb87ae3089edec458939d873db19a4c42809fa --- /dev/null +++ b/test/unittest/UTTest_device_decision_adapter.h @@ -0,0 +1,35 @@ +/* + * 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. + */ +#ifndef OHOS_UTTEST_DM_EXT_DECISION_H +#define OHOS_UTTEST_DM_EXT_DECISION_H + +#include +#include + +#include +#include + +namespace OHOS { +namespace DistributedHardware { +class DeviceDecisionAdapterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 28256c67f467a01f7f0fc4414166ca89e4fc2b21..69076914bb16e5537d1c26ada403bea410c92545 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -337,6 +337,198 @@ HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestS int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); EXPECT_EQ(ret, DM_NOT_INIT); } + +/** + * @tc.name: GetUdidByNetworkId_001 + * @tc.desc: Make success for GetUdidByNetworkId,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string udid = ""; + int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetUdidByNetworkId_002 + * @tc.desc: Make not init for GetUdidByNetworkId,The return value is + * DM_NOT_INIT + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_002, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = false; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string udid = ""; + int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); + EXPECT_EQ(ret, DM_NOT_INIT); +} + +/** + * @tc.name: GetUdidByNetworkId_003 + * @tc.desc: Make pkgName empty for GetUdidByNetworkId,The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_003, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = ""; + std::string netWorkId = ""; + std::string udid = ""; + int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: GetUuidByNetworkId_001 + * @tc.desc: Make success for GetUuidByNetworkId,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string uuid = ""; + int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetUuidByNetworkId_002 + * @tc.desc: Make not init for GetUuidByNetworkId,The return value is + * DM_NOT_INIT + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_002, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = false; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string uuid = ""; + int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); + EXPECT_EQ(ret, DM_NOT_INIT); +} + +/** + * @tc.name: GetUuidByNetworkId_003 + * @tc.desc: Make pkgName empty for GetUuidByNetworkId,The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_003, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = ""; + std::string netWorkId = ""; + std::string uuid = ""; + int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: GetFaParam_001 + * @tc.desc: Make success for GetFaParam,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetFaParam_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + DmAuthParam authParam; + int ret = DeviceManagerService::GetInstance().GetFaParam(pkgName, authParam); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetFaParam_002 + * @tc.desc: Make pkgName empty for GetFaParam, The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetFaParam_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = ""; + DmAuthParam authParam; + int ret = DeviceManagerService::GetInstance().GetFaParam(pkgName, authParam); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: SetUserOperation_001 + * @tc.desc: Make success for SetUserOperation,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, SetUserOperation_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t action = 0; + int ret = DeviceManagerService::GetInstance().SetUserOperation(pkgName, action); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: SetUserOperation_002 + * @tc.desc: Make pkgName empty for SetUserOperation,The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, SetUserOperation_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = ""; + int32_t action = 0; + int ret = DeviceManagerService::GetInstance().SetUserOperation(pkgName, action); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: RegisterDevStateCallback_001 + * @tc.desc: Make success for RegisterDevStateCallback,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, RegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string extra = "extra"; + int ret = DeviceManagerService::GetInstance().RegisterDevStateCallback(pkgName, extra); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: UnRegisterDevStateCallback_001 + * @tc.desc: Make success for UnRegisterDevStateCallback,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, UnRegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string extra = "extra"; + int ret = DeviceManagerService::GetInstance().UnRegisterDevStateCallback(pkgName, extra); + EXPECT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_profile_adapter.cpp b/test/unittest/UTTest_device_profile_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c07818d6adbb627271ee1ad24fb989be160d792a --- /dev/null +++ b/test/unittest/UTTest_device_profile_adapter.cpp @@ -0,0 +1,118 @@ +/* + * 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 "dm_constants.h" +#include "dm_device_state_manager.h" +#include "profile_adapter.h" +#include "profile_connector.h" +#include "device_profile_adapter.h" +#include "UTTest_device_profile_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceProfileAdapterTest::SetUp() +{ +} +void DeviceProfileAdapterTest::TearDown() +{ +} +void DeviceProfileAdapterTest::SetUpTestCase() +{ +} +void DeviceProfileAdapterTest::TearDownTestCase() +{ +} + +namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr deviceStateMgr = std::make_shared(softbusConnector, + listener, + hiChainConnector); +/** + * @tc.name: RegisterProfileListener_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, RegisterProfileListener_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceProfileAdapter->RegisterProfileListener(pkgName, deviceId, deviceStateMgr); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: UnRegisterProfileListener_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, UnRegisterProfileListener_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceProfileAdapter->UnRegisterProfileListener(pkgName); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: OnProfileChanged_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, OnProfileChanged_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + deviceProfileAdapter->OnProfileChanged(pkgName, deviceId); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: OnProfileComplete_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, OnProfileComplete_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + deviceProfileAdapter->OnProfileComplete(pkgName, deviceId); + ASSERT_EQ(ret, DM_OK); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_device_profile_adapter.h b/test/unittest/UTTest_device_profile_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..e219c34e5ac5d65a80d6f051f944577fbd10a429 --- /dev/null +++ b/test/unittest/UTTest_device_profile_adapter.h @@ -0,0 +1,39 @@ +/* + * 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. + */ +#ifndef OHOS_DEVICE_PROFILE_ADAPTER_TEST_H +#define OHOS_DEVICE_PROFILE_ADAPTER_TEST_H + +#include +#include +#include +#include +#include +#include + +#include "distributed_device_profile_client.h" +#include "profile_connector_callback.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceProfileAdapterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/test/unittest/UTTest_dm_device_info_manager.cpp b/test/unittest/UTTest_dm_device_info_manager.cpp index 5dedde908a4e039c74b6624339b40888b2991ca7..0a3446856784106b10c28e6bcf041f64fc21d02b 100644 --- a/test/unittest/UTTest_dm_device_info_manager.cpp +++ b/test/unittest/UTTest_dm_device_info_manager.cpp @@ -51,8 +51,42 @@ std::shared_ptr dmDeviceStateManager = std::make_shared p = std::make_shared(softbusConnector); - ASSERT_NE(p, nullptr); + std::shared_ptr deviceInfoManager = std::make_shared(softbusConnector); + ASSERT_NE(deviceInfoManager, nullptr); +} +/** + * @tc.name: GetTrustedDeviceList_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0) +{ + int32_t ret = DM_OK; + std::string pkgName = ""; + std::string extra = ""; + std::vector deviceList; + std::shared_ptr deviceInfoManager = std::make_shared(softbusConnector); + ret = deviceInfoManager->GetTrustedDeviceList(pkgName, extra, deviceList); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: GetLocalDeviceInfo_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + int32_t ret = DM_OK; + std::shared_ptr deviceInfoManager = std::make_shared(softbusConnector); + ret = deviceInfoManager->GetLocalDeviceInfo(deviceInfo); + ASSERT_EQ(ret, DM_OK); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_multiple_user_connector.cpp b/test/unittest/UTTest_multiple_user_connector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d93acba99f337c3686e74d63997216fdb6644be --- /dev/null +++ b/test/unittest/UTTest_multiple_user_connector.cpp @@ -0,0 +1,84 @@ +/* + * 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 "dm_constants.h" +#include "multiple_user_connector.h" +#include "UTTest_multiple_user_connector.h" + +namespace OHOS { +namespace DistributedHardware { +void MultipleUserConnectorTest::SetUp() +{ +} +void MultipleUserConnectorTest::TearDown() +{ +} +void MultipleUserConnectorTest::SetUpTestCase() +{ +} +void MultipleUserConnectorTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(MultipleUserConnectorTest, GetCurrentAccountUserID_001, testing::ext::TestSize.Level0) +{ + int32_t ret = DM_OK; + ret = MultipleUserConnector::GetCurrentAccountUserID(); + ASSERT_TRUE(ret > 0); +} +/** + * @tc.name: SetSwitchOldUserId_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(MultipleUserConnectorTest, SetSwitchOldUserId_001, testing::ext::TestSize.Level0) +{ + int32_t userIdIn = 1234; + int32_t userIdOut = -1; + MultipleUserConnector::SetSwitchOldUserId(userIdIn); + userIdOut = MultipleUserConnector::GetSwitchOldUserId(); + ASSERT_EQ(userIdIn, userIdOut); +} +/** + * @tc.name: GetSwitchOldUserId_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(MultipleUserConnectorTest, GetSwitchOldUserId_001, testing::ext::TestSize.Level0) +{ + int32_t userIdIn = 1234; + int32_t userIdOut = -1; + MultipleUserConnector::SetSwitchOldUserId(userIdIn); + userIdOut = MultipleUserConnector::GetSwitchOldUserId(); + ASSERT_EQ(userIdIn, userIdOut); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_multiple_user_connector.h b/test/unittest/UTTest_multiple_user_connector.h new file mode 100644 index 0000000000000000000000000000000000000000..c4e783546a56fa6d3fa225e1b28967d8ee2bdde8 --- /dev/null +++ b/test/unittest/UTTest_multiple_user_connector.h @@ -0,0 +1,38 @@ +/* + * 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. + */ +#ifndef OHOS_MULTIPLE_USER_CONNECTOR_TEST_H +#define OHOS_MULTIPLE_USER_CONNECTOR_TEST_H + +#include +#include +#include +#include +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class MultipleUserConnectorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/test/unittest/UTTest_profile_connector.cpp b/test/unittest/UTTest_profile_connector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa14b015c3a06255135d26bde8e3549d4cb7046f --- /dev/null +++ b/test/unittest/UTTest_profile_connector.cpp @@ -0,0 +1,154 @@ +/* + * 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 "dm_constants.h" +#include "dm_device_state_manager.h" +#include "profile_adapter.h" +#include "profile_connector.h" +#include "device_profile_adapter.h" +#include "UTTest_profile_connector.h" + +namespace OHOS { +namespace DistributedHardware { +void ProfileConnectorTest::SetUp() +{ +} +void ProfileConnectorTest::TearDown() +{ +} +void ProfileConnectorTest::SetUpTestCase() +{ +} +void ProfileConnectorTest::TearDownTestCase() +{ +} + +namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr deviceStateMgr = std::make_shared(softbusConnector, + listener, + hiChainConnector); +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, RegisterProfileCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::string profileSoName = "libdevicemanagerext_profile.z.so"; + + DeviceProfileAdapter * deviceProfileAdapter = new DeviceProfileAdapter(); + + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->RegisterProfileCallback(pkgName, deviceId, deviceProfileAdapter); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, UnRegisterProfileCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->UnRegisterProfileCallback(pkgName); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, SubscribeProfileEvents_001, testing::ext::TestSize.Level0) +{ + std::string deviceId = "deviceId"; + std::list serviceIds; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->SubscribeProfileEvents(serviceIds, deviceId); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, UnSubscribeProfileEvents_001, testing::ext::TestSize.Level0) +{ + std::string deviceId = "deviceId"; + std::list serviceIds; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + profileConnector_->SubscribeProfileEvents(serviceIds, deviceId); + ret = profileConnector_->UnSubscribeProfileEvents(); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: OnDecisionFilterResult_002 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, UnSubscribeProfileEvents_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->UnSubscribeProfileEvents(); + ASSERT_EQ(ret, ERR_DM_UNSUBSCRIBE_DP_EVENTS); +} +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, OnSyncCompleted_001, testing::ext::TestSize.Level0) +{ + DeviceProfile::SyncResult syncResults; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + profileConnector_->OnSyncCompleted(syncResults); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_profile_connector.h b/test/unittest/UTTest_profile_connector.h new file mode 100644 index 0000000000000000000000000000000000000000..815c7c9398435a152fed756820e39c057fa8c00e --- /dev/null +++ b/test/unittest/UTTest_profile_connector.h @@ -0,0 +1,40 @@ +/* + * 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. + */ +#ifndef OHOS_PROFILE_CONNECTOR_TEST_H +#define OHOS_PROFILE_CONNECTOR_TEST_H + +#include +#include +#include +#include +#include +#include + +#include "distributed_device_profile_client.h" +#include "profile_connector_callback.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class ProfileConnectorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file