diff options
Diffstat (limited to 'telephony/tests')
-rw-r--r-- | telephony/tests/telephonytests/Android.mk | 2 | ||||
-rw-r--r-- | telephony/tests/telephonytests/AndroidManifest.xml | 7 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java | 23 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/frameworks/telephonytests/TelephonyMockRilTestRunner.java | 93 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/CallerInfoTest.java (renamed from telephony/tests/telephonytests/src/com/android/telephonytest/unit/CallerInfoUnitTest.java) | 5 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java | 194 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java | 304 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/telephonytest/unit/PhoneNumberUtilsUnitTest.java | 63 |
8 files changed, 625 insertions, 66 deletions
diff --git a/telephony/tests/telephonytests/Android.mk b/telephony/tests/telephonytests/Android.mk index 45e265a..98e4403 100644 --- a/telephony/tests/telephonytests/Android.mk +++ b/telephony/tests/telephonytests/Android.mk @@ -5,6 +5,8 @@ LOCAL_MODULE_TAGS := tests LOCAL_SRC_FILES := $(call all-subdir-java-files) +LOCAL_STATIC_JAVA_LIBRARIES := librilproto-java + LOCAL_JAVA_LIBRARIES := android.test.runner LOCAL_PACKAGE_NAME := FrameworksTelephonyTests diff --git a/telephony/tests/telephonytests/AndroidManifest.xml b/telephony/tests/telephonytests/AndroidManifest.xml index 6a97423..ba1d957 100644 --- a/telephony/tests/telephonytests/AndroidManifest.xml +++ b/telephony/tests/telephonytests/AndroidManifest.xml @@ -32,6 +32,13 @@ android:targetPackage="com.android.frameworks.telephonytests" android:label="Frameworks Telephony Tests"> </instrumentation> + + <instrumentation android:name=".TelephonyMockRilTestRunner" + android:targetPackage="com.android.frameworks.telephonytests" + android:label="Test Runner for Mock Ril Tests" + /> + <uses-permission android:name="android.permission.READ_PHONE_STATE" /> + <uses-permission android:name="android.permission.INTERNET" /> </manifest> diff --git a/telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java b/telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java index 2165023..67df510 100644 --- a/telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java +++ b/telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java @@ -16,13 +16,16 @@ package android.telephony; +import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.text.SpannableStringBuilder; import android.telephony.PhoneNumberUtils; +import android.telephony.TelephonyManager; +import android.content.Context; import junit.framework.TestCase; -public class PhoneNumberUtilsTest extends TestCase { +public class PhoneNumberUtilsTest extends AndroidTestCase { @SmallTest public void testExtractNetworkPortion() throws Exception { @@ -482,4 +485,22 @@ public class PhoneNumberUtilsTest extends TestCase { PhoneNumberUtils.cdmaCheckAndProcessPlusCodeByNumberFormat("+18475797000", PhoneNumberUtils.FORMAT_UNKNOWN,PhoneNumberUtils.FORMAT_UNKNOWN)); } + + /** + * Basic checks for the VoiceMail number. + */ + @SmallTest + public void testWithNumberNotEqualToVoiceMail() throws Exception { + assertFalse(PhoneNumberUtils.isVoiceMailNumber("911")); + assertFalse(PhoneNumberUtils.isVoiceMailNumber("tel:911")); + assertFalse(PhoneNumberUtils.isVoiceMailNumber("+18001234567")); + assertFalse(PhoneNumberUtils.isVoiceMailNumber("")); + assertFalse(PhoneNumberUtils.isVoiceMailNumber(null)); + // This test fails on a device without a sim card + /*TelephonyManager mTelephonyManager = + (TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE); + String mVoiceMailNumber = mTelephonyManager.getDefault().getVoiceMailNumber(); + assertTrue(PhoneNumberUtils.isVoiceMailNumber(mVoiceMailNumber)); + */ + } } diff --git a/telephony/tests/telephonytests/src/com/android/frameworks/telephonytests/TelephonyMockRilTestRunner.java b/telephony/tests/telephonytests/src/com/android/frameworks/telephonytests/TelephonyMockRilTestRunner.java new file mode 100644 index 0000000..9192f57 --- /dev/null +++ b/telephony/tests/telephonytests/src/com/android/frameworks/telephonytests/TelephonyMockRilTestRunner.java @@ -0,0 +1,93 @@ +/* + * 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. + */ + +package com.android.frameworks.telephonytests; + +import android.os.Bundle; + +import android.test.InstrumentationTestRunner; +import android.test.InstrumentationTestSuite; +import android.util.Log; + +import java.io.IOException; + +import com.android.internal.telephony.RilChannel; +import com.android.internal.telephony.mockril.MockRilTest; + +import junit.framework.TestSuite; + +public class TelephonyMockRilTestRunner extends InstrumentationTestRunner { + + public RilChannel mMockRilChannel; + + @Override + public TestSuite getAllTests() { + log("getAllTests E"); + TestSuite suite = new InstrumentationTestSuite(this); + suite.addTestSuite(MockRilTest.class); + log("getAllTests X"); + return suite; + } + + @Override + public ClassLoader getLoader() { + log("getLoader EX"); + return TelephonyMockRilTestRunner.class.getClassLoader(); + } + + @Override + public void onCreate(Bundle icicle) { + log("onCreate E"); + try { + mMockRilChannel = RilChannel.makeRilChannel(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + log("onCreate X"); + + super.onCreate(icicle); + } + + @Override + public void onDestroy() { + // I've not seen this called + log("onDestroy EX"); + super.onDestroy(); + } + + @Override + public void onStart() { + // Called when the instrumentation thread is started. + // At the moment we don't need the thread so return + // which will shut down this unused thread. + log("onStart EX"); + super.onStart(); + } + + @Override + public void finish(int resultCode, Bundle results) { + // Called when complete so I ask the mMockRilChannel to quit. + log("finish E"); + mMockRilChannel.close(); + log("finish X"); + super.finish(resultCode, results); + } + + private void log(String s) { + Log.e("TelephonyMockRilTestRunner", s); + } +} diff --git a/telephony/tests/telephonytests/src/com/android/telephonytest/unit/CallerInfoUnitTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/CallerInfoTest.java index 0f24f15..1e5dafb 100644 --- a/telephony/tests/telephonytests/src/com/android/telephonytest/unit/CallerInfoUnitTest.java +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/CallerInfoTest.java @@ -14,7 +14,8 @@ * limitations under the License. */ -package com.android.telephonytest.unit; +package com.android.internal.telephony; + import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; @@ -33,7 +34,7 @@ import android.util.StringBuilderPrinter; * */ -public class CallerInfoUnitTest extends AndroidTestCase { +public class CallerInfoTest extends AndroidTestCase { private CallerInfo mInfo; private Context mContext; diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java new file mode 100644 index 0000000..b214887 --- /dev/null +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/SmsMessageBodyTest.java @@ -0,0 +1,194 @@ +/* + * 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. + */ + +package com.android.internal.telephony; + +import android.telephony.SmsMessage; +import android.telephony.TelephonyManager; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import static android.telephony.SmsMessage.MAX_USER_DATA_SEPTETS; + +public class SmsMessageBodyTest extends AndroidTestCase { + + private static final String sAsciiChars = "@$_ !\"#%&'()*+,-./0123456789" + + ":;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n\r"; + private static final String sGsmBasicChars = "\u00a3\u00a5\u00e8\u00e9" + + "\u00f9\u00ec\u00f2\u00c7\u00d8\u00f8\u00c5\u00e5\u0394\u03a6" + + "\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398\u00c6\u00e6" + + "\u00df\u00c9\u00a4\u00a1\u00c4\u00d6\u00d1\u00dc\u00a7\u00bf" + + "\u00e4\u00f6\u00f1\u00fc\u00e0"; + private static final String sGsmExtendedAsciiChars = "{|}\\[~]^\f"; + private static final String sGsmExtendedEuroSymbol = "\u20ac"; + private static final String sUnicodeChars = "\u4e00\u4e01\u4e02\u4e03" + + "\u4e04\u4e05\u4e06\u4e07\u4e08\u4e09\u4e0a\u4e0b\u4e0c\u4e0d" + + "\u4e0e\u4e0f\u3041\u3042\u3043\u3044\u3045\u3046\u3047\u3048" + + "\u30a1\u30a2\u30a3\u30a4\u30a5\u30a6\u30a7\u30a8" + + "\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18" + + "\uff70\uff71\uff72\uff73\uff74\uff75\uff76\uff77\uff78" + + "\u0400\u0401\u0402\u0403\u0404\u0405\u0406\u0407\u0408" + + "\u00a2\u00a9\u00ae\u2122"; + + private static final int sTestLengthCount = 12; + + private static final int[] sSeptetTestLengths = + { 0, 1, 2, 80, 159, 160, 161, 240, 305, 306, 307, 320}; + + private static final int[] sUnicodeTestLengths = + { 0, 1, 2, 35, 69, 70, 71, 100, 133, 134, 135, 160}; + + private static final int[] sTestMsgCounts = + { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3}; + + private static final int[] sSeptetUnitsRemaining = + {160, 159, 158, 80, 1, 0, 145, 66, 1, 0, 152, 139}; + + private static final int[] sUnicodeUnitsRemaining = + { 70, 69, 68, 35, 1, 0, 63, 34, 1, 0, 66, 41}; + + + @SmallTest + public void testCalcLengthAscii() throws Exception { + StringBuilder sb = new StringBuilder(320); + int[] values = {0, 0, 0, SmsMessage.ENCODING_7BIT}; + int startPos = 0; + int asciiCharsLen = sAsciiChars.length(); + + for (int i = 0; i < sTestLengthCount; i++) { + int len = sSeptetTestLengths[i]; + assertTrue(sb.length() <= len); + + while (sb.length() < len) { + int addCount = len - sb.length(); + int endPos = (asciiCharsLen - startPos > addCount) ? + (startPos + addCount) : asciiCharsLen; + sb.append(sAsciiChars, startPos, endPos); + startPos = (endPos == asciiCharsLen) ? 0 : endPos; + } + assertEquals(len, sb.length()); + + String testStr = sb.toString(); + values[0] = sTestMsgCounts[i]; + values[1] = len; + values[2] = sSeptetUnitsRemaining[i]; + + callGsmLengthMethods(testStr, false, values); + callGsmLengthMethods(testStr, true, values); + callCdmaLengthMethods(testStr, false, values); + callCdmaLengthMethods(testStr, true, values); + } + } + + @SmallTest + public void testCalcLength7bitGsm() throws Exception { + // TODO + } + + @SmallTest + public void testCalcLength7bitGsmExtended() throws Exception { + // TODO + } + + @SmallTest + public void testCalcLengthUnicode() throws Exception { + StringBuilder sb = new StringBuilder(160); + int[] values = {0, 0, 0, SmsMessage.ENCODING_16BIT}; + int[] values7bit = {1, 0, 0, SmsMessage.ENCODING_7BIT}; + int startPos = 0; + int unicodeCharsLen = sUnicodeChars.length(); + + // start with length 1: empty string uses ENCODING_7BIT + for (int i = 1; i < sTestLengthCount; i++) { + int len = sUnicodeTestLengths[i]; + assertTrue(sb.length() <= len); + + while (sb.length() < len) { + int addCount = len - sb.length(); + int endPos = (unicodeCharsLen - startPos > addCount) ? + (startPos + addCount) : unicodeCharsLen; + sb.append(sUnicodeChars, startPos, endPos); + startPos = (endPos == unicodeCharsLen) ? 0 : endPos; + } + assertEquals(len, sb.length()); + + String testStr = sb.toString(); + values[0] = sTestMsgCounts[i]; + values[1] = len; + values[2] = sUnicodeUnitsRemaining[i]; + values7bit[1] = len; + values7bit[2] = MAX_USER_DATA_SEPTETS - len; + + callGsmLengthMethods(testStr, false, values); + callCdmaLengthMethods(testStr, false, values); + callGsmLengthMethods(testStr, true, values7bit); + callCdmaLengthMethods(testStr, true, values7bit); + } + } + + private void callGsmLengthMethods(CharSequence msgBody, boolean use7bitOnly, + int[] expectedValues) + { + // deprecated GSM-specific method + int[] values = android.telephony.gsm.SmsMessage.calculateLength(msgBody, use7bitOnly); + assertEquals("msgCount", expectedValues[0], values[0]); + assertEquals("codeUnitCount", expectedValues[1], values[1]); + assertEquals("codeUnitsRemaining", expectedValues[2], values[2]); + assertEquals("codeUnitSize", expectedValues[3], values[3]); + + int activePhone = TelephonyManager.getDefault().getPhoneType(); + if (TelephonyManager.PHONE_TYPE_GSM == activePhone) { + values = android.telephony.SmsMessage.calculateLength(msgBody, use7bitOnly); + assertEquals("msgCount", expectedValues[0], values[0]); + assertEquals("codeUnitCount", expectedValues[1], values[1]); + assertEquals("codeUnitsRemaining", expectedValues[2], values[2]); + assertEquals("codeUnitSize", expectedValues[3], values[3]); + } + + SmsMessageBase.TextEncodingDetails ted = + com.android.internal.telephony.gsm.SmsMessage.calculateLength(msgBody, use7bitOnly); + assertEquals("msgCount", expectedValues[0], ted.msgCount); + assertEquals("codeUnitCount", expectedValues[1], ted.codeUnitCount); + assertEquals("codeUnitsRemaining", expectedValues[2], ted.codeUnitsRemaining); + assertEquals("codeUnitSize", expectedValues[3], ted.codeUnitSize); + } + + private void callCdmaLengthMethods(CharSequence msgBody, boolean use7bitOnly, + int[] expectedValues) + { + int activePhone = TelephonyManager.getDefault().getPhoneType(); + if (TelephonyManager.PHONE_TYPE_CDMA == activePhone) { + int[] values = android.telephony.SmsMessage.calculateLength(msgBody, use7bitOnly); + assertEquals("msgCount", expectedValues[0], values[0]); + assertEquals("codeUnitCount", expectedValues[1], values[1]); + assertEquals("codeUnitsRemaining", expectedValues[2], values[2]); + assertEquals("codeUnitSize", expectedValues[3], values[3]); + } + + SmsMessageBase.TextEncodingDetails ted = + com.android.internal.telephony.cdma.SmsMessage.calculateLength(msgBody, use7bitOnly); + assertEquals("msgCount", expectedValues[0], ted.msgCount); + assertEquals("codeUnitCount", expectedValues[1], ted.codeUnitCount); + assertEquals("codeUnitsRemaining", expectedValues[2], ted.codeUnitsRemaining); + assertEquals("codeUnitSize", expectedValues[3], ted.codeUnitSize); + + ted = com.android.internal.telephony.cdma.sms.BearerData.calcTextEncodingDetails(msgBody, use7bitOnly); + assertEquals("msgCount", expectedValues[0], ted.msgCount); + assertEquals("codeUnitCount", expectedValues[1], ted.codeUnitCount); + assertEquals("codeUnitsRemaining", expectedValues[2], ted.codeUnitsRemaining); + assertEquals("codeUnitSize", expectedValues[3], ted.codeUnitSize); + } +} 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 new file mode 100644 index 0000000..3149ee1 --- /dev/null +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java @@ -0,0 +1,304 @@ +/* + * 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. + */ + +package com.android.internal.telephony.mockril; + +import android.util.Log; +import android.test.InstrumentationTestCase; + +import java.io.IOException; +import java.nio.ByteBuffer; + +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; + +// Test suite for test ril +public class MockRilTest extends InstrumentationTestCase { + private static final String TAG = "MockRilTest"; + + RilChannel mMockRilChannel; + TelephonyMockRilTestRunner mRunner; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mRunner = (TelephonyMockRilTestRunner)getInstrumentation(); + mMockRilChannel = mRunner.mMockRilChannel; + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + static void log(String s) { + Log.v(TAG, s); + } + + /** + * Test Case 1: Test protobuf serialization and deserialization + * @throws InvalidProtocolBufferMicroException + */ + public void testProtobufSerDes() throws InvalidProtocolBufferMicroException { + log("testProtobufSerdes E"); + + RilCtrlCmds.CtrlRspRadioState rs = new RilCtrlCmds.CtrlRspRadioState(); + assertTrue(String.format("expected rs.state == 0 was %d", rs.getState()), + rs.getState() == 0); + rs.setState(1); + assertTrue(String.format("expected rs.state == 1 was %d", rs.getState()), + rs.getState() == 1); + + byte[] rs_ser = rs.toByteArray(); + RilCtrlCmds.CtrlRspRadioState rsNew = RilCtrlCmds.CtrlRspRadioState.parseFrom(rs_ser); + assertTrue(String.format("expected rsNew.state == 1 was %d", rs.getState()), + rs.getState() == 1); + + log("testProtobufSerdes X"); + } + + /** + * Test case 2: Test echo command works using writeMsg & readMsg + */ + public void testEchoMsg() throws IOException { + log("testEchoMsg E"); + + MsgHeader mh = new MsgHeader(); + mh.setCmd(0); + mh.setToken(1); + mh.setStatus(2); + ByteBuffer data = ByteBuffer.allocate(3); + data.put((byte)3); + data.put((byte)4); + data.put((byte)5); + Msg.send(mMockRilChannel, mh, data); + + Msg respMsg = Msg.recv(mMockRilChannel); + assertTrue(String.format("expected mhd.header.cmd == 0 was %d",respMsg.getCmd()), + respMsg.getCmd() == 0); + assertTrue(String.format("expected mhd.header.token == 1 was %d",respMsg.getToken()), + respMsg.getToken() == 1); + assertTrue(String.format("expected mhd.header.status == 2 was %d", respMsg.getStatus()), + respMsg.getStatus() == 2); + assertTrue(String.format("expected mhd.data[0] == 3 was %d", respMsg.getData(0)), + respMsg.getData(0) == 3); + assertTrue(String.format("expected mhd.data[1] == 4 was %d", respMsg.getData(1)), + respMsg.getData(1) == 4); + assertTrue(String.format("expected mhd.data[2] == 5 was %d", respMsg.getData(2)), + respMsg.getData(2) == 5); + + log("testEchoMsg X"); + } + + /** + * Test case 3: Test get as + */ + public void testGetAs() { + log("testGetAs E"); + + // Use a message header as the protobuf data content + MsgHeader mh = new MsgHeader(); + mh.setCmd(12345); + mh.setToken(9876); + mh.setStatus(7654); + mh.setLengthData(4321); + byte[] data = mh.toByteArray(); + MsgHeader mhResult = Msg.getAs(MsgHeader.class, data); + + assertTrue(String.format("expected cmd == 12345 was %d", mhResult.getCmd()), + mhResult.getCmd() == 12345); + assertTrue(String.format("expected token == 9876 was %d", mhResult.getToken()), + mhResult.getToken() == 9876); + assertTrue(String.format("expected status == 7654 was %d", mhResult.getStatus()), + mhResult.getStatus() == 7654); + assertTrue(String.format("expected lengthData == 4321 was %d", mhResult.getLengthData()), + mhResult.getLengthData() == 4321); + + Msg msg = Msg.obtain(); + msg.setData(ByteBuffer.wrap(data)); + + mhResult = msg.getDataAs(MsgHeader.class); + + assertTrue(String.format("expected cmd == 12345 was %d", mhResult.getCmd()), + mhResult.getCmd() == 12345); + assertTrue(String.format("expected token == 9876 was %d", mhResult.getToken()), + mhResult.getToken() == 9876); + assertTrue(String.format("expected status == 7654 was %d", mhResult.getStatus()), + mhResult.getStatus() == 7654); + assertTrue(String.format("expected lengthData == 4321 was %d", mhResult.getLengthData()), + mhResult.getLengthData() == 4321); + + log("testGetAs X"); + } + + /** + * Test case 3: test get radio state + */ + public void testGetRadioState() throws IOException { + log("testGetRadioState E"); + + Msg.send(mMockRilChannel, 1, 9876, 0, null); + + Msg resp = Msg.recv(mMockRilChannel); + //resp.printHeader("testGetRadioState"); + + assertTrue(String.format("expected cmd == 1 was %d", resp.getCmd()), + resp.getCmd() == 1); + assertTrue(String.format("expected token == 9876 was %d", resp.getToken()), + resp.getToken() == 9876); + assertTrue(String.format("expected status == 0 was %d", resp.getStatus()), + resp.getStatus() == 0); + + RilCtrlCmds.CtrlRspRadioState rsp = resp.getDataAs(RilCtrlCmds.CtrlRspRadioState.class); + + int state = rsp.getState(); + log("testGetRadioState state=" + state); + assertTrue(String.format("expected RadioState >= 0 && RadioState <= 9 was %d", state), + ((state >= 0) && (state <= 9))); + + log("testGetRadioState X"); + } + + /** + * Test case 5: test set radio state + */ + 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); + log("get response status :" + resp.getStatus()); + log("get response for command: " + resp.getCmd()); + log("get command token: " + resp.getToken()); + + 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); + } + + /** + * Test case 6: test start incoming call and hangup it. + */ + public void testStartIncomingCallAndHangup() throws IOException { + log("testStartIncomingCallAndHangup"); + RilCtrlCmds.CtrlReqSetMTCall cmd = new RilCtrlCmds.CtrlReqSetMTCall(); + String incomingCall = "6502889108"; + // set the MT call + cmd.setPhoneNumber(incomingCall); + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_MT_CALL, 0, 0, cmd); + // get response + Msg resp = Msg.recv(mMockRilChannel); + log("Get response status: " + resp.getStatus()); + assertTrue("The ril is not in a proper state to set MT calls.", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + + // allow the incoming call alerting for some time + try { + Thread.sleep(5000); + } catch (InterruptedException e) {} + + // we are playing a trick to assume the current is 1 + RilCtrlCmds.CtrlHangupConnRemote hangupCmd = new RilCtrlCmds.CtrlHangupConnRemote(); + hangupCmd.setConnectionId(1); + hangupCmd.setCallFailCause(16); // normal hangup + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_HANGUP_CONN_REMOTE, 0, 0, hangupCmd); + + // get response + resp = Msg.recv(mMockRilChannel); + log("Get response for hangup connection: " + resp.getStatus()); + assertTrue("CTRL_CMD_HANGUP_CONN_REMOTE failed", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + } + + /** + * Test case 7: test set call transition flag + */ + public void testSetCallTransitionFlag() throws IOException { + log("testSetCallTransitionFlag"); + // Set flag to true: + RilCtrlCmds.CtrlSetCallTransitionFlag cmd = new RilCtrlCmds.CtrlSetCallTransitionFlag(); + cmd.setFlag(true); + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_TRANSITION_FLAG, 0, 0, cmd); + + Msg resp = Msg.recv(mMockRilChannel); + log("Get response status: " + resp.getStatus()); + assertTrue("Set call transition flag failed", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + + // add a dialing call + RilCtrlCmds.CtrlReqAddDialingCall cmdDialCall = new RilCtrlCmds.CtrlReqAddDialingCall(); + String phoneNumber = "5102345678"; + cmdDialCall.setPhoneNumber(phoneNumber); + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_ADD_DIALING_CALL, 0, 0, cmdDialCall); + resp = Msg.recv(mMockRilChannel); + log("Get response status for adding a dialing call: " + resp.getStatus()); + assertTrue("add dialing call failed", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + try { + Thread.sleep(5000); + } catch (InterruptedException e) {} + + // send command to force call state change + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_ALERT, 0, 0, null); + resp = Msg.recv(mMockRilChannel); + log("Get response status: " + resp.getStatus()); + assertTrue("Set call alert failed", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + + try { + Thread.sleep(2000); + } catch (InterruptedException e) {} + + // send command to force call state change + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_ACTIVE, 0, 0, null); + resp = Msg.recv(mMockRilChannel); + log("Get response status: " + resp.getStatus()); + assertTrue("Set call active failed", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + + // hangup the active all remotely + RilCtrlCmds.CtrlHangupConnRemote hangupCmd = new RilCtrlCmds.CtrlHangupConnRemote(); + hangupCmd.setConnectionId(1); + hangupCmd.setCallFailCause(16); // normal hangup + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_HANGUP_CONN_REMOTE, 0, 0, hangupCmd); + resp = Msg.recv(mMockRilChannel); + log("Get response for hangup connection: " + resp.getStatus()); + assertTrue("CTRL_CMD_HANGUP_CONN_REMOTE failed", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + + // set the flag to false + cmd.setFlag(false); + Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_TRANSITION_FLAG, 0, 0, cmd); + resp = Msg.recv(mMockRilChannel); + assertTrue("Set call transition flag failed", + resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK); + } +} diff --git a/telephony/tests/telephonytests/src/com/android/telephonytest/unit/PhoneNumberUtilsUnitTest.java b/telephony/tests/telephonytests/src/com/android/telephonytest/unit/PhoneNumberUtilsUnitTest.java deleted file mode 100644 index 2d3c548..0000000 --- a/telephony/tests/telephonytests/src/com/android/telephonytest/unit/PhoneNumberUtilsUnitTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2009 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. - */ - -package com.android.telephonytest.unit; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; -import android.util.Log; - -import android.telephony.PhoneNumberUtils; -import android.telephony.TelephonyManager; - -/* - * Check the PhoneNumberUtils utility class works as expected. - * - */ - -public class PhoneNumberUtilsUnitTest extends AndroidTestCase { - private String mVoiceMailNumber; - private static final String TAG = "PhoneNumberUtilsUnitTest"; - - @Override - protected void setUp() throws Exception { - super.setUp(); - // FIXME: Why are we getting a security exception here? The - // permission is declared in the manifest.... - // mVoiceMailNumber = TelephonyManager.getDefault().getVoiceMailNumber(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - /** - * Basic checks for the VoiceMail number. - * Assumes READ_PHONE_STATE permission and we don't have it. - */ - // TODO: Figure out why we don't have the permission declared in the manifest. - @SmallTest - public void testWithNumberNotEqualToVoiceMail() throws Exception { - assertFalse(PhoneNumberUtils.isVoiceMailNumber("911")); - assertFalse(PhoneNumberUtils.isVoiceMailNumber("tel:911")); - assertFalse(PhoneNumberUtils.isVoiceMailNumber("+18001234567")); - assertFalse(PhoneNumberUtils.isVoiceMailNumber("")); - assertFalse(PhoneNumberUtils.isVoiceMailNumber(null)); - // FIXME: - // assertTrue(PhoneNumberUtils.isVoiceMailNumber(mVoiceMailNumber)); - } - -} |