1/* 2 * Copyright (C) 2010 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 17package com.android.providers.calendar; 18 19import com.android.calendarcommon2.ICalendar; 20import com.android.calendarcommon2.RecurrenceSet; 21 22import android.content.ContentValues; 23import android.provider.CalendarContract; 24import android.test.suitebuilder.annotation.SmallTest; 25import junit.framework.TestCase; 26 27import java.util.List; 28 29public class RecurrenceSetTest extends TestCase { 30 31 private static String MOCK_COMPONENT_NAME = "mockComponent"; 32 33 private static final String RRULE_LESS_THAN_75_CHARS = 34 "FREQ=WEEKLY;BYDAY=SU,FR,SA;UNTIL=20100326T190000Z;WKST=MO"; 35 36 private static final String RRULE_MORE_THAN_75_CHARS = 37 "FREQ=WEEKLY;WKST=MO;UNTIL=20100129T130000Z;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR, SA,SU"; 38 39 private static final String RRULE_MORE_THAN_75_CHARS_FOLDED = 40 "FREQ=WEEKLY;WKST=MO;UNTIL=20100129T130000Z;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,\r\n SA,SU"; 41 42 private static final String STRING_WITH_160_CHARS = "0123456789" 43 + "0123456789" 44 + "0123456789" 45 + "0123456789" 46 + "0123456789" 47 + "0123456789" 48 + "0123456789" 49 + "0123456789" 50 + "0123456789" 51 + "0123456789" 52 + "0123456789" 53 + "0123456789" 54 + "0123456789" 55 + "0123456789" 56 + "0123456789" 57 + "0123456789"; 58 59 private static final String STRING_WITH_160_CHARS_FOLDED = "0123456789" 60 + "0123456789" 61 + "0123456789" 62 + "0123456789" 63 + "0123456789" 64 + "0123456789" 65 + "0123456789" 66 + "01234" 67 + "\r\n " 68 + "56789" 69 + "0123456789" 70 + "0123456789" 71 + "0123456789" 72 + "0123456789" 73 + "0123456789" 74 + "0123456789" 75 + "0123456789" 76 + "\r\n " 77 + "0123456789"; 78 79 @SmallTest 80 public void testFoldPerRFC2445() { 81 assertEquals(RRULE_LESS_THAN_75_CHARS, 82 RecurrenceSet.fold(RRULE_LESS_THAN_75_CHARS)); 83 84 assertEquals(RRULE_MORE_THAN_75_CHARS_FOLDED, 85 RecurrenceSet.fold(RRULE_MORE_THAN_75_CHARS)); 86 87 assertEquals(STRING_WITH_160_CHARS_FOLDED, 88 RecurrenceSet.fold(STRING_WITH_160_CHARS)); 89 } 90 91 @SmallTest 92 public void testUnFoldPerRFC2445() { 93 assertEquals(RRULE_LESS_THAN_75_CHARS, 94 RecurrenceSet.unfold(RRULE_LESS_THAN_75_CHARS)); 95 96 assertEquals(RRULE_MORE_THAN_75_CHARS, 97 RecurrenceSet.unfold(RRULE_MORE_THAN_75_CHARS_FOLDED)); 98 99 assertEquals(STRING_WITH_160_CHARS, 100 RecurrenceSet.unfold(STRING_WITH_160_CHARS_FOLDED)); 101 } 102 103 @SmallTest 104 public void testRRULEfolding() { 105 ICalendar.Component component = new ICalendar.Component(MOCK_COMPONENT_NAME, null); 106 107 ContentValues values = new ContentValues(); 108 values.put(CalendarContract.Events.DTSTART, 0); 109 values.put(CalendarContract.Events.DURATION, "P3600S"); 110 values.put(CalendarContract.Events.RRULE, RRULE_LESS_THAN_75_CHARS); 111 112 assertTrue(RecurrenceSet.populateComponent(values, component)); 113 List<ICalendar.Property> list = component.getProperties("DTSTART"); 114 assertTrue(list.size() == 1); 115 assertEquals("19700101T000000Z", list.get(0).getValue()); 116 117 list = component.getProperties("RRULE"); 118 assertTrue(list.size() == 1); 119 assertEquals(RRULE_LESS_THAN_75_CHARS,list.get(0).getValue()); 120 121 component = new ICalendar.Component(MOCK_COMPONENT_NAME, null); 122 123 values = new ContentValues(); 124 values.put(CalendarContract.Events.DTSTART, 0); 125 values.put(CalendarContract.Events.DURATION, "P3600S"); 126 values.put(CalendarContract.Events.RRULE, RRULE_MORE_THAN_75_CHARS); 127 128 assertTrue(RecurrenceSet.populateComponent(values, component)); 129 130 list = component.getProperties("RRULE"); 131 assertTrue(list.size() == 1); 132 assertEquals(RRULE_MORE_THAN_75_CHARS_FOLDED, list.get(0).getValue()); 133 134 component = new ICalendar.Component(MOCK_COMPONENT_NAME, null); 135 136 values = new ContentValues(); 137 values.put(CalendarContract.Events.DTSTART, 0); 138 values.put(CalendarContract.Events.DURATION, "P3600S"); 139 values.put(CalendarContract.Events.RRULE, STRING_WITH_160_CHARS); 140 141 assertTrue(RecurrenceSet.populateComponent(values, component)); 142 143 list = component.getProperties("RRULE"); 144 assertTrue(list.size() == 1); 145 assertEquals(STRING_WITH_160_CHARS_FOLDED, list.get(0).getValue()); 146 } 147} 148