• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include <functional>
17 #include <gtest/gtest.h>
18 
19 #define private public
20 #define protected public
21 #include "bundle_manager_helper.h"
22 #undef private
23 #undef protected
24 
25 #include "if_system_ability_manager.h"
26 #include "ipc_skeleton.h"
27 #include "iservice_registry.h"
28 #include "system_ability_definition.h"
29 #include "access_token_helper.h"
30 
31 using namespace testing::ext;
32 namespace OHOS {
33 namespace Notification {
34 class BundleManagerHelperTest : public testing::Test {
35 public:
SetUpTestCase()36     static void SetUpTestCase() {};
TearDownTestCase()37     static void TearDownTestCase() {};
SetUp()38     void SetUp() {};
TearDown()39     void TearDown() {};
40 };
41 
42 /**
43  * @tc.number    : BundleManagerHelperTest_00100
44  * @tc.name      : ANS_GetBundleNameByUid_0100
45  * @tc.desc      : Test GetBundleNameByUid function
46  */
47 HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00100, Function | SmallTest | Level1)
48 {
49     pid_t callingUid = IPCSkeleton::GetCallingUid();
50     std::shared_ptr<BundleManagerHelper> bundleManager = BundleManagerHelper::GetInstance();
51     EXPECT_EQ(bundleManager->GetBundleNameByUid(callingUid), "bundleName");
52 }
53 
54 /**
55  * @tc.number    : BundleManagerHelperTest_00200
56  * @tc.name      : ANS_IsSystemApp_0100
57  * @tc.desc      : Test IsSystemApp function
58  */
59 HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00200, Function | SmallTest | Level1)
60 {
61     pid_t callingUid = IPCSkeleton::GetCallingUid();
62     std::shared_ptr<BundleManagerHelper> bundleManager = BundleManagerHelper::GetInstance();
63     EXPECT_TRUE(bundleManager->IsSystemApp(callingUid));
64 }
65 
66 /**
67  * @tc.number    : BundleManagerHelperTest_00300
68  * @tc.name      : CheckApiCompatibility
69  * @tc.desc      : Test CheckApiCompatibility function when the  bundleOption is nullptr,return is true
70  * @tc.require   : issueI5S4VP
71  */
HWTEST_F(BundleManagerHelperTest,BundleManagerHelperTest_00300,Level1)72 HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00300, Level1)
73 {
74     sptr<NotificationBundleOption> bundleOption = nullptr;
75     BundleManagerHelper bundleManagerHelper;
76     bool result = bundleManagerHelper.CheckApiCompatibility(bundleOption);
77     EXPECT_EQ(result, true);
78 }
79 
80 /**
81  * @tc.number    : BundleManagerHelperTest_00400
82  * @tc.name      : GetBundleInfoByBundleName
83  * @tc.desc      : get bundleinfo by bundlename when the parameeter are normal, return is true
84  * @tc.require   : issueI5S4VP
85  */
HWTEST_F(BundleManagerHelperTest,BundleManagerHelperTest_00400,Level1)86 HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00400, Level1)
87 {
88     std::string bundle = "Bundle";
89     int32_t userId = 1;
90     AppExecFwk::BundleInfo bundleInfo;
91     BundleManagerHelper bundleManagerHelper;
92     bool result = bundleManagerHelper.GetBundleInfoByBundleName(bundle, userId, bundleInfo);
93     EXPECT_EQ(result, true);
94 }
95 
96 /**
97  * @tc.number    : BundleManagerHelperTest_00500
98  * @tc.name      : GetDefaultUidByBundleName
99  * @tc.desc      : Test GetDefaultUidByBundleName function  when the parameeter are normal
100  * @tc.require   : issueI5S4VP
101  */
HWTEST_F(BundleManagerHelperTest,BundleManagerHelperTest_00500,Level1)102 HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00500, Level1)
103 {
104     std::string bundle = "Bundle";
105     int32_t userId = 1;
106     BundleManagerHelper bundleManagerHelper;
107     int32_t result = bundleManagerHelper.GetDefaultUidByBundleName(bundle, userId);
108     EXPECT_EQ(result, 1000);
109 }
110 
111 /**
112  * @tc.number    : GetDistributedNotificationEnabled_00100
113  * @tc.name      : GetDistributedNotificationEnabled
114  * @tc.desc      : Test GetDistributedNotificationEnabled function  when the parameeter are normal
115  */
HWTEST_F(BundleManagerHelperTest,GetDistributedNotificationEnabled_00100,Level1)116 HWTEST_F(BundleManagerHelperTest, GetDistributedNotificationEnabled_00100, Level1)
117 {
118     std::string bundle = "Bundle";
119     int32_t userId = 1;
120     BundleManagerHelper bundleManagerHelper;
121     bool result = bundleManagerHelper.GetDistributedNotificationEnabled(bundle, userId);
122     EXPECT_EQ(result, true);
123 }
124 }  // namespace Notification
125 }  // namespace OHOS
126