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
17package com.android.dialer.dialpad;
18
19import android.test.suitebuilder.annotation.SmallTest;
20
21import com.android.dialer.dialpad.UnicodeDialerKeyListener;
22
23import junit.framework.TestCase;
24/**
25 * Test case for {@link UnicodeDialerKeyListener}.
26 *
27 * adb shell am instrument -w -e class com.android.contacts.dialpad.UnicodeDialerKeyListenerTest \
28       com.android.contacts.tests/android.test.InstrumentationTestRunner
29 */
30@SmallTest
31public class UnicodeDialerKeyListenerTest extends TestCase {
32    private static UnicodeDialerKeyListener mUnicodeDialerKeyListener;
33
34    // Pasted numeric digits should remain unchanged
35    public void testNumericDigits() {
36        // The last 3 arguments don't matter because {@link NumberKeyListener} doesn't care
37        // about dest, dstart, dend in
38        // public CharSequence filter (CharSequence source, int start, int end,
39        //         Spanned dest, int dstart, int dend)
40        // anyway. This applies to all tests.
41        assertEquals(null, mUnicodeDialerKeyListener.filter("111222333", 0, 9, null, 0, 0));
42    }
43
44    // Pasted Arabic digits should be converted to ascii digits
45    public void testArabicDigits() {
46        assertEquals("0123456789", mUnicodeDialerKeyListener.filter("٠١٢٣٤٥٦٧٨٩", 0, 10,
47                null, 0, 0));
48    }
49
50    // Pasted Farsi(Persian) digits should be converted to ascii digits
51    // Note the difference in digits 4, 5 and 6 when compared to arabic. The rest of the digits
52    // look the same compared to the Arabic digits but they actually have different unicode codes.
53    public void testFarsiDigits() {
54        assertEquals("0123456789", mUnicodeDialerKeyListener.filter("۰۱۲۳۴۵۶۷۸۹", 0, 10,
55                null, 0, 0));
56    }
57
58    // This is a rare use case but we should make sure it works all the same.
59    public void testCombinationDigits() {
60        assertEquals("15102849177", mUnicodeDialerKeyListener.filter("۱510٢٨٤۹۱۷۷", 0, 11,
61                null, 0, 0));
62    }
63
64    // Test that a normal digit string with dashes is returned unfiltered
65    public void testDashes() {
66        assertEquals(null, mUnicodeDialerKeyListener.filter("1510-284-9177", 0, 13,
67                null, 0, 0));
68    }
69
70    @Override
71    protected void setUp() throws Exception {
72        mUnicodeDialerKeyListener = UnicodeDialerKeyListener.INSTANCE;
73    }
74}
75