1 /*
2  * Copyright (c) 2023 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 #include "gtest/gtest.h"
16 
17 #include "bundle_manager_helper.h"
18 #include "app_mgr_helper.h"
19 #include "ability_manager_helper.h"
20 #ifdef ENABLE_BACKGROUND_TASK_MGR
21 #include "background_task_helper.h"
22 #endif
23 #include "standby_service_log.h"
24 
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace DevStandbyMgr {
29 class MockStandbyHelperUnitTest : public testing::Test {
30 public:
SetUpTestCase()31     static void SetUpTestCase() {}
TearDownTestCase()32     static void TearDownTestCase() {}
SetUp()33     void SetUp() override {}
TearDown()34     void TearDown() override {}
35 };
36 
37 /**
38  * @tc.name: MockStandbyHelperUnitTest_001
39  * @tc.desc: test AppMgrHelper.
40  * @tc.type: FUNC
41  * @tc.require:
42  */
43 HWTEST_F(MockStandbyHelperUnitTest, MockStandbyHelperUnitTest_001, TestSize.Level1)
44 {
45     std::vector<AppExecFwk::RunningProcessInfo> allAppProcessInfos;
46     bool isRunning {false};
47     sptr<AppExecFwk::IApplicationStateObserver> observer {nullptr};
48     AppMgrHelper::GetInstance()->GetAllRunningProcesses(allAppProcessInfos);
49     AppMgrHelper::GetInstance()->GetAppRunningStateByBundleName("", isRunning);
50     AppMgrHelper::GetInstance()->SubscribeObserver(observer);
51     AppMgrHelper::GetInstance()->UnsubscribeObserver(observer);
52     AppMgrHelper::GetInstance()->Connect();
53     EXPECT_TRUE(allAppProcessInfos.empty());
54 }
55 
56 /**
57  * @tc.name: MockStandbyHelperUnitTest_002
58  * @tc.desc: test BundleManagerHelper.
59  * @tc.type: FUNC
60  * @tc.require:
61  */
62 HWTEST_F(MockStandbyHelperUnitTest, MockStandbyHelperUnitTest_002, TestSize.Level1)
63 {
64     int32_t uid {0};
65     BundleManagerHelper::GetInstance()->GetClientBundleName(uid);
66 
67     AppExecFwk::ApplicationInfo appInfo;
68     BundleManagerHelper::GetInstance()->GetApplicationInfo("", AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO,
69         0, appInfo);
70 
71     std::vector<AppExecFwk::ApplicationInfo> appInfos {};
72     BundleManagerHelper::GetInstance()->GetApplicationInfos(AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO,
73         0, appInfos);
74 
75     EXPECT_FALSE(appInfo.runningResourcesApply);
76 }
77 
78 #ifdef ENABLE_BACKGROUND_TASK_MGR
79 /**
80  * @tc.name: MockStandbyHelperUnitTest_003
81  * @tc.desc: test BackgroundTaskHelper.
82  * @tc.type: FUNC
83  * @tc.require:
84  */
85 HWTEST_F(MockStandbyHelperUnitTest, MockStandbyHelperUnitTest_003, TestSize.Level1)
86 {
87     std::vector<std::shared_ptr<OHOS::BackgroundTaskMgr::ContinuousTaskCallbackInfo>> list;
88     BackgroundTaskHelper::GetInstance()->GetContinuousTaskApps(list);
89     EXPECT_TRUE(list.empty());
90     std::vector<std::shared_ptr<OHOS::BackgroundTaskMgr::TransientTaskAppInfo>> appInfoList;
91     BackgroundTaskHelper::GetInstance()->GetTransientTaskApps(appInfoList);
92 }
93 #endif
94 }  // namespace DevStandbyMgr
95 }  // namespace OHOS
96