• 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 
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: Stop ressched mgr 001
120  * @tc.desc: Verify if stop is success
121  * @tc.type: FUNC
122  * @tc.require: issueI8VZVN
123  * @tc.author:z30053169
124  */
125 HWTEST_F(ResSchedMgrTest, Stop001, TestSize.Level1)
126 {
127     ResSchedMgr::GetInstance().Stop();
128     SUCCEED();
129 }
130 
131 /**
132  * @tc.name: Init ressched ReportData 002
133  * @tc.desc: Verify if ReportData is success
134  * @tc.type: FUNC
135  * @tc.require:
136  */
137 HWTEST_F(ResSchedMgrTest, 002, TestSize.Level1)
138 {
139     nlohmann::json payload;
140     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE, 0, payload);
141     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
142 
143     ResSchedMgr::GetInstance().DispatchResourceInner(ResType::RES_TYPE_WEBVIEW_SCREEN_CAPTURE, 0, payload);
144 }
145 
146 /**
147  * @tc.name: Init ressched ReportData 003
148  * @tc.desc: Verify if ReportData is success
149  * @tc.type: FUNC
150  * @tc.require:
151  */
152 HWTEST_F(ResSchedMgrTest, 003, TestSize.Level1)
153 {
154     nlohmann::json payload;
155     ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE, 0, payload);
156     EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
157 
158     ResSchedMgr::GetInstance().DispatchResourceInner(ResType::RES_TYPE_WEBVIEW_VIDEO_STATUS_CHANGE, 0, payload);
159 }
160 
161 /**
162  * @tc.name: Init Executor plugin mgr 001
163  * @tc.desc: Verify if InitExecutorPlugin is success
164  * @tc.type: FUNC
165  */
166 HWTEST_F(ResSchedMgrTest, InitExecutorPlugin001, TestSize.Level1)
167 {
168     PluginMgr::GetInstance().Init();
169     ResSchedMgr::GetInstance().InitExecutorPlugin();
170     ResSchedMgr::GetInstance().InitExecutorPlugin(true);
171     SUCCEED();
172 }
173 } // namespace ResourceSchedule
174 } // namespace OHOS
175