|
|
@ -10,12 +10,16 @@ package at.bitfire.davdroid.resource;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
|
|
|
|
import lombok.Cleanup;
|
|
|
|
import lombok.Cleanup;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
import android.accounts.Account;
|
|
|
|
import android.accounts.Account;
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.content.ContentProviderClient;
|
|
|
|
import android.content.ContentProviderClient;
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentUris;
|
|
|
|
import android.content.ContentUris;
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Build;
|
|
|
@ -26,6 +30,8 @@ import android.provider.CalendarContract.Calendars;
|
|
|
|
import android.provider.CalendarContract.Events;
|
|
|
|
import android.provider.CalendarContract.Events;
|
|
|
|
import android.provider.CalendarContract.Reminders;
|
|
|
|
import android.provider.CalendarContract.Reminders;
|
|
|
|
import android.test.InstrumentationTestCase;
|
|
|
|
import android.test.InstrumentationTestCase;
|
|
|
|
|
|
|
|
import android.test.IsolatedContext;
|
|
|
|
|
|
|
|
import android.test.mock.MockContentResolver;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import at.bitfire.davdroid.resource.LocalCalendar;
|
|
|
|
import at.bitfire.davdroid.resource.LocalCalendar;
|
|
|
|
import at.bitfire.davdroid.resource.LocalStorageException;
|
|
|
|
import at.bitfire.davdroid.resource.LocalStorageException;
|
|
|
@ -33,9 +39,12 @@ import at.bitfire.davdroid.resource.LocalStorageException;
|
|
|
|
public class LocalCalendarTest extends InstrumentationTestCase {
|
|
|
|
public class LocalCalendarTest extends InstrumentationTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String
|
|
|
|
private static final String
|
|
|
|
TAG = "davroid.test",
|
|
|
|
TAG = "davdroid.test",
|
|
|
|
|
|
|
|
accountName = "at.bitfire.davdroid.test",
|
|
|
|
calendarName = "DAVdroid_Test";
|
|
|
|
calendarName = "DAVdroid_Test";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Context targetContext;
|
|
|
|
|
|
|
|
|
|
|
|
ContentProviderClient providerClient;
|
|
|
|
ContentProviderClient providerClient;
|
|
|
|
Account testAccount = new Account(calendarName, CalendarContract.ACCOUNT_TYPE_LOCAL);
|
|
|
|
Account testAccount = new Account(calendarName, CalendarContract.ACCOUNT_TYPE_LOCAL);
|
|
|
|
LocalCalendar testCalendar;
|
|
|
|
LocalCalendar testCalendar;
|
|
|
@ -45,8 +54,8 @@ public class LocalCalendarTest extends InstrumentationTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
private Uri syncAdapterURI(Uri uri) {
|
|
|
|
private Uri syncAdapterURI(Uri uri) {
|
|
|
|
return uri.buildUpon()
|
|
|
|
return uri.buildUpon()
|
|
|
|
.appendQueryParameter(Calendars.ACCOUNT_NAME, calendarName)
|
|
|
|
|
|
|
|
.appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
|
|
|
|
.appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
|
|
|
|
|
|
|
|
.appendQueryParameter(Calendars.ACCOUNT_NAME, accountName)
|
|
|
|
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true").
|
|
|
|
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true").
|
|
|
|
build();
|
|
|
|
build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -72,20 +81,21 @@ public class LocalCalendarTest extends InstrumentationTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
|
|
|
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
ContentResolver resolver = getInstrumentation().getContext().getContentResolver();
|
|
|
|
targetContext = getInstrumentation().getTargetContext();
|
|
|
|
providerClient = resolver.acquireContentProviderClient(CalendarContract.AUTHORITY);
|
|
|
|
targetContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CALENDAR, "No privileges for enumerating calendars");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
providerClient = targetContext.getContentResolver().acquireContentProviderClient(CalendarContract.AUTHORITY);
|
|
|
|
|
|
|
|
|
|
|
|
long id;
|
|
|
|
long calendarId;
|
|
|
|
|
|
|
|
|
|
|
|
@Cleanup Cursor cursor = providerClient.query(Calendars.CONTENT_URI,
|
|
|
|
@Cleanup Cursor cursor = providerClient.query(Calendars.CONTENT_URI,
|
|
|
|
new String[]{ Calendars._ID },
|
|
|
|
new String[]{ Calendars._ID },
|
|
|
|
Calendars.ACCOUNT_TYPE + "=? AND " + Calendars.NAME + "=?",
|
|
|
|
Calendars.ACCOUNT_TYPE + "=? AND " + Calendars.ACCOUNT_NAME + "=? AND " + Calendars.NAME + "=?",
|
|
|
|
new String[]{ CalendarContract.ACCOUNT_TYPE_LOCAL, calendarName },
|
|
|
|
new String[] { CalendarContract.ACCOUNT_TYPE_LOCAL, accountName, calendarName },
|
|
|
|
null);
|
|
|
|
null);
|
|
|
|
if (cursor != null && cursor.moveToNext()) {
|
|
|
|
if (cursor != null && cursor.moveToNext()) {
|
|
|
|
// found local test calendar
|
|
|
|
calendarId = cursor.getLong(0);
|
|
|
|
id = cursor.getLong(0);
|
|
|
|
Log.i(TAG, "Found test calendar with ID " + calendarId);
|
|
|
|
Log.d(TAG, "Found test calendar with ID " + id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// no local test calendar found, create
|
|
|
|
// no local test calendar found, create
|
|
|
@ -106,11 +116,11 @@ public class LocalCalendarTest extends InstrumentationTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
Uri calendarURI = providerClient.insert(syncAdapterURI(Calendars.CONTENT_URI), values);
|
|
|
|
Uri calendarURI = providerClient.insert(syncAdapterURI(Calendars.CONTENT_URI), values);
|
|
|
|
|
|
|
|
|
|
|
|
id = ContentUris.parseId(calendarURI);
|
|
|
|
calendarId = ContentUris.parseId(calendarURI);
|
|
|
|
Log.d(TAG, "Created test calendar with ID " + id);
|
|
|
|
Log.d(TAG, "Created test calendar with ID " + calendarId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
testCalendar = new LocalCalendar(testAccount, providerClient, id, null);
|
|
|
|
testCalendar = new LocalCalendar(testAccount, providerClient, calendarId, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void tearDown() throws Exception {
|
|
|
|
protected void tearDown() throws Exception {
|
|
|
|