summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristine Chen <christinech@google.com>2013-07-08 18:05:03 -0700
committerChristine Chen <christinech@google.com>2013-07-10 11:32:10 -0700
commita81953a2b1818066ef5e44817f374ac288bab343 (patch)
tree9c2723a0cf793531d72c8efbbeed7f5426fca58b /tests
parent0f290ef69262b8a5032fe287e9ef2c5ac8c53985 (diff)
downloadandroid_packages_apps_ContactsCommon-a81953a2b1818066ef5e44817f374ac288bab343.tar.gz
android_packages_apps_ContactsCommon-a81953a2b1818066ef5e44817f374ac288bab343.tar.bz2
android_packages_apps_ContactsCommon-a81953a2b1818066ef5e44817f374ac288bab343.zip
Changes to support smart dial in search.
- Extends functionalities in text highligher. - Changes pemissions in parent classes. Change-Id: Ib5717fe00760b5a88c747e1ff8fda598d987fa98
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/contacts/common/format/PrefixHighligherTest.java84
-rw-r--r--tests/src/com/android/contacts/common/format/TextHighlighterTest.java110
2 files changed, 110 insertions, 84 deletions
diff --git a/tests/src/com/android/contacts/common/format/PrefixHighligherTest.java b/tests/src/com/android/contacts/common/format/PrefixHighligherTest.java
deleted file mode 100644
index d3bacdb9..00000000
--- a/tests/src/com/android/contacts/common/format/PrefixHighligherTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2011 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.contacts.common.format;
-
-import android.test.suitebuilder.annotation.SmallTest;
-
-import junit.framework.TestCase;
-
-/**
- * Unit tests for {@link com.android.contacts.common.format.PrefixHighlighter}.
- */
-@SmallTest
-public class PrefixHighligherTest extends TestCase {
- private static final int TEST_PREFIX_HIGHLIGHT_COLOR = 0xFF0000;
-
- /** The object under test. */
- private PrefixHighlighter mPrefixHighlighter;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mPrefixHighlighter = new PrefixHighlighter(TEST_PREFIX_HIGHLIGHT_COLOR);
- }
-
- public void testApply_EmptyPrefix() {
- CharSequence seq = mPrefixHighlighter.apply("", "");
- SpannedTestUtils.assertNotSpanned(seq, "");
-
- seq = mPrefixHighlighter.apply("test", "");
- SpannedTestUtils.assertNotSpanned(seq, "test");
- }
-
- public void testSetText_MatchingPrefix() {
- final String prefix = "TE";
-
- CharSequence seq = mPrefixHighlighter.apply("test", prefix);
- SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
-
- seq = mPrefixHighlighter.apply("Test", prefix);
- SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
-
- seq = mPrefixHighlighter.apply("TEst", prefix);
- SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
-
- seq = mPrefixHighlighter.apply("a test", prefix);
- SpannedTestUtils.assertPrefixSpan(seq, 2, 3);
- }
-
- public void testSetText_NotMatchingPrefix() {
- final CharSequence seq = mPrefixHighlighter.apply("test", "TA");
- SpannedTestUtils.assertNotSpanned(seq, "test");
- }
-
- public void testSetText_FirstMatch() {
- final CharSequence seq = mPrefixHighlighter.apply("a test's tests are not tests", "TE");
- SpannedTestUtils.assertPrefixSpan(seq, 2, 3);
- }
-
- public void testSetText_NoMatchingMiddleOfWord() {
- final String prefix = "TE";
- CharSequence seq = mPrefixHighlighter.apply("atest", prefix);
- SpannedTestUtils.assertNotSpanned(seq, "atest");
-
- seq = mPrefixHighlighter.apply("atest otest", prefix);
- SpannedTestUtils.assertNotSpanned(seq, "atest otest");
-
- seq = mPrefixHighlighter.apply("atest test", prefix);
- SpannedTestUtils.assertPrefixSpan(seq, 6, 7);
- }
-}
diff --git a/tests/src/com/android/contacts/common/format/TextHighlighterTest.java b/tests/src/com/android/contacts/common/format/TextHighlighterTest.java
new file mode 100644
index 00000000..2009c317
--- /dev/null
+++ b/tests/src/com/android/contacts/common/format/TextHighlighterTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2011 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.contacts.common.format;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.contacts.common.format.SpannedTestUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for {@link TextHighlighter}.
+ */
+@SmallTest
+public class TextHighlighterTest extends TestCase {
+ private static final int TEST_PREFIX_HIGHLIGHT_COLOR = 0xFF0000;
+
+ /** The object under test. */
+ private TextHighlighter mTextHighlighter;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mTextHighlighter = new TextHighlighter(TEST_PREFIX_HIGHLIGHT_COLOR);
+ }
+
+ public void testApply_EmptyPrefix() {
+ CharSequence seq = mTextHighlighter.applyPrefixHighlight("", "");
+ SpannedTestUtils.assertNotSpanned(seq, "");
+
+ seq = mTextHighlighter.applyPrefixHighlight("test", "");
+ SpannedTestUtils.assertNotSpanned(seq, "test");
+ }
+
+ public void testSetText_MatchingPrefix() {
+ final String prefix = "TE";
+
+ CharSequence seq = mTextHighlighter.applyPrefixHighlight("test", prefix);
+ SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
+
+ seq = mTextHighlighter.applyPrefixHighlight("Test", prefix);
+ SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
+
+ seq = mTextHighlighter.applyPrefixHighlight("TEst", prefix);
+ SpannedTestUtils.assertPrefixSpan(seq, 0, 1);
+
+ seq = mTextHighlighter.applyPrefixHighlight("a test", prefix);
+ SpannedTestUtils.assertPrefixSpan(seq, 2, 3);
+ }
+
+ public void testSetText_NotMatchingPrefix() {
+ final CharSequence seq = mTextHighlighter.applyPrefixHighlight("test", "TA");
+ SpannedTestUtils.assertNotSpanned(seq, "test");
+ }
+
+ public void testSetText_FirstMatch() {
+ final CharSequence seq = mTextHighlighter.applyPrefixHighlight(
+ "a test's tests are not tests", "TE");
+ SpannedTestUtils.assertPrefixSpan(seq, 2, 3);
+ }
+
+ public void testSetText_NoMatchingMiddleOfWord() {
+ final String prefix = "TE";
+ CharSequence seq = mTextHighlighter.applyPrefixHighlight("atest", prefix);
+ SpannedTestUtils.assertNotSpanned(seq, "atest");
+
+ seq = mTextHighlighter.applyPrefixHighlight("atest otest", prefix);
+ SpannedTestUtils.assertNotSpanned(seq, "atest otest");
+
+ seq = mTextHighlighter.applyPrefixHighlight("atest test", prefix);
+ SpannedTestUtils.assertPrefixSpan(seq, 6, 7);
+ }
+
+ public void testSetMask_LengthMismatch() {
+ final String mask = "001101";
+ CharSequence seq = mTextHighlighter.applyMaskingHighlight("atest", mask);
+ SpannedTestUtils.assertNotSpanned(seq, "atest");
+
+ seq = mTextHighlighter.applyMaskingHighlight("alongtest", mask);
+ SpannedTestUtils.assertNotSpanned(seq, "alongtest");
+
+ seq = mTextHighlighter.applyMaskingHighlight("", mask);
+ SpannedTestUtils.assertNotSpanned(seq, "");
+ }
+
+ public void testSetMask_Highlight() {
+ final String mask = "001101011";
+ CharSequence seq = mTextHighlighter.applyMaskingHighlight("alongtest", mask);
+ assertEquals(SpannedTestUtils.getNextTransition(seq, 0), 2);
+ assertEquals(SpannedTestUtils.getNextTransition(seq, 2), 4);
+ assertEquals(SpannedTestUtils.getNextTransition(seq, 4), 5);
+ assertEquals(SpannedTestUtils.getNextTransition(seq, 5), 6);
+ assertEquals(SpannedTestUtils.getNextTransition(seq, 6), 7);
+ assertEquals(SpannedTestUtils.getNextTransition(seq, 7), 9);
+ }
+}