1 /* 2 * Copyright (C) 2021-2023 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_TEL_RIL_TEST_UTIL_H 17 #define OHOS_TEL_RIL_TEST_UTIL_H 18 19 #include <condition_variable> 20 #include <gtest/gtest.h> 21 #include <mutex> 22 23 #include "core_service_client.h" 24 #include "tel_ril_manager.h" 25 #include "sim_state_handle.h" 26 27 namespace OHOS { 28 namespace Telephony { 29 enum class DiffInterfaceId { 30 TEST_GET_SIM_CARD_STATUS = 1, 31 TEST_SIM_IO, 32 TEST_GET_IMSI, 33 TEST_GET_SIM_LOCK_STATUS, 34 TEST_SET_SIM_LOCK, 35 TEST_SET_PIN2_LOCK, 36 TEST_UNSET_SIM_LOCK, 37 TEST_UNSET_PIN2_LOCK, 38 TEST_SET_UNPIN2_LOCK, 39 TEST_GET_CHANGE_SIM_PASSWD, 40 TEST_ENTER_SIM_PIN, 41 TEST_RADIO_RESTART, 42 TEST_UNLOCK_SIM_PIN, 43 TEST_ENTER_ERROR_PIN, 44 TEST_ENTER_ERROR_PIN2, 45 TEST_ENTER_SIM_PIN2, 46 TEST_UNLOCK_SIM_PIN2, 47 TEST_ENABLE_SIM_CARD, 48 TEST_SET_RILCM_DATA_PROFILE, 49 TEST_GET_RILCM_VOICE_REGISTRATION_STATE, 50 TEST_GET_RILCM_DATA_REGISTRATION_STATE, 51 TEST_STK_SEND_TERMINAL_RESPONSE, 52 TEST_STK_SEND_ENVELOPE, 53 TEST_STK_SEND_CALL_SETUP_REQUEST_RESULT, 54 TEST_SEND_SMS_ACK, 55 TEST_RILCM_SET_INIT_APN_INFO, 56 TEST_RILCM_SETUP_DATA_CALL, 57 TEST_RILCM_DEACTIVATE_DATA_CALL, 58 TEST_RILCM_GET_DATA_CALL_LIST, 59 TEST_RILCM_GET_LINK_BANDWIDTH_INFO, 60 TEST_RILCM_SET_LINK_BANDWIDTH_REPORTING_RULE, 61 TEST_RILCM_SET_DATA_PERMITTED_TEST, 62 TEST_RILCM_GET_LINK_CAPABILITY_TEST, 63 TEST_RILCM_CLEAN_ALL_DATA_CONNECTIONS_TEST, 64 TEST_GET_SIGNAL_STRENGTH, 65 TEST_CALL_DIAL, 66 TEST_HANDUP_CONNECT, 67 TEST_ACCEPT_CALL, 68 TEST_HOLD_CALL, 69 TEST_ACTIVE_CALL, 70 TEST_SWAP_CALL, 71 TEST_JOIN_CALL, 72 TEST_SPLIT_CALL, 73 TEST_GET_CALL_WAIT, 74 TEST_SET_CALL_WAIT, 75 TEST_GET_CALL_FORWARD, 76 TEST_SET_CALL_FORWARD, 77 TEST_GET_CALL_DEAL_CLIP, 78 TEST_SET_CALL_CLIP, 79 TEST_GET_CALL_RESTRICTION, 80 TEST_SET_CALL_RESTRICTION, 81 TEST_SET_BARRING_PWD, 82 TEST_SEND_DTMF, 83 TEST_START_DTMF, 84 TEST_STOP_DTMF, 85 TEST_RADIO_LAST_CALL_FAIL_CAUSE, 86 TEST_CURRENT_CALLS, 87 TEST_REJECT_CALL, 88 TEST_SEND_IMS_GSM_SMS, 89 TEST_SEND_SMS, 90 91 TEST_STORAGE_SMS, 92 TEST_DELETE_SMS, 93 TEST_UPDATE_SMS, 94 TEST_SET_SMS_CENTER_ADDRESS, 95 TEST_GET_SMS_CENTER_ADDRESS, 96 TEST_SET_CB_CONFIG, 97 TEST_SET_CDMA_CB_CONFIG, 98 TEST_GET_CB_CONFIG, 99 TEST_GET_CDMA_CB_CONFIG, 100 TEST_SEND_SMS_EXPECT_MORE, 101 TEST_ADD_CDMA_SMS, 102 TEST_DEL_CDMA_SMS, 103 TEST_UPDATE_CDMA_SMS, 104 105 TEST_SET_POWER_STATE, 106 TEST_GET_POWER_STATE, 107 TEST_OPERATOR, 108 TEST_GET_NETWORKS_TO_USE, 109 TEST_GET_SELECTION_MOD_FOR_NETWORKS, 110 TEST_SET_MODE_AUTOMATIC_NETWORKS, 111 TEST_GET_CURRENT_CELL_INFO, 112 TEST_GET_CELL_INFO_LIST, 113 TEST_GET_PREFERRED_NETWORK_TYPE, 114 TEST_SET_PREFERRED_NETWORK_TYPE, 115 TEST_GET_IMEI, 116 TEST_GET_IMEISV, 117 TEST_GET_MEID, 118 TEST_GET_RADIO_PROTOCOL, 119 TEST_SET_RADIO_PROTOCOL, 120 TEST_GET_VOICE_RADIO_INFO, 121 TEST_GET_PHYSICAL_CHANNEL_CONFIG, 122 TEST_SET_LOCATE_UPDATES, 123 TEST_SET_NOTIFICATION_FILTER, 124 TEST_SET_DEVICE_STATE, 125 TEST_SET_USSD, 126 TEST_GET_USSD, 127 TEST_SET_CMUT, 128 TEST_GET_CMUT, 129 TEST_GET_EMERGENCY_CALL_LIST, 130 TEST_SET_VONR_STATUS, 131 TEST_GET_RRC_CONNECTION_STATE, 132 TEST_GET_NR_OPTION_MODE, 133 TEST_SET_NR_OPTION_MODE, 134 TEST_GET_NR_SSBID_INFO, 135 TEST_GET_CELL_INFO_LIST_TYPE, 136 TEST_EXIT, 137 }; 138 139 class TelRilTest : public testing::Test { 140 public: 141 TelRilTest(); 142 ~TelRilTest(); 143 void SetUp(); 144 void TearDown(); 145 static void ReStartTelephony(); 146 static void SetUpTestCase(); 147 static void TearDownTestCase(); 148 static sptr<ICoreService> GetProxy(); 149 bool ProcessTest(int32_t index, int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 150 151 public: 152 class DemoHandler : public AppExecFwk::EventHandler { 153 public: DemoHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner)154 explicit DemoHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner) 155 : AppExecFwk::EventHandler(runner) 156 {} ~DemoHandler()157 virtual ~DemoHandler() {} 158 159 void NotifyAll(); 160 void WaitFor(int32_t timeoutSecond); 161 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 162 void ProcessResponseInfo(const AppExecFwk::InnerEvent::Pointer &event); 163 bool GetBoolResult(int32_t eventId); 164 void Clean(); 165 166 private: 167 std::mutex callbackMutex_; 168 std::condition_variable cv_; 169 int32_t eventId_; 170 std::shared_ptr<RadioResponseInfo> resultInfo_; 171 }; 172 173 public: 174 std::shared_ptr<TelRilTest::DemoHandler> GetHandler(); 175 176 private: 177 void AddRequestToMap(); 178 void InitCall(); 179 void InitData(); 180 void InitSim(); 181 void InitSms(); 182 void InitNetwork(); 183 void InitModem(); 184 185 void CallGetCurrentCallsStatusTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 186 void SimGetSimStatusTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 187 void SimIccIoTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 188 void SimGetImsiTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 189 void GetSimLockStatusTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 190 void SetSimLockTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 191 void UnSetSimLockTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 192 void ChangeSimPasswordTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 193 void EnterSimPinTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 194 void RadioRestartTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 195 void EnterErrorPinTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 196 void UnlockSimPinTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 197 void SetPin2LockTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 198 void UnSetPin2LockTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 199 void EnterSimPin2Test(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 200 void EnterErrorPin2Test(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 201 void UnlockSimPin2Test(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 202 void EnableSimCardTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 203 void SetActiveSimTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 204 void SendTerminalResponseCmdTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 205 void SendEnvelopeCmdTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 206 void SendCallSetupRequestResultTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 207 void NetworkGetRssiTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 208 void RefusedCallTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 209 void GetCallWaitTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 210 void SetCallWaitTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 211 void CallHangupTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 212 void CallJoinTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 213 void CallSplitTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 214 void CallAnswerTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 215 void CallHoldTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 216 void CallDialTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 217 void CallActiveTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 218 void CallSwapTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 219 void GetClipTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 220 void SendDtmfTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 221 void StartDtmfTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 222 void StopDtmfTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 223 void SetClipTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 224 void GetCallRestrictionTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 225 void SetCallRestrictionTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 226 void SetBarringPasswordTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 227 void NetworkVoiceRegistrationStateTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 228 void NetworkDataRegistrationStateTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 229 void GetRadioProtocolTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 230 void SetRadioProtocolTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 231 void GetCallForwardTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 232 void SetCallForwardTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 233 void NetworkOperatorTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 234 void SendRilCmSmsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 235 void StorageRilCmSmsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 236 void DeleteRilCmSmsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 237 void UpdateRilCmSmsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 238 void SetRilCmSmsCenterAddressTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 239 void GetRilCmSmsCenterAddressTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 240 void SetRilCmCBConfigTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 241 void SetRilCmCdmaCBConfigTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 242 void GetRilCmCBConfigTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 243 void GetRilCmCdmaCBConfigTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 244 void SmsSendSmsExpectMoreTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 245 void SetRadioStateTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 246 void GetRadioStateTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 247 void SmsAcknowledgeTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 248 void AddRilCmCdmaSmsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 249 void DelRilCmCdmaSmsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 250 void UpdateRilCmCdmaSmsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 251 void SetVoNRSwitchTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 252 253 /* =========== Cellular Data Start ============= */ 254 void DataSetInitApnInfoTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 255 void DataSetupDataCallTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 256 void DataDisableDataCallTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 257 void GetLinkBandwidthInfoTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 258 void OnRequestSetLinkBandwidthReportingRuleTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 259 void SetDataPermittedTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 260 void GetLinkCapabilityTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 261 void CleanAllConnectionsTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 262 /* =========== Cellular Data End ============= */ 263 264 void GetDataCallListTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 265 void GetNetworkSearchInformationTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 266 void GetNetworkSelectionModeTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 267 void SetNetworkSelectionModeTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 268 void SetPreferredNetworkParaTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 269 void GetPreferredNetworkParaTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 270 void GetImeiTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 271 void GetImeiSvTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 272 void GetMeidTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 273 void GetVoiceRadioTechnologyTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 274 void GetPhysicalChannelConfigTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 275 void SetLocateUpdatesTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 276 void SetNotificationFilterTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 277 void SetDeviceStateTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 278 void SetUssdTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 279 void GetUssdTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 280 void SetMuteTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 281 void GetMuteTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 282 void GetEmergencyCallListTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 283 void GetRrcConnectionStateTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 284 void GetNrOptionModeTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 285 void SetNrOptionModeTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 286 void GetNrSsbIdTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 287 void GetCellInfoListTest(int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 288 289 uint32_t GetRandNum(); 290 std::string GetRandPhoneNum(const int len); 291 bool WaitGetResult(int32_t eventId, std::shared_ptr<AppExecFwk::EventHandler> handler, int32_t timeOut); 292 293 private: 294 static std::shared_ptr<Telephony::ITelRilManager> telRilManager_; 295 using RilManagerAndResponseTestFun = void (TelRilTest::*)( 296 int32_t slotId, std::shared_ptr<AppExecFwk::EventHandler> handler); 297 std::map<DiffInterfaceId, RilManagerAndResponseTestFun> memberFuncMap_; 298 }; 299 300 #ifndef TEL_TEST_UNSUPPORT 301 inline const int32_t SLOT_ID_0 = 0; 302 inline const int32_t SLOT_ID_1 = 1; 303 #endif // TEL_TEST_UNSUPPORT 304 305 } // namespace Telephony 306 } // namespace OHOS 307 #endif // OHOS_TEL_RIL_TEST_UTIL_H 308