blob: c22f00f168c999d4b369350b36c746da4f44cda9 [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 dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import android.content.ContentResolver;
import android.content.IContentProvider;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.cts.ContactsContract_TestDataBuilder.TestContact;
import android.provider.cts.ContactsContract_TestDataBuilder.TestRawContact;
import android.test.InstrumentationTestCase;
@TestTargetClass(ContactsContract.RawContacts.class)
public class ContactsContract_RawContactsTest extends InstrumentationTestCase {
private ContentResolver mResolver;
private ContactsContract_TestDataBuilder mBuilder;
@Override
protected void setUp() throws Exception {
super.setUp();
mResolver = getInstrumentation().getTargetContext().getContentResolver();
IContentProvider provider = mResolver.acquireProvider(ContactsContract.AUTHORITY);
mBuilder = new ContactsContract_TestDataBuilder(provider);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
mBuilder.cleanup();
}
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Test getContactLookupUri(ContentResolver resolver, Uri rawContactUri) " +
"using source id",
method = "getContactLookupUri",
args = {android.content.ContentResolver.class, Uri.class}
)
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.
rawContact.newDataRow(StructuredName.CONTENT_ITEM_TYPE)
.with(StructuredName.DISPLAY_NAME, "test name")
.insert();
Uri lookupUri = RawContacts.getContactLookupUri(mResolver, rawContact.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(), rawContact.load().getContactId());
}
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Test getContactLookupUri(ContentResolver resolver, Uri rawContactUri) " +
"using display name",
method = "getContactLookupUri",
args = {android.content.ContentResolver.class, Uri.class}
)
public void testGetLookupUriByDisplayName() throws Exception {
TestRawContact rawContact = mBuilder.newRawContact()
.with(RawContacts.ACCOUNT_TYPE, "test_type")
.with(RawContacts.ACCOUNT_NAME, "test_name")
.insert();
rawContact.newDataRow(StructuredName.CONTENT_ITEM_TYPE)
.with(StructuredName.DISPLAY_NAME, "test name")
.insert();
Uri lookupUri = RawContacts.getContactLookupUri(mResolver, rawContact.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(), rawContact.load().getContactId());
}
}