1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <radio_hidl_hal_utils.h>
18
19 /*
20 * Test IRadio.getCurrentCalls() for the response returned.
21 */
TEST_F(RadioHidlTest,getCurrentCalls)22 TEST_F(RadioHidlTest, getCurrentCalls) {
23 int serial = GetRandomSerialNumber();
24
25 radio->getCurrentCalls(serial);
26 EXPECT_EQ(std::cv_status::no_timeout, wait());
27 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
28 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
29
30 if (cardStatus.cardState == CardState::ABSENT) {
31 ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE);
32 }
33 }
34
35 /*
36 * Test IRadio.dial() for the response returned.
37 */
TEST_F(RadioHidlTest,dial)38 TEST_F(RadioHidlTest, dial) {
39 int serial = GetRandomSerialNumber();
40
41 Dial dialInfo;
42 memset(&dialInfo, 0, sizeof(dialInfo));
43 dialInfo.address = hidl_string("123456789");
44
45 radio->dial(serial, dialInfo);
46 EXPECT_EQ(std::cv_status::no_timeout, wait());
47 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
48 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
49
50 if (cardStatus.cardState == CardState::ABSENT) {
51 ASSERT_TRUE(CheckGeneralError() ||
52 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
53 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
54 radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
55 radioRsp->rspInfo.error == RadioError::FDN_CHECK_FAILURE ||
56 radioRsp->rspInfo.error == RadioError::NO_SUBSCRIPTION ||
57 radioRsp->rspInfo.error == RadioError::NO_NETWORK_FOUND ||
58 radioRsp->rspInfo.error == RadioError::INVALID_CALL_ID ||
59 radioRsp->rspInfo.error == RadioError::DEVICE_IN_USE ||
60 radioRsp->rspInfo.error == RadioError::MODE_NOT_SUPPORTED ||
61 radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE ||
62 radioRsp->rspInfo.error == RadioError::CANCELLED);
63 }
64 }
65
66 /*
67 * Test IRadio.hangup() for the response returned.
68 */
TEST_F(RadioHidlTest,hangup)69 TEST_F(RadioHidlTest, hangup) {
70 int serial = GetRandomSerialNumber();
71
72 radio->hangup(serial, 1);
73 EXPECT_EQ(std::cv_status::no_timeout, wait());
74 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
75 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
76
77 if (cardStatus.cardState == CardState::ABSENT) {
78 ASSERT_TRUE(CheckGeneralError() ||
79 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
80 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
81 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
82 }
83 }
84
85 /*
86 * Test IRadio.hangupWaitingOrBackground() for the response returned.
87 */
TEST_F(RadioHidlTest,hangupWaitingOrBackground)88 TEST_F(RadioHidlTest, hangupWaitingOrBackground) {
89 int serial = GetRandomSerialNumber();
90
91 radio->hangupWaitingOrBackground(serial);
92 EXPECT_EQ(std::cv_status::no_timeout, wait());
93 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
94 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
95
96 if (cardStatus.cardState == CardState::ABSENT) {
97 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
98 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
99 }
100 }
101
102 /*
103 * Test IRadio.hangupForegroundResumeBackground() for the response returned.
104 */
TEST_F(RadioHidlTest,hangupForegroundResumeBackground)105 TEST_F(RadioHidlTest, hangupForegroundResumeBackground) {
106 int serial = GetRandomSerialNumber();
107
108 radio->hangupForegroundResumeBackground(serial);
109 EXPECT_EQ(std::cv_status::no_timeout, wait());
110 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
111 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
112
113 if (cardStatus.cardState == CardState::ABSENT) {
114 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
115 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
116 }
117 }
118
119 /*
120 * Test IRadio.switchWaitingOrHoldingAndActive() for the response returned.
121 */
TEST_F(RadioHidlTest,switchWaitingOrHoldingAndActive)122 TEST_F(RadioHidlTest, switchWaitingOrHoldingAndActive) {
123 int serial = GetRandomSerialNumber();
124
125 radio->switchWaitingOrHoldingAndActive(serial);
126 EXPECT_EQ(std::cv_status::no_timeout, wait());
127 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
128 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
129
130 if (cardStatus.cardState == CardState::ABSENT) {
131 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
132 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
133 }
134 }
135
136 /*
137 * Test IRadio.conference() for the response returned.
138 */
TEST_F(RadioHidlTest,conference)139 TEST_F(RadioHidlTest, conference) {
140 int serial = GetRandomSerialNumber();
141
142 radio->conference(serial);
143 EXPECT_EQ(std::cv_status::no_timeout, wait());
144 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
145 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
146
147 if (cardStatus.cardState == CardState::ABSENT) {
148 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
149 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
150 }
151 }
152
153 /*
154 * Test IRadio.rejectCall() for the response returned.
155 */
TEST_F(RadioHidlTest,rejectCall)156 TEST_F(RadioHidlTest, rejectCall) {
157 int serial = GetRandomSerialNumber();
158
159 radio->rejectCall(serial);
160 EXPECT_EQ(std::cv_status::no_timeout, wait());
161 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
162 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
163
164 if (cardStatus.cardState == CardState::ABSENT) {
165 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
166 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
167 }
168 }
169
170 /*
171 * Test IRadio.getLastCallFailCause() for the response returned.
172 */
TEST_F(RadioHidlTest,getLastCallFailCause)173 TEST_F(RadioHidlTest, getLastCallFailCause) {
174 int serial = GetRandomSerialNumber();
175
176 radio->getLastCallFailCause(serial);
177 EXPECT_EQ(std::cv_status::no_timeout, wait());
178 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
179 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
180
181 if (cardStatus.cardState == CardState::ABSENT) {
182 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::NONE);
183 }
184 }
185
186 /*
187 * Test IRadio.sendUssd() for the response returned.
188 */
TEST_F(RadioHidlTest,sendUssd)189 TEST_F(RadioHidlTest, sendUssd) {
190 int serial = GetRandomSerialNumber();
191 radio->sendUssd(serial, hidl_string("test"));
192 EXPECT_EQ(std::cv_status::no_timeout, wait());
193 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
194 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
195
196 if (cardStatus.cardState == CardState::ABSENT) {
197 ASSERT_TRUE(CheckGeneralError() ||
198 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
199 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
200 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
201 }
202 }
203
204 /*
205 * Test IRadio.cancelPendingUssd() for the response returned.
206 */
TEST_F(RadioHidlTest,cancelPendingUssd)207 TEST_F(RadioHidlTest, cancelPendingUssd) {
208 int serial = GetRandomSerialNumber();
209
210 radio->cancelPendingUssd(serial);
211 EXPECT_EQ(std::cv_status::no_timeout, wait());
212 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
213 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
214
215 if (cardStatus.cardState == CardState::ABSENT) {
216 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
217 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
218 }
219 }
220
221 /*
222 * Test IRadio.getCallForwardStatus() for the response returned.
223 */
TEST_F(RadioHidlTest,getCallForwardStatus)224 TEST_F(RadioHidlTest, getCallForwardStatus) {
225 int serial = GetRandomSerialNumber();
226 CallForwardInfo callInfo;
227 memset(&callInfo, 0, sizeof(callInfo));
228 callInfo.number = hidl_string();
229
230 radio->getCallForwardStatus(serial, callInfo);
231 EXPECT_EQ(std::cv_status::no_timeout, wait());
232 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
233 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
234
235 if (cardStatus.cardState == CardState::ABSENT) {
236 ASSERT_TRUE(CheckGeneralError() ||
237 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
238 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
239 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
240 }
241 }
242
243 /*
244 * Test IRadio.setCallForward() for the response returned.
245 */
TEST_F(RadioHidlTest,setCallForward)246 TEST_F(RadioHidlTest, setCallForward) {
247 int serial = GetRandomSerialNumber();
248 CallForwardInfo callInfo;
249 memset(&callInfo, 0, sizeof(callInfo));
250 callInfo.number = hidl_string();
251
252 radio->setCallForward(serial, callInfo);
253 EXPECT_EQ(std::cv_status::no_timeout, wait());
254 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
255 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
256
257 if (cardStatus.cardState == CardState::ABSENT) {
258 ASSERT_TRUE(CheckGeneralError() ||
259 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
260 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
261 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
262 }
263 }
264
265 /*
266 * Test IRadio.getCallWaiting() for the response returned.
267 */
TEST_F(RadioHidlTest,getCallWaiting)268 TEST_F(RadioHidlTest, getCallWaiting) {
269 int serial = GetRandomSerialNumber();
270
271 radio->getCallWaiting(serial, 1);
272 EXPECT_EQ(std::cv_status::no_timeout, wait());
273 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
274 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
275
276 if (cardStatus.cardState == CardState::ABSENT) {
277 ASSERT_TRUE(CheckGeneralError() ||
278 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
279 radioRsp->rspInfo.error == RadioError::NONE ||
280 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
281 }
282 }
283
284 /*
285 * Test IRadio.setCallWaiting() for the response returned.
286 */
TEST_F(RadioHidlTest,setCallWaiting)287 TEST_F(RadioHidlTest, setCallWaiting) {
288 int serial = GetRandomSerialNumber();
289
290 radio->setCallWaiting(serial, true, 1);
291 EXPECT_EQ(std::cv_status::no_timeout, wait());
292 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
293 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
294
295 if (cardStatus.cardState == CardState::ABSENT) {
296 ASSERT_TRUE(CheckGeneralError() ||
297 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
298 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
299 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
300 }
301 }
302
303 /*
304 * Test IRadio.acceptCall() for the response returned.
305 */
TEST_F(RadioHidlTest,acceptCall)306 TEST_F(RadioHidlTest, acceptCall) {
307 int serial = GetRandomSerialNumber();
308
309 radio->acceptCall(serial);
310 EXPECT_EQ(std::cv_status::no_timeout, wait());
311 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
312 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
313
314 if (cardStatus.cardState == CardState::ABSENT) {
315 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
316 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
317 }
318 }
319
320 /*
321 * Test IRadio.separateConnection() for the response returned.
322 */
TEST_F(RadioHidlTest,separateConnection)323 TEST_F(RadioHidlTest, separateConnection) {
324 int serial = GetRandomSerialNumber();
325
326 radio->separateConnection(serial, 1);
327 EXPECT_EQ(std::cv_status::no_timeout, wait());
328 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
329 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
330
331 if (cardStatus.cardState == CardState::ABSENT) {
332 ASSERT_TRUE(CheckGeneralError() ||
333 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
334 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
335 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
336 }
337 }
338
339 /*
340 * Test IRadio.explicitCallTransfer() for the response returned.
341 */
TEST_F(RadioHidlTest,explicitCallTransfer)342 TEST_F(RadioHidlTest, explicitCallTransfer) {
343 int serial = GetRandomSerialNumber();
344
345 radio->explicitCallTransfer(serial);
346 EXPECT_EQ(std::cv_status::no_timeout, wait());
347 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
348 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
349
350 if (cardStatus.cardState == CardState::ABSENT) {
351 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
352 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
353 }
354 }
355
356 /*
357 * Test IRadio.sendCDMAFeatureCode() for the response returned.
358 */
TEST_F(RadioHidlTest,sendCDMAFeatureCode)359 TEST_F(RadioHidlTest, sendCDMAFeatureCode) {
360 int serial = GetRandomSerialNumber();
361
362 radio->sendCDMAFeatureCode(serial, hidl_string());
363 EXPECT_EQ(std::cv_status::no_timeout, wait());
364 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
365 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
366
367 if (cardStatus.cardState == CardState::ABSENT) {
368 std::cout << static_cast<int>(radioRsp->rspInfo.error) << std::endl;
369 ASSERT_TRUE(CheckGeneralError() ||
370 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
371 radioRsp->rspInfo.error == RadioError::NONE ||
372 radioRsp->rspInfo.error == RadioError::INVALID_CALL_ID ||
373 radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE ||
374 radioRsp->rspInfo.error == RadioError::MODEM_ERR);
375 }
376 }
377
378 /*
379 * Test IRadio.sendDtmf() for the response returned.
380 */
TEST_F(RadioHidlTest,sendDtmf)381 TEST_F(RadioHidlTest, sendDtmf) {
382 int serial = GetRandomSerialNumber();
383
384 radio->sendDtmf(serial, "1");
385 EXPECT_EQ(std::cv_status::no_timeout, wait());
386 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
387 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
388
389 if (cardStatus.cardState == CardState::ABSENT) {
390 ASSERT_TRUE(CheckGeneralError() ||
391 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
392 radioRsp->rspInfo.error == RadioError::NONE ||
393 radioRsp->rspInfo.error == RadioError::INVALID_CALL_ID ||
394 radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
395 radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE);
396 }
397 }
398
399 /*
400 * Test IRadio.startDtmf() for the response returned.
401 */
TEST_F(RadioHidlTest,startDtmf)402 TEST_F(RadioHidlTest, startDtmf) {
403 int serial = GetRandomSerialNumber();
404
405 radio->startDtmf(serial, "1");
406 EXPECT_EQ(std::cv_status::no_timeout, wait());
407 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
408 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
409
410 if (cardStatus.cardState == CardState::ABSENT) {
411 ASSERT_TRUE(CheckGeneralError() ||
412 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
413 radioRsp->rspInfo.error == RadioError::NONE ||
414 radioRsp->rspInfo.error == RadioError::INVALID_CALL_ID ||
415 radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
416 radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE);
417 }
418 }
419
420 /*
421 * Test IRadio.stopDtmf() for the response returned.
422 */
TEST_F(RadioHidlTest,stopDtmf)423 TEST_F(RadioHidlTest, stopDtmf) {
424 int serial = GetRandomSerialNumber();
425
426 radio->stopDtmf(serial);
427 EXPECT_EQ(std::cv_status::no_timeout, wait());
428 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
429 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
430
431 if (cardStatus.cardState == CardState::ABSENT) {
432 ASSERT_TRUE(CheckGeneralError() || radioRsp->rspInfo.error == RadioError::NONE ||
433 radioRsp->rspInfo.error == RadioError::INVALID_CALL_ID ||
434 radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
435 radioRsp->rspInfo.error == RadioError::INVALID_MODEM_STATE);
436 }
437 }
438
439 /*
440 * Test IRadio.setMute() for the response returned.
441 */
TEST_F(RadioHidlTest,setMute)442 TEST_F(RadioHidlTest, setMute) {
443 int serial = GetRandomSerialNumber();
444
445 radio->setMute(serial, true);
446 EXPECT_EQ(std::cv_status::no_timeout, wait());
447 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
448 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
449
450 if (cardStatus.cardState == CardState::ABSENT) {
451 ASSERT_TRUE(CheckGeneralError() ||
452 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
453 radioRsp->rspInfo.error == RadioError::NONE);
454 }
455 }
456
457 /*
458 * Test IRadio.getMute() for the response returned.
459 */
TEST_F(RadioHidlTest,getMute)460 TEST_F(RadioHidlTest, getMute) {
461 int serial = GetRandomSerialNumber();
462
463 radio->getMute(serial);
464 EXPECT_EQ(std::cv_status::no_timeout, wait());
465 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
466 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
467
468 if (cardStatus.cardState == CardState::ABSENT) {
469 ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE);
470 }
471 }
472
473 /*
474 * Test IRadio.sendBurstDtmf() for the response returned.
475 */
TEST_F(RadioHidlTest,sendBurstDtmf)476 TEST_F(RadioHidlTest, sendBurstDtmf) {
477 int serial = GetRandomSerialNumber();
478
479 radio->sendBurstDtmf(serial, "1", 0, 0);
480 EXPECT_EQ(std::cv_status::no_timeout, wait());
481 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
482 EXPECT_EQ(serial, radioRsp->rspInfo.serial);
483
484 if (cardStatus.cardState == CardState::ABSENT) {
485 ASSERT_TRUE(CheckGeneralError() ||
486 radioRsp->rspInfo.error == RadioError::INVALID_ARGUMENTS ||
487 radioRsp->rspInfo.error == RadioError::INVALID_STATE ||
488 radioRsp->rspInfo.error == RadioError::MODEM_ERR ||
489 radioRsp->rspInfo.error == RadioError::MODE_NOT_SUPPORTED);
490 }
491 }