• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #include "res_sched_mgr_test.h"
17 #include "application_state_observer_stub.h"
18 
19 using namespace std;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 using namespace AppExecFwk;
24 namespace ResourceSchedule {
25 namespace {
26     const string LIB_NAME = "libunittest_plugin.z.so";
27 }
28 
SetUpTestCase()29 void ResSchedMgrTest::SetUpTestCase() {}
30 
TearDownTestCase()31 void ResSchedMgrTest::TearDownTestCase() {}
32 
SetUp()33 void ResSchedMgrTest::SetUp() {}
34 
TearDown()35 void ResSchedMgrTest::TearDown() {}
36 
37 /**
38  * @tc.name: Init ressched mgr 001
39  * @tc.desc: Verify if can Init the plugin correctly
40  * @tc.type: FUNC
41  * @tc.require: issueI798UT
42  * @tc.author:xukuan
43  */
44 HWTEST_F(ResSchedMgrTest, Init001, TestSize.Level1)
45 {
46     ResSchedMgr::GetInstance().Init();
47     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
48 }
49 
50 /**
51  * @tc.name: Init ressched ReportData 001
52  * @tc.desc: Verify if ReportData is success
53  * @tc.type: FUNC
54  * @tc.require: issueI5WWV3
55  * @tc.author:lice
56  */
57 HWTEST_F(ResSchedMgrTest, ReportData001, TestSize.Level1)
58 {
59     nlohmann::json payload;
60     ResSchedMgr::GetInstance().ReportData(0, 0, payload);
61     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
62 }
63 
64 /**
65  * @tc.name: Init ressched ReportData 002
66  * @tc.desc: Verify if ReportData is success
67  * @tc.type: FUNC
68  * @tc.require: issueI897BM
69  */
70 HWTEST_F(ResSchedMgrTest, ReportData002, TestSize.Level1)
71 {
72     nlohmann::json payload;
73     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_REPORT_KEY_THREAD, 0, payload);
74     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
75 }
76 
77 /**
78  * @tc.name: Init ressched ReportData 003
79  * @tc.desc: Verify if ReportData is success
80  * @tc.type: FUNC
81  * @tc.require: issueI897BM
82  */
83 HWTEST_F(ResSchedMgrTest, ReportData003, TestSize.Level1)
84 {
85     nlohmann::json payload;
86     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_REPORT_WINDOW_STATE, 0, payload);
87     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
88 }
89 
90 /**
91  * @tc.name: Init ressched KillProcess 001
92  * @tc.desc: Verify if killProcess is success
93  * @tc.type: FUNC
94  * @tc.require: issueI6D6BM
95  * @tc.author:qiunaiguang
96  */
97 HWTEST_F(ResSchedMgrTest, KillProcess001, TestSize.Level1)
98 {
99     ResSchedMgr::GetInstance().KillProcessByClient(nullptr);
100     nlohmann::json payload;
101     ResSchedMgr::GetInstance().KillProcessByClient(payload);
102     payload["pid"] = 1234567;
103     payload["killReason"] = "0";
104     ResSchedMgr::GetInstance().KillProcessByClient(payload);
105     payload["pid"] = "0";
106     ResSchedMgr::GetInstance().KillProcessByClient(payload);
107     payload["pid"] = "-1";
108     ResSchedMgr::GetInstance().KillProcessByClient(payload);
109     payload["pid"] = "1234567";
110     ResSchedMgr::GetInstance().KillProcessByClient(payload);
111     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
112 }
113 
114 /**
115  * @tc.name: Init ressched ReportData 002
116  * @tc.desc: Verify if ReportData is success
117  * @tc.type: FUNC
118  * @tc.require:
119  */
120 HWTEST_F(ResSchedMgrTest, 002, TestSize.Level1)
121 {
122     nlohmann::json payload;
123     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE, 0, payload);
124     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
125 }
126 
127 /**
128  * @tc.name: Init ressched ReportData 003
129  * @tc.desc: Verify if ReportData is success
130  * @tc.type: FUNC
131  * @tc.require:
132  */
133 HWTEST_F(ResSchedMgrTest, 003, TestSize.Level1)
134 {
135     nlohmann::json payload;
136     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE, 0, payload);
137     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
138 }
139 
140 /**
141  * @tc.name: Init Executor plugin mgr 001
142  * @tc.desc: Verify if InitExecutorPlugin is success
143  * @tc.type: FUNC
144  */
145 HWTEST_F(ResSchedMgrTest, InitExecutorPlugin001, TestSize.Level1)
146 {
147     PluginMgr::GetInstance().Init();
148     ResSchedMgr::GetInstance().InitExecutorPlugin();
149     ResSchedMgr::GetInstance().InitExecutorPlugin(true);
150     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
151 }
152 
153 /**
154  * @tc.name: IsForegroundApp001
155  * @tc.desc: test func IsForegroundApp
156  * @tc.type: FUNC
157  */
158 HWTEST_F(ResSchedMgrTest, IsForegroundApp001, TestSize.Level1)
159 {
160     ResSchedMgr::GetInstance().InitForegroundAppInfo();
161     ResSchedMgr::GetInstance().OnApplicationStateChange((int32_t)ApplicationState::APP_STATE_FOREGROUND, 5000);
162     EXPECT_TRUE(ResSchedMgr::GetInstance().IsForegroundApp(5000));
163     ResSchedMgr::GetInstance().OnApplicationStateChange((int32_t)ApplicationState::APP_STATE_BACKGROUND, 5000);
164     EXPECT_FALSE(ResSchedMgr::GetInstance().IsForegroundApp(5000));
165     ResSchedMgr::GetInstance().OnApplicationStateChange((int32_t)ApplicationState::APP_STATE_FOREGROUND, 5000);
166     ResSchedMgr::GetInstance().OnApplicationStateChange((int32_t)ApplicationState::APP_STATE_TERMINATED, 5000);
167     EXPECT_FALSE(ResSchedMgr::GetInstance().IsForegroundApp(5000));
168     ResSchedMgr::GetInstance().OnApplicationStateChange((int32_t)ApplicationState::APP_STATE_FOREGROUND, 5000);
169     ResSchedMgr::GetInstance().OnApplicationStateChange((int32_t)ApplicationState::APP_STATE_END, 5000);
170     EXPECT_FALSE(ResSchedMgr::GetInstance().IsForegroundApp(5000));
171 }
172 } // namespace ResourceSchedule
173 } // namespace OHOS
174