diff --git a/services/distributeddataservice/framework/test/BUILD.gn b/services/distributeddataservice/framework/test/BUILD.gn index f5a72492881fb703b878c10d00bd78589beaa206..4e1fb58fc8d394bdd63ecb1b2ee82ec7a1f69f5d 100644 --- a/services/distributeddataservice/framework/test/BUILD.gn +++ b/services/distributeddataservice/framework/test/BUILD.gn @@ -399,6 +399,13 @@ 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" ] + external_deps = [ "kv_store:datamgr_common" ] +} ############################################################################### group("unittest") { testonly = true @@ -415,6 +422,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 0000000000000000000000000000000000000000..6ae441b9f46f540bfcf026c3265783a4347eec9f --- /dev/null +++ b/services/distributeddataservice/framework/test/device_sync_app_manager_test.cpp @@ -0,0 +1,98 @@ +/* +* 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 { +public: + void SetUp() + { + 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