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 #ifndef OHOS_MOCK_AP_SERVICE_H 17 #define OHOS_MOCK_AP_SERVICE_H 18 19 #include "ap_root_state.h" 20 #include "ap_idle_state.h" 21 #include "ap_started_state.h" 22 #include "ap_service.h" 23 #include "ap_state_machine.h" 24 #include "ap_monitor.h" 25 #include "ap_config_use.h" 26 #include "ap_stations_manager.h" 27 #include "wifi_logger.h" 28 29 namespace OHOS { 30 namespace Wifi { 31 32 class ApStateMachine; 33 class MockApRootState : public ApRootState { 34 public: 35 void GoInState(); 36 void GoOutState(); 37 bool ExecuteStateMsg(InternalMessagePtr msg); 38 }; /* ApRootState */ 39 40 class MockApIdleState : public ApIdleState { 41 public: MockApIdleState(ApStateMachine & apStateMachine)42 explicit MockApIdleState(ApStateMachine &apStateMachine) : ApIdleState(apStateMachine) 43 {} 44 void GoInState(); 45 void GoOutState(); 46 bool ExecuteStateMsg(InternalMessagePtr msg); 47 }; 48 49 class MockApStartedState : public ApStartedState { 50 public: MockApStartedState(ApStateMachine & apStateMachine,ApConfigUse & apConfigUse,ApMonitor & apMonitor)51 MockApStartedState(ApStateMachine &apStateMachine, ApConfigUse &apConfigUse, ApMonitor &apMonitor) 52 : ApStartedState(apStateMachine, apConfigUse, apMonitor) 53 {} 54 void GoInState(); 55 void GoOutState(); 56 bool ExecuteStateMsg(InternalMessagePtr msg); 57 }; 58 59 class MockApService : public ApService { 60 public: MockApService(ApStateMachine & apStateMachine)61 explicit MockApService(ApStateMachine &apStateMachine) : ApService(apStateMachine) 62 {} 63 ErrCode EnableHotspot(); 64 ErrCode DisableHotspot(); 65 ErrCode AddBlockList(const StationInfo &stationInfo); 66 ErrCode DelBlockList(const StationInfo &stationInfo); 67 ErrCode SetHotspotConfig(const HotspotConfig &hotspotConfig); 68 ErrCode DisconnetStation(const StationInfo &stationInfo); 69 ErrCode GetValidBands(std::vector<BandType> &bands); 70 ErrCode GetValidChannels(BandType band, std::vector<int32_t> &validchannel); 71 ErrCode RegisterApServiceCallbacks(const IApServiceCallbacks &callbacks); 72 }; 73 74 class MockApStateMachine : public ApStateMachine { 75 public: MockApStateMachine(ApStationsManager & apStationsManager,ApRootState & apRootState,ApIdleState & apIdleState,ApStartedState & apStartedState,ApMonitor & apMonitor)76 MockApStateMachine(ApStationsManager &apStationsManager, ApRootState &apRootState, ApIdleState &apIdleState, 77 ApStartedState &apStartedState, ApMonitor &apMonitor) 78 : ApStateMachine(apStationsManager, apRootState, apIdleState, apStartedState, apMonitor) 79 {} ~MockApStateMachine()80 ~MockApStateMachine() 81 {} 82 void SwitchState(State *targetState); 83 void CreateMessage(); 84 void SendMessage(int what); 85 void SendMessage(int what, int arg1); 86 void SendMessage(int what, int arg1, int arg2); 87 void SendMessage(InternalMessagePtr msg); 88 void StartTimer(int timerName, int64_t interval); 89 void StopTimer(int timerName); 90 }; 91 92 class MockApMonitor : public ApMonitor { 93 public: 94 void StationChangeEvent(StationInfo &staInfo, const int event); 95 void StartMonitor(); 96 void StopMonitor(); 97 }; 98 99 class MockApConfigUse : public ApConfigUse { 100 public: 101 void UpdateApChannelConfig(HotspotConfig &apConfig); 102 void JudgeConflictBand(HotspotConfig &apConfig); 103 int GetBestChannelFor2G(); 104 int GetBestChannelFor5G(); 105 std::vector<int> GetChannelFromDrvOrXmlByBand(const BandType &bandType); 106 void FilterIndoorChannel(std::vector<int> &channels); 107 void Filter165Channel(std::vector<int> &channels); 108 void JudgeDbacWithP2p(HotspotConfig &apConfig); 109 std::set<int> GetIndoorChanByCountryCode(const std::string &countryCode); 110 std::vector<int> GetPreferredChannelByBand(const BandType &bandType); 111 }; 112 113 class MockApStationsManager : public ApStationsManager { 114 public: 115 bool AddBlockList(const StationInfo &staInfo); 116 bool DelBlockList(const StationInfo &staInfo); 117 bool EnableAllBlockList(); 118 void StationLeave(const std::string &mac); 119 void StationJoin(const StationInfo &staInfo); 120 bool DisConnectStation(const StationInfo &staInfo); 121 std::vector<std::string> GetAllConnectedStations(); 122 }; 123 124 class MockPendant { 125 public: MockPendant()126 MockPendant() 127 : mockApRootState(), 128 mockApIdleState(mockApStateMachine), 129 mockApStartedState(mockApStateMachine, mockApConfigUse, mockApMonitor), 130 mockApService(mockApStateMachine), 131 mockApStateMachine( 132 mockApStationsManager, mockApRootState, mockApIdleState, mockApStartedState, mockApMonitor), 133 mockApConfigUse(), 134 mockApStationsManager() 135 {} 136 137 public: GetMockApRootState()138 MockApRootState &GetMockApRootState() 139 { 140 return mockApRootState; 141 } 142 GetMockApIdleState()143 MockApIdleState &GetMockApIdleState() 144 { 145 return mockApIdleState; 146 } 147 GetMockApStartedState()148 MockApStartedState &GetMockApStartedState() 149 { 150 return mockApStartedState; 151 } 152 GetMockApService()153 MockApService &GetMockApService() 154 { 155 return mockApService; 156 } 157 GetMockApStateMachine()158 MockApStateMachine &GetMockApStateMachine() 159 { 160 return mockApStateMachine; 161 } 162 GetMockApMonitor()163 MockApMonitor &GetMockApMonitor() 164 { 165 return mockApMonitor; 166 } 167 GetMockApConfigUse()168 MockApConfigUse &GetMockApConfigUse() 169 { 170 return mockApConfigUse; 171 } 172 GetMockApStationsManager()173 MockApStationsManager &GetMockApStationsManager() 174 { 175 return mockApStationsManager; 176 } 177 178 private: 179 MockApRootState mockApRootState; 180 MockApIdleState mockApIdleState; 181 MockApStartedState mockApStartedState; 182 183 MockApService mockApService; 184 MockApStateMachine mockApStateMachine; 185 MockApMonitor mockApMonitor; 186 187 MockApConfigUse mockApConfigUse; 188 MockApStationsManager mockApStationsManager; 189 }; 190 } /* namespace Wifi */ 191 } /* namespace OHOS */ 192 #endif 193