blob: 0644cb21f4d924f698f4e1129832ac7486770011 [file] [log] [blame]
/*
* Copyright (C) 2010 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 android.provider.cts;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.provider.cts.ContactsContract_TestDataBuilder.TestContact;
import android.provider.cts.ContactsContract_TestDataBuilder.TestData;
import android.provider.cts.ContactsContract_TestDataBuilder.TestRawContact;
import android.test.InstrumentationTestCase;
public class ContactsContract_DataTest extends InstrumentationTestCase {
private ContentResolver mResolver;
private ContactsContract_TestDataBuilder mBuilder;
@Override
protected void setUp() throws Exception {
super.setUp();
mResolver = getInstrumentation().getTargetContext().getContentResolver();
ContentProviderClient provider =
mResolver.acquireContentProviderClient(ContactsContract.AUTHORITY);
mBuilder = new ContactsContract_TestDataBuilder(provider);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
mBuilder.cleanup();
}
public void testGetLookupUriBySourceId() throws Exception {
TestRawContact rawContact = mBuilder.newRawContact()
.with(RawContacts.ACCOUNT_TYPE, "test_type")
.with(RawContacts.ACCOUNT_NAME, "test_name")
.with(RawContacts.SOURCE_ID, "source_id")
.insert();
// TODO remove this. The method under test is currently broken: it will not
// work without at least one data row in the raw contact.
TestData data = rawContact.newDataRow(StructuredName.CONTENT_ITEM_TYPE)
.with(StructuredName.DISPLAY_NAME, "test name")
.insert();
Uri lookupUri = Data.getContactLookupUri(mResolver, data.getUri());
assertNotNull("Could not produce a lookup URI", lookupUri);
TestContact lookupContact = mBuilder.newContact().setUri(lookupUri).load();
assertEquals("Lookup URI matched the wrong contact",
lookupContact.getId(), data.load().getRawContact().load().getContactId());
}
public void testGetLookupUriByDisplayName() throws Exception {
TestRawContact rawContact = mBuilder.newRawContact()
.with(RawContacts.ACCOUNT_TYPE, "test_type")
.with(RawContacts.ACCOUNT_NAME, "test_name")
.insert();
TestData data = rawContact.newDataRow(StructuredName.CONTENT_ITEM_TYPE)
.with(StructuredName.DISPLAY_NAME, "test name")
.insert();
Uri lookupUri = Data.getContactLookupUri(mResolver, data.getUri());
assertNotNull("Could not produce a lookup URI", lookupUri);
TestContact lookupContact = mBuilder.newContact().setUri(lookupUri).load();
assertEquals("Lookup URI matched the wrong contact",
lookupContact.getId(), data.load().getRawContact().load().getContactId());
}
}