From 0854f50769382c9ee5eee924d756dbdfece406b1 Mon Sep 17 00:00:00 2001 From: torrizo Date: Wed, 25 Jun 2025 01:55:24 -0700 Subject: [PATCH 1/3] add UT Signed-off-by: torrizo --- test/unittest/BUILD.gn | 63 +++++++++++++++++++ test/unittest/UTTest_app_manager_two.cpp | 75 ++++++++++++++++++++++ test/unittest/UTTest_app_manager_two.h | 33 ++++++++++ test/unittest/UTTest_json_str_handle.cpp | 79 ++++++++++++++++++++++++ test/unittest/UTTest_json_str_handle.h | 35 +++++++++++ 5 files changed, 285 insertions(+) create mode 100755 test/unittest/UTTest_app_manager_two.cpp create mode 100755 test/unittest/UTTest_app_manager_two.h create mode 100755 test/unittest/UTTest_json_str_handle.cpp create mode 100755 test/unittest/UTTest_json_str_handle.h diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 4901c787a..03fde27c6 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -21,6 +21,7 @@ group("unittest") { deps = [ ":UTTest_advertise_manager", ":UTTest_app_manager", + ":UTTest_app_manager_two", ":UTTest_auth_acl", ":UTTest_auth_confirm", ":UTTest_auth_credential_state", @@ -86,6 +87,7 @@ group("unittest") { ":UTTest_ipc_server_listener", ":UTTest_ipc_server_stub", ":UTTest_json_object", + ":UTTest_json_str_handle", ":UTTest_kv_adapter_manager", ":UTTest_mine_hichain_connector", ":UTTest_mine_softbus_listener", @@ -251,6 +253,67 @@ ohos_unittest("UTTest_ipc_cmd_register") { ## UnitTest UTTest_ipc_cmd_register }}} +## UnitTest UTTest_app_manager_two {{{ +ohos_unittest("UTTest_app_manager_two") { + module_out_path = module_out_path + + include_dirs = [ + "${devicemanager_path}/commondependency/include", + "${devicemanager_path}/test/commonunittest", + ] + + sources = [ "${devicemanager_path}/test/unittest/UTTest_app_manager_two.cpp" ] + + deps = [ ":device_manager_test_common" ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "eventhandler:libeventhandler", + "googletest:gmock", + "googletest:gmock_main", + "hilog:libhilog", + "os_account:libaccountkits", + "os_account:os_account_innerkits", + ] +} + +## UnitTest UTTest_app_manager_two }}} + +## UnitTest UTTest_json_str_handle {{{ +ohos_unittest("UTTest_json_str_handle") { + module_out_path = module_out_path + + sources = [ + "UTTest_json_str_handle.cpp", + "${utils_path}/src/jsonstr_handle/dm_jsonstr_handle.cpp" + ] + + deps = [ + ":device_manager_test_common", + "${utils_path}:devicemanagerutilstest" + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "cJSON:cjson", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "googletest:gmock", + "googletest:gmock_main", + "hilog:libhilog", + "selinux_adapter:librestorecon", + ] +} + +## UnitTest UTTest_json_str_handle }}} + ## UnitTest UTTest_dm_pin_holder {{{ ohos_unittest("UTTest_dm_pin_holder") { module_out_path = module_out_path diff --git a/test/unittest/UTTest_app_manager_two.cpp b/test/unittest/UTTest_app_manager_two.cpp new file mode 100755 index 000000000..3ed71c16e --- /dev/null +++ b/test/unittest/UTTest_app_manager_two.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 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_app_manager_two.h" + +#include "dm_error_type.h" + +using namespace OHOS::AppExecFwk; +using namespace testing; + +namespace OHOS { +namespace DistributedHardware { +void AppManagerTwoTest::SetUp() +{ +} + +void AppManagerTwoTest::TearDown() +{ +} + +void AppManagerTwoTest::SetUpTestCase() +{ +} + +void AppManagerTwoTest::TearDownTestCase() +{ +} + +HWTEST_F(AppManagerTwoTest, GetTokenIdByBundleName_001, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + std::string bundleName = ""; + int64_t tokenId = 0; + int32_t ret = AppManager::GetInstance().GetTokenIdByBundleName(userId, bundleName, tokenId); + EXPECT_NE(ret, 0); +} + +HWTEST_F(AppManagerTwoTest, GetTokenIdByBundleName_002, testing::ext::TestSize.Level1) +{ + int32_t userId = 0; + std::string bundleName = "bundleName"; + int64_t tokenId = 0; + int32_t ret = AppManager::GetInstance().GetTokenIdByBundleName(userId, bundleName, tokenId); + EXPECT_NE(ret, 0); +} + +HWTEST_F(AppManagerTwoTest, GetBundleNameByTokenId_001, testing::ext::TestSize.Level1) +{ + int64_t tokenId = -1; + std::string bundleName = "bundleName"; + int32_t ret = AppManager::GetInstance().GetBundleNameByTokenId(tokenId, bundleName); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(AppManagerTwoTest, GetBundleNameByTokenId_002, testing::ext::TestSize.Level1) +{ + int64_t tokenId = 0; + std::string bundleName = "bundleName"; + int32_t ret = AppManager::GetInstance().GetBundleNameByTokenId(tokenId, bundleName); + EXPECT_EQ(ret, ERR_DM_FAILED); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_app_manager_two.h b/test/unittest/UTTest_app_manager_two.h new file mode 100755 index 000000000..1967ec01f --- /dev/null +++ b/test/unittest/UTTest_app_manager_two.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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_APP_MANAGER_TWO_TEST_H +#define OHOS_DM_APP_MANAGER_TWO_TEST_H + +#include +#include "app_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class AppManagerTwoTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/test/unittest/UTTest_json_str_handle.cpp b/test/unittest/UTTest_json_str_handle.cpp new file mode 100755 index 000000000..c9e5b1c13 --- /dev/null +++ b/test/unittest/UTTest_json_str_handle.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025 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_json_str_handle.h" + +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +void JsonStrHandleTest::SetUp() +{ +} + +void JsonStrHandleTest::TearDown() +{ +} + +void JsonStrHandleTest::SetUpTestCase() +{ +} + +void JsonStrHandleTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: GetPeerAppInfoParseExtra_001 + * @tc.desc: GetPeerAppInfoParseExtra + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(JsonStrHandleTest, GetPeerAppInfoParseExtra_001, testing::ext::TestSize.Level1) +{ + std::string extra = ""; + uint64_t peerTokenId = 0; + std::string peerBundleName = ""; + JsonStrHandle::GetInstance().GetPeerAppInfoParseExtra(extra, peerTokenId, peerBundleName); + + extra = "extra"; + peerTokenId = 1; + peerBundleName = "peerBundleName"; + JsonStrHandle::GetInstance().GetPeerAppInfoParseExtra(extra, peerTokenId, peerBundleName); + std::string extraInfo = "extraInfo"; + std::vector tokenIdVec = + JsonStrHandle::GetInstance().GetProxyTokenIdByExtra(extraInfo); + EXPECT_EQ(tokenIdVec.empty(), true); +} + +/** + * @tc.name: GetProxyTokenIdByExtra_001 + * @tc.desc: GetProxyTokenIdByExtra + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(JsonStrHandleTest, GetProxyTokenIdByExtra_001, testing::ext::TestSize.Level1) +{ + std::string extraInfo = ""; + std::vector tokenIdVec = + JsonStrHandle::GetInstance().GetProxyTokenIdByExtra(extraInfo); + EXPECT_EQ(tokenIdVec.empty(), true); +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_json_str_handle.h b/test/unittest/UTTest_json_str_handle.h new file mode 100755 index 000000000..2c0de07d3 --- /dev/null +++ b/test/unittest/UTTest_json_str_handle.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022-2024 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_JSONSTR_HANDLE_TEST_H +#define OHOS_DM_JSONSTR_HANDLE_TEST_H + +#include + +#include "dm_jsonstr_handle.h" + +namespace OHOS { +namespace DistributedHardware { +class JsonStrHandleTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DM_JSONSTR_HANDLE_TEST_H \ No newline at end of file -- Gitee From ce406ab57f5ff3834c13bd8f35cc1085e4709843 Mon Sep 17 00:00:00 2001 From: torrizo Date: Thu, 26 Jun 2025 02:36:13 +0000 Subject: [PATCH 2/3] add Signed-off-by: torrizo --- .../unittest/UTTest_device_manager_service_three.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unittest/UTTest_device_manager_service_three.cpp b/test/unittest/UTTest_device_manager_service_three.cpp index f944566c4..ceb939adb 100644 --- a/test/unittest/UTTest_device_manager_service_three.cpp +++ b/test/unittest/UTTest_device_manager_service_three.cpp @@ -627,6 +627,18 @@ HWTEST_F(DeviceManagerServiceThreeTest, ClearDiscoveryCache_001, testing::ext::T DeviceManagerService::GetInstance().UninitDMServiceListener(); } +HWTEST_F(DeviceManagerServiceThreeTest, GetProxyInfosByParseExtra_001, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkgName"; + std::string extra = "extra"; + std::vector> agentToProxyVec; + std::set> proxyInfos; + DeviceManagerService::GetInstance().InitDMServiceListener(); + proxyInfos = DeviceManagerService::GetInstance().GetProxyInfosByParseExtra(pkgName, extra, agentToProxyVec); + DeviceManagerService::GetInstance().UninitDMServiceListener(); + EXPECT_NE(proxyInfos.empty(), true); +} + HWTEST_F(DeviceManagerServiceThreeTest, ImportAuthCode_302, testing::ext::TestSize.Level1) { std::string pkgName; -- Gitee From 554a6016249aa0b0164da1a37db64d498d42ed7a Mon Sep 17 00:00:00 2001 From: torrizo Date: Thu, 26 Jun 2025 02:36:15 +0000 Subject: [PATCH 3/3] add UT Signed-off-by: torrizo -- Gitee