From 9a7d250919e943704f50c3af52131f87e682bd29 Mon Sep 17 00:00:00 2001 From: gecheng Date: Tue, 24 Jun 2025 21:36:37 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=A1=A5=E5=85=85UT=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../framework/test/BUILD.gn | 7 ++ .../test/device_sync_app_manager_test.cpp | 97 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index f5a724928..a451d53fb 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -399,6 +399,12 @@ ohos_unittest("ConnectManagerTest") { external_deps = [ "kv_store:datamgr_common" ] } +ohos_unittest("DeviceSyncAppManagerTest") { + module_out_path = module_output_path + sources = [ "device_sync_app_manager_test.cpp" ] + configs = [ ":module_private_config" ] + deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] +} ############################################################################### group("unittest") { testonly = true @@ -415,6 +421,7 @@ group("unittest") { ":ConnectManagerTest", ":ConstantTest", ":CryptoTest", + ":DeviceSyncAppManagerTest", ":EventCenterTest", ":EventTest", ":FeatureTest", diff --git a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp new file mode 100644 index 000000000..3cebf31c1 --- /dev/null +++ b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp @@ -0,0 +1,97 @@ +/* +* 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 "device_sync_app/device_sync_app_manager.h" +#include + +using namespace testing::ext; +using namespace OHOS::DistributedData; + +namespace OHOS::Test { +class DeviceSyncAppManagerTest : public testing::Test { +protected: + void SetUp() override { + whiteList1 = {"appId1", "bundleName1", 1}; + whiteList2 = {"appId2", "bundleName2", 2}; + whiteList3 = {"appId3", "bundleName3", 3}; + + std::vector lists = {whiteList1, whiteList2, whiteList3}; + DeviceSyncAppManager::GetInstance().Initialize(lists); + } + + DeviceSyncAppManager::WhiteList whiteList1; + DeviceSyncAppManager::WhiteList whiteList2; + DeviceSyncAppManager::WhiteList whiteList3; +}; + +/** +@tc.name: Check001 +@tc.desc: Checks that the given WhiteList object exists in whiteLists_ list. +@tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check001, TestSize.Level1) +{ + DeviceSyncAppManager::WhiteList whiteList = {"appId1", "bundleName1", 1}; + bool result = DeviceSyncAppManager::GetInstance().Check(whiteList); + EXPECT_TRUE(result); +} + +/** +@tc.name: Check002 +@tc.desc: Check that the given appId object does not match. +@tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check002, TestSize.Level1) +{ + DeviceSyncAppManager::WhiteList testList = {"appId2", "bundleName1", 1}; + bool result = DeviceSyncAppManager::GetInstance().Check(testList); + EXPECT_FALSE(result); +} + +/** +@tc.name: Check003 +@tc.desc: Check that the given bundleName object does not match. +@tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check003, TestSize.Level1) +{ + DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName2", 1}; + bool result = DeviceSyncAppManager::GetInstance().Check(testList); + EXPECT_FALSE(result); +} + +/** +@tc.name: Check004 +@tc.desc: Check that the given version object does not match. +@tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check004, TestSize.Level1) +{ + DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName1", 2}; + bool result = DeviceSyncAppManager::GetInstance().Check(testList); + EXPECT_FALSE(result); +} + +/** +@tc.name: Check005 +@tc.desc: Checks that the given WhiteList object does not exist in whiteLists_ list. +@tc.type: FUNC +*/ +HWTEST_F(DeviceSyncAppManagerTest, Check005, TestSize.Level1) +{ + DeviceSyncAppManager::WhiteList whiteList = {"appId4", "bundleName4", 4}; + bool result = DeviceSyncAppManager::GetInstance().Check(whiteList); + EXPECT_FALSE(result); +} +} // namespace OHOS::Test \ No newline at end of file -- Gitee From 4c316b40759096bd341bc14b67356f644db74889 Mon Sep 17 00:00:00 2001 From: gecheng Date: Tue, 24 Jun 2025 21:40:54 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A1=A5=E5=85=85UT=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../test/device_sync_app_manager_test.cpp | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp index 3cebf31c1..872a565f7 100644 --- a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp +++ b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp @@ -36,9 +36,9 @@ protected: }; /** -@tc.name: Check001 -@tc.desc: Checks that the given WhiteList object exists in whiteLists_ list. -@tc.type: FUNC +* @tc.name: Check001 +* @tc.desc: Checks that the given WhiteList object exists in whiteLists_ list. +* @tc.type: FUNC */ HWTEST_F(DeviceSyncAppManagerTest, Check001, TestSize.Level1) { @@ -48,9 +48,9 @@ HWTEST_F(DeviceSyncAppManagerTest, Check001, TestSize.Level1) } /** -@tc.name: Check002 -@tc.desc: Check that the given appId object does not match. -@tc.type: FUNC +* @tc.name: Check002 +* @tc.desc: Check that the given appId object does not match. +* @tc.type: FUNC */ HWTEST_F(DeviceSyncAppManagerTest, Check002, TestSize.Level1) { @@ -60,9 +60,9 @@ HWTEST_F(DeviceSyncAppManagerTest, Check002, TestSize.Level1) } /** -@tc.name: Check003 -@tc.desc: Check that the given bundleName object does not match. -@tc.type: FUNC +* @tc.name: Check003 +* @tc.desc: Check that the given bundleName object does not match. +* @tc.type: FUNC */ HWTEST_F(DeviceSyncAppManagerTest, Check003, TestSize.Level1) { @@ -72,9 +72,9 @@ HWTEST_F(DeviceSyncAppManagerTest, Check003, TestSize.Level1) } /** -@tc.name: Check004 -@tc.desc: Check that the given version object does not match. -@tc.type: FUNC +* @tc.name: Check004 +* @tc.desc: Check that the given version object does not match. +* @tc.type: FUNC */ HWTEST_F(DeviceSyncAppManagerTest, Check004, TestSize.Level1) { @@ -84,9 +84,9 @@ HWTEST_F(DeviceSyncAppManagerTest, Check004, TestSize.Level1) } /** -@tc.name: Check005 -@tc.desc: Checks that the given WhiteList object does not exist in whiteLists_ list. -@tc.type: FUNC +* @tc.name: Check005 +* @tc.desc: Checks that the given WhiteList object does not exist in whiteLists_ list. +* @tc.type: FUNC */ HWTEST_F(DeviceSyncAppManagerTest, Check005, TestSize.Level1) { -- Gitee From 6757447a4c85af1fb02eb95a95522fc8c63af86c Mon Sep 17 00:00:00 2001 From: gecheng Date: Tue, 24 Jun 2025 21:54:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=A1=A5=E5=85=85UT=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../framework/test/device_sync_app_manager_test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp index 872a565f7..6ae441b9f 100644 --- a/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp +++ b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp @@ -20,8 +20,9 @@ using namespace OHOS::DistributedData; namespace OHOS::Test { class DeviceSyncAppManagerTest : public testing::Test { -protected: - void SetUp() override { +public: + void SetUp() + { whiteList1 = {"appId1", "bundleName1", 1}; whiteList2 = {"appId2", "bundleName2", 2}; whiteList3 = {"appId3", "bundleName3", 3}; -- Gitee From fe1851040f3956ed0c9d5b8a0e6c1b9505f59ffc Mon Sep 17 00:00:00 2001 From: gecheng Date: Tue, 24 Jun 2025 21:56:54 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=A1=A5=E5=85=85UT=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- services/distributeddataservice/framework/test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index a451d53fb..4e1fb58fc 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -404,6 +404,7 @@ ohos_unittest("DeviceSyncAppManagerTest") { sources = [ "device_sync_app_manager_test.cpp" ] configs = [ ":module_private_config" ] deps = [ "${data_service_path}/framework:distributeddatasvcfwk" ] + external_deps = [ "kv_store:datamgr_common" ] } ############################################################################### group("unittest") { -- Gitee