summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBrian Attwell <brianattwell@google.com>2015-03-04 21:01:44 -0800
committerBrian Attwell <brianattwell@google.com>2015-03-05 12:28:04 -0800
commit3cf9ac64046bfd65d419476c900d3d98d3eccfeb (patch)
tree2221ec8db2917311764cc67be044dbd0ee97244a /tests
parentae8f8932b836437e548405387e080388c3686964 (diff)
downloadpackages_providers_ContactsProvider-3cf9ac64046bfd65d419476c900d3d98d3eccfeb.zip
packages_providers_ContactsProvider-3cf9ac64046bfd65d419476c900d3d98d3eccfeb.tar.gz
packages_providers_ContactsProvider-3cf9ac64046bfd65d419476c900d3d98d3eccfeb.tar.bz2
Prioritize regular names over phonetic names. P2/2
When choosing display names, prioritize StructuredNames that have more than phonetic components. I make no attempt to handle the case where a StructuredName with only phonetic components is marked super primary. If clients do this, the behavior is still undefined. Bug: 19587274 Change-Id: I503c0fff6da30b9f1d6b6cbeaedfc4d9314f8a00
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java68
-rw-r--r--tests/src/com/android/providers/contacts/testutil/DataUtil.java25
2 files changed, 86 insertions, 7 deletions
diff --git a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
index 204875b..43fc488 100644
--- a/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
+++ b/tests/src/com/android/providers/contacts/aggregation/ContactAggregatorTest.java
@@ -1618,6 +1618,74 @@ public class ContactAggregatorTest extends BaseContactsProvider2Test {
cursor.close();
}
+ public void testAggregation_phoneticNamePriority1() {
+ // Setup: one raw contact has a complex phonetic name and the other a simple given name
+ long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1);
+ DataUtil.insertPhoneticName(mResolver, rawContactId1, "name phonetic");
+ long rawContactId2 = RawContactUtil.createRawContactWithName(mResolver, null,
+ "name", ACCOUNT_1);
+
+ // Action: aggregate
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1,
+ rawContactId2);
+
+ // Verify: given name is used instead of phonetic, contrary to results of
+ // testAggregation_nameComplexity
+ long contactId = queryContactId(rawContactId1);
+ assertEquals("name", queryDisplayName(contactId));
+ }
+
+ // Same as testAggregation_phoneticNamePriority1, but with setup order reversed
+ public void testAggregation_phoneticNamePriority2() {
+ // Setup: one raw contact has a complex phonetic name and the other a simple given name
+ long rawContactId2 = RawContactUtil.createRawContactWithName(mResolver, null,
+ "name", ACCOUNT_1);
+ long rawContactId1 = RawContactUtil.createRawContact(mResolver, ACCOUNT_1);
+ DataUtil.insertPhoneticName(mResolver, rawContactId1, "name phonetic");
+
+ // Action: aggregate
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1,
+ rawContactId2);
+
+ // Verify: given name is used instead of phonetic, contrary to results of
+ // testAggregation_nameComplexity
+ long contactId = queryContactId(rawContactId1);
+ assertEquals("name", queryDisplayName(contactId));
+ }
+
+ public void testAggregation_nameComplexity1() {
+ // Setup: two names, one of which is unambiguously more complex
+ long rawContactId1 = RawContactUtil.createRawContactWithName(mResolver, null,
+ "name", ACCOUNT_1);
+ long rawContactId2 = RawContactUtil.createRawContactWithName(mResolver, null,
+ "name phonetic", ACCOUNT_1);
+
+ // Action: aggregate
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1,
+ rawContactId2);
+
+ // Verify: more complex name is used
+ long contactId = queryContactId(rawContactId1);
+ assertEquals("name phonetic", queryDisplayName(contactId));
+ }
+
+ // Same as testAggregation_nameComplexity1, but with setup order reversed
+ public void testAggregation_nameComplexity2() {
+ // Setup: two names, one of which is unambiguously more complex
+ long rawContactId2 = RawContactUtil.createRawContactWithName(mResolver, null,
+ "name phonetic", ACCOUNT_1);
+ long rawContactId1 = RawContactUtil.createRawContactWithName(mResolver, null,
+ "name", ACCOUNT_1);
+
+ // Action: aggregate
+ setAggregationException(AggregationExceptions.TYPE_KEEP_TOGETHER, rawContactId1,
+ rawContactId2);
+
+ // Verify: more complex name is used
+ long contactId = queryContactId(rawContactId1);
+ assertEquals("name phonetic", queryDisplayName(contactId));
+ }
+
public void testAggregation_clearSuperPrimary() {
// Three types of mime-type super primary merging are tested here
// 1. both raw contacts have super primary phone numbers
diff --git a/tests/src/com/android/providers/contacts/testutil/DataUtil.java b/tests/src/com/android/providers/contacts/testutil/DataUtil.java
index 1f4f35a..2afd567 100644
--- a/tests/src/com/android/providers/contacts/testutil/DataUtil.java
+++ b/tests/src/com/android/providers/contacts/testutil/DataUtil.java
@@ -59,14 +59,14 @@ public class DataUtil {
public static Uri insertStructuredName(
ContentResolver resolver, long rawContactId, String givenName, String familyName,
- String phoneticGiven) {
- return insertStructuredName(resolver, rawContactId, givenName, familyName, phoneticGiven,
+ String phoneticFamily) {
+ return insertStructuredName(resolver, rawContactId, givenName, familyName, phoneticFamily,
/* isSuperPrimary = true */ false);
}
public static Uri insertStructuredName(
ContentResolver resolver, long rawContactId, String givenName, String familyName,
- String phoneticGiven, boolean isSuperPrimary) {
+ String phoneticFamily, boolean isSuperPrimary) {
ContentValues values = new ContentValues();
StringBuilder sb = new StringBuilder();
if (givenName != null) {
@@ -78,14 +78,16 @@ public class DataUtil {
if (familyName != null) {
sb.append(familyName);
}
- if (sb.length() == 0 && phoneticGiven != null) {
- sb.append(phoneticGiven);
+ if (sb.length() == 0 && phoneticFamily != null) {
+ sb.append(phoneticFamily);
}
values.put(StructuredName.DISPLAY_NAME, sb.toString());
values.put(StructuredName.GIVEN_NAME, givenName);
values.put(StructuredName.FAMILY_NAME, familyName);
- if (phoneticGiven != null) {
- values.put(StructuredName.PHONETIC_GIVEN_NAME, phoneticGiven);
+ if (phoneticFamily != null) {
+ // When creating phonetic names, be careful to use PHONETIC_FAMILY_NAME instead of
+ // PHONETIC_GIVEN_NAME, to work around b/19612393.
+ values.put(StructuredName.PHONETIC_FAMILY_NAME, phoneticFamily);
}
if (isSuperPrimary) {
values.put(Data.IS_PRIMARY, 1);
@@ -94,4 +96,13 @@ public class DataUtil {
return insertStructuredName(resolver, rawContactId, values);
}
+
+ public static Uri insertPhoneticName(ContentResolver resolver, long rawContactId,
+ String phoneticFamilyName) {
+ ContentValues values = new ContentValues();
+ // When creating phonetic names, be careful to use PHONETIC_FAMILY_NAME instead of
+ // PHONETIC_GIVEN_NAME, to work around b/19612393.
+ values.put(StructuredName.PHONETIC_FAMILY_NAME, phoneticFamilyName);
+ return insertStructuredName(resolver, rawContactId, values);
+ }
} \ No newline at end of file