LegacyContactsProviderTest.java revision 33b41fdb8d7c3c654cb070799c9d6e2b4ab16078
1bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov/*
2bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * Copyright (C) 2009 The Android Open Source Project
3bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov *
4bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * Licensed under the Apache License, Version 2.0 (the "License");
5bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * you may not use this file except in compliance with the License.
6bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * You may obtain a copy of the License at
7bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov *
8bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov *      http://www.apache.org/licenses/LICENSE-2.0
9bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov *
10bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * Unless required by applicable law or agreed to in writing, software
11bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * distributed under the License is distributed on an "AS IS" BASIS,
12bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * See the License for the specific language governing permissions and
14bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * limitations under the License.
15bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov */
16bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
17bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovpackage com.android.providers.contacts;
18bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
19bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.content.ContentProvider;
20bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.content.ContentUris;
21bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.content.ContentValues;
22bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.content.res.Resources;
23bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.database.Cursor;
24bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.net.Uri;
25bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts;
26bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.ContactMethods;
27bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.Extensions;
28bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.GroupMembership;
29bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.Groups;
30bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.Organizations;
31bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.People;
32bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.Phones;
33bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.Photos;
34bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.provider.Contacts.Presence;
35bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport android.test.suitebuilder.annotation.LargeTest;
36bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
37bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport java.io.ByteArrayOutputStream;
38bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport java.io.IOException;
39bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovimport java.io.InputStream;
40bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
41bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov/**
42bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov * Tests for legacy contacts APIs.
43bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov */
44bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov@LargeTest
45bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikovpublic class LegacyContactsProviderTest extends BaseContactsProvider2Test {
46bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
47f4e1358f1c8f5fe5e9e7689e36e04c57c2385169Dmitri Plotnikov    private static final boolean USE_LEGACY_PROVIDER = false;
48f4e1358f1c8f5fe5e9e7689e36e04c57c2385169Dmitri Plotnikov
49bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    @Override
50bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    protected Class<? extends ContentProvider> getProviderClass() {
51f4e1358f1c8f5fe5e9e7689e36e04c57c2385169Dmitri Plotnikov       return USE_LEGACY_PROVIDER ? ContactsProvider.class : SynchronousContactsProvider2.class;
52bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
53bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
54bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    @Override
55bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    protected String getAuthority() {
56bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        return Contacts.AUTHORITY;
57bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
58bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
59bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    public void testPeopleInsert() {
60bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
61bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
62bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
63bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri uri = mResolver.insert(People.CONTENT_URI, values);
64bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(uri, values);
65d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertSelection(People.CONTENT_URI, values, People._ID, ContentUris.parseId(uri));
66bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
67bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
6833b41fdb8d7c3c654cb070799c9d6e2b4ab16078Dmitri Plotnikov    public void testPeopleDelete() {
69bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
70bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NAME, "John Doe");
71bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personId = mResolver.insert(People.CONTENT_URI, values);
72bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.delete(personId, null, null);
73bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
74bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Cursor c = mResolver.query(personId, null, People.NAME + "='John Doe'" , null, null);
75bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertEquals("Record count after deletion", 0, c.getCount());
76bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        c.close();
77bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
78bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        try {
79bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            mResolver.query(People.DELETED_CONTENT_URI, null, null, null, null);
80bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        } catch (UnsupportedOperationException e) {
81bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            // Expected exception
82bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        }
83bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
84bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
85445ca81effbb0d61c7bc0033acf2d3dfd228fd4eDmitri Plotnikov    public void testPeopleFilter() {
86bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
87bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NAME, "Deer Doe");
88bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.insert(People.CONTENT_URI, values);
89bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
90bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
91bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NAME, "Dear Dough");
92bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.insert(People.CONTENT_URI, values);
93bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
94bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
95bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NAME, "D.R. Dauwe");
96bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.insert(People.CONTENT_URI, values);
97bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
98bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertFilteredContacts("d", "Deer Doe", "Dear Dough", "D.R. Dauwe");
99bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertFilteredContacts("de", "Deer Doe", "Dear Dough");
100bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertFilteredContacts("dee", "Deer Doe");
101bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertFilteredContacts("der");
102bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
103bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
1040f8f3b3e4a6ad18c5868d0215cc137845a2ddc74Dmitri Plotnikov    public void testDefaultDisplayName() {
105bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
106bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NAME, "John Doe");
107bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
108bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, People.DISPLAY_NAME, "John Doe");
109bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
110bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
1113cebbf7141252768d3e272e049e9c5b0cb9d710eDmitri Plotnikov    public void testPrimaryOrganization() {
112bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
113bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        final Uri personUri = mResolver.insert(People.CONTENT_URI, values);
114bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
115bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
116bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Primary
117bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
118bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.ISPRIMARY, 1);
119bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.COMPANY, "Google");
120bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.TYPE, Organizations.TYPE_WORK);
121bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.PERSON_ID, personId);
122bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri orgUri1 = mResolver.insert(Organizations.CONTENT_URI, values);
123bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
124bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Non-primary
125bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
126bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.COMPANY, "Acme");
127bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.TYPE, Organizations.TYPE_WORK);
128bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.PERSON_ID, personId);
129bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri orgUri2 = mResolver.insert(Organizations.CONTENT_URI, values);
130bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
131bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
132bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRIMARY_ORGANIZATION_ID, ContentUris.parseId(orgUri1));
133bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.DISPLAY_NAME, "Google");
134bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
135bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
136bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Remove the original primary organization
137bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.delete(orgUri1, null, null);
138bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
139bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
140bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRIMARY_ORGANIZATION_ID, ContentUris.parseId(orgUri2));
141bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.DISPLAY_NAME, "Acme");
142bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
143bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
144bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Remove the remaining organization
145bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.delete(orgUri2, null, null);
146bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
147bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
148bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.putNull(People.PRIMARY_ORGANIZATION_ID);
149bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.putNull(People.DISPLAY_NAME);
150bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
151bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
152bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
153e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    public void testPrimaryPhone() {
154bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
155bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
156bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
157bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
158bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Primary
159bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
160bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.ISPRIMARY, 1);
161bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.TYPE, Phones.TYPE_WORK);
162bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.PERSON_ID, personId);
163bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.NUMBER, "12345");
164bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri phoneUri1 = mResolver.insert(Phones.CONTENT_URI, values);
165bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
166bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Non-primary
167bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
168bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.TYPE, Phones.TYPE_WORK);
169bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.PERSON_ID, personId);
170bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.NUMBER, "67890");
171bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri phoneUri2 = mResolver.insert(Phones.CONTENT_URI, values);
172bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
173bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
174bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRIMARY_PHONE_ID, ContentUris.parseId(phoneUri1));
175bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.DISPLAY_NAME, "12345");
176bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
177bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
178bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Remove the primary phone number
179bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.delete(phoneUri1, null, null);
180bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
181bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
182bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRIMARY_PHONE_ID, ContentUris.parseId(phoneUri2));
183bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.DISPLAY_NAME, "67890");
184bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
185bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
186bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Remove the remaining phone number
187bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.delete(phoneUri2, null, null);
188bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
189bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
190bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.putNull(People.PRIMARY_PHONE_ID);
191bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.putNull(People.DISPLAY_NAME);
192bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
193bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
194bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
195e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    public void testPrimaryEmail() {
196bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
197bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
198bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
199bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
200bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Primary
201bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
202bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.PERSON_ID, personId);
203bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.KIND, Contacts.KIND_EMAIL);
204bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.TYPE, ContactMethods.TYPE_HOME);
205bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.DATA, "foo@acme.com");
206bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.ISPRIMARY, 1);
207bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri emailUri1 = mResolver.insert(ContactMethods.CONTENT_URI, values);
208bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
209bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Non-primary
210bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
211bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.PERSON_ID, personId);
212bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.KIND, Contacts.KIND_EMAIL);
213bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.TYPE, ContactMethods.TYPE_WORK);
214bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.DATA, "bar@acme.com");
215bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri emailUri2 = mResolver.insert(ContactMethods.CONTENT_URI, values);
216bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
217bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
218bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRIMARY_EMAIL_ID, ContentUris.parseId(emailUri1));
219bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.DISPLAY_NAME, "foo@acme.com");
220bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
221bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
222bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Remove the primary email
223bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.delete(emailUri1, null, null);
224bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
225bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
226bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRIMARY_EMAIL_ID, ContentUris.parseId(emailUri2));
227bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.DISPLAY_NAME, "bar@acme.com");
228bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
229bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
230bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Remove the remaining email
231bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.delete(emailUri2, null, null);
232bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
233bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
234bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.putNull(People.PRIMARY_EMAIL_ID);
235bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.putNull(People.DISPLAY_NAME);
236bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
237bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
238bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
239bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    public void testMarkAsContacted() {
240bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
241bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
242bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
243bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
244bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        int timesContactedBefore =
245bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                Integer.parseInt(getStoredValue(personUri, People.TIMES_CONTACTED));
246bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long timeBefore = System.currentTimeMillis();
247bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        People.markAsContacted(mResolver, personId);
248bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long timeAfter = System.currentTimeMillis();
249bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
250bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long lastContacted = Long.parseLong(getStoredValue(personUri, People.LAST_TIME_CONTACTED));
251bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        int timesContactedAfter =
252bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            Integer.parseInt(getStoredValue(personUri, People.TIMES_CONTACTED));
253bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
254bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertTrue(lastContacted >= timeBefore);
255bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertTrue(lastContacted <= timeAfter);
256bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertEquals(timesContactedAfter, timesContactedBefore + 1);
257bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
258bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
2593cebbf7141252768d3e272e049e9c5b0cb9d710eDmitri Plotnikov    public void testOrganizationsInsert() {
260bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
261bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
262bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
263bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
264bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
265bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.COMPANY, "Sierra");
266bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.PERSON_ID, personId);
267bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.TYPE, Organizations.TYPE_CUSTOM);
268bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.LABEL, "Club");
269bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.TITLE, "Member");
270bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Organizations.ISPRIMARY, 1);
271bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
272bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri uri = mResolver.insert(Organizations.CONTENT_URI, values);
273bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(uri, values);
274d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertSelection(Organizations.CONTENT_URI, values,
275d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov                Organizations._ID, ContentUris.parseId(uri));
276bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
277bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertPersonIdConstraint(Organizations.CONTENT_URI, Organizations.TYPE,
278bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                Organizations.TYPE_WORK);
279bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
280bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertTypeAndLabelConstraints(Organizations.CONTENT_URI, Organizations.PERSON_ID, personId,
281bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                Organizations.TYPE, Organizations.TYPE_CUSTOM, Organizations.TYPE_OTHER,
282bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                Organizations.LABEL);
283bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
284bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
285e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    public void testPhonesInsert() {
286bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
287bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
288bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
289bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
290bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
291bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
292bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.PERSON_ID, personId);
293bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.TYPE, Phones.TYPE_CUSTOM);
294bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.LABEL, "Directory");
295bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.NUMBER, "1-800-4664-411");
296bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.ISPRIMARY, 1);
297bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
298bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri uri = mResolver.insert(Phones.CONTENT_URI, values);
299bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
300bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Adding another value to assert
301bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Phones.NUMBER_KEY, "11446640081");
302bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
303bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // The result is joined with People
304bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
305bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(uri, values);
306d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertSelection(Phones.CONTENT_URI, values,
307d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov                Phones._ID, ContentUris.parseId(uri));
308bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
309bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Access the phone through People
310bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri twigUri = Uri.withAppendedPath(personUri, People.Phones.CONTENT_DIRECTORY);
311bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(twigUri, values);
312bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
313bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Now the person should be joined with Phone
314bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
315bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
316bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.TYPE, Phones.TYPE_CUSTOM);
317bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.LABEL, "Directory");
318bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NUMBER, "1-800-4664-411");
319bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
320bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
321bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertPersonIdConstraint(Phones.CONTENT_URI, Phones.TYPE, Phones.TYPE_WORK);
322bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
323bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertTypeAndLabelConstraints(Phones.CONTENT_URI, Phones.PERSON_ID, personId, Phones.TYPE,
324bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                Phones.TYPE_CUSTOM, Phones.TYPE_OTHER, Phones.LABEL);
325bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
326bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
327e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    public void testEmailInsert() {
328e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        assertContactMethodInsert(Contacts.KIND_EMAIL, ContactMethods.TYPE_CUSTOM,
329e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov                "Some other way", "foo@acme.com", null, true);
330e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    }
331e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov
332e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    public void testImInsert() {
333e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        assertContactMethodInsert(Contacts.KIND_IM, ContactMethods.TYPE_CUSTOM, "Some other way",
334e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov                "Foo", "Bar", true);
335e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    }
336e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov
337e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    public void testPostalInsert() {
338e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        assertContactMethodInsert(Contacts.KIND_POSTAL, ContactMethods.TYPE_CUSTOM,
339e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov                "Some other way", "Foo", "Bar", true);
340e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    }
341e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov
342e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov    private void assertContactMethodInsert(int kind, int type, String label, String data,
343e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov            String auxData, boolean primary) {
344bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
345bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
346bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        final Uri personUri = mResolver.insert(People.CONTENT_URI, values);
347bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
348bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
349bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
350bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.PERSON_ID, personId);
351e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        values.put(ContactMethods.KIND, kind);
352e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        values.put(ContactMethods.TYPE, type);
353e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        values.put(ContactMethods.LABEL, label);
354e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        values.put(ContactMethods.DATA, data);
355e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        values.put(ContactMethods.AUX_DATA, auxData);
356e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        values.put(ContactMethods.ISPRIMARY, primary ? 1 : 0);
357bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
358bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri uri = mResolver.insert(ContactMethods.CONTENT_URI, values);
359bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
360bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // The result is joined with People
361bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
362bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(uri, values);
363d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertSelection(ContactMethods.CONTENT_URI, values,
364d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov                ContactMethods._ID, ContentUris.parseId(uri));
365bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
366e80e514a6175ad2ee03ea6eff6201e0e47d5a710Dmitri Plotnikov        // Access the contact method through People
367bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri twigUri = Uri.withAppendedPath(personUri, People.ContactMethods.CONTENT_DIRECTORY);
368bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(twigUri, values);
369bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
370bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertPersonIdConstraint(ContactMethods.CONTENT_URI, ContactMethods.TYPE,
371bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                ContactMethods.TYPE_WORK);
372bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
373bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertTypeAndLabelConstraints(ContactMethods.CONTENT_URI, ContactMethods.PERSON_ID,
374bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                personId, ContactMethods.TYPE, ContactMethods.TYPE_CUSTOM,
375bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                ContactMethods.TYPE_OTHER, ContactMethods.LABEL);
376bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
377bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
3780f8f3b3e4a6ad18c5868d0215cc137845a2ddc74Dmitri Plotnikov    public void testExtensionsInsert() {
379bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
380bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        final Uri personUri = mResolver.insert(People.CONTENT_URI, values);
381bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
382bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
383bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
384bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Extensions.PERSON_ID, personId);
385bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Extensions.NAME, "Foo");
386bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Extensions.VALUE, "Bar");
387bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
388bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri uri = mResolver.insert(Extensions.CONTENT_URI, values);
389bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(uri, values);
390d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertSelection(Extensions.CONTENT_URI, values,
391d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov                Extensions._ID, ContentUris.parseId(uri));
392bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
393bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Access the extensions through People
394bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri twigUri = Uri.withAppendedPath(personUri, People.Extensions.CONTENT_DIRECTORY);
395bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(twigUri, values);
396bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
397bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
3980f8f3b3e4a6ad18c5868d0215cc137845a2ddc74Dmitri Plotnikov    public void testGroupsInsert() {
399bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
400bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Groups.NAME, "Galois");
401bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Groups.NOTES, "Abel");
4020f8f3b3e4a6ad18c5868d0215cc137845a2ddc74Dmitri Plotnikov        values.put(Groups.SYSTEM_ID, "12345");
403bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
404bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri groupUri = mResolver.insert(Groups.CONTENT_URI, values);
405bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(groupUri, values);
406bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
407bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
4080f8f3b3e4a6ad18c5868d0215cc137845a2ddc74Dmitri Plotnikov    public void testGroupMembershipsInsert() {
409bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
410bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Groups.NAME, "Galois");
411bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Groups.NOTES, "Abel");
412bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri groupUri = mResolver.insert(Groups.CONTENT_URI, values);
413bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
414bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
415bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NAME, "Klein");
416bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
417bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
418bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long groupId = ContentUris.parseId(groupUri);
419bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
420bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
421d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        values.clear();
422d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        values.put(GroupMembership.GROUP_ID, groupId);
423d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        values.put(GroupMembership.PERSON_ID, personId);
424d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        Uri membershipUri = mResolver.insert(GroupMembership.CONTENT_URI, values);
425d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertStoredValues(membershipUri, values);
426d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertSelection(GroupMembership.CONTENT_URI, values,
427d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov                GroupMembership._ID, ContentUris.parseId(membershipUri));
428bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
429bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personsGroupsUri = Uri.withAppendedPath(personUri, GroupMembership.CONTENT_DIRECTORY);
430d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov        assertStoredValues(personsGroupsUri, values);
431bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
432bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
433d51a83ac4f8032b62d9a23b90a8f43d6b7eb2dbbDmitri Plotnikov    public void testAddToGroup() {
434bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
435bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
436bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
437bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
438bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
439bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Groups.NAME, "Galois");
440bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri groupUri = mResolver.insert(Groups.CONTENT_URI, values);
441bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
442bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        People.addToGroup(mResolver, personId, "Galois");
443bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
444bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
445bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(GroupMembership.GROUP_ID, ContentUris.parseId(groupUri));
446bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(GroupMembership.PERSON_ID, personId);
447bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
448bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personsGroupsUri = Uri.withAppendedPath(personUri, GroupMembership.CONTENT_DIRECTORY);
449bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personsGroupsUri, values);
450bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
451bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
45270b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov    public void testPresenceInsertMatchOnHandle() {
453bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
454bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
455bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
456bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
457bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
458bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        String encodedProtocol =
459bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                ContactMethods.encodePredefinedImProtocol(ContactMethods.PROTOCOL_GOOGLE_TALK);
460bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
461bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
462bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.PERSON_ID, personId);
463bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.KIND, Contacts.KIND_IM);
464bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.TYPE, ContactMethods.TYPE_HOME);
465bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.DATA, "Android");
466bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.AUX_DATA, encodedProtocol);
467bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.insert(ContactMethods.CONTENT_URI, values);
468bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
469bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
470bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.IM_PROTOCOL, encodedProtocol);
471bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.IM_HANDLE, "Android");
472bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.IM_ACCOUNT, "foo");
47370b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.put(Presence.PRESENCE_STATUS, Presence.OFFLINE);
47470b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.put(Presence.PRESENCE_CUSTOM_STATUS, "Coding for Android");
475bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
476bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri presenceUri = mResolver.insert(Presence.CONTENT_URI, values);
47770b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        assertSelection(Presence.CONTENT_URI, values,
47870b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov                Presence._ID, ContentUris.parseId(presenceUri));
479bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
480bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.PERSON_ID, personId);
48170b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        assertStoredValues(presenceUri, values);
482bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
48370b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        // Now the person should be joined with Presence
48470b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.clear();
485bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
48670b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.put(People.IM_PROTOCOL, encodedProtocol);
48770b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.put(People.IM_HANDLE, "Android");
48870b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.put(People.IM_ACCOUNT, "foo");
48970b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.put(People.PRESENCE_STATUS, Presence.OFFLINE);
49070b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        values.put(People.PRESENCE_CUSTOM_STATUS, "Coding for Android");
49170b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        assertStoredValues(personUri, values);
492bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
493bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
49470b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov    public void testPresenceInsertMatchOnEmail() {
495bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
496bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
497bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
498bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        long personId = ContentUris.parseId(personUri);
499bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
500bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        String protocol =
501bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            ContactMethods.encodePredefinedImProtocol(ContactMethods.PROTOCOL_GOOGLE_TALK);
502bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
503bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
504bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.PERSON_ID, personId);
505bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.KIND, Contacts.KIND_EMAIL);
506bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.TYPE, ContactMethods.TYPE_HOME);
507bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(ContactMethods.DATA, "Android@android.com");
508bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.insert(ContactMethods.CONTENT_URI, values);
509bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
510bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
511bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.IM_PROTOCOL, protocol);
512bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.IM_HANDLE, "Android@android.com");
513bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.IM_ACCOUNT, "foo");
514bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.PRESENCE_STATUS, Presence.OFFLINE);
515bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.PRESENCE_CUSTOM_STATUS, "Coding for Android");
516bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
517bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri presenceUri = mResolver.insert(Presence.CONTENT_URI, values);
518bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
519bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Presence.PERSON_ID, personId);
520bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(presenceUri, values);
52170b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov        assertSelection(Presence.CONTENT_URI, values,
52270b5ee6864cb3368d24a9e876fb93008997b12dfDmitri Plotnikov                Presence._ID, ContentUris.parseId(presenceUri));
523bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
524bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Now the person should be joined with Presence
525bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
526bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        putContactValues(values);
527bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.IM_PROTOCOL, protocol);
528bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.IM_HANDLE, "Android@android.com");
529bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.IM_ACCOUNT, "foo");
530bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRESENCE_STATUS, Presence.OFFLINE);
531bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PRESENCE_CUSTOM_STATUS, "Coding for Android");
532bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(personUri, values);
533bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
534bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
535c6ad6f6c5690a28bacb9fa0f4357ea8c8a91e3baDmitri Plotnikov    public void testPhotoUpdate() throws Exception {
536bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        byte[] photo = loadTestPhoto();
537bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
538bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
539bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri personUri = mResolver.insert(People.CONTENT_URI, values);
540bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
541bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
542bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(Photos.DATA, photo);
543c6ad6f6c5690a28bacb9fa0f4357ea8c8a91e3baDmitri Plotnikov        values.put(Photos.LOCAL_VERSION, "10");
544c6ad6f6c5690a28bacb9fa0f4357ea8c8a91e3baDmitri Plotnikov        values.put(Photos.DOWNLOAD_REQUIRED, 1);
545c6ad6f6c5690a28bacb9fa0f4357ea8c8a91e3baDmitri Plotnikov        values.put(Photos.EXISTS_ON_SERVER, 1);
546c6ad6f6c5690a28bacb9fa0f4357ea8c8a91e3baDmitri Plotnikov        values.put(Photos.SYNC_ERROR, "404 does not exist");
547bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
548bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri photoUri = Uri.withAppendedPath(personUri, Photos.CONTENT_DIRECTORY);
549bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        mResolver.update(photoUri, values, null, null);
550bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        assertStoredValues(photoUri, values);
551bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
552bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
553bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    private void putContactValues(ContentValues values) {
554bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        // Populating only unhidden columns
555bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NAME, "Deer Dough");
556bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.PHONETIC_NAME, "Dear Doe");
557bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.NOTES, "Cash Cow");
558bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.TIMES_CONTACTED, 3);
559bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.LAST_TIME_CONTACTED, 10);
560bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.CUSTOM_RINGTONE, "ringtone");
561bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.SEND_TO_VOICEMAIL, 1);
562bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(People.STARRED, 1);
563bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
564bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
565bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    private byte[] loadTestPhoto() throws IOException {
566bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        final Resources resources = getContext().getResources();
567bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        InputStream is =
568bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                resources.openRawResource(com.android.internal.R.drawable.ic_contact_picture);
569bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ByteArrayOutputStream os = new ByteArrayOutputStream();
570bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        byte[] buffer = new byte[1000];
571bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        int count;
572bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        while((count = is.read(buffer)) != -1) {
573bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            os.write(buffer, 0, count);
574bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        }
575bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        return os.toByteArray();
576bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
577bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
578bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    private void assertFilteredContacts(String filter, String... expectedNames) {
579bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Uri filterUri = Uri.withAppendedPath(People.CONTENT_FILTER_URI, filter);
580bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        Cursor c = mResolver.query(filterUri, null, null, null, null);
581bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        try {
582bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            assertEquals("Record count", expectedNames.length, c.getCount());
583bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            int column = c.getColumnIndex(People.NAME);
584bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            for (int i = 0; i < expectedNames.length; i++) {
585bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                c.moveToNext();
586bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov                assertEquals(expectedNames[i], c.getString(column));
587bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            }
588bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        } finally {
589bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            c.close();
590bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        }
591bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
592bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
593bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    private void assertPersonIdConstraint(Uri uri, String typeColumn, int defaultType) {
594bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
595bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(typeColumn, defaultType);
596bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        try {
597bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            mResolver.insert(uri, values);
598bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            fail("Inserted row without person ID");
599bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        } catch (Exception e) {
600bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            // Exception expected
601bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        }
602bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
603bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
604bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    private void assertTypeAndLabelConstraints(Uri uri, String personIdColumn, long personId,
605bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            String typeColumn, int defaultType, int otherType, String labelColumn) {
606bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        ContentValues values = new ContentValues();
607bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(personIdColumn, personId);
608bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(typeColumn, defaultType);
609bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        try {
610bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            mResolver.insert(uri, values);
611bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            fail("Inserted row with custom type but without label");
612bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        } catch (Exception e) {
613bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            // Exception expected
614bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        }
615bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
616bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
617bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(personIdColumn, personId);
618bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        try {
619bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            mResolver.insert(uri, values);
620bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            fail("Inserted row without either type or label");
621bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        } catch (Exception e) {
622bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            // Exception expected
623bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        }
624bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
625bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.clear();
626bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(personIdColumn, personId);
627bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(typeColumn, otherType);
628bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        values.put(labelColumn, "Foo");
629bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        try {
630bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            mResolver.insert(uri, values);
6313cebbf7141252768d3e272e049e9c5b0cb9d710eDmitri Plotnikov            fail("Inserted row with both type and label");
632bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        } catch (Exception e) {
633bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov            // Exception expected
634bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov        }
635bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov    }
636bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov
637bee1a6b2e7cbea778195890e442c9e50f2a4e6d9Dmitri Plotnikov}
638