summaryrefslogtreecommitdiffstats
path: root/telephony/tests
diff options
context:
space:
mode:
Diffstat (limited to 'telephony/tests')
-rw-r--r--telephony/tests/telephonymockriltests/Android.mk14
-rw-r--r--telephony/tests/telephonymockriltests/AndroidManifest.xml40
-rw-r--r--telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/TelephonyMockTestRunner.java64
-rw-r--r--telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java63
-rw-r--r--telephony/tests/telephonytests/Android.mk2
-rw-r--r--telephony/tests/telephonytests/AndroidManifest.xml7
-rw-r--r--telephony/tests/telephonytests/src/android/telephony/PhoneNumberWatcherTest.java65
-rw-r--r--telephony/tests/telephonytests/src/com/android/frameworks/telephonytests/TelephonyMockRilTestRunner.java93
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java26
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java2
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java2
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java (renamed from telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java)40
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberWatcherTest.java214
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/SimUtilsTest.java8
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/TestPhoneNotifier.java12
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/GSMPhoneTest.java6
-rw-r--r--telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java197
17 files changed, 771 insertions, 84 deletions
diff --git a/telephony/tests/telephonymockriltests/Android.mk b/telephony/tests/telephonymockriltests/Android.mk
new file mode 100644
index 0000000..9731d0d
--- /dev/null
+++ b/telephony/tests/telephonymockriltests/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_STATIC_JAVA_LIBRARIES := mockrilcontroller
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_PACKAGE_NAME := TelephonyMockRilTests
+
+include $(BUILD_PACKAGE)
diff --git a/telephony/tests/telephonymockriltests/AndroidManifest.xml b/telephony/tests/telephonymockriltests/AndroidManifest.xml
new file mode 100644
index 0000000..63f44a2
--- /dev/null
+++ b/telephony/tests/telephonymockriltests/AndroidManifest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.telephonymockriltests">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ <activity android:label="TelephonyMockRilTest"
+ android:name="TelephonyMockRilTest">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+ <instrumentation android:name=".TelephonyMockTestRunner"
+ android:targetPackage="com.android.telephonymockriltests"
+ android:label="Test runner for Telephony Tests Using Mock RIL"
+ />
+
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+ <uses-permission android:name="android.permission.INTERNET" />
+
+</manifest>
diff --git a/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/TelephonyMockTestRunner.java b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/TelephonyMockTestRunner.java
new file mode 100644
index 0000000..78ee738
--- /dev/null
+++ b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/TelephonyMockTestRunner.java
@@ -0,0 +1,64 @@
+/*
+ * 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.telephonymockriltests;
+
+import android.os.Bundle;
+import android.test.InstrumentationTestRunner;
+import android.test.InstrumentationTestSuite;
+import com.android.internal.telephony.mockril.MockRilController;
+import android.util.Log;
+
+import com.android.telephonymockriltests.functional.SimpleTestUsingMockRil;
+
+import java.io.IOException;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+
+/**
+ * Test runner for telephony tests that using Mock RIL
+ *
+ */
+public class TelephonyMockTestRunner extends InstrumentationTestRunner {
+ private static final String TAG="TelephonyMockTestRunner";
+ public MockRilController mController;
+
+ @Override
+ public TestSuite getAllTests() {
+ TestSuite suite = new InstrumentationTestSuite(this);
+ suite.addTestSuite(SimpleTestUsingMockRil.class);
+ return suite;
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ try {
+ mController = new MockRilController();
+ } catch (IOException e) {
+ e.printStackTrace();
+ TestCase.assertTrue("Create Mock RIl Controller failed", false);
+ }
+ TestCase.assertNotNull(mController);
+ super.onCreate(icicle);
+ }
+
+ @Override
+ public void finish(int resultCode, Bundle results) {
+ if (mController != null)
+ mController.closeChannel();
+ super.finish(resultCode, results);
+ }
+}
diff --git a/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java
new file mode 100644
index 0000000..3ea1cf2
--- /dev/null
+++ b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java
@@ -0,0 +1,63 @@
+/*
+ * 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.telephonymockriltests.functional;
+
+import com.android.internal.telephony.mockril.MockRilController;
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+
+import com.android.telephonymockriltests.TelephonyMockTestRunner;
+
+/**
+ * A simple test that using Mock RIL Controller
+ */
+public class SimpleTestUsingMockRil extends InstrumentationTestCase {
+ private static final String TAG = "SimpleTestUsingMockRil";
+ private MockRilController mMockRilCtrl = null;
+ private TelephonyMockTestRunner mRunner;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mRunner = (TelephonyMockTestRunner)getInstrumentation();
+ mMockRilCtrl = mRunner.mController;
+ assertNotNull(mMockRilCtrl);
+ }
+
+ /**
+ * Get the current radio state of RIL
+ */
+ public void testGetRadioState() {
+ int state = mMockRilCtrl.getRadioState();
+ 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/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/PhoneNumberWatcherTest.java b/telephony/tests/telephonytests/src/android/telephony/PhoneNumberWatcherTest.java
deleted file mode 100644
index 88eaecd..0000000
--- a/telephony/tests/telephonytests/src/android/telephony/PhoneNumberWatcherTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2008 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.PhoneNumberFormattingTextWatcher;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.text.Selection;
-import android.text.SpannableStringBuilder;
-import android.text.TextWatcher;
-
-import junit.framework.TestCase;
-
-public class PhoneNumberWatcherTest extends TestCase {
- @SmallTest
- public void testHyphenation() throws Exception {
- SpannableStringBuilder number = new SpannableStringBuilder();
- TextWatcher tw = new PhoneNumberFormattingTextWatcher();
- number.append("555-1212");
- // Move the cursor to the left edge
- Selection.setSelection(number, 0);
- tw.beforeTextChanged(number, 0, 0, 1);
- // Insert an 8 at the beginning
- number.insert(0, "8");
- tw.afterTextChanged(number);
- assertEquals("855-512-12", number.toString());
- }
-
- @SmallTest
- public void testHyphenDeletion() throws Exception {
- SpannableStringBuilder number = new SpannableStringBuilder();
- TextWatcher tw = new PhoneNumberFormattingTextWatcher();
- number.append("555-1212");
- // Move the cursor to after the hyphen
- Selection.setSelection(number, 4);
- // Delete the hyphen
- tw.beforeTextChanged(number, 3, 1, 0);
- number.delete(3, 4);
- tw.afterTextChanged(number);
- // Make sure that it deleted the character before the hyphen
- assertEquals("551-212", number.toString());
-
- // Make sure it deals with left edge boundary case
- number.insert(0, "-");
- Selection.setSelection(number, 1);
- tw.beforeTextChanged(number, 0, 1, 0);
- number.delete(0, 1);
- tw.afterTextChanged(number);
- // Make sure that it deleted the character before the hyphen
- assertEquals("551-212", number.toString());
- }
-}
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/internal/telephony/GsmAlphabetTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java
index 3a9c511..7011aeb 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java
@@ -16,6 +16,8 @@
package com.android.internal.telephony;
+import com.android.internal.telephony.GsmAlphabet;
+
import junit.framework.TestCase;
import android.test.suitebuilder.annotation.LargeTest;
@@ -51,7 +53,7 @@ public class GsmAlphabetTest extends TestCase {
// '@' maps to char 0
assertEquals(0, GsmAlphabet.charToGsm('@'));
- // `a (a with grave accent) maps to last GSM charater
+ // `a (a with grave accent) maps to last GSM character
assertEquals(0x7f, GsmAlphabet.charToGsm('\u00e0'));
//
@@ -307,4 +309,26 @@ public class GsmAlphabetTest extends TestCase {
assertEquals("a",
GsmAlphabet.gsm8BitUnpackedToString(unpacked, 1, unpacked.length - 1));
}
+
+ @SmallTest
+ public void testGsm8BitUpackedWithEuckr() throws Exception {
+ // Some feature phones in Korea store contacts as euc-kr.
+ // Test this situations.
+ byte unpacked[];
+
+ // Test general alphabet strings.
+ unpacked = IccUtils.hexStringToBytes("61626320646566FF");
+ assertEquals("abc def",
+ GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length, "euc-kr"));
+
+ // Test korean strings.
+ unpacked = IccUtils.hexStringToBytes("C5D7BDBAC6AEFF");
+ assertEquals("\uD14C\uC2A4\uD2B8",
+ GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length, "euc-kr"));
+
+ // Test gsm Extented Characters.
+ unpacked = GsmAlphabet.stringToGsm8BitPacked(sGsmExtendedChars);
+ assertEquals(sGsmExtendedChars,
+ GsmAlphabet.gsm8BitUnpackedToString(unpacked, 0, unpacked.length, "euc-kr"));
+ }
}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java
index 3103fc1..215c6ce 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java
@@ -24,8 +24,6 @@ import com.android.internal.util.HexDump;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Log;
-
public class GsmSmsTest extends AndroidTestCase {
@SmallTest
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java
index 2d6977c..7eb3df8 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/MccTableTest.java
@@ -28,7 +28,7 @@ public class MccTableTest extends AndroidTestCase {
@SmallTest
public void testTimeZone() throws Exception {
- assertEquals(MccTable.defaultTimeZoneForMcc(208), "Europe/Paris");
+ assertEquals(MccTable.defaultTimeZoneForMcc(208), "ECT");
assertEquals(MccTable.defaultTimeZoneForMcc(232), "Europe/Vienna");
assertEquals(MccTable.defaultTimeZoneForMcc(655), "Africa/Johannesburg");
assertEquals(MccTable.defaultTimeZoneForMcc(440), "Asia/Tokyo");
diff --git a/telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
index de59b81..c4a6f53 100644
--- a/telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java
@@ -20,10 +20,6 @@ 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 AndroidTestCase {
@@ -503,4 +499,40 @@ public class PhoneNumberUtilsTest extends AndroidTestCase {
assertTrue(PhoneNumberUtils.isVoiceMailNumber(mVoiceMailNumber));
*/
}
+
+ @SmallTest
+ public void testFormatNumberToE164() {
+ assertEquals("+16502910000", PhoneNumberUtils.formatNumberToE164("650 2910000", "us"));
+ assertNull(PhoneNumberUtils.formatNumberToE164("1234567", "us"));
+ assertEquals("+18004664114", PhoneNumberUtils.formatNumberToE164("800-GOOG-114", "us"));
+ }
+
+ @SmallTest
+ public void testFormatNumber() {
+ assertEquals("(650) 291-0000", PhoneNumberUtils.formatNumber("650 2910000", "us"));
+ assertEquals("123-4567", PhoneNumberUtils.formatNumber("1234567", "us"));
+ assertEquals("(800) 466-4114", PhoneNumberUtils.formatNumber("800-GOOG-114", "us"));
+
+ }
+
+ @SmallTest
+ public void testNormalizeNumber() {
+ assertEquals("6502910000", PhoneNumberUtils.normalizeNumber("650 2910000"));
+ assertEquals("1234567", PhoneNumberUtils.normalizeNumber("12,3#4*567"));
+ assertEquals("8004664114", PhoneNumberUtils.normalizeNumber("800-GOOG-114"));
+ assertEquals("+16502910000", PhoneNumberUtils.normalizeNumber("+1 650 2910000"));
+ }
+
+ @SmallTest
+ public void testFormatDailabeNumber() {
+ // Using the phoneNumberE164's country code
+ assertEquals("(650) 291-0000",
+ PhoneNumberUtils.formatNumber("6502910000", "+16502910000", "CN"));
+ // The phoneNumberE164 is null
+ assertEquals("(650) 291-0000", PhoneNumberUtils.formatNumber("6502910000", null, "US"));
+ // The given number has a country code.
+ assertEquals("+1 650-291-0000", PhoneNumberUtils.formatNumber("+16502910000", null, "CN"));
+ // The given number was formatted.
+ assertEquals("650-291-0000", PhoneNumberUtils.formatNumber("650-291-0000", null, "US"));
+ }
}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberWatcherTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberWatcherTest.java
new file mode 100644
index 0000000..d2e573c
--- /dev/null
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberWatcherTest.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2008 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.PhoneNumberFormattingTextWatcher;
+import android.test.AndroidTestCase;
+import android.text.Editable;
+import android.text.Selection;
+import android.text.SpannableStringBuilder;
+import android.text.TextWatcher;
+
+public class PhoneNumberWatcherTest extends AndroidTestCase {
+ public void testAppendChars() {
+ final String multiChars = "65012345";
+ final String formatted1 = "(650) 123-45";
+ TextWatcher textWatcher = getTextWatcher();
+ SpannableStringBuilder number = new SpannableStringBuilder();
+ // Append more than one chars
+ textWatcher.beforeTextChanged(number, 0, 0, multiChars.length());
+ number.append(multiChars);
+ Selection.setSelection(number, number.length());
+ textWatcher.onTextChanged(number, 0, 0, number.length());
+ textWatcher.afterTextChanged(number);
+ assertEquals(formatted1, number.toString());
+ assertEquals(formatted1.length(), Selection.getSelectionEnd(number));
+ // Append one chars
+ final char appendChar = '6';
+ final String formatted2 = "(650) 123-456";
+ int len = number.length();
+ textWatcher.beforeTextChanged(number, number.length(), 0, 1);
+ number.append(appendChar);
+ Selection.setSelection(number, number.length());
+ textWatcher.onTextChanged(number, len, 0, 1);
+ textWatcher.afterTextChanged(number);
+ assertEquals(formatted2, number.toString());
+ assertEquals(formatted2.length(), Selection.getSelectionEnd(number));
+ }
+
+ public void testRemoveLastChars() {
+ final String init = "65012345678";
+ final String result1 = "(650) 123-4567";
+ TextWatcher textWatcher = getTextWatcher();
+ // Remove the last char.
+ SpannableStringBuilder number = new SpannableStringBuilder(init);
+ int len = number.length();
+ textWatcher.beforeTextChanged(number, len - 1, 1, 0);
+ number.delete(len - 1, len);
+ Selection.setSelection(number, number.length());
+ textWatcher.onTextChanged(number, number.length() - 1, 1, 0);
+ textWatcher.afterTextChanged(number);
+ assertEquals(result1, number.toString());
+ assertEquals(result1.length(), Selection.getSelectionEnd(number));
+ // Remove last 5 chars
+ final String result2 = "(650) 123";
+ textWatcher.beforeTextChanged(number, number.length() - 4, 4, 0);
+ number.delete(number.length() - 5, number.length());
+ Selection.setSelection(number, number.length());
+ textWatcher.onTextChanged(number, number.length(), 4, 0);
+ textWatcher.afterTextChanged(number);
+ assertEquals(result2, number.toString());
+ assertEquals(result2.length(), Selection.getSelectionEnd(number));
+ }
+
+ public void testInsertChars() {
+ final String init = "(650) 23";
+ final String expected1 = "(650) 123";
+ TextWatcher textWatcher = getTextWatcher();
+
+ // Insert one char
+ SpannableStringBuilder number = new SpannableStringBuilder(init);
+ textWatcher.beforeTextChanged(number, 4, 0, 1);
+ number.insert(4, "1"); // (6501) 23
+ Selection.setSelection(number, 5); // make the cursor at right of 1
+ textWatcher.onTextChanged(number, 4, 0, 1);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected1, number.toString());
+ // the cursor should still at the right of '1'
+ assertEquals(7, Selection.getSelectionEnd(number));
+
+ // Insert multiple chars
+ final String expected2 = "(650) 145-6723";
+ textWatcher.beforeTextChanged(number, 7, 0, 4);
+ number.insert(7, "4567"); // change to (650) 1456723
+ Selection.setSelection(number, 11); // the cursor is at the right of '7'.
+ textWatcher.onTextChanged(number, 7, 0, 4);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected2, number.toString());
+ // the cursor should be still at the right of '7'
+ assertEquals(12, Selection.getSelectionEnd(number));
+ }
+
+ public void testStopFormatting() {
+ final String init = "(650) 123";
+ final String expected1 = "(650) 123 4";
+ TextWatcher textWatcher = getTextWatcher();
+
+ // Append space
+ SpannableStringBuilder number = new SpannableStringBuilder(init);
+ textWatcher.beforeTextChanged(number, 9, 0, 2);
+ number.insert(9, " 4"); // (6501) 23 4
+ Selection.setSelection(number, number.length()); // make the cursor at right of 4
+ textWatcher.onTextChanged(number, 9, 0, 2);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected1, number.toString());
+ // the cursor should still at the right of '1'
+ assertEquals(expected1.length(), Selection.getSelectionEnd(number));
+
+ // Delete a ')'
+ final String expected2 ="(650 123";
+ textWatcher = getTextWatcher();
+ number = new SpannableStringBuilder(init);
+ textWatcher.beforeTextChanged(number, 4, 1, 0);
+ number.delete(4, 5); // (6501 23 4
+ Selection.setSelection(number, 5); // make the cursor at right of 1
+ textWatcher.onTextChanged(number, 4, 1, 0);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected2, number.toString());
+ // the cursor should still at the right of '1'
+ assertEquals(5, Selection.getSelectionEnd(number));
+
+ // Insert a hyphen
+ final String expected3 ="(650) 12-3";
+ textWatcher = getTextWatcher();
+ number = new SpannableStringBuilder(init);
+ textWatcher.beforeTextChanged(number, 8, 0, 1);
+ number.insert(8, "-"); // (650) 12-3
+ Selection.setSelection(number, 9); // make the cursor at right of -
+ textWatcher.onTextChanged(number, 8, 0, 1);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected3, number.toString());
+ // the cursor should still at the right of '-'
+ assertEquals(9, Selection.getSelectionEnd(number));
+ }
+
+ public void testRestartFormatting() {
+ final String init = "(650) 123";
+ final String expected1 = "(650) 123 4";
+ TextWatcher textWatcher = getTextWatcher();
+
+ // Append space
+ SpannableStringBuilder number = new SpannableStringBuilder(init);
+ textWatcher.beforeTextChanged(number, 9, 0, 2);
+ number.insert(9, " 4"); // (650) 123 4
+ Selection.setSelection(number, number.length()); // make the cursor at right of 4
+ textWatcher.onTextChanged(number, 9, 0, 2);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected1, number.toString());
+ // the cursor should still at the right of '4'
+ assertEquals(expected1.length(), Selection.getSelectionEnd(number));
+
+ // Clear the current string, and start formatting again.
+ int len = number.length();
+ textWatcher.beforeTextChanged(number, 0, len, 0);
+ number.delete(0, len);
+ textWatcher.onTextChanged(number, 0, len, 0);
+ textWatcher.afterTextChanged(number);
+
+ final String expected2 = "(650) 123-4";
+ number = new SpannableStringBuilder(init);
+ textWatcher.beforeTextChanged(number, 9, 0, 1);
+ number.insert(9, "4"); // (650) 1234
+ Selection.setSelection(number, number.length()); // make the cursor at right of 4
+ textWatcher.onTextChanged(number, 9, 0, 1);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected2, number.toString());
+ // the cursor should still at the right of '4'
+ assertEquals(expected2.length(), Selection.getSelectionEnd(number));
+ }
+
+ public void testTextChangedByOtherTextWatcher() {
+ final TextWatcher cleanupTextWatcher = new TextWatcher() {
+ public void afterTextChanged(Editable s) {
+ s.clear();
+ }
+
+ public void beforeTextChanged(CharSequence s, int start, int count,
+ int after) {
+ }
+
+ public void onTextChanged(CharSequence s, int start, int before,
+ int count) {
+ }
+ };
+ final String init = "(650) 123";
+ final String expected1 = "";
+ TextWatcher textWatcher = getTextWatcher();
+
+ SpannableStringBuilder number = new SpannableStringBuilder(init);
+ textWatcher.beforeTextChanged(number, 5, 0, 1);
+ number.insert(5, "4"); // (6504) 123
+ Selection.setSelection(number, 5); // make the cursor at right of 4
+ textWatcher.onTextChanged(number, 5, 0, 1);
+ number.setSpan(cleanupTextWatcher, 0, number.length(), 0);
+ textWatcher.afterTextChanged(number);
+ assertEquals(expected1, number.toString());
+ }
+
+ private TextWatcher getTextWatcher() {
+ return new PhoneNumberFormattingTextWatcher("US");
+ }
+}
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/SimUtilsTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/SimUtilsTest.java
index db38ede..ef62d85 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/SimUtilsTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/SimUtilsTest.java
@@ -28,7 +28,7 @@ public class SimUtilsTest extends TestCase {
public void testBasic() throws Exception {
byte[] data, data2;
- /*
+ /*
* bcdToString()
*/
@@ -40,9 +40,13 @@ public class SimUtilsTest extends TestCase {
assertEquals("0126045001448486", IccUtils.bcdToString(data, 1, data.length - 2));
// Stops on invalid BCD value
- data = IccUtils.hexStringToBytes("98F062400510444868f2");
+ data = IccUtils.hexStringToBytes("98E062400510444868f2");
assertEquals("890", IccUtils.bcdToString(data, 0, data.length));
+ // skip the high nibble 'F' since some PLMNs have it
+ data = IccUtils.hexStringToBytes("98F062400510444868f2");
+ assertEquals("890260450014484862", IccUtils.bcdToString(data, 0, data.length));
+
/*
* gsmBcdByteToInt()
*/
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/TestPhoneNotifier.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/TestPhoneNotifier.java
index 427795b..8cb05cc 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/TestPhoneNotifier.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/TestPhoneNotifier.java
@@ -16,6 +16,8 @@
package com.android.internal.telephony;
+import com.android.internal.telephony.Phone;
+
/**
* Stub class used for unit tests
*/
@@ -32,7 +34,7 @@ public class TestPhoneNotifier implements PhoneNotifier {
public void notifyCellLocation(Phone sender) {
}
-
+
public void notifySignalStrength(Phone sender) {
}
@@ -42,10 +44,14 @@ public class TestPhoneNotifier implements PhoneNotifier {
public void notifyCallForwardingChanged(Phone sender) {
}
- public void notifyDataConnection(Phone sender, String reason) {
+ public void notifyDataConnection(Phone sender, String reason, String apnType) {
+ }
+
+ public void notifyDataConnection(Phone sender, String reason, String apnType,
+ Phone.DataState state) {
}
- public void notifyDataConnectionFailed(Phone sender, String reason) {
+ public void notifyDataConnectionFailed(Phone sender, String reason, String apnType) {
}
public void notifyDataActivity(Phone sender) {
diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/GSMPhoneTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/GSMPhoneTest.java
index b96743a..485542b 100644
--- a/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/GSMPhoneTest.java
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/GSMPhoneTest.java
@@ -18,27 +18,21 @@ package com.android.internal.telephony.gsm;
import android.os.AsyncResult;
import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
import android.os.Message;
-import android.os.Process;
import android.telephony.ServiceState;
import android.test.AndroidTestCase;
import android.test.PerformanceTestCase;
-import android.util.Log;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.CallStateException;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.MmiCode;
import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.TestPhoneNotifier;
import com.android.internal.telephony.gsm.CallFailCause;
import com.android.internal.telephony.gsm.GSMPhone;
import com.android.internal.telephony.gsm.GSMTestHandler;
import com.android.internal.telephony.gsm.GsmMmiCode;
import com.android.internal.telephony.gsm.SuppServiceNotification;
-import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.test.SimulatedRadioControl;
import java.util.List;
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..f0d5b31
--- /dev/null
+++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java
@@ -0,0 +1,197 @@
+/*
+ * 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 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 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 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");
+ }
+
+ 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");
+ }
+
+ 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);
+ }
+}