FileDocCategorySizeDatePackage
SyncContactsTest.javaAPI DocAndroid 1.5 API5848Wed May 06 22:42:48 BST 2009com.android.providers.contacts

SyncContactsTest

public class SyncContactsTest extends android.test.SyncBaseInstrumentation

Fields Summary
private android.content.Context
mTargetContext
private String
mAccount
private static final String
PEOPLE_PHONE_JOIN
private static final Set
PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP
android.provider.Sync.Settings.QueryMap
mSyncSettings
Constructors Summary
Methods Summary
private voidcompareCursors(android.database.Cursor incrementalCursor, android.database.Cursor initialSyncCursor, java.util.Set columnsToSkip, java.lang.String tableName)


        assertEquals(tableName + " count failed to match", incrementalCursor.getCount(),
                             initialSyncCursor.getCount());

        String[] cols = incrementalCursor.getColumnNames();
        int length = cols.length;
        Map<String,String> row = Maps.newHashMap();
        
        while (incrementalCursor.moveToNext() && initialSyncCursor.moveToNext()) {
            for (int i = 0; i < length; i++) {
                String col = cols[i];
                if (columnsToSkip != null && columnsToSkip.contains(col)) {
                    continue;
                }
                row.put(col, incrementalCursor.getString(i));
                assertEquals("Row: " + row + " .Column: " + cols[i] + " failed to match",
                             incrementalCursor.getString(i), initialSyncCursor.getString(i));
            }
        }
    
private java.lang.StringgetAccount()

        try {
            return GoogleLoginServiceBlockingHelper.getAccount(mTargetContext, false);
        } catch (GoogleLoginServiceNotFoundException e) {
            Log.e(this.getClass().getName(), "Could not find Google login service");
            return null;
        }
    
protected voidsetUp()

     
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People._ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People.PRIMARY_PHONE_ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People._SYNC_MARK);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People._SYNC_TIME);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People._SYNC_LOCAL_ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People._SYNC_VERSION);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People._SYNC_DIRTY);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People.TIMES_CONTACTED);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People.LAST_TIME_CONTACTED);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.Phones._ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.Phones.PERSON_ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People.PRIMARY_EMAIL_ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People.PRIMARY_ORGANIZATION_ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.People.ContactMethods._ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.Organizations.PERSON_ID);
        PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP.add(Contacts.Organizations._ID);
    
        super.setUp();
        mTargetContext = getInstrumentation().getTargetContext();
        mAccount = getAccount();
    
public voidtestCompareResults()
This test compares the two contacts databases. This works well with the puppetmaster automated script.

throws
Exception

        ContactsProvider incrementalContentProvider =
                RenamingDelegatingContext.providerWithRenamedContext(ContactsProvider.class,
                        mTargetContext, "", true);

        ContactsProvider initialSyncContentProvider =
                RenamingDelegatingContext.providerWithRenamedContext(ContactsProvider.class,
                        mTargetContext, "initialsync.", true);

        SQLiteDatabase incrementalDb = incrementalContentProvider.getDatabase();
        SQLiteDatabase initialSyncDb = initialSyncContentProvider.getDatabase();

        Cursor incrementalPeopleCursor = incrementalDb.rawQuery("select * from " +
                                         PEOPLE_PHONE_JOIN, null);
        Cursor initialPeopleCursor = initialSyncDb.rawQuery("select * from " +
                                     PEOPLE_PHONE_JOIN, null);

        assertNotSame("Incremental db has no values - check test configuration",
                      incrementalPeopleCursor.getCount(), 0);
        try {
            compareCursors(incrementalPeopleCursor, initialPeopleCursor,
                           PEOPLE_PHONES_JOIN_COLUMNS_TO_SKIP, "People");
        } finally {
            incrementalPeopleCursor.close();
            initialPeopleCursor.close();
        }
    
public voidtestSync()
A Simple test that syncs the contacts provider.

throws
Exception

        cancelSyncsandDisableAutoSync();
        syncProvider(Contacts.CONTENT_URI, mAccount, Contacts.AUTHORITY);