diff options
author | Makoto Onuki <omakoto@google.com> | 2011-12-16 10:16:09 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-12-16 10:16:09 -0800 |
commit | 4fe11285fa85147f9ded777a6ebc46adbae40de8 (patch) | |
tree | 41a3b5af0ba884a5bc7e4a4b5399a30ead36ab50 /tests | |
parent | 0ac598e532b15b8eb1d8fccde75ce97885f6411b (diff) | |
parent | ac61fb8b20b05bb7a9af7c6d68bf8cdbdf675102 (diff) | |
download | packages_providers_ContactsProvider-4fe11285fa85147f9ded777a6ebc46adbae40de8.zip packages_providers_ContactsProvider-4fe11285fa85147f9ded777a6ebc46adbae40de8.tar.gz packages_providers_ContactsProvider-4fe11285fa85147f9ded777a6ebc46adbae40de8.tar.bz2 |
Merge "Fix phone_lookup related tests"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java | 9 | ||||
-rw-r--r-- | tests/src/com/android/providers/contacts/ContactsProvider2Test.java | 17 |
2 files changed, 21 insertions, 5 deletions
diff --git a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java index 87196bf..c008003 100644 --- a/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/BaseContactsProvider2Test.java @@ -58,6 +58,7 @@ import android.util.Log; import java.util.ArrayList; import java.util.Arrays; +import java.util.BitSet; import java.util.Comparator; import java.util.Iterator; import java.util.Map; @@ -1039,12 +1040,20 @@ public abstract class BaseContactsProvider2Test extends PhotoLoadingTestCase { protected void assertCursorValues(Cursor cursor, ContentValues[] expectedValues) { StringBuilder message = new StringBuilder(); + + // In case if expectedValues contains multiple identical values, remember which cursor + // rows are "consumed" to prevent multiple ContentValues from hitting the same row. + final BitSet used = new BitSet(cursor.getCount()); + for (ContentValues v : expectedValues) { boolean found = false; cursor.moveToPosition(-1); while (cursor.moveToNext()) { + final int pos = cursor.getPosition(); + if (used.get(pos)) continue; found = equalsWithExpectedValues(cursor, v, message); if (found) { + used.set(pos); break; } } diff --git a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java index a050f43..5725eda 100644 --- a/tests/src/com/android/providers/contacts/ContactsProvider2Test.java +++ b/tests/src/com/android/providers/contacts/ContactsProvider2Test.java @@ -1038,6 +1038,9 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { insertStructuredName(rawContactId, "Hot", "Tamale"); insertPhoneNumber(rawContactId, "18004664411"); + // We'll create two lookup records, 18004664411 and +18004664411, and the below lookup + // will match both. + Uri lookupUri1 = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, "8004664411"); values.clear(); @@ -1048,7 +1051,7 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { values.putNull(PhoneLookup.LABEL); values.put(PhoneLookup.CUSTOM_RINGTONE, "d"); values.put(PhoneLookup.SEND_TO_VOICEMAIL, 1); - assertStoredValues(lookupUri1, values); + assertStoredValues(lookupUri1, null, null, new ContentValues[] {values, values}); // In the context that 8004664411 is a valid number, "4664411" as a // call id should match to both "8004664411" and "+18004664411". @@ -1132,27 +1135,31 @@ public class ContactsProvider2Test extends BaseContactsProvider2Test { Uri phoneUri = insertPhoneNumber(rawContactId, "18004664411"); Uri lookupUri1 = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, "8004664411"); - assertStoredValue(lookupUri1, PhoneLookup.DISPLAY_NAME, "Hot Tamale"); + Uri lookupUri2 = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, "8004664422"); + assertEquals(2, getCount(lookupUri1, null, null)); + assertEquals(0, getCount(lookupUri2, null, null)); values.clear(); values.put(Phone.NUMBER, "18004664422"); mResolver.update(phoneUri, values, null, null); - Uri lookupUri2 = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, "8004664422"); - assertStoredValue(lookupUri2, PhoneLookup.DISPLAY_NAME, "Hot Tamale"); + assertEquals(0, getCount(lookupUri1, null, null)); + assertEquals(2, getCount(lookupUri2, null, null)); // Setting number to null will remove the phone lookup record values.clear(); values.putNull(Phone.NUMBER); mResolver.update(phoneUri, values, null, null); + assertEquals(0, getCount(lookupUri1, null, null)); assertEquals(0, getCount(lookupUri2, null, null)); // Let's restore that phone lookup record values.clear(); values.put(Phone.NUMBER, "18004664422"); mResolver.update(phoneUri, values, null, null); - assertStoredValue(lookupUri2, PhoneLookup.DISPLAY_NAME, "Hot Tamale"); + assertEquals(0, getCount(lookupUri1, null, null)); + assertEquals(2, getCount(lookupUri2, null, null)); assertNetworkNotified(true); } |