• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <iostream>
17 #include <string>
18 
19 #include "common_event_manager.h"
20 #include "ces_system_test.h"
21 #define private public
22 #define protected public
23 #undef private
24 #undef protected
25 
26 #include "datetime_ex.h"
27 
28 #include "power_common.h"
29 #include "power_mgr_client.h"
30 #include "power_mgr_service.h"
31 #include "power_state_machine.h"
32 #include "sys_param.h"
33 
34 using namespace testing::ext;
35 using namespace OHOS::EventFwk;
36 using namespace OHOS::PowerMgr;
37 
38 namespace {
39 std::mutex g_mtx;
40 
41 const std::string COMPARE_STR = "cesComparesStrForCase";
42 const std::string COMPARE_STR_FALSE = "cesComparesStrForCaseFalse";
43 }  // namespace
44 
CommonEventServiCesSystemTest(const CommonEventSubscribeInfo & subscriberInfo)45 CesSystemTest::CommonEventServiCesSystemTest::CommonEventServiCesSystemTest(
46     const CommonEventSubscribeInfo &subscriberInfo)
47     : CommonEventSubscriber(subscriberInfo)
48 {}
49 
OnReceiveEvent(const CommonEventData & data)50 void CesSystemTest::CommonEventServiCesSystemTest::OnReceiveEvent(const CommonEventData &data)
51 {
52     std::string action = data.GetWant().GetAction();
53     if (action == CommonEventSupport::COMMON_EVENT_SHUTDOWN) {
54         POWER_HILOGD(MODULE_SERVICE, "CommonEventServiCesSystemTest::OnReceiveEvent.");
55     }
56     POWER_HILOGD(MODULE_SERVICE, "CommonEventServiCesSystemTest::OnReceiveEvent other.");
57 }
58 
SetUpTestCase()59 void CesSystemTest::SetUpTestCase()
60 {}
61 
TearDownTestCase()62 void CesSystemTest::TearDownTestCase()
63 {}
64 
SetUp()65 void CesSystemTest::SetUp()
66 {}
67 
TearDown()68 void CesSystemTest::TearDown()
69 {}
70 
71 namespace {
72 /*
73  * @tc.number: CES_SubscriptionEvent_0100
74  * @tc.name: SubscribeCommonEvent
75  * @tc.desc: Verify the function when the input string is normal
76  */
77 HWTEST_F(CesSystemTest, CES_SubscriptionEvent_0100, Function | MediumTest | Level1)
78 {
79     bool result = false;
80     MatchingSkills matchingSkills;
81     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SHUTDOWN);
82     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
83     auto subscriberPtr = std::make_shared<CommonEventServiCesSystemTest>(subscribeInfo);
84     result = CommonEventManager::SubscribeCommonEvent(subscriberPtr);
85     EXPECT_TRUE(result);
86     GTEST_LOG_(INFO) << "CES_SubscriptionEvent_0100: ShutDownDevice start.";
87     auto& powerMgrClient = PowerMgrClient::GetInstance();
88     if (false) {
89         powerMgrClient.ShutDownDevice(string("ShutDownDeviceTest001"));
90         sleep(SLEEP_WAIT_TIME_S);
91     }
92     CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
93 }
94 }