1 /*
2  * Copyright (c) 2022 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 }  // namespace BackgroundTaskMgr
131 }  // namespace OHOS
132