simulated_radio_tests.js 14.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17 18 19 20
/**
 * TODO:update tests in the format of test incoming call
 *      Have a global counter to count passes and failures
 */
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/**
 * A test to test set signal strength
 */
if (false) {
    function testSetSignalStrength() {
        print('testSetSignalStrength E:');
        simulatedRadio.printSignalStrength();
        try {
            simulatedRadio.setSignalStrength(0, -1, -1, -1, -1, -1, -1);
        } catch (err) {
            print('test failed');
        }
        simulatedRadio.printSignalStrength();
        try {
            simulatedRadio.setSignalStrength(60, 30, 29 , 28, 27, 26, 25);
        } catch (err) {
            print('test success: ' + err);
        }
        simulatedRadio.printSignalStrength();
    }
    testSetSignalStrength();
}

/**
 * TODO: A test for RIL_REQUEST_GET_CURRENT_CALLS,
 *       remove when satisfied all is well.
 */
if (false) {
    var calls = simulatedRadio.getCalls();

    function testCalls() {
        print('testCalls E:');
        var c0 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502859848', 'w');
        simulatedRadio.printCalls();
        var c1 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502583456', 'm');
        simulatedRadio.printCalls();
        var c2 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502345678', 'x');
        simulatedRadio.printCalls();
        var c3 = simulatedRadio.addCall(CALLSTATE_ACTIVE, '16502349876', 'y');
        simulatedRadio.printCalls();

        simulatedRadio.removeCall(c0.index);
        simulatedRadio.printCalls();
        simulatedRadio.removeCall(c1.index);
        simulatedRadio.printCalls();
        simulatedRadio.removeCall(c2.index);
        simulatedRadio.printCalls();

        result = simulatedRadio.rilRequestGetCurrentCalls();
        newCalls = rilSchema[packageNameAndSeperator +
                            'RspGetCurrentCalls'].parse(result.responseProtobuf);
        simulatedRadio.printCalls(newCalls.calls);

        // Set to false to test RIL_REQUEST_GET_CURRENT_CALLS as there will
        // be on call still active on the first RIL_REQUEST_GET_CURRENT_CALLS
        // request.
        if (false) {
            simulatedRadio.removeCall(c3.index);
            simulatedRadio.printCalls();
        }
        print('testCalls X:');
    }

    testCalls();
}

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
/**
 * A test for creating incoming call
 */
if (false) {
    /* Only one incoming call is in the call list */
    function verifyIncomingCall() {
        var calls = simulatedRadio.getCalls();
        var numIncomingCalls = 0;
        for (var i = 0; i < calls.length; i++) {
            if (typeof calls[i] != 'undefined') {
                if (calls[i].state == CALLSTATE_INCOMING) {
                    numIncomingCalls++;
                }
            }
        }
        return (numIncomingCalls == 1);
    }

    function testStartIncomingCall() {
        print('testCreateIncomingCall E:');

        var req = new Object();
        req.reqNum = CTRL_CMD_SET_MT_CALL;
        req.data = new Object();
        req.data.phoneNumber = '6502249208';

        var numberTestPass = 0;
        var numberTestFail = 0;

        // case 1: incoming call is the only active call
        var result = new Object();
        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
        if ( (result.rilErrCode == CTRL_STATUS_OK) && verifyIncomingCall()) {
            numberTestPass++;
        } else {
            numberTestFail++;
            print('testStartIncomingCall: TEST CASE 1 FAIL');
        }

        // case 2: one incoming call, add another incoming call will fail
        req.data.phoneNumber = '6502223456';
        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
        if ((result.rilErrCode == CTRL_STATUS_ERR) && verifyIncomingCall()) {
            numberTestPass++;
        } else {
            numberTestFail++;
            print('testStartIncomingCall: TEST CASE 2 FAIL');
        }

        // case 3: one dialing call, add another incoming call will fail
        // Make the first call in dialing state
        var calls = simulatedRadio.getCalls();
        for (var i = 0; i < calls.length; i++) {
            if (typeof calls[i] != 'undefined') {
                if (calls[i].state == CALLSTATE_INCOMING) {
                    calls[i].state = CALLSTATE_DIALING;
                    break;
                }
            }
        }
        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
        if (result.rilErrCode == CTRL_STATUS_ERR) {
            numberTestPass++;
        } else {
            numberTestFail++;
            print('testStartIncomingCall: TEST CASE 3 FAIL');
        }

        // case 4: one dialing call, adding another incoming call will fail
        calls[i].state = CALLSTATE_ALERTING;
        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
        if (result.rilErrCode == CTRL_STATUS_ERR) {
            numberTestPass++;
        } else {
            numberTestFail++;
            print('testStartIncomingCall: TEST CASE 4 FAIL');
        }

        // case 5: one active call, adding another incoming call will succeed
        calls[i].state = CALLSTATE_ACTIVE;
        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
        if (result.rilErrCode == CTRL_STATUS_OK) {
            numberTestPass++;
        } else {
            numberTestFail++;
            print('testStartIncomingCall: TEST CASE 5 FAIL');
        }

        print('*************TEST RESULT ****************');
        print('Number of Test Passed: ' + numberTestPass);
        print('Number of Test Failed: ' + numberTestFail);
        print('************   End **********************');
        // after the test, remove any calls
        for (i = 0; i < calls.length; i++) {
            simulatedRadio.removeCall(i);
        }
        print('testStartIncomingCall X:');
    }

    testStartIncomingCall();
}

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
/**
 * A test for RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND
 */
