Home | History | Annotate | Download | only in pim
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.pim;
     18 
     19 import android.content.ContentValues;
     20 import android.pim.ICalendar;
     21 import android.pim.RecurrenceSet;
     22 import android.test.suitebuilder.annotation.SmallTest;
     23 import android.util.Log;
     24 import android.provider.Calendar;
     25 import junit.framework.TestCase;
     26 
     27 /**
     28  * Test some pim.RecurrenceSet functionality.
     29  */
     30 public class RecurrenceSetTest extends TestCase {
     31 
     32     // Test a recurrence
     33     @SmallTest
     34     public void testRecurrenceSet0() throws Exception {
     35         String recurrence = "DTSTART;TZID=America/New_York:20080221T070000\n"
     36                 + "DTEND;TZID=America/New_York:20080221T190000\n"
     37                 + "RRULE:FREQ=DAILY;UNTIL=20080222T000000Z\n"
     38                 + "EXDATE:20080222T120000Z";
     39         verifyPopulateContentValues(recurrence, "FREQ=DAILY;UNTIL=20080222T000000Z", null,
     40                 null, "20080222T120000Z", 1203595200000L, "America/New_York", "P43200S", 0);
     41     }
     42 
     43     // Test 1 day all-day event
     44     @SmallTest
     45     public void testRecurrenceSet1() throws Exception {
     46         String recurrence = "DTSTART;VALUE=DATE:20090821\nDTEND;VALUE=DATE:20090822\n"
     47                 + "RRULE:FREQ=YEARLY;WKST=SU";
     48         verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU", null,
     49                 null, null, 1250812800000L, "UTC", "P1D", 1);
     50     }
     51 
     52     // Test 2 day all-day event
     53     @SmallTest
     54     public void testRecurrenceSet2() throws Exception {
     55         String recurrence = "DTSTART;VALUE=DATE:20090821\nDTEND;VALUE=DATE:20090823\n"
     56                 + "RRULE:FREQ=YEARLY;WKST=SU";
     57         verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU", null,
     58                 null, null, 1250812800000L, "UTC",  "P2D", 1);
     59     }
     60 
     61     // run populateContentValues and verify the results
     62     private void verifyPopulateContentValues(String recurrence, String rrule, String rdate,
     63             String exrule, String exdate, long dtstart, String tzid, String duration, int allDay)
     64             throws ICalendar.FormatException {
     65         ICalendar.Component recurrenceComponent =
     66                 new ICalendar.Component("DUMMY", null /* parent */);
     67         ICalendar.parseComponent(recurrenceComponent, recurrence);
     68         ContentValues values = new ContentValues();
     69         RecurrenceSet.populateContentValues(recurrenceComponent, values);
     70         Log.d("KS", "values " + values);
     71 
     72         assertEquals(rrule, values.get(android.provider.Calendar.Events.RRULE));
     73         assertEquals(rdate, values.get(android.provider.Calendar.Events.RDATE));
     74         assertEquals(exrule, values.get(android.provider.Calendar.Events.EXRULE));
     75         assertEquals(exdate, values.get(android.provider.Calendar.Events.EXDATE));
     76         assertEquals(dtstart, (long) values.getAsLong(Calendar.Events.DTSTART));
     77         assertEquals(tzid, values.get(android.provider.Calendar.Events.EVENT_TIMEZONE));
     78         assertEquals(duration, values.get(android.provider.Calendar.Events.DURATION));
     79         assertEquals(allDay,
     80                 (int) values.getAsInteger(android.provider.Calendar.Events.ALL_DAY));
     81     }
     82 }
     83