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 002
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 KillProcess 001
66 * @tc.desc: Verify if killProcess is success
67 * @tc.type: FUNC
68 * @tc.require: issueI6D6BM
69 * @tc.author:qiunaiguang
70 */
71 HWTEST_F(ResSchedMgrTest, KillProcess001, TestSize.Level1)
72 {
73 ResSchedMgr::GetInstance().KillProcessByClient(nullptr, "resource");
74 nlohmann::json payload;
75 ResSchedMgr::GetInstance().KillProcessByClient(payload, "resource");
76 payload["pid"] = 1234567;
77 ResSchedMgr::GetInstance().KillProcessByClient(payload, "resource");
78 payload["pid"] = "0";
79 ResSchedMgr::GetInstance().KillProcessByClient(payload, "resource");
80 payload["pid"] = "1234567";
81 ResSchedMgr::GetInstance().KillProcessByClient(payload, "resource");
82 ResSchedMgr::GetInstance().KillProcessByClient(payload, "samgr");
83 EXPECT_TRUE(ResSchedMgr::GetInstance().killProcess_ != nullptr);
84 }
85 } // namespace ResourceSchedule
86 } // namespace OHOS
87