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