• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define private public
19 #define protected public
20 
21 #include "background_task_manager.h"
22 #include "bg_continuous_task_mgr.h"
23 #include "bg_transient_task_mgr.h"
24 #include "iservice_registry.h"
25 #include "singleton.h"
26 #include "system_ability_definition.h"
27 
28 #undef private
29 #undef protected
30 
31 using namespace testing::ext;
32 
33 namespace OHOS {
34 namespace BackgroundTaskMgr {
35 class BgtaskDumpTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp();
40     void TearDown();
41 };
42 
SetUpTestCase()43 void BgtaskDumpTest::SetUpTestCase()
44 {
45     DelayedSingleton<BgTransientTaskMgr>::GetInstance()->isReady_.store(true);
46 }
47 
TearDownTestCase()48 void BgtaskDumpTest::TearDownTestCase() {}
49 
SetUp()50 void BgtaskDumpTest::SetUp() {}
51 
TearDown()52 void BgtaskDumpTest::TearDown() {}
53 
54 /*
55  * @tc.name: BgtaskDumpTest_GetServiceObject_001
56  * @tc.desc: Get Service Object
57  * @tc.type: FUNC
58  * @tc.require: SR000GGTET AR000GH86Q
59  */
60 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_GetServiceObject_001, Function | MediumTest | Level0)
61 {
62     sptr<ISystemAbilityManager> systemAbilityManager =
63         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
64     EXPECT_NE(systemAbilityManager, nullptr);
65 
66     sptr<IRemoteObject> remoteObject =
67         systemAbilityManager->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID);
68     EXPECT_NE(remoteObject, nullptr);
69 }
70 
71 /*
72  * @tc.name: BgtaskDumpTest_ShellDump_001
73  * @tc.desc: Shell dump
74  * @tc.type: FUNC
75  * @tc.require: SR000GGTJU AR000GH85V
76  */
77 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_001, Function | MediumTest | Level0)
78 {
79     std::vector<std::string> infos;
80     std::vector<std::string> options;
81     options.push_back("-T");
82     options.push_back("All");
83     auto ret = DelayedSingleton<BgTransientTaskMgr>::GetInstance()->ShellDump(options, infos);
84     EXPECT_EQ(ret, 0);
85 }
86 
87 /*
88  * @tc.name: BgtaskDumpTest_ShellDump_002
89  * @tc.desc: Shell dump
90  * @tc.type: FUNC
91  * @tc.require: SR000GGT80 AR000GH6EQ
92  */
93 HWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_002, Function | MediumTest | Level0)
94 {
95     std::vector<std::string> infos;
96     std::vector<std::string> options;
97     options.push_back("-C");
98     options.push_back("--all");
99     auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos);
100     EXPECT_EQ(ret, 0);
101 }
102 }  // namespace BackgroundTaskMgr
103 }  // namespace OHOS
104