1 /*
2  * Copyright (c) 2021-2024 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 "power_mgr_dump_test.h"
17 
18 #include <csignal>
19 #include <iostream>
20 
21 #define private public
22 #define protected public
23 #include "power_mgr_service.h"
24 #undef private
25 #undef protected
26 #include "power_mgr_dumper.h"
27 #include "key_event.h"
28 #include "pointer_event.h"
29 #include "power_log.h"
30 
31 using namespace testing::ext;
32 using namespace OHOS::PowerMgr;
33 using namespace OHOS;
34 using namespace std;
35 
36 namespace {
37 auto g_pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance();
38 }
39 
SetUpTestCase()40 void PowerMgrDumpTest::SetUpTestCase()
41 {
42     g_pmsTest->isBootCompleted_ = true;
43 }
44 
TearDownTestCase()45 void PowerMgrDumpTest::TearDownTestCase()
46 {
47 }
48 
SetUp(void)49 void PowerMgrDumpTest::SetUp(void)
50 {
51 }
52 
TearDown(void)53 void PowerMgrDumpTest::TearDown(void)
54 {
55 }
56 
57 namespace {
58 /**
59  * @tc.name: PowerMgrDumpNative001
60  * @tc.desc: Test that args in PowerMgrDump is -i.
61  * @tc.type: FUNC
62  */
HWTEST_F(PowerMgrDumpTest, PowerMgrDumpNative001, TestSize.Level0)63 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative001, TestSize.Level0)
64 {
65     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative001 start");
66     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative001 fail to get PowerMgrService";
67     int32_t fd = 1;
68     std::vector<std::u16string> args;
69     std::u16string arg = u"-i";
70     args.push_back(arg);
71     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
72     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative001 end");
73 }
74 
75 /**
76  * @tc.name: PowerMgrDumpNative002
77  * @tc.desc: Test that args in PowerMgrDump is -k.
78  * @tc.type: FUNC
79  */
HWTEST_F(PowerMgrDumpTest, PowerMgrDumpNative002, TestSize.Level0)80 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative002, TestSize.Level0)
81 {
82     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative002 start");
83     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative002 fail to get PowerMgrService";
84     int32_t fd = 1;
85     std::vector<std::u16string> args;
86     std::u16string arg = u"-k";
87     args.push_back(arg);
88     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
89     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative002 end");
90 }
91 
92 /**
93  * @tc.name: PowerMgrDumpNative003
94  * @tc.desc: Test that args in PowerMgrDump is -r, -s, -a.
95  * @tc.type: FUNC
96  */
HWTEST_F(PowerMgrDumpTest, PowerMgrDumpNative003, TestSize.Level0)97 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative003, TestSize.Level0)
98 {
99     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative003 start");
100     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative003 fail to get PowerMgrService";
101     int32_t fd = 1;
102     std::vector<std::u16string> args;
103     std::u16string arg = u"-r";
104     std::u16string arg1 = u"-s";
105     std::u16string arg2 = u"-a";
106     args.push_back(arg);
107     args.push_back(arg1);
108     args.push_back(arg2);
109     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
110     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative003 end");
111 }
112 
113 /**
114  * @tc.name: PowerMgrDumpNative004
115  * @tc.desc: Test that args in PowerMgrDump is -h.
116  * @tc.type: FUNC
117  */
HWTEST_F(PowerMgrDumpTest, PowerMgrDumpNative004, TestSize.Level0)118 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative004, TestSize.Level0)
119 {
120     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative004 start");
121     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative004 fail to get PowerMgrService";
122     int32_t fd = 1;
123     std::vector<std::u16string> args;
124     std::u16string arg = u"-h";
125     args.push_back(arg);
126     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
127     POWER_HILOGD(LABEL_TEST, "PowerMgrDumpNative004 end");
128 }
129 } // namespace
130