if (false) {
    var calls = simulatedRadio.getCalls();

    function testHangUpForegroundResumeBackground() {
        print('testHangUpForegroundResumeBackground E:');
        var testOutput = false;
        for (var state = CALLSTATE_ACTIVE; state <= CALLSTATE_WAITING; state++) {
            var c0 = simulatedRadio.addCall(state, '16502849230', 'smith');
            var req = new Object();
            req.reqNum = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
            var testResult = simulatedRadio.rilRequestHangUpForegroundResumeBackground(req);
            if (state == CALLSTATE_ACTIVE) {
                var testCalls = simulatedRadio.getCalls();
                if (testCalls.length == 0) {
                    testOutput = true;
                } else {
                    testOutput = false;
                }
            } else if (state == CALLSTATE_WAITING) {
                if (c0.state == CALLSTATE_ACTIVE) {
                    testOutput = true;
                } else {
                    testOutput = false;
                }
            } else if (state == CALLSTATE_HOLDING) {
                if (c0.state == CALLSTATE_ACTIVE) {
                    testOutput = true;
                } else {
                    testOutput = false;
                }
            } else {
                if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) {
                    testOutput = true;
                } else {
                    testOutput = false;
                }
            }
            if (testOutput == true) {
                print('testHangUpForegroundResumeBackground, call ' + state + ' PASS \n');
            } else {
                print('testHangUpForegroundResumeBackground, call ' + state + ' FAIL \n');
            }
            simulatedRadio.removeCall(c0.index);
            simulatedRadio.printCalls();
        }
    }

    testHangUpForegroundResumeBackground();
}

/**
 * Test RIL_REQUEST_CONFERENCE
 */
if(false) {
    var calls = simulatedRadio.getCalls();

    function testConference() {
        print('testConference E');

        // test case 1: one holding, one dialing
        var c0 = simulatedRadio.addCall(CALLSTATE_HOLDING, '16502859848', 'w');
        simulatedRadio.printCalls();
        var c1 = simulatedRadio.addCall(CALLSTATE_DIALING, '16502583456', 'm');
        simulatedRadio.printCalls();

        var req = new Object();
        req.reqNum = RIL_REQUEST_CONFERENCE;
        var testResult = new Object();
        testResult.rilErrCode = RIL_E_SUCCESS;
        testResult = simulatedRadio.rilRequestConference(req);
        if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) {
            print('testConference: holding & dialing: pass');
        } else {
            print('testConference: holding & dialing: fail');
        }

        // test case 2: one holding, one alerting
        c1.state = CALLSTATE_ALERTING;
        testResult.rilErrCode = RIL_E_SUCCESS;
        testResult = simulatedRadio.rilRequestConference(req);
        if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) {
            print('testConference: holding & alerting: pass');
        } else {
            print('testConference: holding & alerting: fail');
        }

        // test case 3: one holding, one active
        c1.state = CALLSTATE_ACTIVE;
        testResult.rilErrCode = RIL_E_SUCCESS;
        testResult = simulatedRadio.rilRequestConference(req);
        if (testResult.rilErrCode == RIL_E_SUCCESS) {
            print('testConference: holding & active: pass');
        } else {
            print('testConference: holding & active: fail');
        }

        // test case 4: one holding, one incoming
        c1.state = CALLSTATE_INCOMING;
        testResult.rilErrCode = RIL_E_SUCCESS;
        testResult = simulatedRadio.rilRequestConference(req);
        if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) {
            print('testConference: holding & incoming: pass');
        } else {
            print('testConference: holding & incoming: fail');
        }

        // test case 5: one holding, one waiting
        c1.state = CALLSTATE_WAITING;
        testResult.rilErrCode = RIL_E_SUCCESS;
        testResult = simulatedRadio.rilRequestConference(req);
        if (testResult.rilErrCode == RIL_E_GENERIC_FAILURE) {
            print('testConference: holding & waiting: pass');
        } else {
            print('testConference: holding & waiting: fail');
        }

        simulatedRadio.removeCall(c0.index);
        simulatedRadio.removeCall(c1.index);
        print('testConference: X');
    }

    testConference();
}
/**
 * Test serialization of bad numeric enum
 */
