diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index bc8eb7d9706dfbf35eb09778843bfc723cf400e3..1fe0eb582dbb10349e261ec74a17744e88f1f8ea 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -370,6 +370,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 @@ -377,11 +395,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 0000000000000000000000000000000000000000..d75c0c97919cb1d90190f1b85ef4e6b154020c26 --- /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 0000000000000000000000000000000000000000..9861d09955aa1e5c0e2266cf74583f9f8f7a0df1 --- /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