1 /*
2 * Copyright (c) 2023 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 <gtest/gtest.h>
17 #include <numeric>
18 #define private public
19 #include "bundle_manager_helper.h"
20 #undef private
21 #include "mock_common_event_stub.h"
22
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::EventFwk;
26 using namespace OHOS::AppExecFwk;
27
28 class BundleManagerHelperBranchTest : public testing::Test {
29 public:
BundleManagerHelperBranchTest()30 BundleManagerHelperBranchTest()
31 {}
~BundleManagerHelperBranchTest()32 ~BundleManagerHelperBranchTest()
33 {}
34
35 static void SetUpTestCase(void);
36 static void TearDownTestCase(void);
37 void SetUp();
38 void TearDown();
39 };
40
SetUpTestCase(void)41 void BundleManagerHelperBranchTest::SetUpTestCase(void)
42 {}
43
TearDownTestCase(void)44 void BundleManagerHelperBranchTest::TearDownTestCase(void)
45 {}
46
SetUp(void)47 void BundleManagerHelperBranchTest::SetUp(void)
48 {}
49
TearDown(void)50 void BundleManagerHelperBranchTest::TearDown(void)
51 {}
52
53 using IBundleMgr = OHOS::AppExecFwk::IBundleMgr;
54
55 class TestIBundleMgr : public IBundleMgr {
56 public:
57 TestIBundleMgr() = default;
~TestIBundleMgr()58 virtual ~TestIBundleMgr()
59 {};
AsObject()60 sptr<IRemoteObject> AsObject() override
61 {
62 return nullptr;
63 }
64 };
65
66 /**
67 * @tc.name: BundleManagerHelper_0013
68 * @tc.desc: test QueryExtensionInfos function and GetBundleMgrProxy is true and osAccountIds.size() is 0.
69 * @tc.type: FUNC
70 */
HWTEST_F(BundleManagerHelperBranchTest,BundleManagerHelper_0013,Level1)71 HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_0013, Level1)
72 {
73 GTEST_LOG_(INFO) << "BundleManagerHelper_0013 start";
74 BundleManagerHelper bundleManagerHelper;
75 sptr<IRemoteObject> remoteObject = sptr<IRemoteObject>(new MockCommonEventStub());
76 bundleManagerHelper.sptrBundleMgr_ = iface_cast<IBundleMgr>(remoteObject);
77 std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
78 int32_t userId = 1;
79 EXPECT_EQ(false, bundleManagerHelper.QueryExtensionInfos(extensionInfos, userId));
80 GTEST_LOG_(INFO) << "BundleManagerHelper_0013 end";
81 }
82
83 /**
84 * @tc.name: BundleManagerHelper_1400
85 * @tc.desc: test CheckIsSystemAppByBundleName function and GetBundleMgrProxy is false.
86 * @tc.type: FUNC
87 */
HWTEST_F(BundleManagerHelperBranchTest,BundleManagerHelper_1400,Level1)88 HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_1400, Level1)
89 {
90 GTEST_LOG_(INFO) << "BundleManagerHelper_1400 start";
91 BundleManagerHelper bundleManagerHelper;
92 sptr<IRemoteObject> remoteObject = sptr<IRemoteObject>(new MockCommonEventStub());
93 bundleManagerHelper.sptrBundleMgr_ = iface_cast<IBundleMgr>(remoteObject);
94 std::string bundleName = "aa";
95 int32_t userId = 1;
96 EXPECT_EQ(false, bundleManagerHelper.CheckIsSystemAppByBundleName(bundleName, userId));
97 GTEST_LOG_(INFO) << "BundleManagerHelper_1400 end";
98 }