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 "battery_subscriber_test.h" 17 18 #include <iostream> 19 #include <csignal> 20 #include <chrono> 21 #include <condition_variable> 22 #include <fstream> 23 #include <memory> 24 #include <mutex> 25 #include <streambuf> 26 #include <string> 27 #include <thread> 28 #include <vector> 29 #include <sys/stat.h> 30 31 using namespace testing::ext; 32 using namespace OHOS::PowerMgr; 33 using namespace OHOS::EventFwk; 34 using namespace OHOS; 35 using namespace std; 36 37 /** 38 * @tc.name: BatteryService001 39 * @tc.desc: Test functions subscriber 40 * @tc.type: FUNC 41 */ 42 static HWTEST_F (BatterySubscriberTest, BatteryService001, TestSize.Level1) 43 { 44 BATTERY_HILOGD(LABEL_TEST, "BatteryService::BatteryService001 start."); 45 const std::string EVENT = CommonEventSupport::COMMON_EVENT_BATTERY_CHANGED; 46 MatchingSkills matchingSkills; 47 matchingSkills.AddEvent(EVENT); 48 CommonEventSubscribeInfo subscriberInfo(matchingSkills); 49 std::shared_ptr<SubscriberTest> subscriber = std::make_shared<SubscriberTest>(subscriberInfo); 50 bool subscribeResult = CommonEventManager::SubscribeCommonEvent(subscriber); 51 BATTERY_HILOGD(LABEL_TEST, "subscribeResult=%{public}d", subscribeResult); 52 53 sleep(5); 54 BATTERY_HILOGD(LABEL_TEST, "BatteryService::BatteryService001 end."); 55 } 56