Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

am f4b1756: Fix event color query (which fixes the failing CTS test).

* commit 'f4b1756f88c34efefb33b4103230ee334d9c9262':
  Fix event color query (which fixes the failing CTS test).
  • Loading branch information...
commit d2e4cb09054364f1b09e453426f642961cfbf7cf 2 parents b557005 + f4b1756
Sara Ting authored Android Git Automerger committed
View
2  src/com/android/providers/calendar/CalendarProvider2.java
@@ -203,7 +203,7 @@
private static final String SQL_WHERE_CALENDAR_COLOR = Calendars.ACCOUNT_NAME + "=? AND "
+ Calendars.ACCOUNT_TYPE + "=? AND " + Calendars.CALENDAR_COLOR_KEY + "=?";
- private static final String SQL_WHERE_EVENT_COLOR = Calendars._ID + " in (SELECT _id from "
+ private static final String SQL_WHERE_EVENT_COLOR = "calendar_id in (SELECT _id from "
+ Tables.CALENDARS + " WHERE " + Events.ACCOUNT_NAME + "=? AND " + Events.ACCOUNT_TYPE
+ "=?) AND " + Events.EVENT_COLOR_KEY + "=?";
View
72 tests/src/com/android/providers/calendar/CalendarProvider2Test.java
@@ -83,6 +83,8 @@
private static final String[] WHERE_CALENDARS_ARGS = {
"1"
};
+ private static final String WHERE_COLOR_ACCOUNT_AND_INDEX = Colors.ACCOUNT_NAME + "=? AND "
+ + Colors.ACCOUNT_TYPE + "=? AND " + Colors.COLOR_KEY + "=?";
private static final String DEFAULT_SORT_ORDER = "begin ASC";
private CalendarProvider2ForTesting mProvider;
@@ -1326,7 +1328,19 @@ private void deleteAllEvents() {
mMetaData.clearInstanceRange();
}
- public void testInsertAndUpdateColor() throws Exception {
+ /**
+ * Creates an updated URI that includes query parameters that identify the source as a
+ * sync adapter.
+ */
+ static Uri asSyncAdapter(Uri uri, String account, String accountType) {
+ return uri.buildUpon()
+ .appendQueryParameter(android.provider.CalendarContract.CALLER_IS_SYNCADAPTER,
+ "true")
+ .appendQueryParameter(Calendars.ACCOUNT_NAME, account)
+ .appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
+ }
+
+ public void testInsertUpdateDeleteColor() throws Exception {
// Calendar Color
long colorType = Colors.TYPE_CALENDAR;
String colorKey = "123";
@@ -1347,7 +1361,6 @@ public void testInsertAndUpdateColor() throws Exception {
// Event Color
colorType = Colors.TYPE_EVENT;
colorValue += 11;
-
colorId = insertAndCheckColor(colorType, colorKey, colorValue);
try {
insertAndCheckColor(colorType, colorKey, colorValue);
@@ -1356,9 +1369,63 @@ public void testInsertAndUpdateColor() throws Exception {
// good
}
+ // Create an event with the old color value.
+ int calendarId0 = insertCal("Calendar0", DEFAULT_TIMEZONE);
+ String title = "colorTest";
+ ContentValues cv = this.eventInfoToContentValues(calendarId0, mEvents[0]);
+ cv.put(Events.EVENT_COLOR_KEY, colorKey);
+ cv.put(Events.TITLE, title);
+ Uri uri = insertEvent(calendarId0, mEvents[0], cv);
+ Cursor c = mResolver.query(uri, new String[] {Events.EVENT_COLOR}, null, null, null);
+ try {
+ // Confirm the color is set.
+ c.moveToFirst();
+ assertEquals(colorValue, c.getInt(0));
+ } finally {
+ if (c != null) {
+ c.close();
+ }
+ }
+
// Test Update
colorValue += 11;
updateAndCheckColor(colorId, colorType, colorKey, colorValue);
+
+ // Check if color was updated in event.
+ c = mResolver.query(uri, new String[] {Events.EVENT_COLOR}, null, null, null);
+ try {
+ c.moveToFirst();
+ assertEquals(colorValue, c.getInt(0));
+ } finally {
+ if (c != null) {
+ c.close();
+ }
+ }
+
+ // Test Delete
+ Uri colSyncUri = asSyncAdapter(Colors.CONTENT_URI, DEFAULT_ACCOUNT,
+ DEFAULT_ACCOUNT_TYPE);
+ try {
+ // Delete should fail if color referenced by an event.
+ mResolver.delete(colSyncUri, WHERE_COLOR_ACCOUNT_AND_INDEX,
+ new String[] {DEFAULT_ACCOUNT, DEFAULT_ACCOUNT_TYPE, colorKey});
+ fail("Should not allow deleting referenced color");
+ } catch (UnsupportedOperationException e) {
+ // Exception expected.
+ }
+ Cursor cursor = mResolver.query(Colors.CONTENT_URI, new String[] {Colors.COLOR_KEY},
+ Colors.COLOR_KEY + "=? AND " + Colors.COLOR_TYPE + "=?",
+ new String[] {colorKey, Long.toString(colorType)}, null);
+ assertEquals(1, cursor.getCount());
+
+ // Try again, by deleting the event, then the color.
+ assertEquals(1, deleteMatchingEvents(title, DEFAULT_ACCOUNT, DEFAULT_ACCOUNT_TYPE));
+ mResolver.delete(colSyncUri, WHERE_COLOR_ACCOUNT_AND_INDEX,
+ new String[] {DEFAULT_ACCOUNT, DEFAULT_ACCOUNT_TYPE, colorKey});
+ cursor = mResolver.query(Colors.CONTENT_URI, new String[] {Colors.COLOR_KEY},
+ Colors.COLOR_KEY + "=? AND " + Colors.COLOR_TYPE + "=?",
+ new String[] {colorKey, Long.toString(colorType)}, null);
+ assertEquals(0, cursor.getCount());
}
private void checkColor(long colorId, long colorType, String colorKey, long color) {
@@ -1371,7 +1438,6 @@ private void checkColor(long colorId, long colorType, String colorKey, long colo
Colors._ID, // 5
Colors.DATA, // 6
};
-
Cursor cursor = mResolver.query(Colors.CONTENT_URI, projection, Colors.COLOR_KEY
+ "=? AND " + Colors.COLOR_TYPE + "=?", new String[] {
colorKey, Long.toString(colorType)
Please sign in to comment.
Something went wrong with that request. Please try again.