• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef HAS_MULTIMODALINPUT_INPUT_PART
28 #include "key_event.h"
29 #include "pointer_event.h"
30 #endif
31 #include "power_log.h"
32 
33 using namespace testing::ext;
34 using namespace OHOS::PowerMgr;
35 using namespace OHOS;
36 using namespace std;
37 
38 namespace {
39 auto g_pmsTest = DelayedSpSingleton<PowerMgrService>::GetInstance();
40 }
41 
SetUpTestCase()42 void PowerMgrDumpTest::SetUpTestCase()
43 {
44     g_pmsTest->isBootCompleted_ = true;
45 }
46 
TearDownTestCase()47 void PowerMgrDumpTest::TearDownTestCase()
48 {
49 }
50 
SetUp(void)51 void PowerMgrDumpTest::SetUp(void)
52 {
53 }
54 
TearDown(void)55 void PowerMgrDumpTest::TearDown(void)
56 {
57 }
58 
59 namespace {
60 /**
61  * @tc.name: PowerMgrDumpNative001
62  * @tc.desc: Test that args in PowerMgrDump is -i.
63  * @tc.type: FUNC
64  */
65 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative001, TestSize.Level1)
66 {
67     GTEST_LOG_(INFO) << "PowerMgrDumpNative001 function start!";
68     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative001 function start!");
69     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative001 fail to get PowerMgrService";
70     int32_t fd = 1;
71     std::vector<std::u16string> args;
72     std::u16string arg = u"-i";
73     args.push_back(arg);
74     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
75     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative001 function end!");
76     GTEST_LOG_(INFO) << "PowerMgrDumpNative001 function end!";
77 }
78 
79 /**
80  * @tc.name: PowerMgrDumpNative002
81  * @tc.desc: Test that args in PowerMgrDump is -k.
82  * @tc.type: FUNC
83  */
84 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative002, TestSize.Level1)
85 {
86     GTEST_LOG_(INFO) << "PowerMgrDumpNative002 function start!";
87     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative002 function start!");
88     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative002 fail to get PowerMgrService";
89     int32_t fd = 1;
90     std::vector<std::u16string> args;
91     std::u16string arg = u"-k";
92     args.push_back(arg);
93     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
94     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative002 function end!");
95     GTEST_LOG_(INFO) << "PowerMgrDumpNative002 function end!";
96 }
97 
98 /**
99  * @tc.name: PowerMgrDumpNative003
100  * @tc.desc: Test that args in PowerMgrDump is -r, -s, -a.
101  * @tc.type: FUNC
102  */
103 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative003, TestSize.Level1)
104 {
105     GTEST_LOG_(INFO) << "PowerMgrDumpNative003 function start!";
106     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative003 function start!");
107     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative003 fail to get PowerMgrService";
108     int32_t fd = 1;
109     std::vector<std::u16string> args;
110     std::u16string arg = u"-r";
111     std::u16string arg1 = u"-s";
112     std::u16string arg2 = u"-a";
113     args.push_back(arg);
114     args.push_back(arg1);
115     args.push_back(arg2);
116     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
117     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative003 function end!");
118     GTEST_LOG_(INFO) << "PowerMgrDumpNative003 function end!";
119 }
120 
121 /**
122  * @tc.name: PowerMgrDumpNative004
123  * @tc.desc: Test that args in PowerMgrDump is -h.
124  * @tc.type: FUNC
125  */
126 HWTEST_F (PowerMgrDumpTest, PowerMgrDumpNative004, TestSize.Level1)
127 {
128     GTEST_LOG_(INFO) << "PowerMgrDumpNative004 function start!";
129     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative004 function start!");
130     EXPECT_TRUE(g_pmsTest != nullptr) << "PowerMgrDumpNative004 fail to get PowerMgrService";
131     int32_t fd = 1;
132     std::vector<std::u16string> args;
133     std::u16string arg = u"-h";
134     args.push_back(arg);
135     EXPECT_TRUE(g_pmsTest->Dump(fd, args) == ERR_OK);
136     POWER_HILOGI(LABEL_TEST, "PowerMgrDumpNative004 function end!");
137     GTEST_LOG_(INFO) << "PowerMgrDumpNative004 function end!";
138 }
139 } // namespace
140