1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dialer.dialpad; 18 19 import android.test.suitebuilder.annotation.SmallTest; 20 21 import junit.framework.TestCase; 22 23 /** Unit tests for {@link DialpadFragment}. */ 24 @SmallTest 25 public class DialpadFragmentTest extends TestCase { 26 27 public void testCanAddDigit_Valid() { 28 // end, middle, selection to end, middle selection 29 assertTrue(DialpadFragment.canAddDigit("123", 3, 3, ';')); 30 assertTrue(DialpadFragment.canAddDigit("123", 1, 1, ',')); 31 assertTrue(DialpadFragment.canAddDigit("123", 1, 3, ';')); 32 assertTrue(DialpadFragment.canAddDigit("123", 1, 2, ',')); 33 } 34 35 public void testCanAddDigit_InvalidCharacter() { 36 // only handles wait/pause 37 assertFalse(DialpadFragment.canAddDigit("123", 1, 1, '5')); 38 } 39 40 public void testCanAddDigit_BadOrNoSelection() { 41 // no selection 42 assertFalse(DialpadFragment.canAddDigit("123", -1, -1, ';')); 43 assertFalse(DialpadFragment.canAddDigit("123", -1, 1, ',')); 44 45 // start > end 46 assertFalse(DialpadFragment.canAddDigit("123", 2, 1, ',')); 47 } 48 49 public void testCanAddDigit_OutOfBounds() { 50 // start or end is > digits.length() 51 assertFalse(DialpadFragment.canAddDigit("123", 1, 4, ';')); 52 assertFalse(DialpadFragment.canAddDigit("123", 4, 4, ',')); 53 } 54 55 public void testCanAddDigit_AsFirstCharacter() { 56 assertFalse(DialpadFragment.canAddDigit("", 0, 0, ',')); 57 assertFalse(DialpadFragment.canAddDigit("123", 0, 0, ';')); 58 assertFalse(DialpadFragment.canAddDigit("123", 0, 2, ',')); 59 assertFalse(DialpadFragment.canAddDigit("123", 0, 3, ',')); 60 } 61 62 public void testCanAddDigit_AdjacentCharacters_Before() { 63 // before 64 assertFalse(DialpadFragment.canAddDigit("55;55", 2, 2, ';')); // WAIT 65 assertFalse(DialpadFragment.canAddDigit("55;55", 1, 2, ';')); 66 assertTrue(DialpadFragment.canAddDigit("55,55", 2, 2, ',')); // PAUSE 67 assertTrue(DialpadFragment.canAddDigit("55,55", 1, 2, ',')); 68 assertTrue(DialpadFragment.canAddDigit("55;55", 2, 2, ',')); // WAIT & PAUSE 69 assertTrue(DialpadFragment.canAddDigit("55,55", 1, 2, ';')); 70 } 71 72 public void testCanAddDigit_AdjacentCharacters_After() { 73 // after 74 assertFalse(DialpadFragment.canAddDigit("55;55", 3, 3, ';')); // WAIT 75 assertFalse(DialpadFragment.canAddDigit("55;55", 3, 4, ';')); 76 assertTrue(DialpadFragment.canAddDigit("55,55", 3, 3, ',')); // PAUSE 77 assertTrue(DialpadFragment.canAddDigit("55,55", 3, 4, ',')); 78 assertTrue(DialpadFragment.canAddDigit("55;55", 3, 3, ',')); // WAIT & PAUSE 79 assertTrue(DialpadFragment.canAddDigit("55,55", 3, 4, ';')); 80 } 81 } 82