• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "device_sync_app/device_sync_app_manager.h"
16 #include <gtest/gtest.h>
17 
18 using namespace testing::ext;
19 using namespace OHOS::DistributedData;
20 
21 namespace OHOS::Test {
22 class DeviceSyncAppManagerTest : public testing::Test {
23 public:
SetUp()24     void SetUp()
25     {
26         whiteList1 = {"appId1", "bundleName1", 1};
27         whiteList2 = {"appId2", "bundleName2", 2};
28         whiteList3 = {"appId3", "bundleName3", 3};
29 
30         std::vector<DeviceSyncAppManager::WhiteList> lists = {whiteList1, whiteList2, whiteList3};
31         DeviceSyncAppManager::GetInstance().Initialize(lists);
32     }
33 
34     DeviceSyncAppManager::WhiteList whiteList1;
35     DeviceSyncAppManager::WhiteList whiteList2;
36     DeviceSyncAppManager::WhiteList whiteList3;
37 };
38 
39 /**
40 * @tc.name: Check001
41 * @tc.desc: Checks that the given WhiteList object exists in whiteLists_ list.
42 * @tc.type: FUNC
43 */
44 HWTEST_F(DeviceSyncAppManagerTest, Check001, TestSize.Level1)
45 {
46     DeviceSyncAppManager::WhiteList whiteList = {"appId1", "bundleName1", 1};
47     bool result = DeviceSyncAppManager::GetInstance().Check(whiteList);
48     EXPECT_TRUE(result);
49 }
50 
51 /**
52 * @tc.name: Check002
53 * @tc.desc: Check that the given appId object does not match.
54 * @tc.type: FUNC
55 */
56 HWTEST_F(DeviceSyncAppManagerTest, Check002, TestSize.Level1)
57 {
58     DeviceSyncAppManager::WhiteList testList = {"appId2", "bundleName1", 1};
59     bool result = DeviceSyncAppManager::GetInstance().Check(testList);
60     EXPECT_FALSE(result);
61 }
62 
63 /**
64 * @tc.name: Check003
65 * @tc.desc: Check that the given bundleName object does not match.
66 * @tc.type: FUNC
67 */
68 HWTEST_F(DeviceSyncAppManagerTest, Check003, TestSize.Level1)
69 {
70     DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName2", 1};
71     bool result = DeviceSyncAppManager::GetInstance().Check(testList);
72     EXPECT_FALSE(result);
73 }
74 
75 /**
76 * @tc.name: Check004
77 * @tc.desc: Check that the given version object does not match.
78 * @tc.type: FUNC
79 */
80 HWTEST_F(DeviceSyncAppManagerTest, Check004, TestSize.Level1)
81 {
82     DeviceSyncAppManager::WhiteList testList = {"appId1", "bundleName1", 2};
83     bool result = DeviceSyncAppManager::GetInstance().Check(testList);
84     EXPECT_FALSE(result);
85 }
86 
87 /**
88 * @tc.name: Check005
89 * @tc.desc: Checks that the given WhiteList object does not exist in whiteLists_ list.
90 * @tc.type: FUNC
91 */
92 HWTEST_F(DeviceSyncAppManagerTest, Check005, TestSize.Level1)
93 {
94     DeviceSyncAppManager::WhiteList whiteList = {"appId4", "bundleName4", 4};
95     bool result = DeviceSyncAppManager::GetInstance().Check(whiteList);
96     EXPECT_FALSE(result);
97 }
98 } // namespace OHOS::Test