Permalink
Browse files

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

Bug:7261590
Change-Id: I72c60af1ae8d563db7693fdf7d87972dfc80ab82
  • Loading branch information...
1 parent f98ed2e commit 485a1841b281b83e35229b1bb385986d43608aa1 Sara Ting committed with The Android Automerger Oct 1, 2012
@@ -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 + "=?";
@@ -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;
@@ -1315,7 +1317,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";
@@ -1336,7 +1350,6 @@ public void testInsertAndUpdateColor() throws Exception {
// Event Color
colorType = Colors.TYPE_EVENT;
colorValue += 11;
-
colorId = insertAndCheckColor(colorType, colorKey, colorValue);
try {
insertAndCheckColor(colorType, colorKey, colorValue);
@@ -1345,9 +1358,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) {
@@ -1360,7 +1427,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)

0 comments on commit 485a184

Please sign in to comment.