1 /* 2 * Copyright (c) 2022 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 #ifndef BATTERY_THREAD_TEST_H 17 #define BATTERY_THREAD_TEST_H 18 19 #include "battery_thread.h" 20 21 namespace OHOS { 22 namespace HDI { 23 namespace Battery { 24 namespace V1_2 { 25 namespace { 26 struct BatteryThreadUnitTest {}; 27 struct BatteryConfigUnitTest {}; 28 struct ChargerThreadUnitTest {}; 29 } // namespace 30 31 int32_t OpenUeventSocketTest(BatteryThread& bthread); 32 void UpdateEpollIntervalTest(const int32_t chargeState, BatteryThread& bthread); 33 int GetEpollIntervalTest(BatteryThread& bthread); 34 int32_t InitTest(void* service, BatteryThread& bthread); 35 int32_t GetEpollFdTest(BatteryThread& bthread); 36 int32_t InitUeventTest(BatteryThread& bthread); 37 int32_t GetUeventFdTest(BatteryThread& bthread); 38 39 template <typename Tag, typename PrivateFun, PrivateFun privateFun> 40 class OpenUeventSocketImplement { OpenUeventSocketTest(BatteryThread & bthread)41 friend int32_t OpenUeventSocketTest(BatteryThread& bthread) 42 { 43 return (bthread.*privateFun)(); 44 } 45 }; 46 47 template <typename Tag, typename PrivateFun, PrivateFun privateFun> 48 class UpdateEpollIntervalImplement { UpdateEpollIntervalTest(const int32_t chargeState,BatteryThread & bthread)49 friend void UpdateEpollIntervalTest(const int32_t chargeState, BatteryThread& bthread) 50 { 51 (bthread.*privateFun)(chargeState); 52 } 53 }; 54 55 template <typename Tag, typename PrivateFun, PrivateFun privateFun> 56 class GetEpollIntervalImplement { GetEpollIntervalTest(BatteryThread & bthread)57 friend int GetEpollIntervalTest(BatteryThread& bthread) 58 { 59 return (bthread.*privateFun); 60 } 61 }; 62 63 template <typename Tag, typename PrivateFun, PrivateFun privateFun> 64 class InitImplement { InitTest(void * service,BatteryThread & bthread)65 friend int32_t InitTest(void* service, BatteryThread& bthread) 66 { 67 return (bthread.*privateFun)(service); 68 } 69 }; 70 71 template <typename Tag, typename PrivateFun, PrivateFun privateFun> 72 class GetEpollFdImplement { GetEpollFdTest(BatteryThread & bthread)73 friend int32_t GetEpollFdTest(BatteryThread& bthread) 74 { 75 return (bthread.*privateFun); 76 } 77 }; 78 79 template <typename Tag, typename PrivateFun, PrivateFun privateFun> 80 class InitUeventImplement { InitUeventTest(BatteryThread & bthread)81 friend int32_t InitUeventTest(BatteryThread& bthread) 82 { 83 return (bthread.*privateFun)(); 84 } 85 }; 86 87 template <typename Tag, typename PrivateFun, PrivateFun privateFun> 88 class GetUeventFdImplement { GetUeventFdTest(BatteryThread & bthread)89 friend int32_t GetUeventFdTest(BatteryThread& bthread) 90 { 91 return (bthread.*privateFun); 92 } 93 }; 94 95 template class OpenUeventSocketImplement<BatteryThreadUnitTest, decltype(&BatteryThread::OpenUeventSocket), 96 &BatteryThread::OpenUeventSocket>; 97 98 template class UpdateEpollIntervalImplement<BatteryThreadUnitTest, decltype(&BatteryThread::UpdateEpollInterval), 99 &BatteryThread::UpdateEpollInterval>; 100 101 template class GetEpollIntervalImplement<BatteryThreadUnitTest, decltype(&BatteryThread::epollInterval_), 102 &BatteryThread::epollInterval_>; 103 104 template class InitImplement<BatteryThreadUnitTest, decltype(&BatteryThread::Init), &BatteryThread::Init>; 105 106 template class GetEpollFdImplement<BatteryThreadUnitTest, decltype(&BatteryThread::epFd_), &BatteryThread::epFd_>; 107 108 template class InitUeventImplement<BatteryThreadUnitTest, decltype(&BatteryThread::InitUevent), 109 &BatteryThread::InitUevent>; 110 111 template class GetUeventFdImplement<BatteryThreadUnitTest, decltype(&BatteryThread::ueventFd_), 112 &BatteryThread::ueventFd_>; 113 } // namespace V1_1 114 } // namespace Battery 115 } // namespace HDI 116 } // namespace OHOS 117 #endif // BATTERY_THREAD_TEST_H 118