From e9be34c22789d2cecd7704498c5a20547490863d Mon Sep 17 00:00:00 2001 From: Xia Wang Date: Mon, 9 Aug 2010 16:13:13 -0700 Subject: Add setRadioState to MockRilController and the corresponding test case. Add test case for setRadioState command in Mock Ril Change-Id: I6934bc291f58743d98295b816600a6e7b980bdb1 --- .../telephony/mockril/MockRilController.java | 28 ++++++++++++++++++++++ .../functional/SimpleTestUsingMockRil.java | 14 +++++++++++ .../internal/telephony/mockril/MockRilTest.java | 21 ++++++++++++++++ 3 files changed, 63 insertions(+) (limited to 'telephony') diff --git a/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java b/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java index 0bf321e..a5139bd 100644 --- a/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java +++ b/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java @@ -104,4 +104,32 @@ public class MockRilController { else return -1; } + + /** + * Set the radio state of mock ril to the given state + * @param state for given radio state + * @return true if the state is set successful, false if it fails + */ + public boolean setRadioState(int state) { + RilCtrlCmds.CtrlReqRadioState req = new RilCtrlCmds.CtrlReqRadioState(); + if (state < 0 || state > RilCmds.RADIOSTATE_NV_READY) { + Log.v(TAG, "the give radio state is not valid."); + return false; + } + req.setState(state); + if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_RADIO_STATE, 0, 0, req)) { + Log.v(TAG, "send set radio state request failed."); + return false; + } + Msg response = getCtrlResponse(); + if (response == null) { + Log.v(TAG, "failed to get response for setRadioState"); + return false; + } + response.printHeader(TAG); + RilCtrlCmds.CtrlRspRadioState resp = + response.getDataAs(RilCtrlCmds.CtrlRspRadioState.class); + int curstate = resp.getState(); + return curstate == state; + } } diff --git a/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java index 87001c8..3ea1cf2 100644 --- a/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java +++ b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java @@ -46,4 +46,18 @@ public class SimpleTestUsingMockRil extends InstrumentationTestCase { Log.v(TAG, "testGetRadioState: " + state); assertTrue(state >= 0 && state <= 9); } + + /** + * Set the current radio state of RIL + * and verify the radio state is set correctly + */ + public void testSetRadioState() { + for (int state = 0; state <= 9; state++) { + Log.v(TAG, "set radio state to be " + state); + assertTrue("set radio state: " + state + " failed.", + mMockRilCtrl.setRadioState(state)); + } + assertFalse("use an invalid radio state", mMockRilCtrl.setRadioState(-1)); + assertFalse("the radio state doesn't exist", mMockRilCtrl.setRadioState(10)); + } } diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java index ee03b7c..f0d5b31 100644 --- a/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java @@ -26,6 +26,7 @@ import com.android.internal.communication.MsgHeader; import com.android.internal.communication.Msg; import com.android.internal.telephony.RilChannel; import com.android.internal.telephony.ril_proto.RilCtrlCmds; +import com.android.internal.telephony.ril_proto.RilCmds; import com.android.frameworks.telephonytests.TelephonyMockRilTestRunner; import com.google.protobuf.micro.InvalidProtocolBufferMicroException; @@ -173,4 +174,24 @@ public class MockRilTest extends InstrumentationTestCase { log("testGetRadioState X"); } + + public void testSetRadioState() throws IOException { + log("testSetRadioState E"); + + RilCtrlCmds.CtrlReqRadioState cmdrs = new RilCtrlCmds.CtrlReqRadioState(); + assertEquals(0, cmdrs.getState()); + + cmdrs.setState(RilCmds.RADIOSTATE_SIM_NOT_READY); + assertEquals(2, cmdrs.getState()); + + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_RADIO_STATE, 0, 0, cmdrs); + + Msg resp = Msg.recv(mMockRilChannel); + + RilCtrlCmds.CtrlRspRadioState rsp = resp.getDataAs(RilCtrlCmds.CtrlRspRadioState.class); + + int state = rsp.getState(); + log("get response for testSetRadioState: " + state); + assertTrue(RilCmds.RADIOSTATE_SIM_NOT_READY == state); + } } -- cgit v1.1