1 /** 2 * Copyright (C) 2010 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 /** 18 * TODO:update tests in the format of test incoming call 19 * Have a global counter to count passes and failures 20 */ 21 /** 22 * A test to test set signal strength 23 */ 24 if (false) { 25 function testSetSignalStrength() { 26 print('testSetSignalStrength E:'); 27 simulatedRadio.printSignalStrength(); 28 try { 29 simulatedRadio.setSignalStrength(0, -1, -1, -1, -1, -1, -1); 30 } catch (err) { 31 print('test failed'); 32 } 33 simulatedRadio.printSignalStrength(); 34 try { 35 simulatedRadio.setSignalStrength(60, 30, 29 , 28, 27, 26, 25); 36 } catch (err) { 37 print('test success: ' + err); 38 } 39 simulatedRadio.printSignalStrength(); 40 } 41 testSetSignalStrength(); 42 } 43 44 /** 45 * TODO: A test for RIL_REQUEST_GET_CURRENT_CALLS, 46 * remove when satisfied all is well. 47 */ 48 if (false) { 49 var calls = simulatedRadio.getCalls(); 50 51 function testCalls() { 52 print('testCalls E:'); 53 var c0 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502859848', 'w'); 54 simulatedRadio.printCalls(); 55 var c1 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502583456', 'm'); 56 simulatedRadio.printCalls(); 57 var c2 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502345678', 'x'); 58 simulatedRadio.printCalls(); 59 var c3 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502349876', 'y'); 60 simulatedRadio.printCalls(); 61 62 simulatedRadio.removeCall(c0.index); 63 simulatedRadio.printCalls(); 64 simulatedRadio.removeCall(c1.index); 65 simulatedRadio.printCalls(); 66 simulatedRadio.removeCall(c2.index); 67 simulatedRadio.printCalls(); 68 69 result = simulatedRadio.rilRequestGetCurrentCalls(); 70 newCalls = rilSchema[packageNameAndSeperator + 71 'RspGetCurrentCalls'].parse(result.responseProtobuf); 72 simulatedRadio.printCalls(newCalls.calls); 73 74 // Set to false to test RIL_REQUEST_GET_CURRENT_CALLS as there will 75 // be on call still active on the first RIL_REQUEST_GET_CURRENT_CALLS 76 // request. 77 if (false) { 78 simulatedRadio.removeCall(c3.index); 79 simulatedRadio.printCalls(); 80 } 81 print('testCalls X:'); 82 } 83 84 testCalls(); 85 } 86 87 /** 88 * A test for creating incoming call 89 */ 90 if (false) { 91 /* Only one incoming call is in the call list */ 92 function verifyIncomingCall() { 93 var calls = simulatedRadio.getCalls(); 94 var numIncomingCalls = 0; 95 for (var i = 0; i < calls.length; i++) { 96 if (typeof calls[i] != 'undefined') { 97 if (calls[i].state == CALLSTATE_INCOMING) { 98 numIncomingCalls++; 99 } 100 } 101 } 102 return (numIncomingCalls == 1); 103 } 104 105 function testStartIncomingCall() { 106 print('testCreateIncomingCall E:'); 107 108 var req = new Object(); 109 req.reqNum = CTRL_CMD_SET_MT_CALL; 110 req.data = new Object(); 111 req.data.phoneNumber = '6502249208'; 112 113 var numberTestPass = 0; 114 var numberTestFail = 0; 115 116 // case 1: incoming call is the only active call 117 var result = new Object(); 118 result = simulatedRadio.ctrlServerCmdStartInComingCall(req); 119 if ( (result.rilErrCode == CTRL_STATUS_OK) && verifyIncomingCall()) { 120 numberTestPass++; 121 } else { 122 numberTestFail++; 123 print('testStartIncomingCall: TEST CASE 1 FAIL'); 124 } 125 126 // case 2: one incoming call, add another incoming call will fail 127 req.data.phoneNumber = '6502223456'; 128 result = simulatedRadio.ctrlServerCmdStartInComingCall(req); 129 if ((result.rilErrCode == CTRL_STATUS_ERR) && verifyIncomingCall()) { 130 numberTestPass++; 131 } else { 132 numberTestFail++; 133 print('testStartIncomingCall: TEST CASE 2 FAIL'); 134 } 135 136 // case 3: one dialing call, add another incoming call will fail 137 // Make the first call in dialing state 138 var calls = simulatedRadio.getCalls(); 139 for (var i = 0; i < calls.length; i++) { 140 if (typeof calls[i] != 'undefined') { 141 if (calls[i].state == CALLSTATE_INCOMING) { 142 calls[i].state = CALLSTATE_DIALING; 143 break; 144 } 145 } 146 } 147 result = simulatedRadio.ctrlServerCmdStartInComingCall(req); 148 if (result.rilErrCode == CTRL_STATUS_ERR) { 149 numberTestPass++; 150 } else { 151 numberTestFail++; 152 print('testStartIncomingCall: TEST CASE 3 FAIL'); 153 } 154 155 // case 4: one dialing call, adding another incoming call will fail 156 calls[i].state = CALLSTATE_ALERTING; 157 result = simulatedRadio.ctrlServerCmdStartInComingCall(req); 158 if (result.rilErrCode == CTRL_STATUS_ERR) { 159 numberTestPass++; 160 } else { 161 numberTestFail++; 162 print('testStartIncomingCall: TEST CASE 4 FAIL'); 163 } 164 165 // case 5: one active call, adding another incoming call will succeed 166 calls[i].state = CALLSTATE_ACTIVE; 167 result = simulatedRadio.ctrlServerCmdStartInComingCall(req); 168 if (result.rilErrCode == CTRL_STATUS_OK) { 169 numberTestPass++; 170 } else { 171 numberTestFail++; 172 print('testStartIncomingCall: TEST CASE 5 FAIL'); 173 } 174 175 print('*************TEST RESULT ****************'); 176 print('Number of Test Passed: ' + numberTestPass); 177 print('Number of Test Failed: ' + numberTestFail); 178 print('************ End **********************'); 179 // after the test, remove any calls 180 for (i = 0; i < calls.length; i++) { 181 simulatedRadio.removeCall(i); 182 } 183 print('testStartIncomingCall X:'); 184 } 185 186 testStartIncomingCall(); 187 } 188 189 /** 190 * A test for RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND 191 */ 192 if (false) { 193 var calls = simulatedRadio.getCalls(); 194 195 function testHangUpForegroundResumeBackground() { 196 print('testHangUpForegroundResumeBackground E:'); 197 var testOutput = false; 198 for (var state = CALLSTATE_ACTIVE; state <= CALLSTATE_WAITING; state++) { 199 var c0 = simulatedRadio.addCall(state, '16502849230', 'smith'); 200 var req = new Object(); 201 req.reqNum = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND; 202 var testResult = simulatedRadio.rilRequestHangUpForegroundResumeBackground(req); 203 if (state == CALLSTATE_ACTIVE) { 204 var testCalls = simulatedRadio.getCalls(); 205 if (testCalls.length == 0) { 206 testOutput = true; 207 } else { 208 testOutput = false; 209 } 210 } else if (state == CALLSTATE_WAITING) { 211 if (c0.state == CALLSTATE_ACTIVE) { 212 testOutput = true; 213 } else { 214 testOutput = false; 215 } 216 } else if (state == CALLSTATE_HOLDING) { 217 if (c0.state == CALLSTATE_ACTIVE) { 218 testOutput = true; 219 } else { 220 testOutput = false; 221 } 222 } else { 223 if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) { 224 testOutput = true; 225 } else { 226 testOutput = false; 227 } 228 } 229 if (testOutput == true) { 230 print('testHangUpForegroundResumeBackground, call ' + state + ' PASS \n'); 231 } else { 232 print('testHangUpForegroundResumeBackground, call ' + state + ' FAIL \n'); 233 } 234 simulatedRadio.removeCall(c0.index); 235 simulatedRadio.printCalls(); 236 } 237 } 238 239 testHangUpForegroundResumeBackground(); 240 } 241 242 /** 243 * Test RIL_REQUEST_CONFERENCE 244 */ 245 if(false) { 246 var calls = simulatedRadio.getCalls(); 247 248 function testConference() { 249 print('testConference E'); 250 251 // test case 1: one holding, one dialing 252 var c0 = simulatedRadio.addCall(CALLSTATE_HOLDING, '16502859848', 'w'); 253 simulatedRadio.printCalls(); 254 var c1 = simulatedRadio.addCall(CALLSTATE_DIALING, '16502583456', 'm'); 255 simulatedRadio.printCalls(); 256 257 var req = new Object(); 258 req.reqNum = RIL_REQUEST_CONFERENCE; 259 var testResult = new Object(); 260 testResult.rilErrCode = RIL_E_SUCCESS; 261 testResult = simulatedRadio.rilRequestConference(req); 262 if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) { 263 print('testConference: holding & dialing: pass'); 264 } else { 265 print('testConference: holding & dialing: fail'); 266 } 267 268 // test case 2: one holding, one alerting 269 c1.state = CALLSTATE_ALERTING; 270 testResult.rilErrCode = RIL_E_SUCCESS; 271 testResult = simulatedRadio.rilRequestConference(req); 272 if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) { 273 print('testConference: holding & alerting: pass'); 274 } else { 275 print('testConference: holding & alerting: fail'); 276 } 277 278 // test case 3: one holding, one active 279 c1.state = CALLSTATE_ACTIVE; 280 testResult.rilErrCode = RIL_E_SUCCESS; 281 testResult = simulatedRadio.rilRequestConference(req); 282 if (testResult.rilErrCode == RIL_E_SUCCESS) { 283 print('testConference: holding & active: pass'); 284 } else { 285 print('testConference: holding & active: fail'); 286 } 287 288 // test case 4: one holding, one incoming 289 c1.state = CALLSTATE_INCOMING; 290 testResult.rilErrCode = RIL_E_SUCCESS; 291 testResult = simulatedRadio.rilRequestConference(req); 292 if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) { 293 print('testConference: holding & incoming: pass'); 294 } else { 295 print('testConference: holding & incoming: fail'); 296 } 297 298 // test case 5: one holding, one waiting 299 c1.state = CALLSTATE_WAITING; 300 testResult.rilErrCode = RIL_E_SUCCESS; 301 testResult = simulatedRadio.rilRequestConference(req); 302 if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) { 303 print('testConference: holding & waiting: pass'); 304 } else { 305 print('testConference: holding & waiting: fail'); 306 } 307 308 simulatedRadio.removeCall(c0.index); 309 simulatedRadio.removeCall(c1.index); 310 print('testConference: X'); 311 } 312 313 testConference(); 314 } 315 /** 316 * Test serialization of bad numeric enum 317 */ 318 if (false) { 319 var c = new RilCall(1000, '11234567890', 'me'); 320 rsp = new Object(); 321 rsp.calls = [ c ]; 322 try { 323 rilSchema[packageNameAndSeperator + 'RspGetCurrentCalls'].serialize(rsp); 324 print('test-enum a bad numeric enum value, FAILURE exception expected'); 325 } catch (err) { 326 print('test-enum a bad numeric enum value, SUCCESS exception expected: ' + err); 327 } 328 } 329 330 /** 331 * Test serialization of bad string enum 332 */ 333 if (false) { 334 // The state parameter 'NOT_CALLSTATE_ACTIVE' can get corrupted in ToProto? 335 var c = new RilCall('NOT_CALLSTATE_ACTIVE', '11234567890', 'me'); 336 rsp = new Object(); 337 rsp.calls = [ c ]; 338 try { 339 rilSchema[packageNameAndSeperator + 'RspGetCurrentCalls'].serialize(rsp); 340 print('test-enum a bad string enum value, FAILURE exception expected'); 341 } catch (err) { 342 print('test-enum a bad string enum value, SUCCESS exception expected: ' + err); 343 } 344 } 345 346 /** 347 * Test addDelayed 348 */ 349 if (false) { 350 print("test addDelayed E"); 351 simulatedRadioWorker.add( { 352 'reqNum' : CMD_DELAY_TEST, 353 'hello' : 'hi no delay' }); 354 simulatedRadioWorker.addDelayed( { 355 'reqNum' : CMD_DELAY_TEST, 356 'hello' : 'hi not-a-number is 0 delay' }, "not-a-number"); 357 simulatedRadioWorker.addDelayed( { 358 'reqNum' : CMD_DELAY_TEST, 359 'hello' : 'hi negative delay is 0 delay' }, -1000); 360 simulatedRadioWorker.addDelayed( { 361 'reqNum' : CMD_DELAY_TEST, 362 'hello' : 'hi delayed 2 seconds' }, 2000); 363 print("test addDelayed X"); 364 } 365 366 /** 367 * A test for setRadioState, verify it can handle valid string variable, 368 * undefined varilabe, and invalid radio state correctly. 369 */ 370 if (false) { 371 function testSetRadioState() { 372 print('testSetRadioState E:'); 373 // defined string variable 374 newState = 'RADIOSTATE_UNAVAILABLE'; 375 try { 376 setRadioState(newState); 377 } catch (err) { 378 print('test failed'); 379 } 380 print('Expecting gRadioState to be ' + RADIOSTATE_UNAVAILABLE + 381 ', gRadioState is: ' + gRadioState); 382 383 // undefined string variable, expecting exception 384 try { 385 setRadioState('RADIOSTATE_UNDEFINED'); 386 } catch (err) { 387 if (err.indexOf('Unknow string') >= 0) { 388 print('test success'); 389 print('err: ' + err); 390 } else { 391 print('test failed'); 392 } 393 } 394 395 // valid radio state 396 try { 397 setRadioState(RADIOSTATE_NV_READY); 398 } catch (err) { 399 print('test failed'); 400 } 401 print('Expecting gRadioState to be ' + RADIOSTATE_NV_READY + 402 ', gRadioState is: ' + gRadioState); 403 404 // invalid radio state 405 try { 406 setRadioState(-1); 407 } catch (err) { 408 if (err.indexOf('invalid') >= 0) { 409 print('test success'); 410 print('err: ' + err); 411 } else { 412 print('test failed, err: ' + err); 413 } 414 } 415 print('gRadioState should not be set: ' + gRadioState); 416 417 // set radio state to be SIM_READY 418 setRadioState(RADIOSTATE_SIM_READY); 419 print('Expecting gRadioState to be ' + RADIOSTATE_SIM_READY + 420 ', gRadioState is: ' + gRadioState); 421 print('testSetRadioState X:'); 422 } 423 424 testSetRadioState(); 425 } 426