if (false) {
    var c = new RilCall(1000, '11234567890', 'me');
    rsp = new Object();
    rsp.calls = [ c ];
    try {
        rilSchema[packageNameAndSeperator + 'RspGetCurrentCalls'].serialize(rsp);
        print('test-enum a bad numeric enum value, FAILURE exception expected');
    } catch (err) {
        print('test-enum a bad numeric enum value, SUCCESS exception expected: ' + err);
    }
}

/**
 * Test serialization of bad string enum
 */
if (false) {
    // The state parameter 'NOT_CALLSTATE_ACTIVE' can get corrupted in ToProto?
    var c = new RilCall('NOT_CALLSTATE_ACTIVE', '11234567890', 'me');
    rsp = new Object();
    rsp.calls = [ c ];
    try {
        rilSchema[packageNameAndSeperator + 'RspGetCurrentCalls'].serialize(rsp);
        print('test-enum a bad string enum value, FAILURE exception expected');
    } catch (err) {
        print('test-enum a bad string enum value, SUCCESS exception expected: ' + err);
    }
}

/**
 * Test addDelayed
 */
if (false) {
    print("test addDelayed E");
    simulatedRadioWorker.add( {
        'reqNum' : CMD_DELAY_TEST,
        'hello' : 'hi no delay' });
    simulatedRadioWorker.addDelayed( {
        'reqNum' : CMD_DELAY_TEST,
        'hello' : 'hi not-a-number is 0 delay' }, "not-a-number");
    simulatedRadioWorker.addDelayed( {
        'reqNum' : CMD_DELAY_TEST,
        'hello' : 'hi negative delay is 0 delay' }, -1000);
    simulatedRadioWorker.addDelayed( {
        'reqNum' : CMD_DELAY_TEST,
        'hello' : 'hi delayed 2 seconds' }, 2000);
    print("test addDelayed X");
}

/**
 * A test for setRadioState, verify it can handle valid string variable,
 * undefined varilabe, and invalid radio state correctly.
 */
if (false) {
    function testSetRadioState() {
        print('testSetRadioState E:');
        // defined string variable
        newState = 'RADIOSTATE_UNAVAILABLE';
        try {
            setRadioState(newState);
        } catch (err) {
            print('test failed');
        }
        print('Expecting gRadioState to be ' + RADIOSTATE_UNAVAILABLE +
              ', gRadioState is: ' + gRadioState);

        // undefined string variable, expecting exception
        try {
            setRadioState('RADIOSTATE_UNDEFINED');
        } catch (err) {
            if (err.indexOf('Unknow string') >= 0) {
                print('test success');
                print('err: ' + err);
            } else {
                print('test failed');
            }
        }

        // valid radio state
        try {
            setRadioState(RADIOSTATE_NV_READY);
        } catch (err) {
            print('test failed');
        }
        print('Expecting gRadioState to be ' + RADIOSTATE_NV_READY +
              ', gRadioState is: ' + gRadioState);

        // invalid radio state
        try {
            setRadioState(-1);
        } catch (err) {
            if (err.indexOf('invalid') >= 0) {
                print('test success');
                print('err: ' + err);
            } else {
                print('test failed, err: ' + err);
            }
        }
        print('gRadioState should not be set: ' + gRadioState);

        // set radio state to be SIM_READY
        setRadioState(RADIOSTATE_SIM_READY);
        print('Expecting gRadioState to be ' + RADIOSTATE_SIM_READY +
              ', gRadioState is: ' + gRadioState);
        print('testSetRadioState X:');
    }

    testSetRadioState();
}