• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "power_wakeup_parse_test.h"
16 #include <fstream>
17 #include <thread>
18 #include <unistd.h>
19 
20 #ifdef THERMAL_GTEST
21 #define private   public
22 #define protected public
23 #endif
24 
25 #include <datetime_ex.h>
26 #include <input_manager.h>
27 #include <securec.h>
28 
29 #include "power_mgr_service.h"
30 #include "power_state_machine.h"
31 #include "setting_helper.h"
32 
33 using namespace testing::ext;
34 using namespace OHOS::PowerMgr;
35 using namespace OHOS;
36 using namespace std;
37 static sptr<PowerMgrService> g_service;
38 
SetUpTestCase(void)39 void PowerWakeupParseTest::SetUpTestCase(void)
40 {
41     g_service = DelayedSpSingleton<PowerMgrService>::GetInstance();
42     g_service->OnStart();
43 }
44 
TearDownTestCase(void)45 void PowerWakeupParseTest::TearDownTestCase(void)
46 {
47     g_service->OnStop();
48     DelayedSpSingleton<PowerMgrService>::DestroyInstance();
49 }
50 
51 namespace {
52 static const constexpr uint32_t DOUBLC_CLICK_INNER = 2;
53 static const std::string SYSTEM_POWER_WAKEUP_DB_STRING =
54     "{\"powerkey\": {\"enable\": false},\"keyborad\": {\"enable\": false},\"mouse\": {\"enable\": "
55     "false},\"touchscreen\": {\"enable\": false,\"click\": 2},\"touchpad\": {\"enable\": false},\"pen\": {\"enable\": "
56     "false},\"lid\": {\"enable\": false},\"switch\": {\"enable\": false}}";
57 static const std::string SYSTEM_POWER_WAKEUP_FILE = "./power_wakeup.json";
58 
TestPowerWakeup(PowerMgrService * pmsTest_)59 void TestPowerWakeup(PowerMgrService* pmsTest_)
60 {
61     vector<WakeupSource>::iterator itb = pmsTest_->wakeupController_->sourceList_.begin();
62     vector<WakeupSource>::iterator ite = pmsTest_->wakeupController_->sourceList_.end();
63     vector<WakeupSource>::iterator it = itb;
64 
65     for (; it != ite; it++) {
66         if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_POWER_BUTTON) {
67             if (it->IsEnable() != true) {
68                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
69             }
70         } else if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_KEYBOARD) {
71             if (it->IsEnable() != true) {
72                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
73             }
74         } else if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_TOUCH_SCREEN) {
75             if (it->IsEnable() != true) {
76                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
77             }
78             if (it->GetClick() != DOUBLC_CLICK_INNER) {
79                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Click";
80             }
81         } else if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_TOUCHPAD) {
82             if (it->IsEnable() != true) {
83                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
84             }
85         } else if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_PEN) {
86             if (it->IsEnable() != true) {
87                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
88             }
89         } else if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_LID) {
90             if (it->IsEnable() != true) {
91                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
92             }
93         } else if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_SWITCH) {
94             if (it->IsEnable() != true) {
95                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
96             }
97         } else if (it->GetReason() == WakeupDeviceType::WAKEUP_DEVICE_MOUSE) {
98             if (it->IsEnable() != true) {
99                 GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to parse Enable";
100             }
101         }
102     }
103 }
104 
105 /**
106  * @tc.name: PowerWakeupParse001
107  * @tc.desc: test Wakeup source parse
108  * @tc.type: FUNC
109  */
110 HWTEST_F(PowerWakeupParseTest, PowerWakeupParse001, TestSize.Level0)
111 {
112     GTEST_LOG_(INFO) << "PowerSuspendParse001: start";
113     std::string str = SYSTEM_POWER_WAKEUP_FILE;
114 
115     auto pmsTest_ = DelayedSpSingleton<PowerMgrService>::GetInstance();
116     if (pmsTest_ == nullptr) {
117         GTEST_LOG_(INFO) << "PowerWakeupParse001: Failed to get PowerMgrService";
118     }
119 
120     pmsTest_->Init();
121     pmsTest_->WakeupControllerInit();
122     pmsTest_->wakeupController_->Init();
123 
124     TestPowerWakeup(pmsTest_);
125 
126     GTEST_LOG_(INFO) << "PowerWakeupParse001:  end";
127 }
128 } // namespace