1 /*
2 * Copyright (c) 2024 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 "ability_manager_service.h"
19 #include "main_element_utils.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23 using namespace OHOS::AppExecFwk;
24
25 namespace OHOS {
26 namespace AAFwk {
27 class MainElementUtilsTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 void SetUp();
32 void TearDown();
33 };
34
SetUpTestCase(void)35 void MainElementUtilsTest::SetUpTestCase(void)
36 {}
TearDownTestCase(void)37 void MainElementUtilsTest::TearDownTestCase(void)
38 {}
SetUp()39 void MainElementUtilsTest::SetUp()
40 {}
TearDown()41 void MainElementUtilsTest::TearDown()
42 {}
43
44 /*
45 * Feature: MainElementUtils
46 * Function: CheckMainElement
47 * SubFunction: NA
48 * FunctionPoints:MainElementUtils CheckMainElement
49 * EnvConditions: NA
50 * CaseDescription: Verify CheckMainElement
51 */
52 HWTEST_F(MainElementUtilsTest, CheckMainElement_001, TestSize.Level1)
53 {
54 HapModuleInfo hapModuleInfo;
55 std::string processName = "processName";
56 std::string mainElement = "";
57 bool isDataAbility = false;
58 std::string uriStr;
59 AbilityInfo abilityInfo;
60 hapModuleInfo.mainAbility = "mainAbility";
61 hapModuleInfo.isModuleJson = false;
62 abilityInfo.process = "process";
63 abilityInfo.name = "mainAbility";
64 hapModuleInfo.abilityInfos.push_back(abilityInfo);
65 bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
66 processName, mainElement, isDataAbility, uriStr);
67 EXPECT_FALSE(res);
68 }
69
70 /*
71 * Feature: MainElementUtils
72 * Function: CheckMainElement
73 * SubFunction: NA
74 * FunctionPoints:MainElementUtils CheckMainElement
75 * EnvConditions: NA
76 * CaseDescription: Verify CheckMainElement
77 */
78 HWTEST_F(MainElementUtilsTest, CheckMainElement_002, TestSize.Level1)
79 {
80 HapModuleInfo hapModuleInfo;
81 std::string processName = "processName";
82 std::string mainElement = "";
83 bool isDataAbility = false;
84 std::string uriStr;
85 AbilityInfo abilityInfo;
86 hapModuleInfo.mainAbility = "mainAbility";
87 hapModuleInfo.isModuleJson = false;
88 abilityInfo.process = "processName";
89 abilityInfo.name = "";
90 hapModuleInfo.abilityInfos.push_back(abilityInfo);
91 bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
92 processName, mainElement, isDataAbility, uriStr);
93 EXPECT_FALSE(res);
94 }
95
96 /*
97 * Feature: MainElementUtils
98 * Function: CheckMainElement
99 * SubFunction: NA
100 * FunctionPoints:MainElementUtils CheckMainElement
101 * EnvConditions: NA
102 * CaseDescription: Verify CheckMainElement
103 */
104 HWTEST_F(MainElementUtilsTest, CheckMainElement_003, TestSize.Level1)
105 {
106 HapModuleInfo hapModuleInfo;
107 std::string processName = "processName";
108 std::string mainElement = "";
109 bool isDataAbility = false;
110 std::string uriStr;
111 AbilityInfo abilityInfo;
112 hapModuleInfo.mainAbility = "mainAbility";
113 hapModuleInfo.isModuleJson = false;
114 abilityInfo.process = "processName";
115 abilityInfo.name = "mainAbility";
116 abilityInfo.uri = "//";
117 abilityInfo.type = AbilityType::DATA;
118 hapModuleInfo.abilityInfos.push_back(abilityInfo);
119 bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
120 processName, mainElement, isDataAbility, uriStr);
121 EXPECT_FALSE(res);
122 }
123
124 /*
125 * Feature: MainElementUtils
126 * Function: CheckMainElement
127 * SubFunction: NA
128 * FunctionPoints:MainElementUtils CheckMainElement
129 * EnvConditions: NA
130 * CaseDescription: Verify CheckMainElement
131 */
132 HWTEST_F(MainElementUtilsTest, CheckMainElement_004, TestSize.Level1)
133 {
134 HapModuleInfo hapModuleInfo;
135 std::string processName = "processName";
136 std::string mainElement = "";
137 bool isDataAbility = false;
138 std::string uriStr;
139 AbilityInfo abilityInfo;
140 hapModuleInfo.mainAbility = "mainAbility";
141 hapModuleInfo.isModuleJson = false;
142 abilityInfo.process = "processName";
143 abilityInfo.name = "mainAbility";
144 abilityInfo.uri = "//";
145 abilityInfo.type = AbilityType::PAGE;
146 hapModuleInfo.abilityInfos.push_back(abilityInfo);
147 bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
148 processName, mainElement, isDataAbility, uriStr);
149 EXPECT_FALSE(res);
150 }
151
152 /*
153 * Feature: MainElementUtils
154 * Function: CheckMainElement
155 * SubFunction: NA
156 * FunctionPoints:MainElementUtils CheckMainElement
157 * EnvConditions: NA
158 * CaseDescription: Verify CheckMainElement
159 */
160 HWTEST_F(MainElementUtilsTest, CheckMainElement_005, TestSize.Level1)
161 {
162 HapModuleInfo hapModuleInfo;
163 std::string processName = "processName";
164 std::string mainElement = "";
165 bool isDataAbility = false;
166 std::string uriStr;
167 hapModuleInfo.mainAbility = "";
168 hapModuleInfo.isModuleJson = true;
169 bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
170 processName, mainElement, isDataAbility, uriStr);
171 EXPECT_FALSE(res);
172 }
173
174 /*
175 * Feature: MainElementUtils
176 * Function: CheckMainElement
177 * SubFunction: NA
178 * FunctionPoints:MainElementUtils CheckMainElement
179 * EnvConditions: NA
180 * CaseDescription: Verify CheckMainElement
181 */
182 HWTEST_F(MainElementUtilsTest, CheckMainElement_006, TestSize.Level1)
183 {
184 HapModuleInfo hapModuleInfo;
185 std::string processName = "processName";
186 std::string mainElement = "";
187 bool isDataAbility = false;
188 std::string uriStr;
189 hapModuleInfo.mainAbility = "mainAbility";
190 hapModuleInfo.isModuleJson = true;
191 hapModuleInfo.process = "";
192 bool res = MainElementUtils::CheckMainElement(hapModuleInfo,
193 processName, mainElement, isDataAbility, uriStr);
194 EXPECT_FALSE(res);
195 }
196 } // namespace AAFwk
197 } // namespace OHOS
198