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
16 #include <gtest/gtest.h>
17
18 #include <bundle_mgr_interface.h>
19 #include <bundlemgr/launcher_service.h>
20 #include "session/host/include/ability_info_manager.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 class AbilityInfoManagerTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void AbilityInfoManagerTest::SetUpTestCase()
36 {
37 }
38
TearDownTestCase()39 void AbilityInfoManagerTest::TearDownTestCase()
40 {
41 }
42
SetUp()43 void AbilityInfoManagerTest::SetUp()
44 {
45 }
46
TearDown()47 void AbilityInfoManagerTest::TearDown()
48 {
49 }
50
51 namespace {
52 /**
53 * @tc.name: FindAbilityInfo01
54 * @tc.desc: FindAbilityInfo01
55 * @tc.type: FUNC
56 */
57 HWTEST_F(AbilityInfoManagerTest, FindAbilityInfo01, TestSize.Level1)
58 {
59 std::string moduleName = "testModuleName";
60 std::string abilityName = "testAbilityName";
61 AppExecFwk::BundleInfo bundleInfo;
62 AppExecFwk::AbilityInfo targetAbilityInfo;
63 auto ret = AbilityInfoManager::FindAbilityInfo(bundleInfo, moduleName, abilityName, targetAbilityInfo);
64 EXPECT_FALSE(ret);
65 }
66
67 /**
68 * @tc.name: FindAbilityInfo02
69 * @tc.desc: FindAbilityInfo02
70 * @tc.type: FUNC
71 */
72 HWTEST_F(AbilityInfoManagerTest, FindAbilityInfo02, TestSize.Level1)
73 {
74 std::string moduleName = "testModuleName";
75 std::string abilityName = "testAbilityName";
76 AppExecFwk::BundleInfo bundleInfo;
77 AppExecFwk::AbilityInfo targetAbilityInfo;
78 AppExecFwk::AbilityInfo abilityInfo;
79 abilityInfo.moduleName = moduleName;
80 abilityInfo.name = abilityName;
81 AppExecFwk::HapModuleInfo hapModuleInfo;
82 hapModuleInfo.abilityInfos.emplace_back(abilityInfo);
83 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo);
84 auto ret = AbilityInfoManager::FindAbilityInfo(bundleInfo, moduleName, abilityName, targetAbilityInfo);
85 EXPECT_TRUE(ret);
86 EXPECT_EQ(targetAbilityInfo.moduleName, moduleName);
87 EXPECT_EQ(targetAbilityInfo.name, abilityName);
88 }
89 } // namespace
90 } // namespace Rosen
91 } // namespace OHOS