From f72e527989fdaa0dc73fd8344b6c6cc86a5e0f77 Mon Sep 17 00:00:00 2001 From: gecheng Date: Wed, 18 Jun 2025 09:28:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UT=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../framework/test/BUILD.gn | 20 ++++++ .../app_id_mapping_config_manager_test.cpp | 51 +++++++++++++++ .../framework/test/connect_manager_test.cpp | 64 +++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp create mode 100644 services/distributeddataservice/framework/test/connect_manager_test.cpp diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index cf488b7af..f5a724928 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -381,6 +381,24 @@ ohos_unittest("ScreenManagerTest") { external_deps = [ "kv_store:datamgr_common" ] } +ohos_unittest("AppIdMappingConfigManagerTest") { + module_out_path = module_output_path + sources = [ "app_id_mapping_config_manager_test.cpp" ] + configs = [ ":module_private_config" ] + cflags = [ "-fno-access-control" ] + deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] + external_deps = [ "kv_store:datamgr_common" ] +} + +ohos_unittest("ConnectManagerTest") { + module_out_path = module_output_path + sources = [ "connect_manager_test.cpp" ] + configs = [ ":module_private_config" ] + cflags = [ "-fno-access-control" ] + deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] + external_deps = [ "kv_store:datamgr_common" ] +} + ############################################################################### group("unittest") { testonly = true @@ -388,11 +406,13 @@ group("unittest") { deps = [] deps += [ + ":AppIdMappingConfigManagerTest", ":AssetLoaderTest", ":BackupRuleManagerTest", ":BindEventTest", ":CheckerManagerTest", ":CloudInfoTest", + ":ConnectManagerTest", ":ConstantTest", ":CryptoTest", ":EventCenterTest", diff --git a/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp new file mode 100644 index 000000000..d75c0c979 --- /dev/null +++ b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp @@ -0,0 +1,51 @@ +/* +* 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 "app_id_mapping/app_id_mapping_config_manager.h" + +#include + +using namespace testing::ext; +using namespace OHOS::DistributedData; + +class AppIdMappingConfigManagerTest : public testing::Test {}; + +/** +* @tc.name: Convert +* @tc.desc: Convert. +* @tc.type: FUNC +*/ +HWTEST_F(AppIdMappingConfigManagerTest, Convert01, TestSize.Level1) +{ + auto result = AppIdMappingConfigManager::GetInstance().Convert("123", "123456789"); + ASSERT_EQ(result.first, "123"); + ASSERT_EQ(result.second, "123456789"); + result = AppIdMappingConfigManager::GetInstance().Convert("123", "987654321"); + ASSERT_EQ(result.first, "123456789"); + ASSERT_EQ(result.second, "default"); +} + +/** +* @tc.name: Convert +* @tc.desc: Convert. +* @tc.type: FUNC +*/ +HWTEST_F(AppIdMappingConfigManagerTest, Convert02, TestSize.Level1) +{ + auto result = AppIdMappingConfigManager::GetInstance().Convert("321"); + ASSERT_EQ(result, "321");; + result = AppIdMappingConfigManager::GetInstance().Convert("123"); + ASSERT_EQ(result, "123456789"); +} \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/connect_manager_test.cpp b/services/distributeddataservice/framework/test/connect_manager_test.cpp new file mode 100644 index 000000000..9861d0995 --- /dev/null +++ b/services/distributeddataservice/framework/test/connect_manager_test.cpp @@ -0,0 +1,64 @@ +/* +* 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 "communication/connect_manager.h" + +#include + +using namespace testing::ext; +using namespace OHOS::AppDistributedKv; + +class ConnectManagerTest : public testing::Test {}; + +/** +* @tc.name: RegisterInstance +* @tc.desc: RegisterInstance. +* @tc.type: FUNC +*/ +HWTEST_F(ConnectManagerTest, RegisterInstance, TestSize.Level1) +{ + auto result = ConnectManager::RegisterInstance(std::make_shared()); + ASSERT_TRUE(result); + ASSERT_NE(ConnectManager::GetInstance(), nullptr); +} + +/** +* @tc.name: CloseSession +* @tc.desc: CloseSession. +* @tc.type: FUNC +*/ +HWTEST_F(ConnectManagerTest, CloseSession, TestSize.Level1) +{ + auto ret = ConnectManager::GetInstance()->CloseSession(""); + ASSERT_FALSE(ret); + ConnectManager::GetInstance()->closeSessionTask_ = [](const std::string &networkId) { + return true; + }; + ret = ConnectManager::GetInstance()->CloseSession(""); + ASSERT_FALSE(ret); +} + +/** +* @tc.name: RegisterCloseSessionTask +* @tc.desc: RegisterCloseSessionTask. +* @tc.type: FUNC +*/ +HWTEST_F(ConnectManagerTest, RegisterCloseSessionTask, TestSize.Level1) +{ + auto ret = ConnectManager::GetInstance()->RegisterCloseSessionTask([](const std::string &networkId) { + return true; + }); + ASSERT_FALSE(ret); +} \ No newline at end of file -- Gitee From 533b21a6c939f47fb66061547720650c9cc5b07d Mon Sep 17 00:00:00 2001 From: gecheng Date: Wed, 18 Jun 2025 17:48:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UT=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../app_id_mapping_config_manager_test.cpp | 33 +++++++++++++------ .../framework/test/connect_manager_test.cpp | 12 +++++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp index d75c0c979..5485090ea 100644 --- a/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp +++ b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp @@ -19,7 +19,7 @@ using namespace testing::ext; using namespace OHOS::DistributedData; - +namespace OHOS::Test { class AppIdMappingConfigManagerTest : public testing::Test {}; /** @@ -29,12 +29,18 @@ class AppIdMappingConfigManagerTest : public testing::Test {}; */ HWTEST_F(AppIdMappingConfigManagerTest, Convert01, TestSize.Level1) { + std::vector mapper = { + {"src1", "dst1"}, + {"src2", "dst2"}, + {"src3", "dst3"} + }; + AppIdMappingConfigManager::GetInstance().Initialize(mapper); auto result = AppIdMappingConfigManager::GetInstance().Convert("123", "123456789"); - ASSERT_EQ(result.first, "123"); - ASSERT_EQ(result.second, "123456789"); - result = AppIdMappingConfigManager::GetInstance().Convert("123", "987654321"); - ASSERT_EQ(result.first, "123456789"); - ASSERT_EQ(result.second, "default"); + EXPECT_EQ(result.first, "123"); + EXPECT_EQ(result.second, "123456789"); + result = AppIdMappingConfigManager::GetInstance().Convert("src1", "987654321"); + EXPECT_EQ(result.first, "dst1"); + EXPECT_EQ(result.second, "default"); } /** @@ -44,8 +50,15 @@ HWTEST_F(AppIdMappingConfigManagerTest, Convert01, TestSize.Level1) */ HWTEST_F(AppIdMappingConfigManagerTest, Convert02, TestSize.Level1) { + std::vector mapper = { + {"src1", "dst1"}, + {"src2", "dst2"}, + {"src3", "dst3"} + }; + AppIdMappingConfigManager::GetInstance().Initialize(mapper); auto result = AppIdMappingConfigManager::GetInstance().Convert("321"); - ASSERT_EQ(result, "321");; - result = AppIdMappingConfigManager::GetInstance().Convert("123"); - ASSERT_EQ(result, "123456789"); -} \ No newline at end of file + EXPECT_EQ(result, "321");; + result = AppIdMappingConfigManager::GetInstance().Convert("src1"); + EXPECT_EQ(result, "dst1"); +} +} // namespace OHOS::Test \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/connect_manager_test.cpp b/services/distributeddataservice/framework/test/connect_manager_test.cpp index 9861d0995..d2eeb5200 100644 --- a/services/distributeddataservice/framework/test/connect_manager_test.cpp +++ b/services/distributeddataservice/framework/test/connect_manager_test.cpp @@ -19,7 +19,7 @@ using namespace testing::ext; using namespace OHOS::AppDistributedKv; - +namespace OHOS::Test { class ConnectManagerTest : public testing::Test {}; /** @@ -29,6 +29,8 @@ class ConnectManagerTest : public testing::Test {}; */ HWTEST_F(ConnectManagerTest, RegisterInstance, TestSize.Level1) { + auto instance = ConnectManager::GetInstance(); + ASSERT_NE(instance, nullptr); auto result = ConnectManager::RegisterInstance(std::make_shared()); ASSERT_TRUE(result); ASSERT_NE(ConnectManager::GetInstance(), nullptr); @@ -47,7 +49,7 @@ HWTEST_F(ConnectManagerTest, CloseSession, TestSize.Level1) return true; }; ret = ConnectManager::GetInstance()->CloseSession(""); - ASSERT_FALSE(ret); + ASSERT_TRUE(ret); } /** @@ -57,8 +59,12 @@ HWTEST_F(ConnectManagerTest, CloseSession, TestSize.Level1) */ HWTEST_F(ConnectManagerTest, RegisterCloseSessionTask, TestSize.Level1) { + ConnectManager::GetInstance()->closeSessionTask_ = [](const std::string &networkId) { + return true; + }; auto ret = ConnectManager::GetInstance()->RegisterCloseSessionTask([](const std::string &networkId) { return true; }); ASSERT_FALSE(ret); -} \ No newline at end of file +} +} // namespace OHOS::Test \ No newline at end of file -- Gitee From 56d58a4d9fd79c3c742dbb7abfe48dba5c2f7ee2 Mon Sep 17 00:00:00 2001 From: gecheng Date: Thu, 19 Jun 2025 11:00:01 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UT=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../framework/test/app_id_mapping_config_manager_test.cpp | 4 ++-- .../framework/test/connect_manager_test.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp index 5485090ea..4d674301d 100644 --- a/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp +++ b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp @@ -24,7 +24,7 @@ class AppIdMappingConfigManagerTest : public testing::Test {}; /** * @tc.name: Convert -* @tc.desc: Convert. +* @tc.desc: appId and accountId Convert. * @tc.type: FUNC */ HWTEST_F(AppIdMappingConfigManagerTest, Convert01, TestSize.Level1) @@ -45,7 +45,7 @@ HWTEST_F(AppIdMappingConfigManagerTest, Convert01, TestSize.Level1) /** * @tc.name: Convert -* @tc.desc: Convert. +* @tc.desc: app id Convert. * @tc.type: FUNC */ HWTEST_F(AppIdMappingConfigManagerTest, Convert02, TestSize.Level1) diff --git a/services/distributeddataservice/framework/test/connect_manager_test.cpp b/services/distributeddataservice/framework/test/connect_manager_test.cpp index d2eeb5200..096d0c88b 100644 --- a/services/distributeddataservice/framework/test/connect_manager_test.cpp +++ b/services/distributeddataservice/framework/test/connect_manager_test.cpp @@ -24,7 +24,7 @@ class ConnectManagerTest : public testing::Test {}; /** * @tc.name: RegisterInstance -* @tc.desc: RegisterInstance. +* @tc.desc: Register Instance. * @tc.type: FUNC */ HWTEST_F(ConnectManagerTest, RegisterInstance, TestSize.Level1) @@ -38,7 +38,7 @@ HWTEST_F(ConnectManagerTest, RegisterInstance, TestSize.Level1) /** * @tc.name: CloseSession -* @tc.desc: CloseSession. +* @tc.desc: Close Session. * @tc.type: FUNC */ HWTEST_F(ConnectManagerTest, CloseSession, TestSize.Level1) @@ -54,7 +54,7 @@ HWTEST_F(ConnectManagerTest, CloseSession, TestSize.Level1) /** * @tc.name: RegisterCloseSessionTask -* @tc.desc: RegisterCloseSessionTask. +* @tc.desc: Only one session closing task can be registered. * @tc.type: FUNC */ HWTEST_F(ConnectManagerTest, RegisterCloseSessionTask, TestSize.Level1) -- Gitee From 65555c3e30d5be11b2e53009ed65d51bf351fd14 Mon Sep 17 00:00:00 2001 From: gecheng Date: Thu, 19 Jun 2025 14:07:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UT=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../framework/test/app_id_mapping_config_manager_test.cpp | 4 ++-- .../framework/test/connect_manager_test.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp index 4d674301d..c441ba910 100644 --- a/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp +++ b/services/distributeddataservice/framework/test/app_id_mapping_config_manager_test.cpp @@ -24,7 +24,7 @@ class AppIdMappingConfigManagerTest : public testing::Test {}; /** * @tc.name: Convert -* @tc.desc: appId and accountId Convert. +* @tc.desc: Generate a pair based on the input appId and accountId. * @tc.type: FUNC */ HWTEST_F(AppIdMappingConfigManagerTest, Convert01, TestSize.Level1) @@ -45,7 +45,7 @@ HWTEST_F(AppIdMappingConfigManagerTest, Convert01, TestSize.Level1) /** * @tc.name: Convert -* @tc.desc: app id Convert. +* @tc.desc: Convert the input appId to another id. * @tc.type: FUNC */ HWTEST_F(AppIdMappingConfigManagerTest, Convert02, TestSize.Level1) diff --git a/services/distributeddataservice/framework/test/connect_manager_test.cpp b/services/distributeddataservice/framework/test/connect_manager_test.cpp index 096d0c88b..7965d9eb0 100644 --- a/services/distributeddataservice/framework/test/connect_manager_test.cpp +++ b/services/distributeddataservice/framework/test/connect_manager_test.cpp @@ -38,7 +38,7 @@ HWTEST_F(ConnectManagerTest, RegisterInstance, TestSize.Level1) /** * @tc.name: CloseSession -* @tc.desc: Close Session. +* @tc.desc: Close the session related to the networkid. * @tc.type: FUNC */ HWTEST_F(ConnectManagerTest, CloseSession, TestSize.Level1) -- Gitee