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