1 /*
2 * Copyright (c) 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 <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
33 using namespace testing::ext;
34 using namespace OHOS::EventFwk;
35 using namespace OHOS::PowerMgr;
36
CommonEventServiCesSystemTest(const CommonEventSubscribeInfo & subscriberInfo)37 CesSystemTest::CommonEventServiCesSystemTest::CommonEventServiCesSystemTest(
38 const CommonEventSubscribeInfo &subscriberInfo)
39 : CommonEventSubscriber(subscriberInfo)
40 {}
41
OnReceiveEvent(const CommonEventData & data)42 void CesSystemTest::CommonEventServiCesSystemTest::OnReceiveEvent(const CommonEventData &data)
43 {
44 std::string action = data.GetWant().GetAction();
45 if (action == CommonEventSupport::COMMON_EVENT_SHUTDOWN) {
46 POWER_HILOGI(LABEL_TEST, "CommonEventServiCesSystemTest::OnReceiveEvent.");
47 }
48 POWER_HILOGI(LABEL_TEST, "CommonEventServiCesSystemTest::OnReceiveEvent other.");
49 }
50
SetUpTestCase()51 void CesSystemTest::SetUpTestCase()
52 {}
53
TearDownTestCase()54 void CesSystemTest::TearDownTestCase()
55 {}
56
SetUp()57 void CesSystemTest::SetUp()
58 {}
59
TearDown()60 void CesSystemTest::TearDown()
61 {}
62
63 namespace {
64 /*
65 * @tc.number: CES_SubscriptionEvent_01
66 * @tc.name: SubscribeCommonEvent
67 * @tc.desc: Verify the function when the input string is normal
68 */
69 HWTEST_F(CesSystemTest, CES_SubscriptionEvent_01, Function | MediumTest | Level1)
70 {
71 POWER_HILOGI(LABEL_TEST, "CES_SubscriptionEvent_01 function start!");
72 bool result = false;
73 MatchingSkills matchingSkills;
74 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SHUTDOWN);
75 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
76 auto subscriberPtr = std::make_shared<CommonEventServiCesSystemTest>(subscribeInfo);
77 result = CommonEventManager::SubscribeCommonEvent(subscriberPtr);
78 EXPECT_TRUE(result);
79 GTEST_LOG_(INFO) << "CES_SubscriptionEvent_01: ShutDownDevice start.";
80 auto& powerMgrClient = PowerMgrClient::GetInstance();
81 if (false) {
82 powerMgrClient.ShutDownDevice(string("ShutDownDeviceTest001"));
83 sleep(SLEEP_WAIT_TIME_S);
84 }
85 CommonEventManager::UnSubscribeCommonEvent(subscriberPtr);
86 POWER_HILOGI(LABEL_TEST, "CES_SubscriptionEvent_01 function end!");
87 }
88 }