• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "background_task_manager.h"
19 #include "bg_continuous_task_mgr.h"
20 #include "bg_transient_task_mgr.h"
21 #include "iservice_registry.h"
22 #include "singleton.h"
23 #include "system_ability_definition.h"
24 
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace BackgroundTaskMgr {
29 class BgtaskDumpTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp();
34     void TearDown();
35 };
36 
SetUpTestCase()37 void BgtaskDumpTest::SetUpTestCase()
38 {
39     DelayedSingleton<BgTransientTaskMgr>::GetInstance()->isReady_.store(true);
40 }
41 
TearDownTestCase()42 void BgtaskDumpTest::TearDownTestCase() {}
43 
SetUp()44 void BgtaskDumpTest::SetUp() {}
45 
TearDown()46 void BgtaskDumpTest::TearDown() {}
47 
48 /*
49  * @tc.name: BgtaskDumpTest_GetServiceObject_001
50  * @tc.desc: Get Service Object
51  * @tc.type: FUNC
52  * @tc.require: SR000GGTET AR000GH86Q
53  */
54 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_GetServiceObject_001, Function | MediumTest | Level0)
55 {
56     sptr<ISystemAbilityManager> systemAbilityManager =
57         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
58     EXPECT_NE(systemAbilityManager, nullptr);
59 
60     sptr<IRemoteObject> remoteObject =
61         systemAbilityManager->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID);
62     EXPECT_NE(remoteObject, nullptr);
63 }
64 
65 /*
66  * @tc.name: BgtaskDumpTest_ShellDump_001
67  * @tc.desc: Shell dump
68  * @tc.type: FUNC
69  * @tc.require: SR000GGTJU AR000GH85V
70  */
71 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_001, Function | MediumTest | Level0)
72 {
73     std::vector<std::string> infos;
74     std::vector<std::string> options;
75     options.push_back("-T");
76     options.push_back("All");
77     auto ret = DelayedSingleton<BgTransientTaskMgr>::GetInstance()->ShellDump(options, infos);
78     EXPECT_EQ(ret, 0);
79 }
80 
81 /*
82  * @tc.name: BgtaskDumpTest_ShellDump_002
83  * @tc.desc: Shell dump
84  * @tc.type: FUNC
85  * @tc.require: SR000GGT80 AR000GH6EQ
86  */
87 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_002, Function | MediumTest | Level0)
88 {
89     std::vector<std::string> infos;
90     std::vector<std::string> options;
91     options.push_back("-C");
92     options.push_back("--all");
93     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
94     EXPECT_EQ(ret, 0);
95 }
96 
97 /*
98  * @tc.name: BgtaskDumpTest_ShellDump_003
99  * @tc.desc: Shell dump
100  * @tc.type: FUNC
101  * @tc.require: issueI936BL
102  */
103 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_003, Function | MediumTest | Level0)
104 {
105     std::vector<std::string> infos;
106     std::vector<std::string> options;
107     options.push_back("-T");
108     options.push_back("PAUSE");
109     options.push_back("-1");
110     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
111     EXPECT_EQ(ret, 0);
112 }
113 
114 /*
115  * @tc.name: BgtaskDumpTest_ShellDump_004
116  * @tc.desc: Shell dump
117  * @tc.type: FUNC
118  * @tc.require: issueI936BL
119  */
120 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_004, Function | MediumTest | Level0)
121 {
122     std::vector<std::string> infos;
123     std::vector<std::string> options;
124     options.push_back("-T");
125     options.push_back("START");
126     options.push_back("-1");
127     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
128     EXPECT_EQ(ret, 0);
129 }
130 
131 /*
132  * @tc.name: BgtaskDumpTest_ShellDump_005
133  * @tc.desc: Shell dump
134  * @tc.type: FUNC
135  * @tc.require: issueIBY0DN
136  */
137 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_005, Function | MediumTest | Level0)
138 {
139     std::vector<std::string> infos;
140     std::vector<std::string> options;
141     options.push_back("-C");
142     options.push_back("--get");
143     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
144     EXPECT_EQ(ret, 0);
145 }
146 
147 /*
148  * @tc.name: BgtaskDumpTest_ShellDump_006
149  * @tc.desc: Shell dump
150  * @tc.type: FUNC
151  * @tc.require: issueIBY0DN
152  */
153 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_006, Function | MediumTest | Level0)
154 {
155     std::vector<std::string> infos;
156     std::vector<std::string> options;
157     options.push_back("-C");
158     options.push_back("--get 20020056");
159     BgContinuousTaskMgr::GetInstance()->continuousTaskInfosMap_.clear();
160     std::shared_ptr<ContinuousTaskRecord> continuousTaskRecord1 = std::make_shared<ContinuousTaskRecord>();
161     continuousTaskRecord1->abilityName_ = "abilityName";
162     continuousTaskRecord1->uid_ = 20020056;
163     continuousTaskRecord1->bgModeId_ = 2;
164     continuousTaskRecord1->bgModeIds_.push_back(2);
165     continuousTaskRecord1->bgSubModeIds_.push_back(2);
166     continuousTaskRecord1->notificationId_ = 1;
167     continuousTaskRecord1->continuousTaskId_ = 1;
168     continuousTaskRecord1->abilityId_ = 1;
169     std::shared_ptr<WantAgentInfo> info = std::make_shared<WantAgentInfo>();
170     info->bundleName_ = "wantAgentBundleName";
171     info->abilityName_ = "wantAgentAbilityName";
172     continuousTaskRecord1->wantAgentInfo_ = info;
173     BgContinuousTaskMgr::GetInstance()->continuousTaskInfosMap_["key1"] = continuousTaskRecord1;
174     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
175     EXPECT_EQ(ret, 0);
176 }
177 
178 /*
179  * @tc.name: BgtaskDumpTest_ShellDump_007
180  * @tc.desc: Shell dump
181  * @tc.type: FUNC
182  * @tc.require: issueIC4IFG
183  */
184 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_007, Function | MediumTest | Level0)
185 {
186     std::vector<std::string> infos;
187     std::vector<std::string> options;
188     options.push_back("-C");
189     options.push_back("--inner_task");
190     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
191     EXPECT_EQ(ret, 0);
192 }
193 
194 /*
195  * @tc.name: BgtaskDumpTest_ShellDump_008
196  * @tc.desc: Shell dump
197  * @tc.type: FUNC
198  * @tc.require: issueIC4IFG
199  */
200 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_008, Function | MediumTest | Level0)
201 {
202     std::vector<std::string> infos;
203     std::vector<std::string> options;
204     options.push_back("-C");
205     options.push_back("--inner_task DEMO apply");
206     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
207     EXPECT_EQ(ret, 0);
208 }
209 
210 /*
211  * @tc.name: BgtaskDumpTest_ShellDump_009
212  * @tc.desc: Shell dump
213  * @tc.type: FUNC
214  * @tc.require: issueIC4IFG
215  */
216 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_009, Function | MediumTest | Level0)
217 {
218     std::vector<std::string> infos;
219     std::vector<std::string> options;
220     options.push_back("-C");
221     options.push_back("--inner_task WORKOUT DEMO");
222     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
223     EXPECT_EQ(ret, 0);
224 }
225 
226 /*
227  * @tc.name: BgtaskDumpTest_ShellDump_010
228  * @tc.desc: Shell dump
229  * @tc.type: FUNC
230  * @tc.require: issueIC4IFG
231  */
232 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_010, Function | MediumTest | Level0)
233 {
234     std::vector<std::string> infos;
235     std::vector<std::string> options;
236     options.push_back("-C");
237     options.push_back("--inner_task WORKOUT apply");
238     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
239     EXPECT_EQ(ret, 0);
240 }
241 
242 /*
243  * @tc.name: BgtaskDumpTest_ShellDump_011
244  * @tc.desc: Shell dump
245  * @tc.type: FUNC
246  * @tc.require: issueIC4IFG
247  */
248 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_011, Function | MediumTest | Level0)
249 {
250     std::vector<std::string> infos;
251     std::vector<std::string> options;
252     options.push_back("-C");
253     options.push_back("--inner_task WORKOUT reset");
254     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
255     EXPECT_EQ(ret, 0);
256 }
257 }  // namespace BackgroundTaskMgr
258 }  // namespace OHOS
259