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 
18 using namespace std;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace ResourceSchedule {
23 namespace {
24     const string LIB_NAME = "libunittest_plugin.z.so";
25 }
26 
SetUpTestCase()27 void ResSchedMgrTest::SetUpTestCase() {}
28 
TearDownTestCase()29 void ResSchedMgrTest::TearDownTestCase() {}
30 
SetUp()31 void ResSchedMgrTest::SetUp() {}
32 
TearDown()33 void ResSchedMgrTest::TearDown() {}
34 
35 /**
36  * @tc.name: Init ressched mgr 001
37  * @tc.desc: Verify if can Init the plugin correctly
38  * @tc.type: FUNC
39  * @tc.require: issueI798UT
40  * @tc.author:xukuan
41  */
42 HWTEST_F(ResSchedMgrTest, Init001, TestSize.Level1)
43 {
44     ResSchedMgr::GetInstance().Init();
45     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
46 }
47 
48 /**
49  * @tc.name: Init ressched ReportData 001
50  * @tc.desc: Verify if ReportData is success
51  * @tc.type: FUNC
52  * @tc.require: issueI5WWV3
53  * @tc.author:lice
54  */
55 HWTEST_F(ResSchedMgrTest, ReportData001, TestSize.Level1)
56 {
57     nlohmann::json payload;
58     ResSchedMgr::GetInstance().ReportData(0, 0, payload);
59     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
60 
61     ResSchedMgr::GetInstance().DispatchResourceInner(0, 0, payload);
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     ResSchedMgr::GetInstance().DispatchResourceInner(ResType::RES_TYPE_REPORT_KEY_THREAD, 0, payload);
77 }
78 
79 /**
80  * @tc.name: Init ressched ReportData 003
81  * @tc.desc: Verify if ReportData is success
82  * @tc.type: FUNC
83  * @tc.require: issueI897BM
84  */
85 HWTEST_F(ResSchedMgrTest, ReportData003, TestSize.Level1)
86 {
87     nlohmann::json payload;
88     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_REPORT_WINDOW_STATE, 0, payload);
89     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
90 
91     ResSchedMgr::GetInstance().DispatchResourceInner(ResType::RES_TYPE_REPORT_WINDOW_STATE, 0, payload);
92 }
93 
94 /**
95  * @tc.name: Init ressched KillProcess 001
96  * @tc.desc: Verify if killProcess is success
97  * @tc.type: FUNC
98  * @tc.require: issueI6D6BM
99  * @tc.author:qiunaiguang
100  */
101 HWTEST_F(ResSchedMgrTest, KillProcess001, TestSize.Level1)
102 {
103     ResSchedMgr::GetInstance().KillProcessByClient(nullptr);
104     nlohmann::json payload;
105     ResSchedMgr::GetInstance().KillProcessByClient(payload);
106     payload["pid"] = 1234567;
107     payload["killReason"] = "0";
108     ResSchedMgr::GetInstance().KillProcessByClient(payload);
109     payload["pid"] = "0";
110     ResSchedMgr::GetInstance().KillProcessByClient(payload);
111     payload["pid"] = "-1";
112     ResSchedMgr::GetInstance().KillProcessByClient(payload);
113     payload["pid"] = "1234567";
114     ResSchedMgr::GetInstance().KillProcessByClient(payload);
115     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
116 }
117 
118 /**
119  * @tc.name: Init ressched ReportData 002
120  * @tc.desc: Verify if ReportData is success
121  * @tc.type: FUNC
122  * @tc.require:
123  */
124 HWTEST_F(ResSchedMgrTest, 002, TestSize.Level1)
125 {
126     nlohmann::json payload;
127     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE, 0, payload);
128     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
129 
130     ResSchedMgr::GetInstance().DispatchResourceInner(ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE, 0, payload);
131 }
132 
133 /**
134  * @tc.name: Init ressched ReportData 003
135  * @tc.desc: Verify if ReportData is success
136  * @tc.type: FUNC
137  * @tc.require:
138  */
139 HWTEST_F(ResSchedMgrTest, 003, TestSize.Level1)
140 {
141     nlohmann::json payload;
142     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE, 0, payload);
143     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
144 
145     ResSchedMgr::GetInstance().DispatchResourceInner(ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE, 0, payload);
146 }
147 
148 /**
149  * @tc.name: Init Executor plugin mgr 001
150  * @tc.desc: Verify if InitExecutorPlugin is success
151  * @tc.type: FUNC
152  */
153 HWTEST_F(ResSchedMgrTest, InitExecutorPlugin001, TestSize.Level1)
154 {
155     PluginMgr::GetInstance().Init();
156     ResSchedMgr::GetInstance().InitExecutorPlugin();
157     ResSchedMgr::GetInstance().InitExecutorPlugin(true);
158     EXPECT_TRUE(PluginMgr::GetInstance().pluginSwitch_ != nullptr);
159     EXPECT_TRUE(PluginMgr::GetInstance().configReader_ != nullptr);
160 }
161 } // namespace ResourceSchedule
162 } // namespace OHOS
163