11ebd3d54Sopenharmony_ci/* 21ebd3d54Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 31ebd3d54Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41ebd3d54Sopenharmony_ci * you may not use this file except in compliance with the License. 51ebd3d54Sopenharmony_ci * You may obtain a copy of the License at 61ebd3d54Sopenharmony_ci * 71ebd3d54Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81ebd3d54Sopenharmony_ci * 91ebd3d54Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101ebd3d54Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111ebd3d54Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121ebd3d54Sopenharmony_ci * See the License for the specific language governing permissions and 131ebd3d54Sopenharmony_ci * limitations under the License. 141ebd3d54Sopenharmony_ci */ 151ebd3d54Sopenharmony_ci 161ebd3d54Sopenharmony_ci#include <gtest/gtest.h> 171ebd3d54Sopenharmony_ci 181ebd3d54Sopenharmony_ci#include "background_task_manager.h" 191ebd3d54Sopenharmony_ci#include "bg_continuous_task_mgr.h" 201ebd3d54Sopenharmony_ci#include "bg_transient_task_mgr.h" 211ebd3d54Sopenharmony_ci#include "iservice_registry.h" 221ebd3d54Sopenharmony_ci#include "singleton.h" 231ebd3d54Sopenharmony_ci#include "system_ability_definition.h" 241ebd3d54Sopenharmony_ci 251ebd3d54Sopenharmony_ciusing namespace testing::ext; 261ebd3d54Sopenharmony_ci 271ebd3d54Sopenharmony_cinamespace OHOS { 281ebd3d54Sopenharmony_cinamespace BackgroundTaskMgr { 291ebd3d54Sopenharmony_ciclass BgtaskDumpTest : public testing::Test { 301ebd3d54Sopenharmony_cipublic: 311ebd3d54Sopenharmony_ci static void SetUpTestCase(); 321ebd3d54Sopenharmony_ci static void TearDownTestCase(); 331ebd3d54Sopenharmony_ci void SetUp(); 341ebd3d54Sopenharmony_ci void TearDown(); 351ebd3d54Sopenharmony_ci}; 361ebd3d54Sopenharmony_ci 371ebd3d54Sopenharmony_civoid BgtaskDumpTest::SetUpTestCase() 381ebd3d54Sopenharmony_ci{ 391ebd3d54Sopenharmony_ci DelayedSingleton<BgTransientTaskMgr>::GetInstance()->isReady_.store(true); 401ebd3d54Sopenharmony_ci} 411ebd3d54Sopenharmony_ci 421ebd3d54Sopenharmony_civoid BgtaskDumpTest::TearDownTestCase() {} 431ebd3d54Sopenharmony_ci 441ebd3d54Sopenharmony_civoid BgtaskDumpTest::SetUp() {} 451ebd3d54Sopenharmony_ci 461ebd3d54Sopenharmony_civoid BgtaskDumpTest::TearDown() {} 471ebd3d54Sopenharmony_ci 481ebd3d54Sopenharmony_ci/* 491ebd3d54Sopenharmony_ci * @tc.name: BgtaskDumpTest_GetServiceObject_001 501ebd3d54Sopenharmony_ci * @tc.desc: Get Service Object 511ebd3d54Sopenharmony_ci * @tc.type: FUNC 521ebd3d54Sopenharmony_ci * @tc.require: SR000GGTET AR000GH86Q 531ebd3d54Sopenharmony_ci */ 541ebd3d54Sopenharmony_ciHWTEST_F(BgtaskDumpTest, BgtaskDumpTest_GetServiceObject_001, Function | MediumTest | Level0) 551ebd3d54Sopenharmony_ci{ 561ebd3d54Sopenharmony_ci sptr<ISystemAbilityManager> systemAbilityManager = 571ebd3d54Sopenharmony_ci SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 581ebd3d54Sopenharmony_ci EXPECT_NE(systemAbilityManager, nullptr); 591ebd3d54Sopenharmony_ci 601ebd3d54Sopenharmony_ci sptr<IRemoteObject> remoteObject = 611ebd3d54Sopenharmony_ci systemAbilityManager->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID); 621ebd3d54Sopenharmony_ci EXPECT_NE(remoteObject, nullptr); 631ebd3d54Sopenharmony_ci} 641ebd3d54Sopenharmony_ci 651ebd3d54Sopenharmony_ci/* 661ebd3d54Sopenharmony_ci * @tc.name: BgtaskDumpTest_ShellDump_001 671ebd3d54Sopenharmony_ci * @tc.desc: Shell dump 681ebd3d54Sopenharmony_ci * @tc.type: FUNC 691ebd3d54Sopenharmony_ci * @tc.require: SR000GGTJU AR000GH85V 701ebd3d54Sopenharmony_ci */ 711ebd3d54Sopenharmony_ciHWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_001, Function | MediumTest | Level0) 721ebd3d54Sopenharmony_ci{ 731ebd3d54Sopenharmony_ci std::vector<std::string> infos; 741ebd3d54Sopenharmony_ci std::vector<std::string> options; 751ebd3d54Sopenharmony_ci options.push_back("-T"); 761ebd3d54Sopenharmony_ci options.push_back("All"); 771ebd3d54Sopenharmony_ci auto ret = DelayedSingleton<BgTransientTaskMgr>::GetInstance()->ShellDump(options, infos); 781ebd3d54Sopenharmony_ci EXPECT_EQ(ret, 0); 791ebd3d54Sopenharmony_ci} 801ebd3d54Sopenharmony_ci 811ebd3d54Sopenharmony_ci/* 821ebd3d54Sopenharmony_ci * @tc.name: BgtaskDumpTest_ShellDump_002 831ebd3d54Sopenharmony_ci * @tc.desc: Shell dump 841ebd3d54Sopenharmony_ci * @tc.type: FUNC 851ebd3d54Sopenharmony_ci * @tc.require: SR000GGT80 AR000GH6EQ 861ebd3d54Sopenharmony_ci */ 871ebd3d54Sopenharmony_ciHWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_002, Function | MediumTest | Level0) 881ebd3d54Sopenharmony_ci{ 891ebd3d54Sopenharmony_ci std::vector<std::string> infos; 901ebd3d54Sopenharmony_ci std::vector<std::string> options; 911ebd3d54Sopenharmony_ci options.push_back("-C"); 921ebd3d54Sopenharmony_ci options.push_back("--all"); 931ebd3d54Sopenharmony_ci auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos); 941ebd3d54Sopenharmony_ci EXPECT_EQ(ret, 0); 951ebd3d54Sopenharmony_ci} 961ebd3d54Sopenharmony_ci 971ebd3d54Sopenharmony_ci/* 981ebd3d54Sopenharmony_ci * @tc.name: BgtaskDumpTest_ShellDump_003 991ebd3d54Sopenharmony_ci * @tc.desc: Shell dump 1001ebd3d54Sopenharmony_ci * @tc.type: FUNC 1011ebd3d54Sopenharmony_ci * @tc.require: issueI936BL 1021ebd3d54Sopenharmony_ci */ 1031ebd3d54Sopenharmony_ciHWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_003, Function | MediumTest | Level0) 1041ebd3d54Sopenharmony_ci{ 1051ebd3d54Sopenharmony_ci std::vector<std::string> infos; 1061ebd3d54Sopenharmony_ci std::vector<std::string> options; 1071ebd3d54Sopenharmony_ci options.push_back("-T"); 1081ebd3d54Sopenharmony_ci options.push_back("PAUSE"); 1091ebd3d54Sopenharmony_ci options.push_back("-1"); 1101ebd3d54Sopenharmony_ci auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos); 1111ebd3d54Sopenharmony_ci EXPECT_EQ(ret, 0); 1121ebd3d54Sopenharmony_ci} 1131ebd3d54Sopenharmony_ci 1141ebd3d54Sopenharmony_ci/* 1151ebd3d54Sopenharmony_ci * @tc.name: BgtaskDumpTest_ShellDump_004 1161ebd3d54Sopenharmony_ci * @tc.desc: Shell dump 1171ebd3d54Sopenharmony_ci * @tc.type: FUNC 1181ebd3d54Sopenharmony_ci * @tc.require: issueI936BL 1191ebd3d54Sopenharmony_ci */ 1201ebd3d54Sopenharmony_ciHWTEST_F(BgtaskDumpTest, BgtaskDumpTest_ShellDump_004, Function | MediumTest | Level0) 1211ebd3d54Sopenharmony_ci{ 1221ebd3d54Sopenharmony_ci std::vector<std::string> infos; 1231ebd3d54Sopenharmony_ci std::vector<std::string> options; 1241ebd3d54Sopenharmony_ci options.push_back("-T"); 1251ebd3d54Sopenharmony_ci options.push_back("START"); 1261ebd3d54Sopenharmony_ci options.push_back("-1"); 1271ebd3d54Sopenharmony_ci auto ret = BgContinuousTaskMgr::GetInstance()->ShellDumpInner(options, infos); 1281ebd3d54Sopenharmony_ci EXPECT_EQ(ret, 0); 1291ebd3d54Sopenharmony_ci} 1301ebd3d54Sopenharmony_ci} // namespace BackgroundTaskMgr 1311ebd3d54Sopenharmony_ci} // namespace OHOS 132