• 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 <fcntl.h>
17 #include <fstream>
18 #include <future>
19 #include <gtest/gtest.h>
20 
21 #include "app_log_wrapper.h"
22 #include "bundle_mgr_proxy.h"
23 #include "common_tool.h"
24 #include "iservice_registry.h"
25 #include "system_ability_definition.h"
26 
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace AppExecFwk {
30 class BmsCheckServiceTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp();
35     void TearDown();
36     static sptr<IBundleMgr> GetBundleMgr();
37 };
38 
GetBundleMgr()39 sptr<IBundleMgr> BmsCheckServiceTest::GetBundleMgr()
40 {
41     sptr<ISystemAbilityManager> systemAbilityManager =
42         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
43     if (!systemAbilityManager) {
44         APP_LOGE("fail to get system ability mgr.");
45         return nullptr;
46     }
47 
48     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
49     if (!remoteObject) {
50         APP_LOGE("fail to get bundle manager.");
51         return nullptr;
52     }
53 
54     APP_LOGI("get bundle manager success.");
55     return iface_cast<IBundleMgr>(remoteObject);
56 }
57 
TearDownTestCase()58 void BmsCheckServiceTest::TearDownTestCase()
59 {}
60 
SetUp()61 void BmsCheckServiceTest::SetUp()
62 {}
63 
TearDown()64 void BmsCheckServiceTest::TearDown()
65 {}
66 
SetUpTestCase()67 void BmsCheckServiceTest::SetUpTestCase()
68 {}
69 
70 /**
71  * @tc.number: GetBundleMgr_0100
72  * @tc.name: test get BMS
73  * @tc.desc: get BMS form SystemAbilityManager
74  */
75 HWTEST_F(BmsCheckServiceTest, GetBundleMgr_0100, Function | MediumTest | Level0)
76 {
77     sptr<IBundleMgr> bundleMgr = GetBundleMgr();
78     if (!bundleMgr) {
79         APP_LOGE("bundle mgr is nullptr.");
80         EXPECT_NE(bundleMgr, nullptr);
81     }
82 }
83 /**
84  * @tc.number: GetBundleInfos_0100
85  * @tc.name: test query bundleinfos
86  * @tc.desc: 1.under '/system/app/',there exist bundles
87  *           2.install the bundles
88  *           3.query all bundleinfos
89  */
90 HWTEST_F(BmsCheckServiceTest, GetBundleInfos_0100, Function | MediumTest | Level0)
91 {
92     sptr<IBundleMgr> bundleMgr = GetBundleMgr();
93     if (!bundleMgr) {
94         APP_LOGE("bundle mgr is nullptr.");
95         EXPECT_NE(bundleMgr, nullptr);
96     } else {
97         std::cout << "GetBundleInfos" << std::endl;
98         std::vector<BundleInfo> bundleInfos;
99         bool getInfoResult = bundleMgr->GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos);
100         EXPECT_TRUE(getInfoResult);
101     }
102 }
103 }  // namespace AppExecFwk
104 }  // namespace OHOS
105