diff options
Diffstat (limited to 'telephony/tests/telephonytests')
-rw-r--r-- | telephony/tests/telephonytests/src/android/telephony/PhoneNumberWatcherTest.java | 65 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java | 2 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/GsmSmsTest.java | 2 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java (renamed from telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java) | 0 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberWatcherTest.java | 214 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/TestPhoneNotifier.java | 12 | ||||
-rw-r--r-- | telephony/tests/telephonytests/src/com/android/internal/telephony/gsm/GSMPhoneTest.java | 6 |
7 files changed, 224 insertions, 77 deletions
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/internal/telephony/GsmAlphabetTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java index 3a9c511..a6b9a2a 100644 --- a/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/GsmAlphabetTest.java @@ -51,7 +51,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')); // 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/android/telephony/PhoneNumberUtilsTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java index de59b81..de59b81 100644 --- a/telephony/tests/telephonytests/src/android/telephony/PhoneNumberUtilsTest.java +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/PhoneNumberUtilsTest.java 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/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; |