From 06b3293d5af3454a39681cfd659271551354b8a0 Mon Sep 17 00:00:00 2001 From: Michael Chan Date: Tue, 26 Jun 2012 17:49:56 -0700 Subject: Rename calendarcommon to calendarcommon2 to workaround OEM silliness Change-Id: I5bd618866d6484037671376e192ee3217c42c366 --- .../com/android/calendarcommon/DurationTest.java | 77 - .../calendarcommon/EventRecurrenceTest.java | 889 ------- .../src/com/android/calendarcommon/RRuleTest.java | 756 ------ .../calendarcommon/RecurrenceProcessorTest.java | 2537 -------------------- .../android/calendarcommon/RecurrenceSetTest.java | 155 -- .../com/android/calendarcommon2/DurationTest.java | 77 + .../calendarcommon2/EventRecurrenceTest.java | 889 +++++++ .../src/com/android/calendarcommon2/RRuleTest.java | 756 ++++++ .../calendarcommon2/RecurrenceProcessorTest.java | 2537 ++++++++++++++++++++ .../android/calendarcommon2/RecurrenceSetTest.java | 155 ++ 10 files changed, 4414 insertions(+), 4414 deletions(-) delete mode 100644 tests/src/com/android/calendarcommon/DurationTest.java delete mode 100644 tests/src/com/android/calendarcommon/EventRecurrenceTest.java delete mode 100644 tests/src/com/android/calendarcommon/RRuleTest.java delete mode 100644 tests/src/com/android/calendarcommon/RecurrenceProcessorTest.java delete mode 100644 tests/src/com/android/calendarcommon/RecurrenceSetTest.java create mode 100644 tests/src/com/android/calendarcommon2/DurationTest.java create mode 100644 tests/src/com/android/calendarcommon2/EventRecurrenceTest.java create mode 100644 tests/src/com/android/calendarcommon2/RRuleTest.java create mode 100644 tests/src/com/android/calendarcommon2/RecurrenceProcessorTest.java create mode 100644 tests/src/com/android/calendarcommon2/RecurrenceSetTest.java (limited to 'tests/src/com/android') diff --git a/tests/src/com/android/calendarcommon/DurationTest.java b/tests/src/com/android/calendarcommon/DurationTest.java deleted file mode 100644 index b264713..0000000 --- a/tests/src/com/android/calendarcommon/DurationTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* //device/content/providers/pim/DurationTest.java -** -** Copyright 2006, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -package com.android.calendarcommon; - -import junit.framework.TestCase; - -import android.test.suitebuilder.annotation.SmallTest; - -public class DurationTest extends TestCase { - - private void verifyDuration(String str, - int sign, int weeks, int days, int hours, - int minutes, int seconds) throws DateException { - - Duration duration = new Duration(); - duration.parse(str); - - assertEquals("Duration sign is not equal for " + str, sign, duration.sign); - assertEquals("Duration weeks is not equal for " + str, weeks, duration.weeks); - assertEquals("Duration days is not equal for " + str, days, duration.days); - assertEquals("Duration hours is not equal for " + str, hours, duration.hours); - assertEquals("Duration minutes is not equal for " + str, minutes, duration.minutes); - assertEquals("Duration seconds is not equal for " + str, seconds, duration.seconds); - } - - @SmallTest - public void testParse() throws Exception { - verifyDuration("P7W", 1, 7, 0, 0, 0, 0); - verifyDuration("PT7W", 1, 7, 0, 0, 0, 0); - verifyDuration("-PT7W", -1, 7, 0, 0, 0, 0); - verifyDuration("P15DT5H0M20S", 1, 0, 15, 5, 0, 20); - verifyDuration("-P15DT5H0M20S", -1, 0, 15, 5, 0, 20); - verifyDuration("PT1H2M3S", 1, 0, 0, 1, 2, 3); - - verifyDuration("", 1, 0, 0, 0, 0, 0); - verifyDuration("P", 1, 0, 0, 0, 0, 0); - verifyDuration("P0W", 1, 0, 0, 0, 0, 0); - verifyDuration("P0D", 1, 0, 0, 0, 0, 0); - verifyDuration("PT0H0M0S", 1, 0, 0, 0, 0, 0); - verifyDuration("P0DT0H0M0S", 1, 0, 0, 0, 0, 0); - } - - @SmallTest - public void testParseInvalidStrings() throws Exception { - try { - verifyDuration(" -P15DT5H0M20S", 0, 0, 0, 0, 0, 0); - fail("test didn't throw an exception but we expected it to"); - } catch (DateException e) { - // expected - } - - try { - verifyDuration(" not even close", 0, 0, 0, 0, 0, 0); - fail("test didn't throw an exception but we expected it to"); - } catch (DateException e) { - // expected - } - } -} - - - diff --git a/tests/src/com/android/calendarcommon/EventRecurrenceTest.java b/tests/src/com/android/calendarcommon/EventRecurrenceTest.java deleted file mode 100644 index efd5f1c..0000000 --- a/tests/src/com/android/calendarcommon/EventRecurrenceTest.java +++ /dev/null @@ -1,889 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.calendarcommon; - -import com.android.calendarcommon.EventRecurrence.InvalidFormatException; - -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; - -import junit.framework.TestCase; - -import java.util.Arrays; - -/** - * Test android.pim.EventRecurrence. - * - * adb shell am instrument -w -e class com.android.calendarcommon.EventRecurrenceTest \ - * com.android.calendarcommon.tests/android.test.InstrumentationTestRunner - */ -public class EventRecurrenceTest extends TestCase { - - @SmallTest - public void test0() throws Exception { - verifyRecurType("FREQ=SECONDLY", - /* int freq */ EventRecurrence.SECONDLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test1() throws Exception { - verifyRecurType("FREQ=MINUTELY", - /* int freq */ EventRecurrence.MINUTELY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test2() throws Exception { - verifyRecurType("FREQ=HOURLY", - /* int freq */ EventRecurrence.HOURLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test3() throws Exception { - verifyRecurType("FREQ=DAILY", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test4() throws Exception { - verifyRecurType("FREQ=WEEKLY", - /* int freq */ EventRecurrence.WEEKLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test5() throws Exception { - verifyRecurType("FREQ=MONTHLY", - /* int freq */ EventRecurrence.MONTHLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test6() throws Exception { - verifyRecurType("FREQ=YEARLY", - /* int freq */ EventRecurrence.YEARLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test7() throws Exception { - // with an until - verifyRecurType("FREQ=DAILY;UNTIL=112233T223344Z", - /* int freq */ EventRecurrence.DAILY, - /* String until */ "112233T223344Z", - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test8() throws Exception { - // with a count - verifyRecurType("FREQ=DAILY;COUNT=334", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 334, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test9() throws Exception { - // with a count - verifyRecurType("FREQ=DAILY;INTERVAL=5000", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 5000, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @SmallTest - public void test10() throws Exception { - // verifyRecurType all of the BY* ones with one element - verifyRecurType("FREQ=DAILY" - + ";BYSECOND=0" - + ";BYMINUTE=1" - + ";BYHOUR=2" - + ";BYMONTHDAY=30" - + ";BYYEARDAY=300" - + ";BYWEEKNO=53" - + ";BYMONTH=12" - + ";BYSETPOS=-15" - + ";WKST=SU", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ new int[]{0}, - /* int[] byminute */ new int[]{1}, - /* int[] byhour */ new int[]{2}, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ new int[]{30}, - /* int[] byyearday */ new int[]{300}, - /* int[] byweekno */ new int[]{53}, - /* int[] bymonth */ new int[]{12}, - /* int[] bysetpos */ new int[]{-15}, - /* int wkst */ EventRecurrence.SU - ); - } - - @SmallTest - public void test11() throws Exception { - // verifyRecurType all of the BY* ones with one element - verifyRecurType("FREQ=DAILY" - + ";BYSECOND=0,30,59" - + ";BYMINUTE=0,41,59" - + ";BYHOUR=0,4,23" - + ";BYMONTHDAY=-31,-1,1,31" - + ";BYYEARDAY=-366,-1,1,366" - + ";BYWEEKNO=-53,-1,1,53" - + ";BYMONTH=1,12" - + ";BYSETPOS=1,2,3,4,500,10000" - + ";WKST=SU", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ new int[]{0, 30, 59}, - /* int[] byminute */ new int[]{0, 41, 59}, - /* int[] byhour */ new int[]{0, 4, 23}, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ new int[]{-31, -1, 1, 31}, - /* int[] byyearday */ new int[]{-366, -1, 1, 366}, - /* int[] byweekno */ new int[]{-53, -1, 1, 53}, - /* int[] bymonth */ new int[]{1, 12}, - /* int[] bysetpos */ new int[]{1, 2, 3, 4, 500, 10000}, - /* int wkst */ EventRecurrence.SU - ); - } - - private static class Check { - Check(String k, int... v) { - key = k; - values = v; - } - - String key; - int[] values; - } - - // this is a negative verifyRecurType case to verifyRecurType the range of the numbers accepted - @SmallTest - public void test12() throws Exception { - Check[] checks = new Check[]{ - new Check("BYSECOND", -100, -1, 60, 100), - new Check("BYMINUTE", -100, -1, 60, 100), - new Check("BYHOUR", -100, -1, 24, 100), - new Check("BYMONTHDAY", -100, -32, 0, 32, 100), - new Check("BYYEARDAY", -400, -367, 0, 367, 400), - new Check("BYWEEKNO", -100, -54, 0, 54, 100), - new Check("BYMONTH", -100, -5, 0, 13, 100) - }; - - for (Check ck : checks) { - for (int n : ck.values) { - String recur = "FREQ=DAILY;" + ck.key + "=" + n; - try { - EventRecurrence er = new EventRecurrence(); - er.parse(recur); - fail("Negative verifyRecurType failed. " - + " parse failed to throw an exception for '" - + recur + "'"); - } catch (EventRecurrence.InvalidFormatException e) { - // expected - } - } - } - } - - // verifyRecurType BYDAY - @SmallTest - public void test13() throws Exception { - verifyRecurType("FREQ=DAILY;BYDAY=1SU,-2MO,+33TU,WE,TH,FR,SA", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.SU, - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - EventRecurrence.TH, - EventRecurrence.FR, - EventRecurrence.SA - }, - /* int[] bydayNum */ new int[]{1, -2, 33, 0, 0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - @Suppress - // Repro bug #2331761 - this should fail because of the last comma into BYDAY - public void test14() throws Exception { - verifyRecurType("FREQ=WEEKLY;WKST=MO;UNTIL=20100129T130000Z;INTERVAL=1;BYDAY=MO,TU,WE,", - /* int freq */ EventRecurrence.WEEKLY, - /* String until */ "20100129T130000Z", - /* int count */ 0, - /* int interval */ 1, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - }, - /* int[] bydayNum */ new int[]{0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // This test should pass - public void test15() throws Exception { - verifyRecurType("FREQ=WEEKLY;WKST=MO;UNTIL=20100129T130000Z;INTERVAL=1;" - + "BYDAY=MO,TU,WE,TH,FR,SA,SU", - /* int freq */ EventRecurrence.WEEKLY, - /* String until */ "20100129T130000Z", - /* int count */ 0, - /* int interval */ 1, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - EventRecurrence.TH, - EventRecurrence.FR, - EventRecurrence.SA, - EventRecurrence.SU - }, - /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // Sample coming from RFC2445 - public void test16() throws Exception { - verifyRecurType("FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1", - /* int freq */ EventRecurrence.MONTHLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - EventRecurrence.TH, - EventRecurrence.FR - }, - /* int[] bydayNum */ new int[] {0, 0, 0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ new int[] { -1 }, - /* int wkst */ EventRecurrence.MO - ); - } - - // Sample coming from RFC2445 - public void test17() throws Exception { - verifyRecurType("FREQ=DAILY;COUNT=10;INTERVAL=2", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 10, - /* int interval */ 2, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // Sample coming from RFC2445 - public void test18() throws Exception { - verifyRecurType("FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10", - /* int freq */ EventRecurrence.YEARLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.SU - }, - /* int[] bydayNum */ new int[] { -1 }, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ new int[] { 10 }, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // Sample coming from bug #1640517 - public void test19() throws Exception { - verifyRecurType("FREQ=YEARLY;BYMONTH=3;BYDAY=TH", - /* int freq */ EventRecurrence.YEARLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.TH - }, - /* int[] bydayNum */ new int[] { 0 }, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ new int[] { 3 }, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // INTERVAL = 0 -> Interval = 1 bug #5676414 - public void test20() throws Exception { - verifyRecurType("FREQ=YEARLY;BYMONTHDAY=18;BYMONTH=10;INTERVAL=0;", - /* int freq */ EventRecurrence.YEARLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 1, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ new int[]{18}, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ new int[]{10}, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // Working case: INTERVAL=1 -> Interval = 1 bug #5676414 - public void test21() throws Exception { - verifyRecurType("FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR", - /* int freq */ EventRecurrence.WEEKLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 1, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - EventRecurrence.TH, - EventRecurrence.FR, - }, - /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.SU - ); - } - - // Working case: INTERVAL=2 -> Interval = 2 bug #5676414 - public void test22() throws Exception { - verifyRecurType("FREQ=WEEKLY;WKST=SU;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR", - /* int freq */ EventRecurrence.WEEKLY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 2, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - EventRecurrence.TH, - EventRecurrence.FR, - }, - /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.SU - ); - } - - // COUNT < 0 -> Count = 1 bug #5676414 - public void test23() throws Exception { - verifyRecurType("FREQ=WEEKLY;COUNT=-20;BYDAY=MO,TU,WE,TH,FR;", - /* int freq */ EventRecurrence.WEEKLY, - /* String until */ null, - /* int count */ 1, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - EventRecurrence.TH, - EventRecurrence.FR, - }, - /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // Working case: COUNT=2 -> Count=2 bug #5676414 - public void test24() throws Exception { - verifyRecurType("FREQ=WEEKLY;COUNT=2;BYDAY=MO,TU,WE,TH,FR;", - /* int freq */ EventRecurrence.WEEKLY, - /* String until */ null, - /* int count */ 2, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ new int[] { - EventRecurrence.MO, - EventRecurrence.TU, - EventRecurrence.WE, - EventRecurrence.TH, - EventRecurrence.FR, - }, - /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - // for your copying pleasure - public void fakeTestXX() throws Exception { - verifyRecurType("FREQ=DAILY;", - /* int freq */ EventRecurrence.DAILY, - /* String until */ null, - /* int count */ 0, - /* int interval */ 0, - /* int[] bysecond */ null, - /* int[] byminute */ null, - /* int[] byhour */ null, - /* int[] byday */ null, - /* int[] bydayNum */ null, - /* int[] bymonthday */ null, - /* int[] byyearday */ null, - /* int[] byweekno */ null, - /* int[] bymonth */ null, - /* int[] bysetpos */ null, - /* int wkst */ EventRecurrence.MO - ); - } - - private static void cmp(int vlen, int[] v, int[] correct, String name) { - if ((correct == null && v != null) - || (correct != null && v == null)) { - throw new RuntimeException("One is null, one isn't for " + name - + ": correct=" + Arrays.toString(correct) - + " actual=" + Arrays.toString(v)); - } - if ((correct == null && vlen != 0) - || (vlen != (correct == null ? 0 : correct.length))) { - throw new RuntimeException("Reported length mismatch for " + name - + ": correct=" + ((correct == null) ? "null" : correct.length) - + " actual=" + vlen); - } - if (correct == null) { - return; - } - if (v.length < correct.length) { - throw new RuntimeException("Array length mismatch for " + name - + ": correct=" + Arrays.toString(correct) - + " actual=" + Arrays.toString(v)); - } - for (int i = 0; i < correct.length; i++) { - if (v[i] != correct[i]) { - throw new RuntimeException("Array value mismatch for " + name - + ": correct=" + Arrays.toString(correct) - + " actual=" + Arrays.toString(v)); - } - } - } - - private static boolean eq(String a, String b) { - if ((a == null && b != null) || (a != null && b == null)) { - return false; - } else { - return a == b || a.equals(b); - } - } - - private static void verifyRecurType(String recur, - int freq, String until, int count, int interval, - int[] bysecond, int[] byminute, int[] byhour, - int[] byday, int[] bydayNum, int[] bymonthday, - int[] byyearday, int[] byweekno, int[] bymonth, - int[] bysetpos, int wkst) { - EventRecurrence eventRecurrence = new EventRecurrence(); - eventRecurrence.parse(recur); - if (eventRecurrence.freq != freq - || !eq(eventRecurrence.until, until) - || eventRecurrence.count != count - || eventRecurrence.interval != interval - || eventRecurrence.wkst != wkst) { - System.out.println("Error... got:"); - print(eventRecurrence); - System.out.println("expected:"); - System.out.println("{"); - System.out.println(" freq=" + freq); - System.out.println(" until=" + until); - System.out.println(" count=" + count); - System.out.println(" interval=" + interval); - System.out.println(" wkst=" + wkst); - System.out.println(" bysecond=" + Arrays.toString(bysecond)); - System.out.println(" byminute=" + Arrays.toString(byminute)); - System.out.println(" byhour=" + Arrays.toString(byhour)); - System.out.println(" byday=" + Arrays.toString(byday)); - System.out.println(" bydayNum=" + Arrays.toString(bydayNum)); - System.out.println(" bymonthday=" + Arrays.toString(bymonthday)); - System.out.println(" byyearday=" + Arrays.toString(byyearday)); - System.out.println(" byweekno=" + Arrays.toString(byweekno)); - System.out.println(" bymonth=" + Arrays.toString(bymonth)); - System.out.println(" bysetpos=" + Arrays.toString(bysetpos)); - System.out.println("}"); - throw new RuntimeException("Mismatch in fields"); - } - cmp(eventRecurrence.bysecondCount, eventRecurrence.bysecond, bysecond, "bysecond"); - cmp(eventRecurrence.byminuteCount, eventRecurrence.byminute, byminute, "byminute"); - cmp(eventRecurrence.byhourCount, eventRecurrence.byhour, byhour, "byhour"); - cmp(eventRecurrence.bydayCount, eventRecurrence.byday, byday, "byday"); - cmp(eventRecurrence.bydayCount, eventRecurrence.bydayNum, bydayNum, "bydayNum"); - cmp(eventRecurrence.bymonthdayCount, eventRecurrence.bymonthday, bymonthday, "bymonthday"); - cmp(eventRecurrence.byyeardayCount, eventRecurrence.byyearday, byyearday, "byyearday"); - cmp(eventRecurrence.byweeknoCount, eventRecurrence.byweekno, byweekno, "byweekno"); - cmp(eventRecurrence.bymonthCount, eventRecurrence.bymonth, bymonth, "bymonth"); - cmp(eventRecurrence.bysetposCount, eventRecurrence.bysetpos, bysetpos, "bysetpos"); - } - - private static void print(EventRecurrence er) { - System.out.println("{"); - System.out.println(" freq=" + er.freq); - System.out.println(" until=" + er.until); - System.out.println(" count=" + er.count); - System.out.println(" interval=" + er.interval); - System.out.println(" wkst=" + er.wkst); - System.out.println(" bysecond=" + Arrays.toString(er.bysecond)); - System.out.println(" bysecondCount=" + er.bysecondCount); - System.out.println(" byminute=" + Arrays.toString(er.byminute)); - System.out.println(" byminuteCount=" + er.byminuteCount); - System.out.println(" byhour=" + Arrays.toString(er.byhour)); - System.out.println(" byhourCount=" + er.byhourCount); - System.out.println(" byday=" + Arrays.toString(er.byday)); - System.out.println(" bydayNum=" + Arrays.toString(er.bydayNum)); - System.out.println(" bydayCount=" + er.bydayCount); - System.out.println(" bymonthday=" + Arrays.toString(er.bymonthday)); - System.out.println(" bymonthdayCount=" + er.bymonthdayCount); - System.out.println(" byyearday=" + Arrays.toString(er.byyearday)); - System.out.println(" byyeardayCount=" + er.byyeardayCount); - System.out.println(" byweekno=" + Arrays.toString(er.byweekno)); - System.out.println(" byweeknoCount=" + er.byweeknoCount); - System.out.println(" bymonth=" + Arrays.toString(er.bymonth)); - System.out.println(" bymonthCount=" + er.bymonthCount); - System.out.println(" bysetpos=" + Arrays.toString(er.bysetpos)); - System.out.println(" bysetposCount=" + er.bysetposCount); - System.out.println("}"); - } - - - /** A list of valid rules. The parser must accept these. */ - private static final String[] GOOD_RRULES = { - /* extracted wholesale from from RFC 2445 section 4.8.5.4 */ - "FREQ=DAILY;COUNT=10", - "FREQ=DAILY;UNTIL=19971224T000000Z", - "FREQ=DAILY;INTERVAL=2", - "FREQ=DAILY;INTERVAL=10;COUNT=5", - "FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA", - "FREQ=DAILY;UNTIL=20000131T090000Z;BYMONTH=1", - "FREQ=WEEKLY;COUNT=10", - "FREQ=WEEKLY;UNTIL=19971224T000000Z", - "FREQ=WEEKLY;INTERVAL=2;WKST=SU", - "FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH", - "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH", - "FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR", - "FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH", - "FREQ=MONTHLY;COUNT=10;BYDAY=1FR", - "FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR", - "FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU", - "FREQ=MONTHLY;COUNT=6;BYDAY=-2MO", - "FREQ=MONTHLY;BYMONTHDAY=-3", - "FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15", - "FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1", - "FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15", - "FREQ=MONTHLY;INTERVAL=2;BYDAY=TU", - "FREQ=YEARLY;COUNT=10;BYMONTH=6,7", - "FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3", - "FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200", - "FREQ=YEARLY;BYDAY=20MO", - "FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO", - "FREQ=YEARLY;BYMONTH=3;BYDAY=TH", - "FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8", - "FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13", - "FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13", - "FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8", - "FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3", - "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2", - "FREQ=HOURLY;INTERVAL=3;UNTIL=19970902T170000Z", - "FREQ=MINUTELY;INTERVAL=15;COUNT=6", - "FREQ=MINUTELY;INTERVAL=90;COUNT=4", - "FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40", - "FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16", - "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO", - "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU", - /* a few more */ - "FREQ=SECONDLY;BYSECOND=0,15,59", - "FREQ=MINUTELY;BYMINUTE=0,15,59", - "FREQ=HOURLY;BYHOUR=+0,+15,+23", - "INTERVAL=4;FREQ=YEARLY", - "FREQ=DAILY;X-WHATEVER=blah", - //"freq=daily;wkst=su", // mixed case currently not allowed - "FREQ=WEEKLY;INTERVAL=2;BYDAY=Mo;;UNTIL=20120327T000000Z", // double simicolon should be allowed - "FREQ=MONTHLY;BYDAY=1Mo", - "FREQ=MONTHLY;BYDAY=2Mo,2We,4Mo,4We", - "FREQ=MONTHLY;WKST=SU;BYMONTHDAY=25;UNTIL=20110524", - "FREQ=WEEKLY;BYDAY=MO;WKST=SU;UNTIL=20111218T010000Z" - }; - - /** The parser must reject these. */ - private static final String[] BAD_RRULES = { - "FREQ=MONTHLY;FREQ=MONTHLY", // can't specify twice - "FREQ=MONTHLY;COUNT=1;COUNT=1", // can't specify twice - "FREQ=SECONDLY;BYSECOND=60", // range - "FREQ=MINUTELY;BYMINUTE=-1", // range - "FREQ=HOURLY;BYHOUR=24", // range - "FREQ=YEARLY;BYMONTHDAY=0", // zero not valid - "BYMONTHDAY=1", // must specify FREQ - //"FREQ=YEARLY;COUNT=1;UNTIL=12345", // can't have both COUNT and UNTIL - //"FREQ=DAILY;UNTIL=19970829T021400e", // invalid date - }; - - /** - * Simple test of good/bad rules. - */ - @SmallTest - public void testBasicParse() { - for (String rule : GOOD_RRULES) { - EventRecurrence recur = new EventRecurrence(); - recur.parse(rule); - } - - for (String rule : BAD_RRULES) { - EventRecurrence recur = new EventRecurrence(); - boolean didThrow = false; - - try { - recur.parse(rule); - } catch (InvalidFormatException ife) { - didThrow = true; - } - - assertTrue("Expected throw on " + rule, didThrow); - } - } -} diff --git a/tests/src/com/android/calendarcommon/RRuleTest.java b/tests/src/com/android/calendarcommon/RRuleTest.java deleted file mode 100644 index 743e236..0000000 --- a/tests/src/com/android/calendarcommon/RRuleTest.java +++ /dev/null @@ -1,756 +0,0 @@ -/* -** -** Copyright 2009, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -/* Based on http://code.google.com/p/google-rfc-2445/source/browse/trunk/test/com/google/ical/iter/RRuleIteratorImplTest.java */ - -package com.android.calendarcommon; - -import com.android.calendarcommon.RecurrenceSet; - -import android.os.Debug; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.Suppress; -import android.text.format.Time; -import junit.framework.TestCase; - -/** - * You can run those tests with: - * - * adb shell am instrument - * -e debug false - * -w - * -e - * class com.android.providers.calendar.RRuleTest - * com.android.providers.calendar.tests/android.test.InstrumentationTestRunner - */ - -public class RRuleTest extends TestCase { - private static final String TAG = "RRuleTest"; - private static final boolean METHOD_TRACE = false; - - private static String[] getFormattedDates(long[] dates, Time time, boolean truncate) { - String[] out = new String[dates.length]; - int i = 0; - for (long date : dates) { - time.set(date); - if (truncate) { - out[i] = time.format2445().substring(0, 8); // Just YYMMDD - } else { - out[i] = time.format2445().substring(0, 15); // YYMMDDThhmmss - } - ++i; - } - return out; - } - - static final String PST = "America/Los_Angeles"; - static final String UTC = "UTC"; - // Use this date as end of recurrence unlessotherwise specified. - static final String DEFAULT_END = "20091212"; - - private void runRecurrenceIteratorTest(String rruleText, String dtStart, int limit, - String golden) throws Exception { - runRecurrenceIteratorTest(rruleText, dtStart, limit, golden, null, null, UTC); - } - - private void runRecurrenceIteratorTest(String rrule, String dtstartStr, int limit, - String golden, String advanceTo, String tz) throws Exception { - runRecurrenceIteratorTest(rrule, dtstartStr, limit, golden, advanceTo, null, tz); - } - - /** - * Tests a recurrence rule - * @param rrule The rule to expand - * @param dtstartStr The dtstart to use - * @param limit Maximum number of entries to expand. if there are more, "..." is appended to - * the result. Note that Android's recurrence expansion doesn't support expanding n results, - * so this is faked by expanding until the endAt date, and then taking limit results. - * @param golden The desired results - * @param advanceTo The starting date for expansion. dtstartStr is used if null is passed in. - * @param endAt The ending date. DEFAULT_END is used if null is passed in. - * @param tz The time zone. UTC is used if null is passed in. - * @throws Exception if anything goes wrong. - */ - private void runRecurrenceIteratorTest(String rrule, String dtstartStr, int limit, - String golden, String advanceTo, String endAt, String tz) throws Exception { - - String rdate = ""; - String exrule = ""; - String exdate = ""; - rrule = rrule.replace("RRULE:", ""); - // RecurrenceSet does not support folding of lines, so fold here - rrule = rrule.replace("\n ", ""); - - Time dtstart = new Time(tz); - Time rangeStart = new Time(tz); - Time rangeEnd = new Time(tz); - Time outCal = new Time(tz); - - dtstart.parse(dtstartStr); - if (advanceTo == null) { - advanceTo = dtstartStr; - } - if (endAt == null) { - endAt = DEFAULT_END; - } - - rangeStart.parse(advanceTo); - rangeEnd.parse(endAt); - - - RecurrenceProcessor rp = new RecurrenceProcessor(); - RecurrenceSet recur = new RecurrenceSet(rrule, rdate, exrule, exdate); - - long[] out = rp.expand(dtstart, recur, rangeStart.toMillis(false /* use isDst */), - rangeEnd.toMillis(false /* use isDst */)); - - if (METHOD_TRACE) { - Debug.stopMethodTracing(); - } - - boolean truncate = dtstartStr.length() <= 8; // Just date, not date-time - String[] actual = getFormattedDates(out, outCal, truncate); - - StringBuilder sb = new StringBuilder(); - int k = 0; - while (k < actual.length && --limit >= 0) { - if (k != 0) { - sb.append(','); - } - sb.append(actual[k]); - k++; - } - if (limit < 0) { - sb.append(",..."); - } - assertEquals(golden, sb.toString()); - } - - // Infinite loop, bug 1662110 - @MediumTest - public void testFrequencyLimits() throws Exception { - try { - runRecurrenceIteratorTest("RRULE:FREQ=SECONDLY;BYSECOND=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14," + "15,16,17,18,19,20,21,22,23,24,25,26,27,28,29," + "30,31,32,33,34,35,36,37,38,39,40,41,42,43,44," + "45,46,47,48,49,50,51,52,53,54,55,56,57,58,59", "20000101", 1, ""); - fail("Don't do that"); - } catch (DateException ex) { - // pass - } - } - - @MediumTest - public void testSimpleDaily() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=DAILY", "20060120", 5, "20060120,20060121,20060122,20060123,20060124,..."); - } - - @MediumTest - public void testSimpleWeekly() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY", "20060120", 5, "20060120,20060127,20060203,20060210,20060217,..."); - } - - @MediumTest - public void testSimpleMonthly() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY", "20060120", 5, "20060120,20060220,20060320,20060420,20060520,..."); - } - - @MediumTest - public void testSimpleYearly() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY", "20060120", 5, "20060120,20070120,20080120,20090120,20100120,...", null, "20120101", UTC); - } - - // from section 4.3.10 - @MediumTest - public void testMultipleByParts() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU", "19970105", 8, "19970105,19970112,19970119,19970126," + "19990103,19990110,19990117,19990124,..."); - } - - @MediumTest - public void testCountWithInterval() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=DAILY;COUNT=10;INTERVAL=2", "19970105", 11, "19970105,19970107,19970109,19970111,19970113," + "19970115,19970117,19970119,19970121,19970123"); - } - - // from section 4.6.5 - // Fails: wrong dates - @MediumTest - @Suppress - public void testNegativeOffsetsA() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10", "19970105", 5, "19971026,19981025,19991031,20001029,20011028,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testNegativeOffsetsB() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4", "19970105", 5, "19970406,19980405,19990404,20000402,20010401,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testNegativeOffsetsC() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=19980404T150000Z", "19970105", 5, "19970406"); - } - - // feom section 4.8.5.4 - @MediumTest - public void testDailyFor10Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=DAILY;COUNT=10", "19970902T090000", 11, "19970902T090000,19970903T090000,19970904T090000,19970905T090000," + "19970906T090000,19970907T090000,19970908T090000,19970909T090000," + "19970910T090000,19970911T090000"); - - } - - @MediumTest - public void testDailyUntilDec4() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=DAILY;UNTIL=19971204", "19971128", 11, "19971128,19971129,19971130,19971201,19971202,19971203,19971204"); - } - - // Fails: infinite loop - @MediumTest - @Suppress - public void testEveryOtherDayForever() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=DAILY;INTERVAL=2", "19971128", 5, "19971128,19971130,19971202,19971204,19971206,..."); - } - - @MediumTest - public void testEvery10Days5Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5", "19970902", 5, "19970902,19970912,19970922,19971002,19971012"); - } - - @MediumTest - public void testWeeklyFor10Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;COUNT=10", "19970902", 10, "19970902,19970909,19970916,19970923,19970930," + "19971007,19971014,19971021,19971028,19971104"); - } - - @MediumTest - public void testWeeklyUntilDec24() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971224", "19970902", 25, "19970902,19970909,19970916,19970923,19970930," + "19971007,19971014,19971021,19971028,19971104," + "19971111,19971118,19971125,19971202,19971209," + "19971216,19971223"); - } - - @MediumTest - public void testEveryOtherWeekForever() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU", "19970902", 11, "19970902,19970916,19970930,19971014,19971028," + "19971111,19971125,19971209,19971223,19980106," + "19980120,..."); - } - - @MediumTest - public void testWeeklyOnTuesdayAndThursdayFor5Weeks() throws Exception { - // if UNTIL date does not match start date, then until date treated as - // occurring on midnight. - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971007;WKST=SU;BYDAY=TU,TH", "19970902T090000", 11, "19970902T090000,19970904T090000,19970909T090000,19970911T090000," + "19970916T090000,19970918T090000,19970923T090000,19970925T090000," + "19970930T090000,19971002T090000"); - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH", "19970902T090000", 11, "19970902T090000,19970904T090000,19970909T090000,19970911T090000," + "19970916T090000,19970918T090000,19970923T090000,19970925T090000," + "19970930T090000,19971002T090000"); - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH", "19970902", 11, "19970902,19970904,19970909,19970911,19970916," + "19970918,19970923,19970925,19970930,19971002"); - } - - @MediumTest - public void testEveryOtherWeekOnMWFUntilDec24() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;\n" + " BYDAY=MO,WE,FR", "19970903T090000", 25, "19970903T090000,19970905T090000,19970915T090000,19970917T090000," + "19970919T090000,19970929T090000,19971001T090000,19971003T090000," + "19971013T090000,19971015T090000,19971017T090000,19971027T090000," + "19971029T090000,19971031T090000,19971110T090000,19971112T090000," + "19971114T090000,19971124T090000,19971126T090000,19971128T090000," + "19971208T090000,19971210T090000,19971212T090000,19971222T090000"); - } - - @MediumTest - public void testEveryOtherWeekOnMWFUntilDec24a() throws Exception { - // if the UNTIL date is timed, when the start is not, the time should be - // ignored, so we get one more instance - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;\n" + " BYDAY=MO,WE,FR", "19970903", 25, "19970903,19970905,19970915,19970917," + "19970919,19970929,19971001,19971003," + "19971013,19971015,19971017,19971027," + "19971029,19971031,19971110,19971112," + "19971114,19971124,19971126,19971128," + "19971208,19971210,19971212,19971222," + "19971224"); - } - - // Fails with wrong times - @MediumTest - @Suppress - public void testEveryOtherWeekOnMWFUntilDec24b() throws Exception { - // test with an alternate timezone - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T090000Z;WKST=SU;\n" + " BYDAY=MO,WE,FR", "19970903T090000", 25, "19970903T160000,19970905T160000,19970915T160000,19970917T160000," + "19970919T160000,19970929T160000,19971001T160000,19971003T160000," + "19971013T160000,19971015T160000,19971017T160000,19971027T170000," + "19971029T170000,19971031T170000,19971110T170000,19971112T170000," + "19971114T170000,19971124T170000,19971126T170000,19971128T170000," + "19971208T170000,19971210T170000,19971212T170000,19971222T170000", null, PST); - } - - @MediumTest - public void testEveryOtherWeekOnTuThFor8Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH", "19970902", 8, "19970902,19970904,19970916,19970918,19970930," + "19971002,19971014,19971016"); - } - - @MediumTest - public void testMonthlyOnThe1stFridayFor10Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=10;BYDAY=1FR", "19970905", 10, "19970905,19971003,19971107,19971205,19980102," + "19980206,19980306,19980403,19980501,19980605"); - } - - @MediumTest - public void testMonthlyOnThe1stFridayUntilDec24() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR", "19970905", 4, "19970905,19971003,19971107,19971205"); - } - - @MediumTest - public void testEveryOtherMonthOnThe1stAndLastSundayFor10Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU", "19970907", 10, "19970907,19970928,19971102,19971130,19980104," + "19980125,19980301,19980329,19980503,19980531"); - } - - @MediumTest - public void testMonthlyOnTheSecondToLastMondayOfTheMonthFor6Months() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO", "19970922", 6, "19970922,19971020,19971117,19971222,19980119," + "19980216"); - } - - @MediumTest - public void testMonthlyOnTheThirdToLastDay() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTHDAY=-3", "19970928", 6, "19970928,19971029,19971128,19971229,19980129,19980226,..."); - } - - @MediumTest - public void testMonthlyOnThe2ndAnd15thFor10Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15", "19970902", 10, "19970902,19970915,19971002,19971015,19971102," + "19971115,19971202,19971215,19980102,19980115"); - } - - @MediumTest - public void testMonthlyOnTheFirstAndLastFor10Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1", "19970930", 10, "19970930,19971001,19971031,19971101,19971130," + "19971201,19971231,19980101,19980131,19980201"); - } - - @MediumTest - public void testEvery18MonthsOnThe10thThru15thFor10Occ() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,\n" + " 15", "19970910", 10, "19970910,19970911,19970912,19970913,19970914," + "19970915,19990310,19990311,19990312,19990313"); - } - - @MediumTest - public void testEveryTuesdayEveryOtherMonth() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU", "19970902", 18, "19970902,19970909,19970916,19970923,19970930," + "19971104,19971111,19971118,19971125,19980106," + "19980113,19980120,19980127,19980303,19980310," + "19980317,19980324,19980331,..."); - } - - @MediumTest - public void testYearlyInJuneAndJulyFor10Occurrences() throws Exception { - // Note: Since none of the BYDAY, BYMONTHDAY or BYYEARDAY components - // are specified, the day is gotten from DTSTART - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7", "19970610", 10, "19970610,19970710,19980610,19980710,19990610," + "19990710,20000610,20000710,20010610,20010710"); - } - - @MediumTest - public void testEveryOtherYearOnJanuaryFebruaryAndMarchFor10Occurrences() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3", "19970310", 10, "19970310,19990110,19990210,19990310,20010110," + "20010210,20010310,20030110,20030210,20030310"); - } - - //Fails: wrong dates - @MediumTest - @Suppress - public void testEvery3rdYearOnThe1st100thAnd200thDayFor10Occurrences() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200", "19970101", 10, "19970101,19970410,19970719,20000101,20000409," + "20000718,20030101,20030410,20030719,20060101"); - } - - // Fails: infinite loop - @MediumTest - @Suppress - public void testEvery20thMondayOfTheYearForever() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=20MO", "19970519", 3, "19970519,19980518,19990517,..."); - } - - // Fails: generates wrong dates - @MediumTest - @Suppress - public void testMondayOfWeekNumber20WhereTheDefaultStartOfTheWeekIsMonday() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO", "19970512", 3, "19970512,19980511,19990517,..."); - } - - @MediumTest - public void testEveryThursdayInMarchForever() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH", "19970313", 11, "19970313,19970320,19970327,19980305,19980312," + "19980319,19980326,19990304,19990311,19990318," + "19990325,..."); - } - - //Fails: wrong dates - @MediumTest - @Suppress - public void testEveryThursdayButOnlyDuringJuneJulyAndAugustForever() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8", "19970605", 39, "19970605,19970612,19970619,19970626,19970703," + "19970710,19970717,19970724,19970731,19970807," + "19970814,19970821,19970828,19980604,19980611," + "19980618,19980625,19980702,19980709,19980716," + "19980723,19980730,19980806,19980813,19980820," + "19980827,19990603,19990610,19990617,19990624," + "19990701,19990708,19990715,19990722,19990729," + "19990805,19990812,19990819,19990826,..."); - } - - //Fails: infinite loop - @MediumTest - @Suppress - public void testEveryFridayThe13thForever() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13", "19970902", 5, "19980213,19980313,19981113,19990813,20001013," + "..."); - } - - @MediumTest - public void testTheFirstSaturdayThatFollowsTheFirstSundayOfTheMonthForever() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13", "19970913", 10, "19970913,19971011,19971108,19971213,19980110," + "19980207,19980307,19980411,19980509,19980613," + "..."); - } - - @MediumTest - public void testEvery4YearsThe1stTuesAfterAMonInNovForever() throws Exception { - // US Presidential Election Day - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,\n" + " 5,6,7,8", "19961105", 3, "19961105,20001107,20041102,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testThe3rdInstanceIntoTheMonthOfOneOfTuesWedThursForNext3Months() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3", "19970904", 3, "19970904,19971007,19971106"); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testThe2ndToLastWeekdayOfTheMonth() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2", "19970929", 7, "19970929,19971030,19971127,19971230,19980129," + "19980226,19980330,..."); - } - - // Fails: infinite loop - @MediumTest - @Suppress - public void testEvery3HoursFrom900AmTo500PmOnASpecificDay() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=HOURLY;INTERVAL=3;UNTIL=19970903T010000Z", "19970902", 7, "00000902,19970909,19970900,19970912,19970900," + "19970915,19970900"); - } - - // Fails: infinite loop - @MediumTest - @Suppress - public void testEvery15MinutesFor6Occurrences() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MINUTELY;INTERVAL=15;COUNT=6", "19970902", 13, "00000902,19970909,19970900,19970909,19970915," + "19970909,19970930,19970909,19970945,19970910," + "19970900,19970910,19970915"); - } - - @MediumTest - @Suppress - public void testEveryHourAndAHalfFor4Occurrences() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MINUTELY;INTERVAL=90;COUNT=4", "19970902", 9, "00000902,19970909,19970900,19970910,19970930," + "19970912,19970900,19970913,19970930"); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testAnExampleWhereTheDaysGeneratedMakesADifferenceBecauseOfWkst() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO", "19970805", 4, "19970805,19970810,19970819,19970824"); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testAnExampleWhereTheDaysGeneratedMakesADifferenceBecauseOfWkst2() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU", "19970805", 8, "19970805,19970817,19970819,19970831"); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testWithByDayAndByMonthDayFilter() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;COUNT=4;BYDAY=TU,SU;" + "BYMONTHDAY=13,14,15,16,17,18,19,20", "19970805", 8, "19970817,19970819,19970914,19970916"); - } - - // Failed: wrong dates - @MediumTest - @Suppress - public void testAnnuallyInAugustOnTuesAndSunBetween13thAnd20th() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,SU;" + "BYMONTHDAY=13,14,15,16,17,18,19,20;BYMONTH=8", "19970605", 8, "19970817,19970819,19980816,19980818"); - } - - // Failed: wrong dates - @MediumTest - @Suppress - public void testLastDayOfTheYearIsASundayOrTuesday() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,SU;BYYEARDAY=-1", "19940605", 8, "19951231,19961231,20001231,20021231"); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testLastWeekdayOfMonth() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYSETPOS=-1;BYDAY=-1MO,-1TU,-1WE,-1TH,-1FR", "19940605", 8, "19940630,19940729,19940831,19940930," + "19941031,19941130,19941230,19950131,..."); - } - - // Fails: generates wrong dates - @MediumTest - @Suppress - public void testMonthsThatStartOrEndOnFriday() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTHDAY=1,-1;BYDAY=FR;COUNT=6", "19940605", 8, "19940701,19940930,19950331,19950630,19950901,19951201"); - } - - // Fails: can't go that far into future - @MediumTest - @Suppress - public void testCenturiesThatAreNotLeapYears() throws Exception { - // I can't think of a good reason anyone would want to specify both a - // month day and a year day, so here's a really contrived example - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=100;BYYEARDAY=60;BYMONTHDAY=1", "19000101", 4, "19000301,21000301,22000301,23000301,...", null, "25000101", UTC); - } - - // Fails: generates instances when it shouldn't - @MediumTest - @Suppress - public void testNoInstancesGenerated() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=DAILY;UNTIL=19990101", "20000101", 4, ""); - } - - // Fails: generates instances when it shouldn't - @MediumTest - @Suppress - public void testNoInstancesGenerated2() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30", "20000101", 4, ""); - } - - // Fails: generates instances when it shouldn't - @MediumTest - @Suppress - public void testNoInstancesGenerated3() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=4;BYYEARDAY=366", "20000101", 4, ""); - } - - //Fails: wrong dates - @MediumTest - @Suppress - public void testLastWeekdayOfMarch() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTH=3;BYDAY=SA,SU;BYSETPOS=-1", "20000101", 4, "20000326,20010331,20020331,20030330,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testFirstWeekdayOfMarch() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTH=3;BYDAY=SA,SU;BYSETPOS=1", "20000101", 4, "20000304,20010303,20020302,20030301,..."); - } - - // January 1999 - // Mo Tu We Th Fr Sa Su - // 1 2 3 // < 4 days, so not a week - // 4 5 6 7 8 9 10 - - // January 2000 - // Mo Tu We Th Fr Sa Su - // 1 2 // < 4 days, so not a week - // 3 4 5 6 7 8 9 - - // January 2001 - // Mo Tu We Th Fr Sa Su - // 1 2 3 4 5 6 7 - // 8 9 10 11 12 13 14 - - // January 2002 - // Mo Tu We Th Fr Sa Su - // 1 2 3 4 5 6 - // 7 8 9 10 11 12 13 - - /** - * Find the first weekday of the first week of the year. - * The first week of the year may be partial, and the first week is considered - * to be the first one with at least four days. - */ - // Fails: wrong dates - @MediumTest - @Suppress - public void testFirstWeekdayOfFirstWeekOfYear() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=1;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1", "19990101", 4, "19990104,20000103,20010101,20020101,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testFirstSundayOfTheYear1() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=1;BYDAY=SU", "19990101", 4, "19990110,20000109,20010107,20020106,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testFirstSundayOfTheYear2() throws Exception { - // TODO(msamuel): is this right? - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=1SU", "19990101", 4, "19990103,20000102,20010107,20020106,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testFirstSundayOfTheYear3() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=SU;BYYEARDAY=1,2,3,4,5,6,7,8,9,10,11,12,13" + ";BYSETPOS=1", "19990101", 4, "19990103,20000102,20010107,20020106,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testFirstWeekdayOfYear() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1", "19990101", 4, "19990101,20000103,20010101,20020101,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testLastWeekdayOfFirstWeekOfYear() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=1;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1", "19990101", 4, "19990108,20000107,20010105,20020104,..."); - } - - // January 1999 - // Mo Tu We Th Fr Sa Su - // 1 2 3 - // 4 5 6 7 8 9 10 - // 11 12 13 14 15 16 17 - // 18 19 20 21 22 23 24 - // 25 26 27 28 29 30 31 - - // Fails: wrong dates - @MediumTest - @Suppress - public void testSecondWeekday1() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=2", "19990101", 4, "19990105,19990112,19990119,19990126,..."); - } - - // January 1997 - // Mo Tu We Th Fr Sa Su - // 1 2 3 4 5 - // 6 7 8 9 10 11 12 - // 13 14 15 16 17 18 19 - // 20 21 22 23 24 25 26 - // 27 28 29 30 31 - - // Fails: wrong dates - @MediumTest - @Suppress - public void testSecondWeekday2() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=2", "19970101", 4, "19970102,19970107,19970114,19970121,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testByYearDayAndByDayFilterInteraction() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYYEARDAY=15;BYDAY=3MO", "19990101", 4, "20010115,20070115,20180115,20240115,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testByDayWithNegWeekNoAsFilter() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTHDAY=26;BYDAY=-1FR", "19990101", 4, "19990226,19990326,19991126,20000526,..."); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testLastWeekOfTheYear() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=-1", "19990101", 6, "19991227,19991228,19991229,19991230,19991231,20001225,..."); - } - - // Fails: not enough dates generated - @MediumTest - @Suppress - public void testUserSubmittedTest1() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=WE;BYDAY=SU,TU,TH,SA" + ";UNTIL=20000215T113000Z", "20000127T033000", 20, "20000127T033000,20000129T033000,20000130T033000,20000201T033000," + "20000210T033000,20000212T033000,20000213T033000,20000215T033000"); - } - - @MediumTest - public void testAdvanceTo1() throws Exception { - // a bunch of tests grabbed from above with an advance-to date tacked on - - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH", "19970313", 11, - /*"19970313,19970320,19970327,"*/"19980305,19980312," + "19980319,19980326,19990304,19990311,19990318," + "19990325,20000302,20000309,20000316,...", "19970601", UTC); - } - - // Fails: infinite loop - @MediumTest - @Suppress - public void testAdvanceTo2() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=20MO", "19970519", 3, - /*"19970519,"*/"19980518,19990517,20000515,...", "19980515", UTC); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testAdvanceTo3() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=3;UNTIL=20090101;BYYEARDAY=1,100,200", "19970101", 10, - /*"19970101,19970410,19970719,20000101,"*/"20000409," + "20000718,20030101,20030410,20030719,20060101,20060410,20060719," + "20090101", "20000228", UTC); - } - - //Fails: wrong dates - @MediumTest - @Suppress - public void testAdvanceTo4() throws Exception { - // make sure that count preserved - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200", "19970101", 10, - /*"19970101,19970410,19970719,20000101,"*/"20000409," + "20000718,20030101,20030410,20030719,20060101", "20000228", UTC); - } - - // Fails: too many dates - @MediumTest - @Suppress - public void testAdvanceTo5() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3", "19970310", 10, - /*"19970310,"*/"19990110,19990210,19990310,20010110," + "20010210,20010310,20030110,20030210,20030310", "19980401", UTC); - } - - @MediumTest - public void testAdvanceTo6() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971224", "19970902", 25, - /*"19970902,19970909,19970916,19970923,"*/"19970930," + "19971007,19971014,19971021,19971028,19971104," + "19971111,19971118,19971125,19971202,19971209," + "19971216,19971223", "19970930", UTC); - } - - @MediumTest - public void testAdvanceTo7() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=18;BYMONTHDAY=10,11,12,13,14,\n" + " 15", "19970910", 5, - /*"19970910,19970911,19970912,19970913,19970914," + - "19970915,"*/"19990310,19990311,19990312,19990313,19990314,...", "19990101", UTC); - } - - @MediumTest - public void testAdvanceTo8() throws Exception { - // advancing into the past - runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=18;BYMONTHDAY=10,11,12,13,14,\n" + " 15", "19970910", 11, "19970910,19970911,19970912,19970913,19970914," + "19970915,19990310,19990311,19990312,19990313,19990314,...", "19970901", UTC); - } - - // Fails: wrong dates - @MediumTest - @Suppress - public void testAdvanceTo9() throws Exception { - // skips first instance - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=100;BYMONTH=2;BYMONTHDAY=29", "19000101", 5, - // would return 2000 - "24000229,28000229,32000229,36000229,40000229,...", "20040101", UTC); - } - - // Infinite loop in native code (bug 1686327) - @MediumTest - @Suppress - public void testAdvanceTo10() throws Exception { - // filter hits until date before first instnace - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=100;BYMONTH=2;BYMONTHDAY=29;UNTIL=21000101", "19000101", 5, "", "20040101", UTC); - } - - // Fails: generates wrong dates - @MediumTest - @Suppress - public void testAdvanceTo11() throws Exception { - // advancing something that returns no instances - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30", "20000101", 10, "", "19970901", UTC); - } - - // Fails: generates wrong dates - @MediumTest - @Suppress - public void testAdvanceTo12() throws Exception { - // advancing something that returns no instances and has a BYSETPOS rule - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30,31;BYSETPOS=1", "20000101", 10, "", "19970901", UTC); - } - - // Fails: generates wrong dates - @MediumTest - @Suppress - public void testAdvanceTo13() throws Exception { - // advancing way past year generator timeout - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=28", "20000101", 10, "", "25000101", UTC); - } - - /** - * a testcase that yielded dupes due to bysetPos evilness - */ - @MediumTest - @Suppress - public void testCaseThatYieldedDupes() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYMONTH=9,1,12,8" + ";BYMONTHDAY=-9,-29,24;BYSETPOS=-1,-4,10,-6,-1,-10,-10,-9,-8", "20060528", 200, "20060924,20061203,20061224,20070902,20071223,20080803,20080824," + "20090823,20100103,20100124,20110123,20120902,20121223,20130922," + "20140803,20140824,20150823,20160103,20160124,20170924,20171203," + "20171224,20180902,20181223,20190922,20200823,20210103,20210124," + "20220123,20230924,20231203,20231224,20240922,20250803,20250824," + "20260823,20270103,20270124,20280123,20280924,20281203,20281224," + "20290902,20291223,20300922,20310803,20310824,20330123,20340924," + "20341203,20341224,20350902,20351223,20360803,20360824,20370823," + "20380103,20380124,20390123,20400902,20401223,20410922,20420803," + "20420824,20430823,20440103,20440124,20450924,20451203,20451224," + "20460902,20461223,20470922,20480823,20490103,20490124,20500123," + "20510924,20511203,20511224,20520922,20530803,20530824,20540823," + "20550103,20550124,20560123,20560924,20561203,20561224,20570902," + "20571223,20580922,20590803,20590824,20610123,20620924,20621203," + "20621224,20630902,20631223,20640803,20640824,20650823,20660103," + "20660124,20670123,20680902,20681223,20690922,20700803,20700824," + "20710823,20720103,20720124,20730924,20731203,20731224,20740902," + "20741223,20750922,20760823,20770103,20770124,20780123,20790924," + "20791203,20791224,20800922,20810803,20810824,20820823,20830103," + "20830124,20840123,20840924,20841203,20841224,20850902,20851223," + "20860922,20870803,20870824,20890123,20900924,20901203,20901224," + "20910902,20911223,20920803,20920824,20930823,20940103,20940124," + "20950123,20960902,20961223,20970922,20980803,20980824,20990823," + "21000103,21000124,21010123,21020924,21021203,21021224,21030902," + "21031223,21040803,21040824,21050823,21060103,21060124,21070123," + "21080902,21081223,21090922,21100803,21100824,21110823,21120103," + "21120124,21130924,21131203,21131224,21140902,21141223,21150922," + "21160823,21170103,21170124,21180123,21190924,21191203,21191224," + "21200922,21210803,21210824,21220823,..."); - } - - @MediumTest - public void testEveryThursdayinMarchEachYear() throws Exception { - runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH", "20100304", 9, "20100304,20100311,20100318,20100325,20110303,20110310,20110317,20110324,20110331", null, "20111231", UTC); - } -} diff --git a/tests/src/com/android/calendarcommon/RecurrenceProcessorTest.java b/tests/src/com/android/calendarcommon/RecurrenceProcessorTest.java deleted file mode 100644 index ba5ec0c..0000000 --- a/tests/src/com/android/calendarcommon/RecurrenceProcessorTest.java +++ /dev/null @@ -1,2537 +0,0 @@ -/* //device/content/providers/pim/RecurrenceProcessorTest.java -** -** Copyright 2006, The Android Open Source Project -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -*/ - -package com.android.calendarcommon; - -import android.os.Debug; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.text.TextUtils; -import android.text.format.Time; -import android.util.Log; -import android.util.TimeFormatException; -import junit.framework.TestCase; - -import java.util.TreeSet; - -public class RecurrenceProcessorTest extends TestCase { - private static final String TAG = "RecurrenceProcessorTest"; - private static final boolean SPEW = true; - private static final boolean METHOD_TRACE = false; - - private static String[] getFormattedDates(long[] dates, Time time) { - String[] out = new String[dates.length]; - int i = 0; - for (long date : dates) { - time.set(date); - out[i] = time.format2445(); - ++i; - } - return out; - } - - private static void printLists(String[] expected, String[] out) { - Log.i(TAG, " expected out"); - int i; - for (i = 0; i < expected.length && i < out.length; i++) { - Log.i(TAG, " [" + i + "] " + expected[i] - + " " + out[i]); - } - for (; i < expected.length; i++) { - Log.i(TAG, " [" + i + "] " + expected[i]); - } - for (; i < out.length; i++) { - Log.i(TAG, " [" + i + "] " + out[i]); - } - } - - public void verifyRecurrence(String dtstartStr, String rrule, String rdate, String exrule, - String exdate, String rangeStartStr, String rangeEndStr, String[] expected) - throws Exception { - verifyRecurrence(dtstartStr, rrule, rdate, exrule, exdate, rangeStartStr, - rangeEndStr, expected, expected[expected.length - 1]); - } - - public void verifyRecurrence(String dtstartStr, String rrule, String rdate, String exrule, - String exdate, String rangeStartStr, String rangeEndStr, String[] expected, - String last) throws Exception { - - // note that the zulu of all parameters here must be the same, expand - // doesn't work otherwise - - if (SPEW) { - Log.i(TAG, "DTSTART:" + dtstartStr - + " RRULE:" + rrule - + " RDATE:" + rdate - + " EXRULE:" + exrule - + " EXDATE:" + exdate); - } - - // we could use any timezone, incl. UTC, but we use a non-UTC - // timezone to make sure there are no UTC assumptions in the - // recurrence processing code. - String tz = "America/Los_Angeles"; - Time dtstart = new Time(tz); - Time rangeStart = new Time(tz); - Time rangeEnd = new Time(tz); - Time outCal = new Time(tz); - - dtstart.parse(dtstartStr); - - rangeStart.parse(rangeStartStr); - rangeEnd.parse(rangeEndStr); - - if (METHOD_TRACE) { - String fn = "/tmp/trace/" + this.getClass().getName().replace('$', '_'); - String df = fn + ".data"; - String kf = fn + ".key"; - Debug.startMethodTracing(fn, 8 * 1024 * 1024); - } - - RecurrenceProcessor rp = new RecurrenceProcessor(); - RecurrenceSet recur = new RecurrenceSet(rrule, rdate, exrule, exdate); - - long[] out = rp.expand(dtstart, recur, rangeStart.toMillis(false /* use isDst */), - rangeEnd.toMillis(false /* use isDst */)); - - if (METHOD_TRACE) { - Debug.stopMethodTracing(); - } - - int count = out.length; - String[] actual = getFormattedDates(out, outCal); - - if (count != expected.length) { - if (SPEW) { - Log.i(TAG, "DTSTART:" + dtstartStr + " RRULE:" + rrule); - printLists(expected, actual); - } - throw new RuntimeException("result lengths don't match. " - + " expected=" + expected.length - + " actual=" + count); - } - - for (int i = 0; i < count; i++) { - String s = actual[i]; - if (!s.equals(expected[i])) { - if (SPEW) { - Log.i(TAG, "DTSTART:" + dtstartStr + " RRULE:" + rrule); - printLists(expected, actual); - Log.i(TAG, "i=" + i); - } - throw new RuntimeException("expected[" + i + "]=" - + expected[i] + " actual=" + actual[i]); - } - } - - long lastOccur = rp.getLastOccurence(dtstart, rangeEnd, recur); - if (lastOccur == 0 && out.length == 0) { - // No occurrence found and 0 returned for lastOccur, this is ok. - return; - } - long lastMillis = -1; - long expectedMillis = -1; - String lastStr = ""; - if (lastOccur != -1) { - outCal.set(lastOccur); - lastStr = outCal.format2445(); - lastMillis = outCal.toMillis(true /* ignore isDst */); - } - if (last != null && last.length() > 0) { - Time expectedLast = new Time(tz); - expectedLast.parse(last); - expectedMillis = expectedLast.toMillis(true /* ignore isDst */); - } - if (lastMillis != expectedMillis) { - if (SPEW) { - Log.i(TAG, "DTSTART:" + dtstartStr + " RRULE:" + rrule); - Log.i(TAG, "Expected: " + last + "; Actual: " + lastStr); - printLists(expected, actual); - } - - throw new RuntimeException("expected last occurrence date does not match." - + " expected=" + last - + " actual=" + lastStr); - } - } - - @SmallTest - public void testMonthly0() throws Exception { - verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060205T100000", - "20060305T100000", - "20060405T100000" - }); - } - - @SmallTest - public void testMonthly1() throws Exception { - verifyRecurrence("20060205T100000", "FREQ=MONTHLY;INTERVAL=2;COUNT=3", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060205T100000", - "20060405T100000", - "20060605T100000" - }); - } - - @SmallTest - public void testMonthly2() throws Exception { - // this tests wrapping the year when the interval isn't divisible - // by 12 - verifyRecurrence("20060205T100000", "FREQ=MONTHLY;INTERVAL=5;COUNT=5", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060205T100000", - "20060705T100000", - "20061205T100000", - "20070505T100000", - "20071005T100000" - }); - } - - @SmallTest - public void testMonthly3() throws Exception { - // with a simple BYDAY, spanning two months - verifyRecurrence("20060104T123456", - "FREQ=MONTHLY;UNTIL=20060201T200000Z;BYDAY=TU,WE", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060104T123456", - "20060110T123456", - "20060111T123456", - "20060117T123456", - "20060118T123456", - "20060124T123456", - "20060125T123456", - "20060131T123456" - }, - "20060201T120000"); - } - - @SmallTest - public void testMonthly4() throws Exception { - // with a BYDAY with +1 / etc., spanning two months and - // one day which isn't in the result - verifyRecurrence("20060101T123456", - "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYDAY=+1SU,+2MO,+3TU,+4WE,+5MO,+5TU,+5WE,+6TH", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060101T123456", - "20060109T123456", - "20060117T123456", - "20060125T123456", - "20060130T123456", - "20060131T123456", - "20060205T123456", - "20060213T123456", - "20060221T123456", - "20060222T123456" - }, - "20060301T120000"); - } - - @SmallTest - public void testMonthly5() throws Exception { - // with a BYDAY with -1 / etc. - verifyRecurrence("20060201T123456", - "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYDAY=-1SU,-2MO,-3TU,-4TU,-4WE,-5MO,-5TU,-5WE,-6TH", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060201T123456", - "20060207T123456", - "20060214T123456", - "20060220T123456", - "20060226T123456" - }, - "20060301T120000"); - } - - @SmallTest - public void testMonthly6() throws Exception { - // With positive BYMONTHDAYs - verifyRecurrence("20060201T123456", - "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYMONTHDAY=1,2,5,28,31", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060201T123456", - "20060202T123456", - "20060205T123456", - "20060228T123456" - }, - "20060301T120000"); - } - - @SmallTest - public void testMonthly7() throws Exception { - // With negative BYMONTHDAYs - verifyRecurrence("20060201T123456", - "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYMONTHDAY=-1,-5,-27,-28,-31", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060201T123456", - "20060202T123456", - "20060224T123456", - "20060228T123456" - }, - "20060301T120000"); - } - - @SmallTest - public void testMonthly8() throws Exception { - verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3", - "America/Los_Angeles;20060207T140000,20060307T160000,20060407T180000", - null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060205T100000", - "20060207T140000", - "20060305T100000", - "20060307T160000", - "20060405T100000", - "20060407T180000", - }); - } - - @SmallTest - public void testMonthly9() throws Exception { - verifyRecurrence("20060205T100000", null /* rrule */, - "America/Los_Angeles;20060207T140000,20060307T160000,20060407T180000", - null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060207T140000", - "20060307T160000", - "20060407T180000", - }); - } - - @SmallTest - public void testMonthly10() throws Exception { - verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3\nFREQ=WEEKLY;COUNT=2", - "America/Los_Angeles;20060207T140000,20060307T160000,20060407T180000", - null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060205T100000", - "20060207T140000", - "20060212T100000", - "20060305T100000", - "20060307T160000", - "20060405T100000", - "20060407T180000", - }); - } - - @SmallTest - public void testMonthly11() throws Exception { - verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3\nFREQ=WEEKLY;COUNT=2", - null /* rdate */, - "FREQ=MONTHLY;COUNT=2", null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060212T100000", - "20060405T100000", - }); - } - - @SmallTest - public void testMonthly12() throws Exception { - verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3\nFREQ=WEEKLY;COUNT=2", - null /* rdate */, null /* exrule */, - "20060212T180000Z,20060405T170000Z" /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060205T100000", - "20060305T100000", - }); - } - - @SmallTest - public void testMonthly13() throws Exception { - verifyRecurrence("20060101T100000", "FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13;COUNT=10", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20101231T000000", - new String[]{ - "20060101T100000", - "20060113T100000", - "20061013T100000", - "20070413T100000", - "20070713T100000", - "20080613T100000", - "20090213T100000", - "20090313T100000", - "20091113T100000", - "20100813T100000", - }); - } - - @SmallTest - public void testMonthly14() throws Exception { - verifyRecurrence("20110103T100000", "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1", - null /* rdate */, null /* exrule */, null /* exdate */, - "20110101T000000", "20110331T235959", - new String[]{ - "20110103T100000", - "20110131T100000", - "20110201T100000", - "20110228T100000", - "20110301T100000", - "20110331T100000", - }); - } - - @SmallTest - public void testMonthly15() throws Exception { - verifyRecurrence("20110703T100000", "FREQ=MONTHLY;BYDAY=SA,SU;BYSETPOS=2,-2", - null /* rdate */, null /* exrule */, null /* exdate */, - "20110701T000000", "20110931T235959", - new String[]{ - "20110703T100000", - "20110730T100000", - "20110807T100000", - "20110827T100000", - "20110904T100000", - "20110924T100000", - }); - } - - @SmallTest - public void testWeekly0() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;COUNT=3", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060222T100000", - "20060301T100000" - }); - } - - @SmallTest - public void testWeekly1() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060301T100000Z", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060222T100000" - }, "20060301T020000"); - } - - @SmallTest - public void testWeekly2() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060301T100001Z", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060222T100000" - }, "20060301T020001"); - } - - @SmallTest - public void testWeekly3() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060301T090000Z", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060222T100000" - }, "20060301T010000"); - } - - @SmallTest - public void testWeekly4() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060311T100001Z;BYDAY=TU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060221T100000", - "20060228T100000", - "20060307T100000" - }, "20060311T020001"); - } - - // until without "Z" - @SmallTest - public void testWeekly4a() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060311T100001;BYDAY=TU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060221T100000", - "20060228T100000", - "20060307T100000" - }, "20060311T100001"); - } - - @SmallTest - public void testWeekly5() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060311T100001Z;BYDAY=TH", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060216T100000", - "20060223T100000", - "20060302T100000", - "20060309T100000" - }, "20060311T020001"); - } - - @SmallTest - public void testWeekly6() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060309T100001Z;BYDAY=WE,TH", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060216T100000", - "20060222T100000", - "20060223T100000", - "20060301T100000", - "20060302T100000", - "20060308T100000" - }, "20060309T020001"); - } - - @SmallTest - public void testWeekly7() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060220T100001Z;BYDAY=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060219T100000" - }, "20060220T020001"); - } - - @SmallTest - public void testWeekly8() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;COUNT=4;WKST=SU;BYDAY=TU,TH", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060216T100000", - "20060221T100000", - "20060223T100000" - }); - } - - @SmallTest - public void testWeekly9() throws Exception { - verifyRecurrence("19970805T100000", - "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU", // uses default WKST=MO - null /* rdate */, null /* exrule */, null /* exdate */, - "19970101T000000", "19980101T000000", - new String[]{ - "19970805T100000", - "19970810T100000", - "19970819T100000", - "19970824T100000", - }); - } - - @SmallTest - public void testWeekly10() throws Exception { - verifyRecurrence("19970805T100000", - "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "19970101T000000", "19980101T000000", - new String[]{ - "19970805T100000", - "19970817T100000", - "19970819T100000", - "19970831T100000", - }); - } - - // BUG 1658567: UNTIL=date - @SmallTest - public void testWeekly11() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060220;BYDAY=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060219T100000" - }, "20060220T000000"); - } - - @SmallTest - public void testWeekly12() throws Exception { - try { - verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=junk;BYDAY=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060219T100000" - }, "20060220T020001"); - fail("Bad UNTIL string failed to throw exception"); - } catch (TimeFormatException e) { - // expected - } - } - - /** - * Test repeating weekly event with dtstart and dtend (only one occurrence) - * See bug #3267616 - * @throws Exception - */ - @SmallTest - public void testWeekly13() throws Exception { - verifyRecurrence("20101117T150000", - "FREQ=WEEKLY;BYDAY=WE", - null /* rdate */, null /* exrule */, null /* exdate */, - "20101117T150000", "20101117T160000", - new String[]{ "20101117T150000" }); - } - - @SmallTest - public void testWeekly14() throws Exception { - verifyRecurrence("19970805T100000", - "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=TH", - null /* rdate */, null /* exrule */, null /* exdate */, - "19970101T000000", "19980101T000000", - new String[]{ - "19970805T100000", - "19970817T100000", - "19970819T100000", - "19970831T100000", - }); - } - - @SmallTest - public void testDaily0() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=DAILY;COUNT=3", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060216T100000", - "20060217T100000" - }); - } - - @SmallTest - public void testDaily1() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=DAILY;UNTIL=20060302T100001Z", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060216T100000", - "20060217T100000", - "20060218T100000", - "20060219T100000", - "20060220T100000", - "20060221T100000", - "20060222T100000", - "20060223T100000", - "20060224T100000", - "20060225T100000", - "20060226T100000", - "20060227T100000", - "20060228T100000", - "20060301T100000" - }, "20060302T100001Z"); - } - - @SmallTest - public void testDaily2() throws Exception { - verifyRecurrence("20060215T100000", "FREQ=DAILY;UNTIL=20060220T100001Z;BYDAY=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060215T100000", - "20060219T100000" - }, "20060220T020001"); - } - - @SmallTest - public void testDaily3() throws Exception { - verifyRecurrence("20060219T100000", - "FREQ=DAILY;UNTIL=20060225T180304Z;BYDAY=SU,MO,SA;BYHOUR=5,10,22;BYMINUTE=3,59;BYSECOND=2,5", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20080101T000000", - new String[]{ - "20060219T100000", - "20060219T100302", - "20060219T100305", - "20060219T105902", - "20060219T105905", - "20060219T220302", - "20060219T220305", - "20060219T225902", - "20060219T225905", - "20060220T050302", - "20060220T050305", - "20060220T055902", - "20060220T055905", - "20060220T100302", - "20060220T100305", - "20060220T105902", - "20060220T105905", - "20060220T220302", - "20060220T220305", - "20060220T225902", - "20060220T225905", - "20060225T050302", - "20060225T050305", - "20060225T055902", - "20060225T055905", - "20060225T100302" - }, "20060225T100304"); - } - - @MediumTest - public void testFromGoogleCalendar0() throws Exception { - // Tuesday, Thursday (10/2) - verifyRecurrence("20061002T050000", - "FREQ=WEEKLY;UNTIL=20071031T200000Z;INTERVAL=1;BYDAY=TU,TH;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061002T050000", - "20061003T050000", - "20061005T050000", - "20061010T050000", - "20061012T050000", - "20061017T050000", - "20061019T050000", - "20061024T050000", - "20061026T050000", - "20061031T050000", - "20061102T050000", - "20061107T050000", - "20061109T050000", - "20061114T050000", - "20061116T050000", - "20061121T050000", - "20061123T050000", - "20061128T050000", - "20061130T050000", - "20061205T050000", - "20061207T050000", - "20061212T050000", - "20061214T050000", - "20061219T050000", - "20061221T050000", - "20061226T050000", - "20061228T050000", - "20070102T050000", - "20070104T050000", - "20070109T050000", - "20070111T050000", - "20070116T050000", - "20070118T050000", - "20070123T050000", - "20070125T050000", - "20070130T050000", - "20070201T050000", - "20070206T050000", - "20070208T050000", - "20070213T050000", - "20070215T050000", - "20070220T050000", - "20070222T050000", - "20070227T050000", - "20070301T050000", - "20070306T050000", - "20070308T050000", - "20070313T050000", - "20070315T050000", - "20070320T050000", - "20070322T050000", - "20070327T050000", - "20070329T050000", - "20070403T050000", - "20070405T050000", - "20070410T050000", - "20070412T050000", - "20070417T050000", - "20070419T050000", - "20070424T050000", - "20070426T050000", - "20070501T050000", - "20070503T050000", - "20070508T050000", - "20070510T050000", - "20070515T050000", - "20070517T050000", - "20070522T050000", - "20070524T050000", - "20070529T050000", - "20070531T050000", - "20070605T050000", - "20070607T050000", - "20070612T050000", - "20070614T050000", - "20070619T050000", - "20070621T050000", - "20070626T050000", - "20070628T050000", - "20070703T050000", - "20070705T050000", - "20070710T050000", - "20070712T050000", - "20070717T050000", - "20070719T050000", - "20070724T050000", - "20070726T050000", - "20070731T050000", - "20070802T050000", - "20070807T050000", - "20070809T050000", - "20070814T050000", - "20070816T050000", - "20070821T050000", - "20070823T050000", - "20070828T050000", - "20070830T050000", - "20070904T050000", - "20070906T050000", - "20070911T050000", - "20070913T050000", - "20070918T050000", - "20070920T050000", - "20070925T050000", - "20070927T050000", - "20071002T050000", - "20071004T050000", - "20071009T050000", - "20071011T050000", - "20071016T050000", - "20071018T050000", - "20071023T050000", - "20071025T050000", - "20071030T050000", - }, "20071031T130000"); - } - - @MediumTest - public void testFromGoogleCalendar1() throws Exception { - // Mon Wed Fri - verifyRecurrence("20061002T030000", - "FREQ=WEEKLY;UNTIL=20071025T180000Z;INTERVAL=1;BYDAY=MO,WE,FR;", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061002T030000", - "20061004T030000", - "20061006T030000", - "20061009T030000", - "20061011T030000", - "20061013T030000", - "20061016T030000", - "20061018T030000", - "20061020T030000", - "20061023T030000", - "20061025T030000", - "20061027T030000", - "20061030T030000", - "20061101T030000", - "20061103T030000", - "20061106T030000", - "20061108T030000", - "20061110T030000", - "20061113T030000", - "20061115T030000", - "20061117T030000", - "20061120T030000", - "20061122T030000", - "20061124T030000", - "20061127T030000", - "20061129T030000", - "20061201T030000", - "20061204T030000", - "20061206T030000", - "20061208T030000", - "20061211T030000", - "20061213T030000", - "20061215T030000", - "20061218T030000", - "20061220T030000", - "20061222T030000", - "20061225T030000", - "20061227T030000", - "20061229T030000", - "20070101T030000", - "20070103T030000", - "20070105T030000", - "20070108T030000", - "20070110T030000", - "20070112T030000", - "20070115T030000", - "20070117T030000", - "20070119T030000", - "20070122T030000", - "20070124T030000", - "20070126T030000", - "20070129T030000", - "20070131T030000", - "20070202T030000", - "20070205T030000", - "20070207T030000", - "20070209T030000", - "20070212T030000", - "20070214T030000", - "20070216T030000", - "20070219T030000", - "20070221T030000", - "20070223T030000", - "20070226T030000", - "20070228T030000", - "20070302T030000", - "20070305T030000", - "20070307T030000", - "20070309T030000", - "20070312T030000", - "20070314T030000", - "20070316T030000", - "20070319T030000", - "20070321T030000", - "20070323T030000", - "20070326T030000", - "20070328T030000", - "20070330T030000", - "20070402T030000", - "20070404T030000", - "20070406T030000", - "20070409T030000", - "20070411T030000", - "20070413T030000", - "20070416T030000", - "20070418T030000", - "20070420T030000", - "20070423T030000", - "20070425T030000", - "20070427T030000", - "20070430T030000", - "20070502T030000", - "20070504T030000", - "20070507T030000", - "20070509T030000", - "20070511T030000", - "20070514T030000", - "20070516T030000", - "20070518T030000", - "20070521T030000", - "20070523T030000", - "20070525T030000", - "20070528T030000", - "20070530T030000", - "20070601T030000", - "20070604T030000", - "20070606T030000", - "20070608T030000", - "20070611T030000", - "20070613T030000", - "20070615T030000", - "20070618T030000", - "20070620T030000", - "20070622T030000", - "20070625T030000", - "20070627T030000", - "20070629T030000", - "20070702T030000", - "20070704T030000", - "20070706T030000", - "20070709T030000", - "20070711T030000", - "20070713T030000", - "20070716T030000", - "20070718T030000", - "20070720T030000", - "20070723T030000", - "20070725T030000", - "20070727T030000", - "20070730T030000", - "20070801T030000", - "20070803T030000", - "20070806T030000", - "20070808T030000", - "20070810T030000", - "20070813T030000", - "20070815T030000", - "20070817T030000", - "20070820T030000", - "20070822T030000", - "20070824T030000", - "20070827T030000", - "20070829T030000", - "20070831T030000", - "20070903T030000", - "20070905T030000", - "20070907T030000", - "20070910T030000", - "20070912T030000", - "20070914T030000", - "20070917T030000", - "20070919T030000", - "20070921T030000", - "20070924T030000", - "20070926T030000", - "20070928T030000", - "20071001T030000", - "20071003T030000", - "20071005T030000", - "20071008T030000", - "20071010T030000", - "20071012T030000", - "20071015T030000", - "20071017T030000", - "20071019T030000", - "20071022T030000", - "20071024T030000", - }, "20071025T110000"); - } - - @SmallTest - public void testFromGoogleCalendar2() throws Exception { - // Monthly on day 2 - verifyRecurrence("20061002T070000", - "FREQ=MONTHLY;INTERVAL=1;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061002T070000", - "20061102T070000", - "20061202T070000", - "20070102T070000", - "20070202T070000", - "20070302T070000", - "20070402T070000", - "20070502T070000", - "20070602T070000", - "20070702T070000", - "20070802T070000", - "20070902T070000", - "20071002T070000", - "20071102T070000", - "20071202T070000", - "20080102T070000", - "20080202T070000", - "20080302T070000", - "20080402T070000", - "20080502T070000", - "20080602T070000", - "20080702T070000", - "20080802T070000", - "20080902T070000", - "20081002T070000", - "20081102T070000", - "20081202T070000", - }, "20081202T070000"); - } - - @MediumTest - public void testFromGoogleCalendar3() throws Exception { - // Every Weekday - verifyRecurrence("20061002T100000", - "FREQ=WEEKLY;UNTIL=20070215T100000Z;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061002T100000", - "20061003T100000", - "20061004T100000", - "20061005T100000", - "20061006T100000", - "20061009T100000", - "20061010T100000", - "20061011T100000", - "20061012T100000", - "20061013T100000", - "20061016T100000", - "20061017T100000", - "20061018T100000", - "20061019T100000", - "20061020T100000", - "20061023T100000", - "20061024T100000", - "20061025T100000", - "20061026T100000", - "20061027T100000", - "20061030T100000", - "20061031T100000", - "20061101T100000", - "20061102T100000", - "20061103T100000", - "20061106T100000", - "20061107T100000", - "20061108T100000", - "20061109T100000", - "20061110T100000", - "20061113T100000", - "20061114T100000", - "20061115T100000", - "20061116T100000", - "20061117T100000", - "20061120T100000", - "20061121T100000", - "20061122T100000", - "20061123T100000", - "20061124T100000", - "20061127T100000", - "20061128T100000", - "20061129T100000", - "20061130T100000", - "20061201T100000", - "20061204T100000", - "20061205T100000", - "20061206T100000", - "20061207T100000", - "20061208T100000", - "20061211T100000", - "20061212T100000", - "20061213T100000", - "20061214T100000", - "20061215T100000", - "20061218T100000", - "20061219T100000", - "20061220T100000", - "20061221T100000", - "20061222T100000", - "20061225T100000", - "20061226T100000", - "20061227T100000", - "20061228T100000", - "20061229T100000", - "20070101T100000", - "20070102T100000", - "20070103T100000", - "20070104T100000", - "20070105T100000", - "20070108T100000", - "20070109T100000", - "20070110T100000", - "20070111T100000", - "20070112T100000", - "20070115T100000", - "20070116T100000", - "20070117T100000", - "20070118T100000", - "20070119T100000", - "20070122T100000", - "20070123T100000", - "20070124T100000", - "20070125T100000", - "20070126T100000", - "20070129T100000", - "20070130T100000", - "20070131T100000", - "20070201T100000", - "20070202T100000", - "20070205T100000", - "20070206T100000", - "20070207T100000", - "20070208T100000", - "20070209T100000", - "20070212T100000", - "20070213T100000", - "20070214T100000", - }, "20070215T020000"); - } - - @SmallTest - public void testFromGoogleCalendar4() throws Exception { - // Every 5 months on day 2 - verifyRecurrence("20061003T100000", - "FREQ=MONTHLY;INTERVAL=5;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061003T100000", - "20070303T100000", - "20070803T100000", - "20080103T100000", - "20080603T100000", - "20081103T100000", - }, "20081103T100000"); - } - - @MediumTest - public void testFromGoogleCalendar5() throws Exception { - // Tuesday, Thursday (10/3) - verifyRecurrence("20061003T040000", - "FREQ=WEEKLY;INTERVAL=1;BYDAY=TU,TH;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061003T040000", - "20061005T040000", - "20061010T040000", - "20061012T040000", - "20061017T040000", - "20061019T040000", - "20061024T040000", - "20061026T040000", - "20061031T040000", - "20061102T040000", - "20061107T040000", - "20061109T040000", - "20061114T040000", - "20061116T040000", - "20061121T040000", - "20061123T040000", - "20061128T040000", - "20061130T040000", - "20061205T040000", - "20061207T040000", - "20061212T040000", - "20061214T040000", - "20061219T040000", - "20061221T040000", - "20061226T040000", - "20061228T040000", - "20070102T040000", - "20070104T040000", - "20070109T040000", - "20070111T040000", - "20070116T040000", - "20070118T040000", - "20070123T040000", - "20070125T040000", - "20070130T040000", - "20070201T040000", - "20070206T040000", - "20070208T040000", - "20070213T040000", - "20070215T040000", - "20070220T040000", - "20070222T040000", - "20070227T040000", - "20070301T040000", - "20070306T040000", - "20070308T040000", - "20070313T040000", - "20070315T040000", - "20070320T040000", - "20070322T040000", - "20070327T040000", - "20070329T040000", - "20070403T040000", - "20070405T040000", - "20070410T040000", - "20070412T040000", - "20070417T040000", - "20070419T040000", - "20070424T040000", - "20070426T040000", - "20070501T040000", - "20070503T040000", - "20070508T040000", - "20070510T040000", - "20070515T040000", - "20070517T040000", - "20070522T040000", - "20070524T040000", - "20070529T040000", - "20070531T040000", - "20070605T040000", - "20070607T040000", - "20070612T040000", - "20070614T040000", - "20070619T040000", - "20070621T040000", - "20070626T040000", - "20070628T040000", - "20070703T040000", - "20070705T040000", - "20070710T040000", - "20070712T040000", - "20070717T040000", - "20070719T040000", - "20070724T040000", - "20070726T040000", - "20070731T040000", - "20070802T040000", - "20070807T040000", - "20070809T040000", - "20070814T040000", - "20070816T040000", - "20070821T040000", - "20070823T040000", - "20070828T040000", - "20070830T040000", - "20070904T040000", - "20070906T040000", - "20070911T040000", - "20070913T040000", - "20070918T040000", - "20070920T040000", - "20070925T040000", - "20070927T040000", - "20071002T040000", - "20071004T040000", - "20071009T040000", - "20071011T040000", - "20071016T040000", - "20071018T040000", - "20071023T040000", - "20071025T040000", - "20071030T040000", - "20071101T040000", - "20071106T040000", - "20071108T040000", - "20071113T040000", - "20071115T040000", - "20071120T040000", - "20071122T040000", - "20071127T040000", - "20071129T040000", - "20071204T040000", - "20071206T040000", - "20071211T040000", - "20071213T040000", - "20071218T040000", - "20071220T040000", - "20071225T040000", - "20071227T040000", - "20080101T040000", - "20080103T040000", - "20080108T040000", - "20080110T040000", - "20080115T040000", - "20080117T040000", - "20080122T040000", - "20080124T040000", - "20080129T040000", - "20080131T040000", - "20080205T040000", - "20080207T040000", - "20080212T040000", - "20080214T040000", - "20080219T040000", - "20080221T040000", - "20080226T040000", - "20080228T040000", - "20080304T040000", - "20080306T040000", - "20080311T040000", - "20080313T040000", - "20080318T040000", - "20080320T040000", - "20080325T040000", - "20080327T040000", - "20080401T040000", - "20080403T040000", - "20080408T040000", - "20080410T040000", - "20080415T040000", - "20080417T040000", - "20080422T040000", - "20080424T040000", - "20080429T040000", - "20080501T040000", - "20080506T040000", - "20080508T040000", - "20080513T040000", - "20080515T040000", - "20080520T040000", - "20080522T040000", - "20080527T040000", - "20080529T040000", - "20080603T040000", - "20080605T040000", - "20080610T040000", - "20080612T040000", - "20080617T040000", - "20080619T040000", - "20080624T040000", - "20080626T040000", - "20080701T040000", - "20080703T040000", - "20080708T040000", - "20080710T040000", - "20080715T040000", - "20080717T040000", - "20080722T040000", - "20080724T040000", - "20080729T040000", - "20080731T040000", - "20080805T040000", - "20080807T040000", - "20080812T040000", - "20080814T040000", - "20080819T040000", - "20080821T040000", - "20080826T040000", - "20080828T040000", - "20080902T040000", - "20080904T040000", - "20080909T040000", - "20080911T040000", - "20080916T040000", - "20080918T040000", - "20080923T040000", - "20080925T040000", - "20080930T040000", - "20081002T040000", - "20081007T040000", - "20081009T040000", - "20081014T040000", - "20081016T040000", - "20081021T040000", - "20081023T040000", - "20081028T040000", - "20081030T040000", - "20081104T040000", - "20081106T040000", - "20081111T040000", - "20081113T040000", - "20081118T040000", - "20081120T040000", - "20081125T040000", - "20081127T040000", - "20081202T040000", - "20081204T040000", - "20081209T040000", - "20081211T040000", - "20081216T040000", - "20081218T040000", - "20081223T040000", - "20081225T040000", - "20081230T040000", - }, "20081230T040000"); - } - - @MediumTest - public void testFromGoogleCalendar6() throws Exception { - // Weekly on all days - verifyRecurrence("20061003T060000", - "FREQ=WEEKLY;INTERVAL=1;BYDAY=SU,MO,TU,WE,TH,FR,SA;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20071003T060000", - new String[]{ - "20061003T060000", - "20061004T060000", - "20061005T060000", - "20061006T060000", - "20061007T060000", - "20061008T060000", - "20061009T060000", - "20061010T060000", - "20061011T060000", - "20061012T060000", - "20061013T060000", - "20061014T060000", - "20061015T060000", - "20061016T060000", - "20061017T060000", - "20061018T060000", - "20061019T060000", - "20061020T060000", - "20061021T060000", - "20061022T060000", - "20061023T060000", - "20061024T060000", - "20061025T060000", - "20061026T060000", - "20061027T060000", - "20061028T060000", - "20061029T060000", - "20061030T060000", - "20061031T060000", - "20061101T060000", - "20061102T060000", - "20061103T060000", - "20061104T060000", - "20061105T060000", - "20061106T060000", - "20061107T060000", - "20061108T060000", - "20061109T060000", - "20061110T060000", - "20061111T060000", - "20061112T060000", - "20061113T060000", - "20061114T060000", - "20061115T060000", - "20061116T060000", - "20061117T060000", - "20061118T060000", - "20061119T060000", - "20061120T060000", - "20061121T060000", - "20061122T060000", - "20061123T060000", - "20061124T060000", - "20061125T060000", - "20061126T060000", - "20061127T060000", - "20061128T060000", - "20061129T060000", - "20061130T060000", - "20061201T060000", - "20061202T060000", - "20061203T060000", - "20061204T060000", - "20061205T060000", - "20061206T060000", - "20061207T060000", - "20061208T060000", - "20061209T060000", - "20061210T060000", - "20061211T060000", - "20061212T060000", - "20061213T060000", - "20061214T060000", - "20061215T060000", - "20061216T060000", - "20061217T060000", - "20061218T060000", - "20061219T060000", - "20061220T060000", - "20061221T060000", - "20061222T060000", - "20061223T060000", - "20061224T060000", - "20061225T060000", - "20061226T060000", - "20061227T060000", - "20061228T060000", - "20061229T060000", - "20061230T060000", - "20061231T060000", - "20070101T060000", - "20070102T060000", - "20070103T060000", - "20070104T060000", - "20070105T060000", - "20070106T060000", - "20070107T060000", - "20070108T060000", - "20070109T060000", - "20070110T060000", - "20070111T060000", - "20070112T060000", - "20070113T060000", - "20070114T060000", - "20070115T060000", - "20070116T060000", - "20070117T060000", - "20070118T060000", - "20070119T060000", - "20070120T060000", - "20070121T060000", - "20070122T060000", - "20070123T060000", - "20070124T060000", - "20070125T060000", - "20070126T060000", - "20070127T060000", - "20070128T060000", - "20070129T060000", - "20070130T060000", - "20070131T060000", - "20070201T060000", - "20070202T060000", - "20070203T060000", - "20070204T060000", - "20070205T060000", - "20070206T060000", - "20070207T060000", - "20070208T060000", - "20070209T060000", - "20070210T060000", - "20070211T060000", - "20070212T060000", - "20070213T060000", - "20070214T060000", - "20070215T060000", - "20070216T060000", - "20070217T060000", - "20070218T060000", - "20070219T060000", - "20070220T060000", - "20070221T060000", - "20070222T060000", - "20070223T060000", - "20070224T060000", - "20070225T060000", - "20070226T060000", - "20070227T060000", - "20070228T060000", - "20070301T060000", - "20070302T060000", - "20070303T060000", - "20070304T060000", - "20070305T060000", - "20070306T060000", - "20070307T060000", - "20070308T060000", - "20070309T060000", - "20070310T060000", - "20070311T060000", - "20070312T060000", - "20070313T060000", - "20070314T060000", - "20070315T060000", - "20070316T060000", - "20070317T060000", - "20070318T060000", - "20070319T060000", - "20070320T060000", - "20070321T060000", - "20070322T060000", - "20070323T060000", - "20070324T060000", - "20070325T060000", - "20070326T060000", - "20070327T060000", - "20070328T060000", - "20070329T060000", - "20070330T060000", - "20070331T060000", - "20070401T060000", - "20070402T060000", - "20070403T060000", - "20070404T060000", - "20070405T060000", - "20070406T060000", - "20070407T060000", - "20070408T060000", - "20070409T060000", - "20070410T060000", - "20070411T060000", - "20070412T060000", - "20070413T060000", - "20070414T060000", - "20070415T060000", - "20070416T060000", - "20070417T060000", - "20070418T060000", - "20070419T060000", - "20070420T060000", - "20070421T060000", - "20070422T060000", - "20070423T060000", - "20070424T060000", - "20070425T060000", - "20070426T060000", - "20070427T060000", - "20070428T060000", - "20070429T060000", - "20070430T060000", - "20070501T060000", - "20070502T060000", - "20070503T060000", - "20070504T060000", - "20070505T060000", - "20070506T060000", - "20070507T060000", - "20070508T060000", - "20070509T060000", - "20070510T060000", - "20070511T060000", - "20070512T060000", - "20070513T060000", - "20070514T060000", - "20070515T060000", - "20070516T060000", - "20070517T060000", - "20070518T060000", - "20070519T060000", - "20070520T060000", - "20070521T060000", - "20070522T060000", - "20070523T060000", - "20070524T060000", - "20070525T060000", - "20070526T060000", - "20070527T060000", - "20070528T060000", - "20070529T060000", - "20070530T060000", - "20070531T060000", - "20070601T060000", - "20070602T060000", - "20070603T060000", - "20070604T060000", - "20070605T060000", - "20070606T060000", - "20070607T060000", - "20070608T060000", - "20070609T060000", - "20070610T060000", - "20070611T060000", - "20070612T060000", - "20070613T060000", - "20070614T060000", - "20070615T060000", - "20070616T060000", - "20070617T060000", - "20070618T060000", - "20070619T060000", - "20070620T060000", - "20070621T060000", - "20070622T060000", - "20070623T060000", - "20070624T060000", - "20070625T060000", - "20070626T060000", - "20070627T060000", - "20070628T060000", - "20070629T060000", - "20070630T060000", - "20070701T060000", - "20070702T060000", - "20070703T060000", - "20070704T060000", - "20070705T060000", - "20070706T060000", - "20070707T060000", - "20070708T060000", - "20070709T060000", - "20070710T060000", - "20070711T060000", - "20070712T060000", - "20070713T060000", - "20070714T060000", - "20070715T060000", - "20070716T060000", - "20070717T060000", - "20070718T060000", - "20070719T060000", - "20070720T060000", - "20070721T060000", - "20070722T060000", - "20070723T060000", - "20070724T060000", - "20070725T060000", - "20070726T060000", - "20070727T060000", - "20070728T060000", - "20070729T060000", - "20070730T060000", - "20070731T060000", - "20070801T060000", - "20070802T060000", - "20070803T060000", - "20070804T060000", - "20070805T060000", - "20070806T060000", - "20070807T060000", - "20070808T060000", - "20070809T060000", - "20070810T060000", - "20070811T060000", - "20070812T060000", - "20070813T060000", - "20070814T060000", - "20070815T060000", - "20070816T060000", - "20070817T060000", - "20070818T060000", - "20070819T060000", - "20070820T060000", - "20070821T060000", - "20070822T060000", - "20070823T060000", - "20070824T060000", - "20070825T060000", - "20070826T060000", - "20070827T060000", - "20070828T060000", - "20070829T060000", - "20070830T060000", - "20070831T060000", - "20070901T060000", - "20070902T060000", - "20070903T060000", - "20070904T060000", - "20070905T060000", - "20070906T060000", - "20070907T060000", - "20070908T060000", - "20070909T060000", - "20070910T060000", - "20070911T060000", - "20070912T060000", - "20070913T060000", - "20070914T060000", - "20070915T060000", - "20070916T060000", - "20070917T060000", - "20070918T060000", - "20070919T060000", - "20070920T060000", - "20070921T060000", - "20070922T060000", - "20070923T060000", - "20070924T060000", - "20070925T060000", - "20070926T060000", - "20070927T060000", - "20070928T060000", - "20070929T060000", - "20070930T060000", - "20071001T060000", - "20071002T060000", - }, "20071002T060000"); - } - - @MediumTest - public void testFromGoogleCalendar7() throws Exception { - // Every 3 days - verifyRecurrence("20061003T080000", - "FREQ=DAILY;INTERVAL=3;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061003T080000", - "20061006T080000", - "20061009T080000", - "20061012T080000", - "20061015T080000", - "20061018T080000", - "20061021T080000", - "20061024T080000", - "20061027T080000", - "20061030T080000", - "20061102T080000", - "20061105T080000", - "20061108T080000", - "20061111T080000", - "20061114T080000", - "20061117T080000", - "20061120T080000", - "20061123T080000", - "20061126T080000", - "20061129T080000", - "20061202T080000", - "20061205T080000", - "20061208T080000", - "20061211T080000", - "20061214T080000", - "20061217T080000", - "20061220T080000", - "20061223T080000", - "20061226T080000", - "20061229T080000", - "20070101T080000", - "20070104T080000", - "20070107T080000", - "20070110T080000", - "20070113T080000", - "20070116T080000", - "20070119T080000", - "20070122T080000", - "20070125T080000", - "20070128T080000", - "20070131T080000", - "20070203T080000", - "20070206T080000", - "20070209T080000", - "20070212T080000", - "20070215T080000", - "20070218T080000", - "20070221T080000", - "20070224T080000", - "20070227T080000", - "20070302T080000", - "20070305T080000", - "20070308T080000", - "20070311T080000", - "20070314T080000", - "20070317T080000", - "20070320T080000", - "20070323T080000", - "20070326T080000", - "20070329T080000", - "20070401T080000", - "20070404T080000", - "20070407T080000", - "20070410T080000", - "20070413T080000", - "20070416T080000", - "20070419T080000", - "20070422T080000", - "20070425T080000", - "20070428T080000", - "20070501T080000", - "20070504T080000", - "20070507T080000", - "20070510T080000", - "20070513T080000", - "20070516T080000", - "20070519T080000", - "20070522T080000", - "20070525T080000", - "20070528T080000", - "20070531T080000", - "20070603T080000", - "20070606T080000", - "20070609T080000", - "20070612T080000", - "20070615T080000", - "20070618T080000", - "20070621T080000", - "20070624T080000", - "20070627T080000", - "20070630T080000", - "20070703T080000", - "20070706T080000", - "20070709T080000", - "20070712T080000", - "20070715T080000", - "20070718T080000", - "20070721T080000", - "20070724T080000", - "20070727T080000", - "20070730T080000", - "20070802T080000", - "20070805T080000", - "20070808T080000", - "20070811T080000", - "20070814T080000", - "20070817T080000", - "20070820T080000", - "20070823T080000", - "20070826T080000", - "20070829T080000", - "20070901T080000", - "20070904T080000", - "20070907T080000", - "20070910T080000", - "20070913T080000", - "20070916T080000", - "20070919T080000", - "20070922T080000", - "20070925T080000", - "20070928T080000", - "20071001T080000", - "20071004T080000", - "20071007T080000", - "20071010T080000", - "20071013T080000", - "20071016T080000", - "20071019T080000", - "20071022T080000", - "20071025T080000", - "20071028T080000", - "20071031T080000", - "20071103T080000", - "20071106T080000", - "20071109T080000", - "20071112T080000", - "20071115T080000", - "20071118T080000", - "20071121T080000", - "20071124T080000", - "20071127T080000", - "20071130T080000", - "20071203T080000", - "20071206T080000", - "20071209T080000", - "20071212T080000", - "20071215T080000", - "20071218T080000", - "20071221T080000", - "20071224T080000", - "20071227T080000", - "20071230T080000", - "20080102T080000", - "20080105T080000", - "20080108T080000", - "20080111T080000", - "20080114T080000", - "20080117T080000", - "20080120T080000", - "20080123T080000", - "20080126T080000", - "20080129T080000", - "20080201T080000", - "20080204T080000", - "20080207T080000", - "20080210T080000", - "20080213T080000", - "20080216T080000", - "20080219T080000", - "20080222T080000", - "20080225T080000", - "20080228T080000", - "20080302T080000", - "20080305T080000", - "20080308T080000", - "20080311T080000", - "20080314T080000", - "20080317T080000", - "20080320T080000", - "20080323T080000", - "20080326T080000", - "20080329T080000", - "20080401T080000", - "20080404T080000", - "20080407T080000", - "20080410T080000", - "20080413T080000", - "20080416T080000", - "20080419T080000", - "20080422T080000", - "20080425T080000", - "20080428T080000", - "20080501T080000", - "20080504T080000", - "20080507T080000", - "20080510T080000", - "20080513T080000", - "20080516T080000", - "20080519T080000", - "20080522T080000", - "20080525T080000", - "20080528T080000", - "20080531T080000", - "20080603T080000", - "20080606T080000", - "20080609T080000", - "20080612T080000", - "20080615T080000", - "20080618T080000", - "20080621T080000", - "20080624T080000", - "20080627T080000", - "20080630T080000", - "20080703T080000", - "20080706T080000", - "20080709T080000", - "20080712T080000", - "20080715T080000", - "20080718T080000", - "20080721T080000", - "20080724T080000", - "20080727T080000", - "20080730T080000", - "20080802T080000", - "20080805T080000", - "20080808T080000", - "20080811T080000", - "20080814T080000", - "20080817T080000", - "20080820T080000", - "20080823T080000", - "20080826T080000", - "20080829T080000", - "20080901T080000", - "20080904T080000", - "20080907T080000", - "20080910T080000", - "20080913T080000", - "20080916T080000", - "20080919T080000", - "20080922T080000", - "20080925T080000", - "20080928T080000", - "20081001T080000", - "20081004T080000", - "20081007T080000", - "20081010T080000", - "20081013T080000", - "20081016T080000", - "20081019T080000", - "20081022T080000", - "20081025T080000", - "20081028T080000", - "20081031T080000", - "20081103T080000", - "20081106T080000", - "20081109T080000", - "20081112T080000", - "20081115T080000", - "20081118T080000", - "20081121T080000", - "20081124T080000", - "20081127T080000", - "20081130T080000", - "20081203T080000", - "20081206T080000", - "20081209T080000", - "20081212T080000", - "20081215T080000", - "20081218T080000", - "20081221T080000", - "20081224T080000", - "20081227T080000", - "20081230T080000", - }, "20081230T080000"); - } - - @SmallTest - public void testFromGoogleCalendar8() throws Exception { - // Annually on October 4 - verifyRecurrence("20061004T130000", - "FREQ=YEARLY;INTERVAL=1;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061004T130000", - "20071004T130000", - "20081004T130000", - }, "20081004T130000"); - } - - @MediumTest - public void testFromGoogleCalendar9() throws Exception { - // Monthly on the last Monday - verifyRecurrence("20061030T170000", - "FREQ=MONTHLY;INTERVAL=1;BYDAY=-1MO;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061030T170000", - "20061127T170000", - "20061225T170000", - "20070129T170000", - "20070226T170000", - "20070326T170000", - "20070430T170000", - "20070528T170000", - "20070625T170000", - "20070730T170000", - "20070827T170000", - "20070924T170000", - "20071029T170000", - "20071126T170000", - "20071231T170000", - "20080128T170000", - "20080225T170000", - "20080331T170000", - "20080428T170000", - "20080526T170000", - "20080630T170000", - "20080728T170000", - "20080825T170000", - "20080929T170000", - "20081027T170000", - "20081124T170000", - "20081229T170000", - }, "20081229T170000"); - } - - @SmallTest - public void testFromGoogleCalendar10() throws Exception { - // Every 7 weeks on Tuesday, Wednesday - verifyRecurrence("20061004T090000", - "FREQ=WEEKLY;UNTIL=20070223T010000Z;INTERVAL=7;BYDAY=TU,WE;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061004T090000", - "20061121T090000", - "20061122T090000", - "20070109T090000", - "20070110T090000", - }, "20070222T170000"); - } - - @SmallTest - public void testFromGoogleCalendar11() throws Exception { - // Monthly on day 31 - verifyRecurrence("20061031T160000", - "FREQ=MONTHLY;INTERVAL=1;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061031T160000", - "20061231T160000", - "20070131T160000", - "20070331T160000", - "20070531T160000", - "20070731T160000", - "20070831T160000", - "20071031T160000", - "20071231T160000", - "20080131T160000", - "20080331T160000", - "20080531T160000", - "20080731T160000", - "20080831T160000", - "20081031T160000", - "20081231T160000", - }, - "20081231T160000"); - } - - @SmallTest - public void testFromGoogleCalendar12() throws Exception { - // Every 2 months on the first Tuesday - verifyRecurrence("20061004T110000", - "FREQ=MONTHLY;INTERVAL=2;BYDAY=1TU;WKST=SU", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090101T000000", - new String[]{ - "20061004T110000", - "20061205T110000", - "20070206T110000", - "20070403T110000", - "20070605T110000", - "20070807T110000", - "20071002T110000", - "20071204T110000", - "20080205T110000", - "20080401T110000", - "20080603T110000", - "20080805T110000", - "20081007T110000", - "20081202T110000", - }, - "20081202T110000"); - } - - @SmallTest - public void testYearly0() throws Exception { - verifyRecurrence("20080101T100000", - "FREQ=YEARLY;UNTIL=20090131T090000Z;BYMONTH=1;BYDAY=SU,MO", - null /* rdate */, null /* exrule */, null /* exdate */, - "20080101T000000", "20090130T000000", - new String[]{ - "20080101T100000", - "20080106T100000", - "20080107T100000", - "20080113T100000", - "20080114T100000", - "20080120T100000", - "20080121T100000", - "20080127T100000", - "20080128T100000", - "20090104T100000", - "20090105T100000", - "20090111T100000", - "20090112T100000", - "20090118T100000", - "20090119T100000", - "20090125T100000", - "20090126T100000", - }, "20090131T010000"); - } - - /** - * This test fails because of a bug in RecurrenceProcessor.expand(). We - * don't have time to fix the bug yet but we don't want to lose track of - * this test either. The "failing" prefix on the method name prevents this - * test from being run. Remove the "failing" prefix when the bug is fixed. - * - * @throws Exception - */ - @SmallTest - public void failingTestYearly1() throws Exception { - verifyRecurrence("20060101T100000", - "FREQ=YEARLY;COUNT=10;BYYEARDAY=1,100,200", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090131T000000", - new String[]{ - "20060101T100000", - "20060409T100000", - "20060718T100000", - "20070101T100000", - "20070409T100000", - "20070718T100000", - "20080101T100000", - "20080410T100000", - "20080719T100000", - "20090101T100000", - }); - } - - /** - * This test fails because of a bug in RecurrenceProcessor.expand(). We - * don't have time to fix the bug yet but we don't want to lose track of - * this test either. The "failing" prefix on the method name prevents this - * test from being run. Remove the "failing" prefix when the bug is fixed. - * - * @throws Exception - */ - @SmallTest - public void failingTestYearly2() throws Exception { - verifyRecurrence("20060101T100000", - "FREQ=YEARLY;COUNT=5;BYWEEKNO=6;BYDAY=MO;WKST=MO", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090131T000000", - new String[]{ - "20060101T100000", - "20060206T100000", - "20070205T100000", - "20080204T100000", - "20090209T100000", - }); - } - - /** - * This test fails because of a bug in RecurrenceProcessor.expand(). We - * don't have time to fix the bug yet but we don't want to lose track of - * this test either. The "failing" prefix on the method name prevents this - * test from being run. Remove the "failing" prefix when the bug is fixed. - * - * @throws Exception - */ - @SmallTest - public void failingTestYearly3() throws Exception { - verifyRecurrence("20060101T100000", - "FREQ=YEARLY;BYMONTH=3;BYDAY=TH", - null /* rdate */, null /* exrule */, null /* exdate */, - "20060101T000000", "20090131T000000", - new String[]{ - "20060101T100000", - "20060302T100000", - "20060309T100000", - "20060316T100000", - "20060323T100000", - "20060330T100000", - "20070301T100000", - "20070308T100000", - "20070315T100000", - "20070322T100000", - "20070329T100000", - "20080306T100000", - "20080313T100000", - "20080320T100000", - "20080327T100000", - }); - } - - /** - * This test fails because of a bug in RecurrenceProcessor.expand(). We - * don't have time to fix the bug yet but we don't want to lose track of - * this test either. The "failing" prefix on the method name prevents this - * test from being run. Remove the "failing" prefix when the bug is fixed. - * - * @throws Exception - */ - @SmallTest - public void failingTestYearly4() throws Exception { - verifyRecurrence("19920101T100000", - "FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8", - null /* rdate */, null /* exrule */, null /* exdate */, - "19920101T000000", "20121231T000000", - new String[]{ - "19920101T100000", - "19921103T100000", - "19961105T100000", - "20001107T100000", - "20041102T100000", - "20081104T100000", - "20121106T100000", - }); - } - - /** - * Test repeating event from Exchange with count field. - * Time range covers the whole repetition. - * - * @throws Exception - */ - public void testCount1() throws Exception { - verifyRecurrence("20100324T153000", - "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", - null /* rdate */, null /* exrule */, null /* exdate */, - "20100301T000000", "20100630T000000", - new String[]{ - "20100324T153000", - "20100331T153000", - "20100407T153000", - "20100414T153000", - "20100421T153000", - "20100428T153000", - "20100505T153000", - "20100512T153000", - "20100519T153000", - "20100526T153000", - }); - } - - /** - * Test repeating event from Exchange with count field. - * Time range covers the first part of the repetition. - * @throws Exception - */ - public void testCount2() throws Exception { - verifyRecurrence("20100324T153000", - "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", - null /* rdate */, null /* exrule */, null /* exdate */, - "20100501T000000", "20100630T000000", - new String[]{ - "20100505T153000", - "20100512T153000", - "20100519T153000", - "20100526T153000", - }); - } - - /** - * Test repeating event from Exchange with count field. - * Time range is beyond the repetition. - * @throws Exception - */ - public void testCount3() throws Exception { - verifyRecurrence("20100324T153000", - "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", - null /* rdate */, null /* exrule */, null /* exdate */, - "20100601T000000", "20100630T000000", - new String[]{}, - "20100526T153000" /* last */); - } - - /** - * Test repeating event from Exchange with count field. - * Time range is before the repetition - * @throws Exception - */ - public void testCount4() throws Exception { - verifyRecurrence("20100324T153000", - "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", - null /* rdate */, null /* exrule */, null /* exdate */, - "20100101T000000", "20100301T000000", - new String[]{}, - null /* last */); - } - - - // These recurrence rules are used in the loop that measures the performance - // of recurrence expansion. - private static final String[] performanceRrules = new String[] { - "FREQ=DAILY;COUNT=100", - "FREQ=DAILY;INTERVAL=2;UNTIL=20080101T000000Z", - "FREQ=YEARLY;UNTIL=20090131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA", - "FREQ=WEEKLY;INTERVAL=2;WKST=SU", - "FREQ=WEEKLY;COUNT=100;WKST=SU;BYDAY=MO,TU,WE,TH,FR", - "FREQ=MONTHLY;COUNT=100;BYDAY=1FR", - "FREQ=MONTHLY;INTERVAL=2;COUNT=100;BYDAY=1SU,-1SU", - "FREQ=MONTHLY;BYMONTHDAY=1,15", - "FREQ=MONTHLY;INTERVAL=3;COUNT=100;BYMONTHDAY=10,11,12,13,14", - "FREQ=YEARLY;COUNT=100;BYMONTH=6,7,8", - "FREQ=YEARLY;INTERVAL=2;BYMONTH=1,2,3,6,7,8", - "FREQ=YEARLY;COUNT=100;BYYEARDAY=1,100,200", - "FREQ=YEARLY;BYDAY=2MO", - "FREQ=YEARLY;BYWEEKNO=2,3,4;BYDAY=MO", - "FREQ=YEARLY;BYMONTH=3,4,5;BYDAY=TH", - "FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13", - "FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13", - "FREQ=YEARLY;INTERVAL=2;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8", - "FREQ=WEEKLY;INTERVAL=2;COUNT=100;BYDAY=TU,SU;WKST=MO", - "FREQ=WEEKLY;INTERVAL=2;COUNT=100;BYDAY=TU,SU;WKST=SU", - }; - - /** - * This test never fails. It just runs for a while (about 10 seconds) - * in order to measure the performance of recurrence expansion. - * - * @throws Exception - */ - @LargeTest - public void performanceTextExpand() throws Exception { - String tz = "America/Los_Angeles"; - Time dtstart = new Time(tz); - Time rangeStart = new Time(tz); - Time rangeEnd = new Time(tz); - TreeSet out = new TreeSet(); - - dtstart.parse("20010101T000000"); - rangeStart.parse("20010101T000000"); - rangeEnd.parse("20090101T000000"); - long rangeStartMillis = rangeStart.toMillis(false /* use isDst */); - long rangeEndMillis = rangeEnd.toMillis(false /* use isDst */); - - long startTime = System.currentTimeMillis(); - for (int iterations = 0; iterations < 5; iterations++) { - RecurrenceProcessor rp = new RecurrenceProcessor(); - - int len = performanceRrules.length; - for (int i = 0; i < len; i++) { - String rrule = performanceRrules[i]; - //Log.i(TAG, "expanding rule: " + rrule); - RecurrenceSet recur = new RecurrenceSet(rrule, null, null, null); - - long [] dates = rp.expand(dtstart, recur, rangeStartMillis, rangeEndMillis); - //Log.i(TAG, "num instances: " + out.size()); - - // Also include the time to iterate through the expanded values - for (long date : dates) { - // Use the date so that this loop is not optimized away. - if (date == -1) { - Log.e(TAG, "unexpected date"); - break; - } - } - out.clear(); - } - } - - long endTime = System.currentTimeMillis(); - long elapsed = endTime - startTime; - Log.i(TAG, "testPerformanceExpand() expand() elapsed millis: " + elapsed); - } - - @LargeTest - public void performanceTestNormalize() throws Exception { - final int ITERATIONS = 50000; - - String tz = "America/Los_Angeles"; - Time date = new Time(tz); - date.parse("20090404T100000"); - - long startTime = System.currentTimeMillis(); - - for (int i = 0; i < ITERATIONS; i++) { - date.month += 1; - date.monthDay += 100; - date.normalize(true); - date.month -= 1; - date.monthDay -= 100; - date.normalize(true); - } - - long endTime = System.currentTimeMillis(); - long elapsed = endTime - startTime; - Log.i(TAG, "date: " + date.format2445()); - Log.i(TAG, "testPerformanceNormalize() normalize() elapsed millis: " + elapsed); - - // Time the unsafe version - date.parse("20090404T100000"); - startTime = System.currentTimeMillis(); - for (int i = 0; i < ITERATIONS; i++) { - date.month += 1; - date.monthDay += 100; - RecurrenceProcessor.unsafeNormalize(date); - date.month -= 1; - date.monthDay -= 100; - RecurrenceProcessor.unsafeNormalize(date); - } - - endTime = System.currentTimeMillis(); - elapsed = endTime - startTime; - Log.i(TAG, "date: " + date.format2445()); - Log.i(TAG, "testPerformanceNormalize() unsafeNormalize() elapsed millis: " + elapsed); - } - } diff --git a/tests/src/com/android/calendarcommon/RecurrenceSetTest.java b/tests/src/com/android/calendarcommon/RecurrenceSetTest.java deleted file mode 100644 index 3b348b0..0000000 --- a/tests/src/com/android/calendarcommon/RecurrenceSetTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.calendarcommon; - -import com.android.calendarcommon.ICalendar; -import com.android.calendarcommon.RecurrenceSet; - -import android.content.ContentValues; -import android.test.suitebuilder.annotation.SmallTest; -import android.util.Log; -import android.provider.CalendarContract; -import junit.framework.TestCase; - -/** - * Test some pim.RecurrenceSet functionality. - */ -public class RecurrenceSetTest extends TestCase { - - // Test a recurrence - @SmallTest - public void testRecurrenceSet0() throws Exception { - String recurrence = "DTSTART;TZID=America/New_York:20080221T070000\n" - + "DTEND;TZID=America/New_York:20080221T190000\n" - + "RRULE:FREQ=DAILY;UNTIL=20080222T000000Z\n" - + "EXDATE:20080222T120000Z"; - verifyPopulateContentValues(recurrence, "FREQ=DAILY;UNTIL=20080222T000000Z", null, - null, "20080222T120000Z", 1203595200000L, "America/New_York", "P43200S", 0, false); - } - - // Test 1 day all-day event - @SmallTest - public void testRecurrenceSet1() throws Exception { - String recurrence = "DTSTART;VALUE=DATE:20090821\nDTEND;VALUE=DATE:20090822\n" - + "RRULE:FREQ=YEARLY;WKST=SU"; - verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU", null, - null, null, 1250812800000L, "UTC", "P1D", 1, false); - } - - // Test 2 day all-day event - @SmallTest - public void testRecurrenceSet2() throws Exception { - String recurrence = "DTSTART;VALUE=DATE:20090821\nDTEND;VALUE=DATE:20090823\n" - + "RRULE:FREQ=YEARLY;WKST=SU"; - verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU", null, - null, null, 1250812800000L, "UTC", "P2D", 1, false); - } - - // Test multi-rule RRULE. - @SmallTest - public void testRecurrenceSet3() throws Exception { - String recurrence = "DTSTART;VALUE=DATE:20090821\n" - + "RRULE:FREQ=YEARLY;WKST=SU\n" - + "RRULE:FREQ=MONTHLY;COUNT=3\n" - + "DURATION:P2H"; - verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU\nFREQ=MONTHLY;COUNT=3", null, - null, null, 1250812800000L, "UTC", "P2H", 1 /*allDay*/, false); - // allDay=1 just means the start time is 00:00:00 UTC. - } - - // Test RDATE with VALUE=DATE. - @SmallTest - public void testRecurrenceSet4() throws Exception { - String recurrence = "DTSTART;TZID=America/Los_Angeles:20090821T010203\n" - + "RDATE;TZID=America/Los_Angeles;VALUE=DATE:20110601,20110602,20110603\n" - + "DURATION:P2H"; - verifyPopulateContentValues(recurrence, null, - //"TZID=America/Los_Angeles;VALUE=DATE:20110601,20110602,20110603", - "America/Los_Angeles;20110601,20110602,20110603", // incorrect - null, null, 1250841723000L, "America/Los_Angeles", "P2H", 0 /*allDay*/, false); - // allDay=1 just means the start time is 00:00:00 UTC. - } - - // Check generation of duration from events in different time zones. - @SmallTest - public void testRecurrenceSet5() throws Exception { - String recurrence = "DTSTART;TZID=America/Los_Angeles:20090821T070000\n" - + "DTEND;TZID=America/New_York:20090821T110000\n" - + "RRULE:FREQ=YEARLY\n"; - verifyPopulateContentValues(recurrence, "FREQ=YEARLY", null, - null, null, 1250863200000L, "America/Los_Angeles", "P3600S" /*P1H*/, 0 /*allDay*/, - false); - // TODO: would like to use P1H for duration - - String recurrence2 = "DTSTART;TZID=America/New_York:20090821T100000\n" - + "DTEND;TZID=America/Los_Angeles:20090821T080000\n" - + "RRULE:FREQ=YEARLY\n"; - verifyPopulateContentValues(recurrence, "FREQ=YEARLY", null, - null, null, 1250863200000L, "America/Los_Angeles", "P3600S" /*P1H*/, 0 /*allDay*/, - false); - // TODO: should we rigorously define which tzid becomes the "event timezone"? - } - - // Test a failure to parse the recurrence data - @SmallTest - public void testRecurrenceSetBadDstart() throws Exception { - String recurrence = "DTSTART;TZID=GMT+05:30:20080221T070000\n" - + "DTEND;TZID=GMT+05:30:20080221T190000\n" - + "RRULE:FREQ=DAILY;UNTIL=20080222T000000Z\n" - + "EXDATE:20080222T120000Z"; - verifyPopulateContentValues(recurrence, "FREQ=DAILY;UNTIL=20080222T000000Z", null, - null, "20080222T120000Z", 1203595200000L, "America/New_York", "P43200S", 0, true); - } - - @SmallTest - public void testRecurrenceSetBadRrule() throws Exception { - String recurrence = "DTSTART;TZID=America/New_York:20080221T070000\n" - + "DTEND;TZID=GMT+05:30:20080221T190000\n" - + "RRULE:FREQ=NEVER;UNTIL=20080222T000000Z\n" - + "EXDATE:20080222T120000Z"; - verifyPopulateContentValues(recurrence, "FREQ=DAILY;UNTIL=20080222T000000Z", null, - null, "20080222T120000Z", 1203595200000L, "America/New_York", "P43200S", 0, true); - } - - // run populateContentValues and verify the results - private void verifyPopulateContentValues(String recurrence, String rrule, String rdate, - String exrule, String exdate, long dtstart, String tzid, String duration, int allDay, - boolean badFormat) - throws ICalendar.FormatException { - ICalendar.Component recurrenceComponent = - new ICalendar.Component("DUMMY", null /* parent */); - ICalendar.parseComponent(recurrenceComponent, recurrence); - ContentValues values = new ContentValues(); - boolean result = RecurrenceSet.populateContentValues(recurrenceComponent, values); - Log.d("KS", "values " + values); - - if (badFormat) { - assertEquals(result, !badFormat); - return; - } - assertEquals(rrule, values.get(android.provider.CalendarContract.Events.RRULE)); - assertEquals(rdate, values.get(android.provider.CalendarContract.Events.RDATE)); - assertEquals(exrule, values.get(android.provider.CalendarContract.Events.EXRULE)); - assertEquals(exdate, values.get(android.provider.CalendarContract.Events.EXDATE)); - assertEquals(dtstart, (long) values.getAsLong(CalendarContract.Events.DTSTART)); - assertEquals(tzid, values.get(android.provider.CalendarContract.Events.EVENT_TIMEZONE)); - assertEquals(duration, values.get(android.provider.CalendarContract.Events.DURATION)); - assertEquals(allDay, - (int) values.getAsInteger(android.provider.CalendarContract.Events.ALL_DAY)); - } - -} diff --git a/tests/src/com/android/calendarcommon2/DurationTest.java b/tests/src/com/android/calendarcommon2/DurationTest.java new file mode 100644 index 0000000..39320a3 --- /dev/null +++ b/tests/src/com/android/calendarcommon2/DurationTest.java @@ -0,0 +1,77 @@ +/* //device/content/providers/pim/DurationTest.java +** +** Copyright 2006, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +package com.android.calendarcommon2; + +import junit.framework.TestCase; + +import android.test.suitebuilder.annotation.SmallTest; + +public class DurationTest extends TestCase { + + private void verifyDuration(String str, + int sign, int weeks, int days, int hours, + int minutes, int seconds) throws DateException { + + Duration duration = new Duration(); + duration.parse(str); + + assertEquals("Duration sign is not equal for " + str, sign, duration.sign); + assertEquals("Duration weeks is not equal for " + str, weeks, duration.weeks); + assertEquals("Duration days is not equal for " + str, days, duration.days); + assertEquals("Duration hours is not equal for " + str, hours, duration.hours); + assertEquals("Duration minutes is not equal for " + str, minutes, duration.minutes); + assertEquals("Duration seconds is not equal for " + str, seconds, duration.seconds); + } + + @SmallTest + public void testParse() throws Exception { + verifyDuration("P7W", 1, 7, 0, 0, 0, 0); + verifyDuration("PT7W", 1, 7, 0, 0, 0, 0); + verifyDuration("-PT7W", -1, 7, 0, 0, 0, 0); + verifyDuration("P15DT5H0M20S", 1, 0, 15, 5, 0, 20); + verifyDuration("-P15DT5H0M20S", -1, 0, 15, 5, 0, 20); + verifyDuration("PT1H2M3S", 1, 0, 0, 1, 2, 3); + + verifyDuration("", 1, 0, 0, 0, 0, 0); + verifyDuration("P", 1, 0, 0, 0, 0, 0); + verifyDuration("P0W", 1, 0, 0, 0, 0, 0); + verifyDuration("P0D", 1, 0, 0, 0, 0, 0); + verifyDuration("PT0H0M0S", 1, 0, 0, 0, 0, 0); + verifyDuration("P0DT0H0M0S", 1, 0, 0, 0, 0, 0); + } + + @SmallTest + public void testParseInvalidStrings() throws Exception { + try { + verifyDuration(" -P15DT5H0M20S", 0, 0, 0, 0, 0, 0); + fail("test didn't throw an exception but we expected it to"); + } catch (DateException e) { + // expected + } + + try { + verifyDuration(" not even close", 0, 0, 0, 0, 0, 0); + fail("test didn't throw an exception but we expected it to"); + } catch (DateException e) { + // expected + } + } +} + + + diff --git a/tests/src/com/android/calendarcommon2/EventRecurrenceTest.java b/tests/src/com/android/calendarcommon2/EventRecurrenceTest.java new file mode 100644 index 0000000..c25e3ec --- /dev/null +++ b/tests/src/com/android/calendarcommon2/EventRecurrenceTest.java @@ -0,0 +1,889 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.calendarcommon2; + +import com.android.calendarcommon2.EventRecurrence.InvalidFormatException; + +import android.test.suitebuilder.annotation.SmallTest; +import android.test.suitebuilder.annotation.Suppress; + +import junit.framework.TestCase; + +import java.util.Arrays; + +/** + * Test android.pim.EventRecurrence. + * + * adb shell am instrument -w -e class com.android.calendarcommon2.EventRecurrenceTest \ + * com.android.calendarcommon2.tests/android.test.InstrumentationTestRunner + */ +public class EventRecurrenceTest extends TestCase { + + @SmallTest + public void test0() throws Exception { + verifyRecurType("FREQ=SECONDLY", + /* int freq */ EventRecurrence.SECONDLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test1() throws Exception { + verifyRecurType("FREQ=MINUTELY", + /* int freq */ EventRecurrence.MINUTELY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test2() throws Exception { + verifyRecurType("FREQ=HOURLY", + /* int freq */ EventRecurrence.HOURLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test3() throws Exception { + verifyRecurType("FREQ=DAILY", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test4() throws Exception { + verifyRecurType("FREQ=WEEKLY", + /* int freq */ EventRecurrence.WEEKLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test5() throws Exception { + verifyRecurType("FREQ=MONTHLY", + /* int freq */ EventRecurrence.MONTHLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test6() throws Exception { + verifyRecurType("FREQ=YEARLY", + /* int freq */ EventRecurrence.YEARLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test7() throws Exception { + // with an until + verifyRecurType("FREQ=DAILY;UNTIL=112233T223344Z", + /* int freq */ EventRecurrence.DAILY, + /* String until */ "112233T223344Z", + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test8() throws Exception { + // with a count + verifyRecurType("FREQ=DAILY;COUNT=334", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 334, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test9() throws Exception { + // with a count + verifyRecurType("FREQ=DAILY;INTERVAL=5000", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 5000, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @SmallTest + public void test10() throws Exception { + // verifyRecurType all of the BY* ones with one element + verifyRecurType("FREQ=DAILY" + + ";BYSECOND=0" + + ";BYMINUTE=1" + + ";BYHOUR=2" + + ";BYMONTHDAY=30" + + ";BYYEARDAY=300" + + ";BYWEEKNO=53" + + ";BYMONTH=12" + + ";BYSETPOS=-15" + + ";WKST=SU", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ new int[]{0}, + /* int[] byminute */ new int[]{1}, + /* int[] byhour */ new int[]{2}, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ new int[]{30}, + /* int[] byyearday */ new int[]{300}, + /* int[] byweekno */ new int[]{53}, + /* int[] bymonth */ new int[]{12}, + /* int[] bysetpos */ new int[]{-15}, + /* int wkst */ EventRecurrence.SU + ); + } + + @SmallTest + public void test11() throws Exception { + // verifyRecurType all of the BY* ones with one element + verifyRecurType("FREQ=DAILY" + + ";BYSECOND=0,30,59" + + ";BYMINUTE=0,41,59" + + ";BYHOUR=0,4,23" + + ";BYMONTHDAY=-31,-1,1,31" + + ";BYYEARDAY=-366,-1,1,366" + + ";BYWEEKNO=-53,-1,1,53" + + ";BYMONTH=1,12" + + ";BYSETPOS=1,2,3,4,500,10000" + + ";WKST=SU", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ new int[]{0, 30, 59}, + /* int[] byminute */ new int[]{0, 41, 59}, + /* int[] byhour */ new int[]{0, 4, 23}, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ new int[]{-31, -1, 1, 31}, + /* int[] byyearday */ new int[]{-366, -1, 1, 366}, + /* int[] byweekno */ new int[]{-53, -1, 1, 53}, + /* int[] bymonth */ new int[]{1, 12}, + /* int[] bysetpos */ new int[]{1, 2, 3, 4, 500, 10000}, + /* int wkst */ EventRecurrence.SU + ); + } + + private static class Check { + Check(String k, int... v) { + key = k; + values = v; + } + + String key; + int[] values; + } + + // this is a negative verifyRecurType case to verifyRecurType the range of the numbers accepted + @SmallTest + public void test12() throws Exception { + Check[] checks = new Check[]{ + new Check("BYSECOND", -100, -1, 60, 100), + new Check("BYMINUTE", -100, -1, 60, 100), + new Check("BYHOUR", -100, -1, 24, 100), + new Check("BYMONTHDAY", -100, -32, 0, 32, 100), + new Check("BYYEARDAY", -400, -367, 0, 367, 400), + new Check("BYWEEKNO", -100, -54, 0, 54, 100), + new Check("BYMONTH", -100, -5, 0, 13, 100) + }; + + for (Check ck : checks) { + for (int n : ck.values) { + String recur = "FREQ=DAILY;" + ck.key + "=" + n; + try { + EventRecurrence er = new EventRecurrence(); + er.parse(recur); + fail("Negative verifyRecurType failed. " + + " parse failed to throw an exception for '" + + recur + "'"); + } catch (EventRecurrence.InvalidFormatException e) { + // expected + } + } + } + } + + // verifyRecurType BYDAY + @SmallTest + public void test13() throws Exception { + verifyRecurType("FREQ=DAILY;BYDAY=1SU,-2MO,+33TU,WE,TH,FR,SA", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.SU, + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + EventRecurrence.TH, + EventRecurrence.FR, + EventRecurrence.SA + }, + /* int[] bydayNum */ new int[]{1, -2, 33, 0, 0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + @Suppress + // Repro bug #2331761 - this should fail because of the last comma into BYDAY + public void test14() throws Exception { + verifyRecurType("FREQ=WEEKLY;WKST=MO;UNTIL=20100129T130000Z;INTERVAL=1;BYDAY=MO,TU,WE,", + /* int freq */ EventRecurrence.WEEKLY, + /* String until */ "20100129T130000Z", + /* int count */ 0, + /* int interval */ 1, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + }, + /* int[] bydayNum */ new int[]{0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // This test should pass + public void test15() throws Exception { + verifyRecurType("FREQ=WEEKLY;WKST=MO;UNTIL=20100129T130000Z;INTERVAL=1;" + + "BYDAY=MO,TU,WE,TH,FR,SA,SU", + /* int freq */ EventRecurrence.WEEKLY, + /* String until */ "20100129T130000Z", + /* int count */ 0, + /* int interval */ 1, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + EventRecurrence.TH, + EventRecurrence.FR, + EventRecurrence.SA, + EventRecurrence.SU + }, + /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // Sample coming from RFC2445 + public void test16() throws Exception { + verifyRecurType("FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1", + /* int freq */ EventRecurrence.MONTHLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + EventRecurrence.TH, + EventRecurrence.FR + }, + /* int[] bydayNum */ new int[] {0, 0, 0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ new int[] { -1 }, + /* int wkst */ EventRecurrence.MO + ); + } + + // Sample coming from RFC2445 + public void test17() throws Exception { + verifyRecurType("FREQ=DAILY;COUNT=10;INTERVAL=2", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 10, + /* int interval */ 2, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // Sample coming from RFC2445 + public void test18() throws Exception { + verifyRecurType("FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10", + /* int freq */ EventRecurrence.YEARLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.SU + }, + /* int[] bydayNum */ new int[] { -1 }, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ new int[] { 10 }, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // Sample coming from bug #1640517 + public void test19() throws Exception { + verifyRecurType("FREQ=YEARLY;BYMONTH=3;BYDAY=TH", + /* int freq */ EventRecurrence.YEARLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.TH + }, + /* int[] bydayNum */ new int[] { 0 }, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ new int[] { 3 }, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // INTERVAL = 0 -> Interval = 1 bug #5676414 + public void test20() throws Exception { + verifyRecurType("FREQ=YEARLY;BYMONTHDAY=18;BYMONTH=10;INTERVAL=0;", + /* int freq */ EventRecurrence.YEARLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 1, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ new int[]{18}, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ new int[]{10}, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // Working case: INTERVAL=1 -> Interval = 1 bug #5676414 + public void test21() throws Exception { + verifyRecurType("FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR", + /* int freq */ EventRecurrence.WEEKLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 1, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + EventRecurrence.TH, + EventRecurrence.FR, + }, + /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.SU + ); + } + + // Working case: INTERVAL=2 -> Interval = 2 bug #5676414 + public void test22() throws Exception { + verifyRecurType("FREQ=WEEKLY;WKST=SU;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR", + /* int freq */ EventRecurrence.WEEKLY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 2, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + EventRecurrence.TH, + EventRecurrence.FR, + }, + /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.SU + ); + } + + // COUNT < 0 -> Count = 1 bug #5676414 + public void test23() throws Exception { + verifyRecurType("FREQ=WEEKLY;COUNT=-20;BYDAY=MO,TU,WE,TH,FR;", + /* int freq */ EventRecurrence.WEEKLY, + /* String until */ null, + /* int count */ 1, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + EventRecurrence.TH, + EventRecurrence.FR, + }, + /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // Working case: COUNT=2 -> Count=2 bug #5676414 + public void test24() throws Exception { + verifyRecurType("FREQ=WEEKLY;COUNT=2;BYDAY=MO,TU,WE,TH,FR;", + /* int freq */ EventRecurrence.WEEKLY, + /* String until */ null, + /* int count */ 2, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ new int[] { + EventRecurrence.MO, + EventRecurrence.TU, + EventRecurrence.WE, + EventRecurrence.TH, + EventRecurrence.FR, + }, + /* int[] bydayNum */ new int[]{0, 0, 0, 0, 0}, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + // for your copying pleasure + public void fakeTestXX() throws Exception { + verifyRecurType("FREQ=DAILY;", + /* int freq */ EventRecurrence.DAILY, + /* String until */ null, + /* int count */ 0, + /* int interval */ 0, + /* int[] bysecond */ null, + /* int[] byminute */ null, + /* int[] byhour */ null, + /* int[] byday */ null, + /* int[] bydayNum */ null, + /* int[] bymonthday */ null, + /* int[] byyearday */ null, + /* int[] byweekno */ null, + /* int[] bymonth */ null, + /* int[] bysetpos */ null, + /* int wkst */ EventRecurrence.MO + ); + } + + private static void cmp(int vlen, int[] v, int[] correct, String name) { + if ((correct == null && v != null) + || (correct != null && v == null)) { + throw new RuntimeException("One is null, one isn't for " + name + + ": correct=" + Arrays.toString(correct) + + " actual=" + Arrays.toString(v)); + } + if ((correct == null && vlen != 0) + || (vlen != (correct == null ? 0 : correct.length))) { + throw new RuntimeException("Reported length mismatch for " + name + + ": correct=" + ((correct == null) ? "null" : correct.length) + + " actual=" + vlen); + } + if (correct == null) { + return; + } + if (v.length < correct.length) { + throw new RuntimeException("Array length mismatch for " + name + + ": correct=" + Arrays.toString(correct) + + " actual=" + Arrays.toString(v)); + } + for (int i = 0; i < correct.length; i++) { + if (v[i] != correct[i]) { + throw new RuntimeException("Array value mismatch for " + name + + ": correct=" + Arrays.toString(correct) + + " actual=" + Arrays.toString(v)); + } + } + } + + private static boolean eq(String a, String b) { + if ((a == null && b != null) || (a != null && b == null)) { + return false; + } else { + return a == b || a.equals(b); + } + } + + private static void verifyRecurType(String recur, + int freq, String until, int count, int interval, + int[] bysecond, int[] byminute, int[] byhour, + int[] byday, int[] bydayNum, int[] bymonthday, + int[] byyearday, int[] byweekno, int[] bymonth, + int[] bysetpos, int wkst) { + EventRecurrence eventRecurrence = new EventRecurrence(); + eventRecurrence.parse(recur); + if (eventRecurrence.freq != freq + || !eq(eventRecurrence.until, until) + || eventRecurrence.count != count + || eventRecurrence.interval != interval + || eventRecurrence.wkst != wkst) { + System.out.println("Error... got:"); + print(eventRecurrence); + System.out.println("expected:"); + System.out.println("{"); + System.out.println(" freq=" + freq); + System.out.println(" until=" + until); + System.out.println(" count=" + count); + System.out.println(" interval=" + interval); + System.out.println(" wkst=" + wkst); + System.out.println(" bysecond=" + Arrays.toString(bysecond)); + System.out.println(" byminute=" + Arrays.toString(byminute)); + System.out.println(" byhour=" + Arrays.toString(byhour)); + System.out.println(" byday=" + Arrays.toString(byday)); + System.out.println(" bydayNum=" + Arrays.toString(bydayNum)); + System.out.println(" bymonthday=" + Arrays.toString(bymonthday)); + System.out.println(" byyearday=" + Arrays.toString(byyearday)); + System.out.println(" byweekno=" + Arrays.toString(byweekno)); + System.out.println(" bymonth=" + Arrays.toString(bymonth)); + System.out.println(" bysetpos=" + Arrays.toString(bysetpos)); + System.out.println("}"); + throw new RuntimeException("Mismatch in fields"); + } + cmp(eventRecurrence.bysecondCount, eventRecurrence.bysecond, bysecond, "bysecond"); + cmp(eventRecurrence.byminuteCount, eventRecurrence.byminute, byminute, "byminute"); + cmp(eventRecurrence.byhourCount, eventRecurrence.byhour, byhour, "byhour"); + cmp(eventRecurrence.bydayCount, eventRecurrence.byday, byday, "byday"); + cmp(eventRecurrence.bydayCount, eventRecurrence.bydayNum, bydayNum, "bydayNum"); + cmp(eventRecurrence.bymonthdayCount, eventRecurrence.bymonthday, bymonthday, "bymonthday"); + cmp(eventRecurrence.byyeardayCount, eventRecurrence.byyearday, byyearday, "byyearday"); + cmp(eventRecurrence.byweeknoCount, eventRecurrence.byweekno, byweekno, "byweekno"); + cmp(eventRecurrence.bymonthCount, eventRecurrence.bymonth, bymonth, "bymonth"); + cmp(eventRecurrence.bysetposCount, eventRecurrence.bysetpos, bysetpos, "bysetpos"); + } + + private static void print(EventRecurrence er) { + System.out.println("{"); + System.out.println(" freq=" + er.freq); + System.out.println(" until=" + er.until); + System.out.println(" count=" + er.count); + System.out.println(" interval=" + er.interval); + System.out.println(" wkst=" + er.wkst); + System.out.println(" bysecond=" + Arrays.toString(er.bysecond)); + System.out.println(" bysecondCount=" + er.bysecondCount); + System.out.println(" byminute=" + Arrays.toString(er.byminute)); + System.out.println(" byminuteCount=" + er.byminuteCount); + System.out.println(" byhour=" + Arrays.toString(er.byhour)); + System.out.println(" byhourCount=" + er.byhourCount); + System.out.println(" byday=" + Arrays.toString(er.byday)); + System.out.println(" bydayNum=" + Arrays.toString(er.bydayNum)); + System.out.println(" bydayCount=" + er.bydayCount); + System.out.println(" bymonthday=" + Arrays.toString(er.bymonthday)); + System.out.println(" bymonthdayCount=" + er.bymonthdayCount); + System.out.println(" byyearday=" + Arrays.toString(er.byyearday)); + System.out.println(" byyeardayCount=" + er.byyeardayCount); + System.out.println(" byweekno=" + Arrays.toString(er.byweekno)); + System.out.println(" byweeknoCount=" + er.byweeknoCount); + System.out.println(" bymonth=" + Arrays.toString(er.bymonth)); + System.out.println(" bymonthCount=" + er.bymonthCount); + System.out.println(" bysetpos=" + Arrays.toString(er.bysetpos)); + System.out.println(" bysetposCount=" + er.bysetposCount); + System.out.println("}"); + } + + + /** A list of valid rules. The parser must accept these. */ + private static final String[] GOOD_RRULES = { + /* extracted wholesale from from RFC 2445 section 4.8.5.4 */ + "FREQ=DAILY;COUNT=10", + "FREQ=DAILY;UNTIL=19971224T000000Z", + "FREQ=DAILY;INTERVAL=2", + "FREQ=DAILY;INTERVAL=10;COUNT=5", + "FREQ=YEARLY;UNTIL=20000131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA", + "FREQ=DAILY;UNTIL=20000131T090000Z;BYMONTH=1", + "FREQ=WEEKLY;COUNT=10", + "FREQ=WEEKLY;UNTIL=19971224T000000Z", + "FREQ=WEEKLY;INTERVAL=2;WKST=SU", + "FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH", + "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH", + "FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR", + "FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH", + "FREQ=MONTHLY;COUNT=10;BYDAY=1FR", + "FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR", + "FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU", + "FREQ=MONTHLY;COUNT=6;BYDAY=-2MO", + "FREQ=MONTHLY;BYMONTHDAY=-3", + "FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15", + "FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1", + "FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15", + "FREQ=MONTHLY;INTERVAL=2;BYDAY=TU", + "FREQ=YEARLY;COUNT=10;BYMONTH=6,7", + "FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3", + "FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200", + "FREQ=YEARLY;BYDAY=20MO", + "FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO", + "FREQ=YEARLY;BYMONTH=3;BYDAY=TH", + "FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8", + "FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13", + "FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13", + "FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8", + "FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3", + "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2", + "FREQ=HOURLY;INTERVAL=3;UNTIL=19970902T170000Z", + "FREQ=MINUTELY;INTERVAL=15;COUNT=6", + "FREQ=MINUTELY;INTERVAL=90;COUNT=4", + "FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40", + "FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16", + "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO", + "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU", + /* a few more */ + "FREQ=SECONDLY;BYSECOND=0,15,59", + "FREQ=MINUTELY;BYMINUTE=0,15,59", + "FREQ=HOURLY;BYHOUR=+0,+15,+23", + "INTERVAL=4;FREQ=YEARLY", + "FREQ=DAILY;X-WHATEVER=blah", + //"freq=daily;wkst=su", // mixed case currently not allowed + "FREQ=WEEKLY;INTERVAL=2;BYDAY=Mo;;UNTIL=20120327T000000Z", // double simicolon should be allowed + "FREQ=MONTHLY;BYDAY=1Mo", + "FREQ=MONTHLY;BYDAY=2Mo,2We,4Mo,4We", + "FREQ=MONTHLY;WKST=SU;BYMONTHDAY=25;UNTIL=20110524", + "FREQ=WEEKLY;BYDAY=MO;WKST=SU;UNTIL=20111218T010000Z" + }; + + /** The parser must reject these. */ + private static final String[] BAD_RRULES = { + "FREQ=MONTHLY;FREQ=MONTHLY", // can't specify twice + "FREQ=MONTHLY;COUNT=1;COUNT=1", // can't specify twice + "FREQ=SECONDLY;BYSECOND=60", // range + "FREQ=MINUTELY;BYMINUTE=-1", // range + "FREQ=HOURLY;BYHOUR=24", // range + "FREQ=YEARLY;BYMONTHDAY=0", // zero not valid + "BYMONTHDAY=1", // must specify FREQ + //"FREQ=YEARLY;COUNT=1;UNTIL=12345", // can't have both COUNT and UNTIL + //"FREQ=DAILY;UNTIL=19970829T021400e", // invalid date + }; + + /** + * Simple test of good/bad rules. + */ + @SmallTest + public void testBasicParse() { + for (String rule : GOOD_RRULES) { + EventRecurrence recur = new EventRecurrence(); + recur.parse(rule); + } + + for (String rule : BAD_RRULES) { + EventRecurrence recur = new EventRecurrence(); + boolean didThrow = false; + + try { + recur.parse(rule); + } catch (InvalidFormatException ife) { + didThrow = true; + } + + assertTrue("Expected throw on " + rule, didThrow); + } + } +} diff --git a/tests/src/com/android/calendarcommon2/RRuleTest.java b/tests/src/com/android/calendarcommon2/RRuleTest.java new file mode 100644 index 0000000..53988e2 --- /dev/null +++ b/tests/src/com/android/calendarcommon2/RRuleTest.java @@ -0,0 +1,756 @@ +/* +** +** Copyright 2009, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +/* Based on http://code.google.com/p/google-rfc-2445/source/browse/trunk/test/com/google/ical/iter/RRuleIteratorImplTest.java */ + +package com.android.calendarcommon2; + +import com.android.calendarcommon2.RecurrenceSet; + +import android.os.Debug; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.Suppress; +import android.text.format.Time; +import junit.framework.TestCase; + +/** + * You can run those tests with: + * + * adb shell am instrument + * -e debug false + * -w + * -e + * class com.android.providers.calendar.RRuleTest + * com.android.providers.calendar.tests/android.test.InstrumentationTestRunner + */ + +public class RRuleTest extends TestCase { + private static final String TAG = "RRuleTest"; + private static final boolean METHOD_TRACE = false; + + private static String[] getFormattedDates(long[] dates, Time time, boolean truncate) { + String[] out = new String[dates.length]; + int i = 0; + for (long date : dates) { + time.set(date); + if (truncate) { + out[i] = time.format2445().substring(0, 8); // Just YYMMDD + } else { + out[i] = time.format2445().substring(0, 15); // YYMMDDThhmmss + } + ++i; + } + return out; + } + + static final String PST = "America/Los_Angeles"; + static final String UTC = "UTC"; + // Use this date as end of recurrence unlessotherwise specified. + static final String DEFAULT_END = "20091212"; + + private void runRecurrenceIteratorTest(String rruleText, String dtStart, int limit, + String golden) throws Exception { + runRecurrenceIteratorTest(rruleText, dtStart, limit, golden, null, null, UTC); + } + + private void runRecurrenceIteratorTest(String rrule, String dtstartStr, int limit, + String golden, String advanceTo, String tz) throws Exception { + runRecurrenceIteratorTest(rrule, dtstartStr, limit, golden, advanceTo, null, tz); + } + + /** + * Tests a recurrence rule + * @param rrule The rule to expand + * @param dtstartStr The dtstart to use + * @param limit Maximum number of entries to expand. if there are more, "..." is appended to + * the result. Note that Android's recurrence expansion doesn't support expanding n results, + * so this is faked by expanding until the endAt date, and then taking limit results. + * @param golden The desired results + * @param advanceTo The starting date for expansion. dtstartStr is used if null is passed in. + * @param endAt The ending date. DEFAULT_END is used if null is passed in. + * @param tz The time zone. UTC is used if null is passed in. + * @throws Exception if anything goes wrong. + */ + private void runRecurrenceIteratorTest(String rrule, String dtstartStr, int limit, + String golden, String advanceTo, String endAt, String tz) throws Exception { + + String rdate = ""; + String exrule = ""; + String exdate = ""; + rrule = rrule.replace("RRULE:", ""); + // RecurrenceSet does not support folding of lines, so fold here + rrule = rrule.replace("\n ", ""); + + Time dtstart = new Time(tz); + Time rangeStart = new Time(tz); + Time rangeEnd = new Time(tz); + Time outCal = new Time(tz); + + dtstart.parse(dtstartStr); + if (advanceTo == null) { + advanceTo = dtstartStr; + } + if (endAt == null) { + endAt = DEFAULT_END; + } + + rangeStart.parse(advanceTo); + rangeEnd.parse(endAt); + + + RecurrenceProcessor rp = new RecurrenceProcessor(); + RecurrenceSet recur = new RecurrenceSet(rrule, rdate, exrule, exdate); + + long[] out = rp.expand(dtstart, recur, rangeStart.toMillis(false /* use isDst */), + rangeEnd.toMillis(false /* use isDst */)); + + if (METHOD_TRACE) { + Debug.stopMethodTracing(); + } + + boolean truncate = dtstartStr.length() <= 8; // Just date, not date-time + String[] actual = getFormattedDates(out, outCal, truncate); + + StringBuilder sb = new StringBuilder(); + int k = 0; + while (k < actual.length && --limit >= 0) { + if (k != 0) { + sb.append(','); + } + sb.append(actual[k]); + k++; + } + if (limit < 0) { + sb.append(",..."); + } + assertEquals(golden, sb.toString()); + } + + // Infinite loop, bug 1662110 + @MediumTest + public void testFrequencyLimits() throws Exception { + try { + runRecurrenceIteratorTest("RRULE:FREQ=SECONDLY;BYSECOND=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14," + "15,16,17,18,19,20,21,22,23,24,25,26,27,28,29," + "30,31,32,33,34,35,36,37,38,39,40,41,42,43,44," + "45,46,47,48,49,50,51,52,53,54,55,56,57,58,59", "20000101", 1, ""); + fail("Don't do that"); + } catch (DateException ex) { + // pass + } + } + + @MediumTest + public void testSimpleDaily() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=DAILY", "20060120", 5, "20060120,20060121,20060122,20060123,20060124,..."); + } + + @MediumTest + public void testSimpleWeekly() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY", "20060120", 5, "20060120,20060127,20060203,20060210,20060217,..."); + } + + @MediumTest + public void testSimpleMonthly() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY", "20060120", 5, "20060120,20060220,20060320,20060420,20060520,..."); + } + + @MediumTest + public void testSimpleYearly() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY", "20060120", 5, "20060120,20070120,20080120,20090120,20100120,...", null, "20120101", UTC); + } + + // from section 4.3.10 + @MediumTest + public void testMultipleByParts() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU", "19970105", 8, "19970105,19970112,19970119,19970126," + "19990103,19990110,19990117,19990124,..."); + } + + @MediumTest + public void testCountWithInterval() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=DAILY;COUNT=10;INTERVAL=2", "19970105", 11, "19970105,19970107,19970109,19970111,19970113," + "19970115,19970117,19970119,19970121,19970123"); + } + + // from section 4.6.5 + // Fails: wrong dates + @MediumTest + @Suppress + public void testNegativeOffsetsA() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10", "19970105", 5, "19971026,19981025,19991031,20001029,20011028,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testNegativeOffsetsB() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4", "19970105", 5, "19970406,19980405,19990404,20000402,20010401,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testNegativeOffsetsC() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4;UNTIL=19980404T150000Z", "19970105", 5, "19970406"); + } + + // feom section 4.8.5.4 + @MediumTest + public void testDailyFor10Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=DAILY;COUNT=10", "19970902T090000", 11, "19970902T090000,19970903T090000,19970904T090000,19970905T090000," + "19970906T090000,19970907T090000,19970908T090000,19970909T090000," + "19970910T090000,19970911T090000"); + + } + + @MediumTest + public void testDailyUntilDec4() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=DAILY;UNTIL=19971204", "19971128", 11, "19971128,19971129,19971130,19971201,19971202,19971203,19971204"); + } + + // Fails: infinite loop + @MediumTest + @Suppress + public void testEveryOtherDayForever() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=DAILY;INTERVAL=2", "19971128", 5, "19971128,19971130,19971202,19971204,19971206,..."); + } + + @MediumTest + public void testEvery10Days5Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5", "19970902", 5, "19970902,19970912,19970922,19971002,19971012"); + } + + @MediumTest + public void testWeeklyFor10Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;COUNT=10", "19970902", 10, "19970902,19970909,19970916,19970923,19970930," + "19971007,19971014,19971021,19971028,19971104"); + } + + @MediumTest + public void testWeeklyUntilDec24() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971224", "19970902", 25, "19970902,19970909,19970916,19970923,19970930," + "19971007,19971014,19971021,19971028,19971104," + "19971111,19971118,19971125,19971202,19971209," + "19971216,19971223"); + } + + @MediumTest + public void testEveryOtherWeekForever() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=SU", "19970902", 11, "19970902,19970916,19970930,19971014,19971028," + "19971111,19971125,19971209,19971223,19980106," + "19980120,..."); + } + + @MediumTest + public void testWeeklyOnTuesdayAndThursdayFor5Weeks() throws Exception { + // if UNTIL date does not match start date, then until date treated as + // occurring on midnight. + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971007;WKST=SU;BYDAY=TU,TH", "19970902T090000", 11, "19970902T090000,19970904T090000,19970909T090000,19970911T090000," + "19970916T090000,19970918T090000,19970923T090000,19970925T090000," + "19970930T090000,19971002T090000"); + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971007T000000Z;WKST=SU;BYDAY=TU,TH", "19970902T090000", 11, "19970902T090000,19970904T090000,19970909T090000,19970911T090000," + "19970916T090000,19970918T090000,19970923T090000,19970925T090000," + "19970930T090000,19971002T090000"); + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH", "19970902", 11, "19970902,19970904,19970909,19970911,19970916," + "19970918,19970923,19970925,19970930,19971002"); + } + + @MediumTest + public void testEveryOtherWeekOnMWFUntilDec24() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;\n" + " BYDAY=MO,WE,FR", "19970903T090000", 25, "19970903T090000,19970905T090000,19970915T090000,19970917T090000," + "19970919T090000,19970929T090000,19971001T090000,19971003T090000," + "19971013T090000,19971015T090000,19971017T090000,19971027T090000," + "19971029T090000,19971031T090000,19971110T090000,19971112T090000," + "19971114T090000,19971124T090000,19971126T090000,19971128T090000," + "19971208T090000,19971210T090000,19971212T090000,19971222T090000"); + } + + @MediumTest + public void testEveryOtherWeekOnMWFUntilDec24a() throws Exception { + // if the UNTIL date is timed, when the start is not, the time should be + // ignored, so we get one more instance + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;\n" + " BYDAY=MO,WE,FR", "19970903", 25, "19970903,19970905,19970915,19970917," + "19970919,19970929,19971001,19971003," + "19971013,19971015,19971017,19971027," + "19971029,19971031,19971110,19971112," + "19971114,19971124,19971126,19971128," + "19971208,19971210,19971212,19971222," + "19971224"); + } + + // Fails with wrong times + @MediumTest + @Suppress + public void testEveryOtherWeekOnMWFUntilDec24b() throws Exception { + // test with an alternate timezone + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T090000Z;WKST=SU;\n" + " BYDAY=MO,WE,FR", "19970903T090000", 25, "19970903T160000,19970905T160000,19970915T160000,19970917T160000," + "19970919T160000,19970929T160000,19971001T160000,19971003T160000," + "19971013T160000,19971015T160000,19971017T160000,19971027T170000," + "19971029T170000,19971031T170000,19971110T170000,19971112T170000," + "19971114T170000,19971124T170000,19971126T170000,19971128T170000," + "19971208T170000,19971210T170000,19971212T170000,19971222T170000", null, PST); + } + + @MediumTest + public void testEveryOtherWeekOnTuThFor8Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH", "19970902", 8, "19970902,19970904,19970916,19970918,19970930," + "19971002,19971014,19971016"); + } + + @MediumTest + public void testMonthlyOnThe1stFridayFor10Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=10;BYDAY=1FR", "19970905", 10, "19970905,19971003,19971107,19971205,19980102," + "19980206,19980306,19980403,19980501,19980605"); + } + + @MediumTest + public void testMonthlyOnThe1stFridayUntilDec24() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;UNTIL=19971224T000000Z;BYDAY=1FR", "19970905", 4, "19970905,19971003,19971107,19971205"); + } + + @MediumTest + public void testEveryOtherMonthOnThe1stAndLastSundayFor10Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU", "19970907", 10, "19970907,19970928,19971102,19971130,19980104," + "19980125,19980301,19980329,19980503,19980531"); + } + + @MediumTest + public void testMonthlyOnTheSecondToLastMondayOfTheMonthFor6Months() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO", "19970922", 6, "19970922,19971020,19971117,19971222,19980119," + "19980216"); + } + + @MediumTest + public void testMonthlyOnTheThirdToLastDay() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTHDAY=-3", "19970928", 6, "19970928,19971029,19971128,19971229,19980129,19980226,..."); + } + + @MediumTest + public void testMonthlyOnThe2ndAnd15thFor10Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15", "19970902", 10, "19970902,19970915,19971002,19971015,19971102," + "19971115,19971202,19971215,19980102,19980115"); + } + + @MediumTest + public void testMonthlyOnTheFirstAndLastFor10Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1", "19970930", 10, "19970930,19971001,19971031,19971101,19971130," + "19971201,19971231,19980101,19980131,19980201"); + } + + @MediumTest + public void testEvery18MonthsOnThe10thThru15thFor10Occ() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,\n" + " 15", "19970910", 10, "19970910,19970911,19970912,19970913,19970914," + "19970915,19990310,19990311,19990312,19990313"); + } + + @MediumTest + public void testEveryTuesdayEveryOtherMonth() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU", "19970902", 18, "19970902,19970909,19970916,19970923,19970930," + "19971104,19971111,19971118,19971125,19980106," + "19980113,19980120,19980127,19980303,19980310," + "19980317,19980324,19980331,..."); + } + + @MediumTest + public void testYearlyInJuneAndJulyFor10Occurrences() throws Exception { + // Note: Since none of the BYDAY, BYMONTHDAY or BYYEARDAY components + // are specified, the day is gotten from DTSTART + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7", "19970610", 10, "19970610,19970710,19980610,19980710,19990610," + "19990710,20000610,20000710,20010610,20010710"); + } + + @MediumTest + public void testEveryOtherYearOnJanuaryFebruaryAndMarchFor10Occurrences() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3", "19970310", 10, "19970310,19990110,19990210,19990310,20010110," + "20010210,20010310,20030110,20030210,20030310"); + } + + //Fails: wrong dates + @MediumTest + @Suppress + public void testEvery3rdYearOnThe1st100thAnd200thDayFor10Occurrences() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200", "19970101", 10, "19970101,19970410,19970719,20000101,20000409," + "20000718,20030101,20030410,20030719,20060101"); + } + + // Fails: infinite loop + @MediumTest + @Suppress + public void testEvery20thMondayOfTheYearForever() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=20MO", "19970519", 3, "19970519,19980518,19990517,..."); + } + + // Fails: generates wrong dates + @MediumTest + @Suppress + public void testMondayOfWeekNumber20WhereTheDefaultStartOfTheWeekIsMonday() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO", "19970512", 3, "19970512,19980511,19990517,..."); + } + + @MediumTest + public void testEveryThursdayInMarchForever() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH", "19970313", 11, "19970313,19970320,19970327,19980305,19980312," + "19980319,19980326,19990304,19990311,19990318," + "19990325,..."); + } + + //Fails: wrong dates + @MediumTest + @Suppress + public void testEveryThursdayButOnlyDuringJuneJulyAndAugustForever() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8", "19970605", 39, "19970605,19970612,19970619,19970626,19970703," + "19970710,19970717,19970724,19970731,19970807," + "19970814,19970821,19970828,19980604,19980611," + "19980618,19980625,19980702,19980709,19980716," + "19980723,19980730,19980806,19980813,19980820," + "19980827,19990603,19990610,19990617,19990624," + "19990701,19990708,19990715,19990722,19990729," + "19990805,19990812,19990819,19990826,..."); + } + + //Fails: infinite loop + @MediumTest + @Suppress + public void testEveryFridayThe13thForever() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13", "19970902", 5, "19980213,19980313,19981113,19990813,20001013," + "..."); + } + + @MediumTest + public void testTheFirstSaturdayThatFollowsTheFirstSundayOfTheMonthForever() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13", "19970913", 10, "19970913,19971011,19971108,19971213,19980110," + "19980207,19980307,19980411,19980509,19980613," + "..."); + } + + @MediumTest + public void testEvery4YearsThe1stTuesAfterAMonInNovForever() throws Exception { + // US Presidential Election Day + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,\n" + " 5,6,7,8", "19961105", 3, "19961105,20001107,20041102,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testThe3rdInstanceIntoTheMonthOfOneOfTuesWedThursForNext3Months() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3", "19970904", 3, "19970904,19971007,19971106"); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testThe2ndToLastWeekdayOfTheMonth() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2", "19970929", 7, "19970929,19971030,19971127,19971230,19980129," + "19980226,19980330,..."); + } + + // Fails: infinite loop + @MediumTest + @Suppress + public void testEvery3HoursFrom900AmTo500PmOnASpecificDay() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=HOURLY;INTERVAL=3;UNTIL=19970903T010000Z", "19970902", 7, "00000902,19970909,19970900,19970912,19970900," + "19970915,19970900"); + } + + // Fails: infinite loop + @MediumTest + @Suppress + public void testEvery15MinutesFor6Occurrences() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MINUTELY;INTERVAL=15;COUNT=6", "19970902", 13, "00000902,19970909,19970900,19970909,19970915," + "19970909,19970930,19970909,19970945,19970910," + "19970900,19970910,19970915"); + } + + @MediumTest + @Suppress + public void testEveryHourAndAHalfFor4Occurrences() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MINUTELY;INTERVAL=90;COUNT=4", "19970902", 9, "00000902,19970909,19970900,19970910,19970930," + "19970912,19970900,19970913,19970930"); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testAnExampleWhereTheDaysGeneratedMakesADifferenceBecauseOfWkst() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO", "19970805", 4, "19970805,19970810,19970819,19970824"); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testAnExampleWhereTheDaysGeneratedMakesADifferenceBecauseOfWkst2() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU", "19970805", 8, "19970805,19970817,19970819,19970831"); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testWithByDayAndByMonthDayFilter() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;COUNT=4;BYDAY=TU,SU;" + "BYMONTHDAY=13,14,15,16,17,18,19,20", "19970805", 8, "19970817,19970819,19970914,19970916"); + } + + // Failed: wrong dates + @MediumTest + @Suppress + public void testAnnuallyInAugustOnTuesAndSunBetween13thAnd20th() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,SU;" + "BYMONTHDAY=13,14,15,16,17,18,19,20;BYMONTH=8", "19970605", 8, "19970817,19970819,19980816,19980818"); + } + + // Failed: wrong dates + @MediumTest + @Suppress + public void testLastDayOfTheYearIsASundayOrTuesday() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;COUNT=4;BYDAY=TU,SU;BYYEARDAY=-1", "19940605", 8, "19951231,19961231,20001231,20021231"); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testLastWeekdayOfMonth() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYSETPOS=-1;BYDAY=-1MO,-1TU,-1WE,-1TH,-1FR", "19940605", 8, "19940630,19940729,19940831,19940930," + "19941031,19941130,19941230,19950131,..."); + } + + // Fails: generates wrong dates + @MediumTest + @Suppress + public void testMonthsThatStartOrEndOnFriday() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTHDAY=1,-1;BYDAY=FR;COUNT=6", "19940605", 8, "19940701,19940930,19950331,19950630,19950901,19951201"); + } + + // Fails: can't go that far into future + @MediumTest + @Suppress + public void testCenturiesThatAreNotLeapYears() throws Exception { + // I can't think of a good reason anyone would want to specify both a + // month day and a year day, so here's a really contrived example + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=100;BYYEARDAY=60;BYMONTHDAY=1", "19000101", 4, "19000301,21000301,22000301,23000301,...", null, "25000101", UTC); + } + + // Fails: generates instances when it shouldn't + @MediumTest + @Suppress + public void testNoInstancesGenerated() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=DAILY;UNTIL=19990101", "20000101", 4, ""); + } + + // Fails: generates instances when it shouldn't + @MediumTest + @Suppress + public void testNoInstancesGenerated2() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30", "20000101", 4, ""); + } + + // Fails: generates instances when it shouldn't + @MediumTest + @Suppress + public void testNoInstancesGenerated3() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=4;BYYEARDAY=366", "20000101", 4, ""); + } + + //Fails: wrong dates + @MediumTest + @Suppress + public void testLastWeekdayOfMarch() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTH=3;BYDAY=SA,SU;BYSETPOS=-1", "20000101", 4, "20000326,20010331,20020331,20030330,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testFirstWeekdayOfMarch() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTH=3;BYDAY=SA,SU;BYSETPOS=1", "20000101", 4, "20000304,20010303,20020302,20030301,..."); + } + + // January 1999 + // Mo Tu We Th Fr Sa Su + // 1 2 3 // < 4 days, so not a week + // 4 5 6 7 8 9 10 + + // January 2000 + // Mo Tu We Th Fr Sa Su + // 1 2 // < 4 days, so not a week + // 3 4 5 6 7 8 9 + + // January 2001 + // Mo Tu We Th Fr Sa Su + // 1 2 3 4 5 6 7 + // 8 9 10 11 12 13 14 + + // January 2002 + // Mo Tu We Th Fr Sa Su + // 1 2 3 4 5 6 + // 7 8 9 10 11 12 13 + + /** + * Find the first weekday of the first week of the year. + * The first week of the year may be partial, and the first week is considered + * to be the first one with at least four days. + */ + // Fails: wrong dates + @MediumTest + @Suppress + public void testFirstWeekdayOfFirstWeekOfYear() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=1;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1", "19990101", 4, "19990104,20000103,20010101,20020101,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testFirstSundayOfTheYear1() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=1;BYDAY=SU", "19990101", 4, "19990110,20000109,20010107,20020106,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testFirstSundayOfTheYear2() throws Exception { + // TODO(msamuel): is this right? + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=1SU", "19990101", 4, "19990103,20000102,20010107,20020106,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testFirstSundayOfTheYear3() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=SU;BYYEARDAY=1,2,3,4,5,6,7,8,9,10,11,12,13" + ";BYSETPOS=1", "19990101", 4, "19990103,20000102,20010107,20020106,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testFirstWeekdayOfYear() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1", "19990101", 4, "19990101,20000103,20010101,20020101,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testLastWeekdayOfFirstWeekOfYear() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=1;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1", "19990101", 4, "19990108,20000107,20010105,20020104,..."); + } + + // January 1999 + // Mo Tu We Th Fr Sa Su + // 1 2 3 + // 4 5 6 7 8 9 10 + // 11 12 13 14 15 16 17 + // 18 19 20 21 22 23 24 + // 25 26 27 28 29 30 31 + + // Fails: wrong dates + @MediumTest + @Suppress + public void testSecondWeekday1() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=2", "19990101", 4, "19990105,19990112,19990119,19990126,..."); + } + + // January 1997 + // Mo Tu We Th Fr Sa Su + // 1 2 3 4 5 + // 6 7 8 9 10 11 12 + // 13 14 15 16 17 18 19 + // 20 21 22 23 24 25 26 + // 27 28 29 30 31 + + // Fails: wrong dates + @MediumTest + @Suppress + public void testSecondWeekday2() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=2", "19970101", 4, "19970102,19970107,19970114,19970121,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testByYearDayAndByDayFilterInteraction() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYYEARDAY=15;BYDAY=3MO", "19990101", 4, "20010115,20070115,20180115,20240115,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testByDayWithNegWeekNoAsFilter() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;BYMONTHDAY=26;BYDAY=-1FR", "19990101", 4, "19990226,19990326,19991126,20000526,..."); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testLastWeekOfTheYear() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYWEEKNO=-1", "19990101", 6, "19991227,19991228,19991229,19991230,19991231,20001225,..."); + } + + // Fails: not enough dates generated + @MediumTest + @Suppress + public void testUserSubmittedTest1() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;INTERVAL=2;WKST=WE;BYDAY=SU,TU,TH,SA" + ";UNTIL=20000215T113000Z", "20000127T033000", 20, "20000127T033000,20000129T033000,20000130T033000,20000201T033000," + "20000210T033000,20000212T033000,20000213T033000,20000215T033000"); + } + + @MediumTest + public void testAdvanceTo1() throws Exception { + // a bunch of tests grabbed from above with an advance-to date tacked on + + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH", "19970313", 11, + /*"19970313,19970320,19970327,"*/"19980305,19980312," + "19980319,19980326,19990304,19990311,19990318," + "19990325,20000302,20000309,20000316,...", "19970601", UTC); + } + + // Fails: infinite loop + @MediumTest + @Suppress + public void testAdvanceTo2() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYDAY=20MO", "19970519", 3, + /*"19970519,"*/"19980518,19990517,20000515,...", "19980515", UTC); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testAdvanceTo3() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=3;UNTIL=20090101;BYYEARDAY=1,100,200", "19970101", 10, + /*"19970101,19970410,19970719,20000101,"*/"20000409," + "20000718,20030101,20030410,20030719,20060101,20060410,20060719," + "20090101", "20000228", UTC); + } + + //Fails: wrong dates + @MediumTest + @Suppress + public void testAdvanceTo4() throws Exception { + // make sure that count preserved + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200", "19970101", 10, + /*"19970101,19970410,19970719,20000101,"*/"20000409," + "20000718,20030101,20030410,20030719,20060101", "20000228", UTC); + } + + // Fails: too many dates + @MediumTest + @Suppress + public void testAdvanceTo5() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3", "19970310", 10, + /*"19970310,"*/"19990110,19990210,19990310,20010110," + "20010210,20010310,20030110,20030210,20030310", "19980401", UTC); + } + + @MediumTest + public void testAdvanceTo6() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;UNTIL=19971224", "19970902", 25, + /*"19970902,19970909,19970916,19970923,"*/"19970930," + "19971007,19971014,19971021,19971028,19971104," + "19971111,19971118,19971125,19971202,19971209," + "19971216,19971223", "19970930", UTC); + } + + @MediumTest + public void testAdvanceTo7() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=18;BYMONTHDAY=10,11,12,13,14,\n" + " 15", "19970910", 5, + /*"19970910,19970911,19970912,19970913,19970914," + + "19970915,"*/"19990310,19990311,19990312,19990313,19990314,...", "19990101", UTC); + } + + @MediumTest + public void testAdvanceTo8() throws Exception { + // advancing into the past + runRecurrenceIteratorTest("RRULE:FREQ=MONTHLY;INTERVAL=18;BYMONTHDAY=10,11,12,13,14,\n" + " 15", "19970910", 11, "19970910,19970911,19970912,19970913,19970914," + "19970915,19990310,19990311,19990312,19990313,19990314,...", "19970901", UTC); + } + + // Fails: wrong dates + @MediumTest + @Suppress + public void testAdvanceTo9() throws Exception { + // skips first instance + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=100;BYMONTH=2;BYMONTHDAY=29", "19000101", 5, + // would return 2000 + "24000229,28000229,32000229,36000229,40000229,...", "20040101", UTC); + } + + // Infinite loop in native code (bug 1686327) + @MediumTest + @Suppress + public void testAdvanceTo10() throws Exception { + // filter hits until date before first instnace + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;INTERVAL=100;BYMONTH=2;BYMONTHDAY=29;UNTIL=21000101", "19000101", 5, "", "20040101", UTC); + } + + // Fails: generates wrong dates + @MediumTest + @Suppress + public void testAdvanceTo11() throws Exception { + // advancing something that returns no instances + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30", "20000101", 10, "", "19970901", UTC); + } + + // Fails: generates wrong dates + @MediumTest + @Suppress + public void testAdvanceTo12() throws Exception { + // advancing something that returns no instances and has a BYSETPOS rule + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=30,31;BYSETPOS=1", "20000101", 10, "", "19970901", UTC); + } + + // Fails: generates wrong dates + @MediumTest + @Suppress + public void testAdvanceTo13() throws Exception { + // advancing way past year generator timeout + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=28", "20000101", 10, "", "25000101", UTC); + } + + /** + * a testcase that yielded dupes due to bysetPos evilness + */ + @MediumTest + @Suppress + public void testCaseThatYieldedDupes() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=1;BYMONTH=9,1,12,8" + ";BYMONTHDAY=-9,-29,24;BYSETPOS=-1,-4,10,-6,-1,-10,-10,-9,-8", "20060528", 200, "20060924,20061203,20061224,20070902,20071223,20080803,20080824," + "20090823,20100103,20100124,20110123,20120902,20121223,20130922," + "20140803,20140824,20150823,20160103,20160124,20170924,20171203," + "20171224,20180902,20181223,20190922,20200823,20210103,20210124," + "20220123,20230924,20231203,20231224,20240922,20250803,20250824," + "20260823,20270103,20270124,20280123,20280924,20281203,20281224," + "20290902,20291223,20300922,20310803,20310824,20330123,20340924," + "20341203,20341224,20350902,20351223,20360803,20360824,20370823," + "20380103,20380124,20390123,20400902,20401223,20410922,20420803," + "20420824,20430823,20440103,20440124,20450924,20451203,20451224," + "20460902,20461223,20470922,20480823,20490103,20490124,20500123," + "20510924,20511203,20511224,20520922,20530803,20530824,20540823," + "20550103,20550124,20560123,20560924,20561203,20561224,20570902," + "20571223,20580922,20590803,20590824,20610123,20620924,20621203," + "20621224,20630902,20631223,20640803,20640824,20650823,20660103," + "20660124,20670123,20680902,20681223,20690922,20700803,20700824," + "20710823,20720103,20720124,20730924,20731203,20731224,20740902," + "20741223,20750922,20760823,20770103,20770124,20780123,20790924," + "20791203,20791224,20800922,20810803,20810824,20820823,20830103," + "20830124,20840123,20840924,20841203,20841224,20850902,20851223," + "20860922,20870803,20870824,20890123,20900924,20901203,20901224," + "20910902,20911223,20920803,20920824,20930823,20940103,20940124," + "20950123,20960902,20961223,20970922,20980803,20980824,20990823," + "21000103,21000124,21010123,21020924,21021203,21021224,21030902," + "21031223,21040803,21040824,21050823,21060103,21060124,21070123," + "21080902,21081223,21090922,21100803,21100824,21110823,21120103," + "21120124,21130924,21131203,21131224,21140902,21141223,21150922," + "21160823,21170103,21170124,21180123,21190924,21191203,21191224," + "21200922,21210803,21210824,21220823,..."); + } + + @MediumTest + public void testEveryThursdayinMarchEachYear() throws Exception { + runRecurrenceIteratorTest("RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=TH", "20100304", 9, "20100304,20100311,20100318,20100325,20110303,20110310,20110317,20110324,20110331", null, "20111231", UTC); + } +} diff --git a/tests/src/com/android/calendarcommon2/RecurrenceProcessorTest.java b/tests/src/com/android/calendarcommon2/RecurrenceProcessorTest.java new file mode 100644 index 0000000..af850f8 --- /dev/null +++ b/tests/src/com/android/calendarcommon2/RecurrenceProcessorTest.java @@ -0,0 +1,2537 @@ +/* //device/content/providers/pim/RecurrenceProcessorTest.java +** +** Copyright 2006, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +package com.android.calendarcommon2; + +import android.os.Debug; +import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.SmallTest; +import android.text.TextUtils; +import android.text.format.Time; +import android.util.Log; +import android.util.TimeFormatException; +import junit.framework.TestCase; + +import java.util.TreeSet; + +public class RecurrenceProcessorTest extends TestCase { + private static final String TAG = "RecurrenceProcessorTest"; + private static final boolean SPEW = true; + private static final boolean METHOD_TRACE = false; + + private static String[] getFormattedDates(long[] dates, Time time) { + String[] out = new String[dates.length]; + int i = 0; + for (long date : dates) { + time.set(date); + out[i] = time.format2445(); + ++i; + } + return out; + } + + private static void printLists(String[] expected, String[] out) { + Log.i(TAG, " expected out"); + int i; + for (i = 0; i < expected.length && i < out.length; i++) { + Log.i(TAG, " [" + i + "] " + expected[i] + + " " + out[i]); + } + for (; i < expected.length; i++) { + Log.i(TAG, " [" + i + "] " + expected[i]); + } + for (; i < out.length; i++) { + Log.i(TAG, " [" + i + "] " + out[i]); + } + } + + public void verifyRecurrence(String dtstartStr, String rrule, String rdate, String exrule, + String exdate, String rangeStartStr, String rangeEndStr, String[] expected) + throws Exception { + verifyRecurrence(dtstartStr, rrule, rdate, exrule, exdate, rangeStartStr, + rangeEndStr, expected, expected[expected.length - 1]); + } + + public void verifyRecurrence(String dtstartStr, String rrule, String rdate, String exrule, + String exdate, String rangeStartStr, String rangeEndStr, String[] expected, + String last) throws Exception { + + // note that the zulu of all parameters here must be the same, expand + // doesn't work otherwise + + if (SPEW) { + Log.i(TAG, "DTSTART:" + dtstartStr + + " RRULE:" + rrule + + " RDATE:" + rdate + + " EXRULE:" + exrule + + " EXDATE:" + exdate); + } + + // we could use any timezone, incl. UTC, but we use a non-UTC + // timezone to make sure there are no UTC assumptions in the + // recurrence processing code. + String tz = "America/Los_Angeles"; + Time dtstart = new Time(tz); + Time rangeStart = new Time(tz); + Time rangeEnd = new Time(tz); + Time outCal = new Time(tz); + + dtstart.parse(dtstartStr); + + rangeStart.parse(rangeStartStr); + rangeEnd.parse(rangeEndStr); + + if (METHOD_TRACE) { + String fn = "/tmp/trace/" + this.getClass().getName().replace('$', '_'); + String df = fn + ".data"; + String kf = fn + ".key"; + Debug.startMethodTracing(fn, 8 * 1024 * 1024); + } + + RecurrenceProcessor rp = new RecurrenceProcessor(); + RecurrenceSet recur = new RecurrenceSet(rrule, rdate, exrule, exdate); + + long[] out = rp.expand(dtstart, recur, rangeStart.toMillis(false /* use isDst */), + rangeEnd.toMillis(false /* use isDst */)); + + if (METHOD_TRACE) { + Debug.stopMethodTracing(); + } + + int count = out.length; + String[] actual = getFormattedDates(out, outCal); + + if (count != expected.length) { + if (SPEW) { + Log.i(TAG, "DTSTART:" + dtstartStr + " RRULE:" + rrule); + printLists(expected, actual); + } + throw new RuntimeException("result lengths don't match. " + + " expected=" + expected.length + + " actual=" + count); + } + + for (int i = 0; i < count; i++) { + String s = actual[i]; + if (!s.equals(expected[i])) { + if (SPEW) { + Log.i(TAG, "DTSTART:" + dtstartStr + " RRULE:" + rrule); + printLists(expected, actual); + Log.i(TAG, "i=" + i); + } + throw new RuntimeException("expected[" + i + "]=" + + expected[i] + " actual=" + actual[i]); + } + } + + long lastOccur = rp.getLastOccurence(dtstart, rangeEnd, recur); + if (lastOccur == 0 && out.length == 0) { + // No occurrence found and 0 returned for lastOccur, this is ok. + return; + } + long lastMillis = -1; + long expectedMillis = -1; + String lastStr = ""; + if (lastOccur != -1) { + outCal.set(lastOccur); + lastStr = outCal.format2445(); + lastMillis = outCal.toMillis(true /* ignore isDst */); + } + if (last != null && last.length() > 0) { + Time expectedLast = new Time(tz); + expectedLast.parse(last); + expectedMillis = expectedLast.toMillis(true /* ignore isDst */); + } + if (lastMillis != expectedMillis) { + if (SPEW) { + Log.i(TAG, "DTSTART:" + dtstartStr + " RRULE:" + rrule); + Log.i(TAG, "Expected: " + last + "; Actual: " + lastStr); + printLists(expected, actual); + } + + throw new RuntimeException("expected last occurrence date does not match." + + " expected=" + last + + " actual=" + lastStr); + } + } + + @SmallTest + public void testMonthly0() throws Exception { + verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060205T100000", + "20060305T100000", + "20060405T100000" + }); + } + + @SmallTest + public void testMonthly1() throws Exception { + verifyRecurrence("20060205T100000", "FREQ=MONTHLY;INTERVAL=2;COUNT=3", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060205T100000", + "20060405T100000", + "20060605T100000" + }); + } + + @SmallTest + public void testMonthly2() throws Exception { + // this tests wrapping the year when the interval isn't divisible + // by 12 + verifyRecurrence("20060205T100000", "FREQ=MONTHLY;INTERVAL=5;COUNT=5", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060205T100000", + "20060705T100000", + "20061205T100000", + "20070505T100000", + "20071005T100000" + }); + } + + @SmallTest + public void testMonthly3() throws Exception { + // with a simple BYDAY, spanning two months + verifyRecurrence("20060104T123456", + "FREQ=MONTHLY;UNTIL=20060201T200000Z;BYDAY=TU,WE", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060104T123456", + "20060110T123456", + "20060111T123456", + "20060117T123456", + "20060118T123456", + "20060124T123456", + "20060125T123456", + "20060131T123456" + }, + "20060201T120000"); + } + + @SmallTest + public void testMonthly4() throws Exception { + // with a BYDAY with +1 / etc., spanning two months and + // one day which isn't in the result + verifyRecurrence("20060101T123456", + "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYDAY=+1SU,+2MO,+3TU,+4WE,+5MO,+5TU,+5WE,+6TH", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060101T123456", + "20060109T123456", + "20060117T123456", + "20060125T123456", + "20060130T123456", + "20060131T123456", + "20060205T123456", + "20060213T123456", + "20060221T123456", + "20060222T123456" + }, + "20060301T120000"); + } + + @SmallTest + public void testMonthly5() throws Exception { + // with a BYDAY with -1 / etc. + verifyRecurrence("20060201T123456", + "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYDAY=-1SU,-2MO,-3TU,-4TU,-4WE,-5MO,-5TU,-5WE,-6TH", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060201T123456", + "20060207T123456", + "20060214T123456", + "20060220T123456", + "20060226T123456" + }, + "20060301T120000"); + } + + @SmallTest + public void testMonthly6() throws Exception { + // With positive BYMONTHDAYs + verifyRecurrence("20060201T123456", + "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYMONTHDAY=1,2,5,28,31", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060201T123456", + "20060202T123456", + "20060205T123456", + "20060228T123456" + }, + "20060301T120000"); + } + + @SmallTest + public void testMonthly7() throws Exception { + // With negative BYMONTHDAYs + verifyRecurrence("20060201T123456", + "FREQ=MONTHLY;UNTIL=20060301T200000Z;BYMONTHDAY=-1,-5,-27,-28,-31", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060201T123456", + "20060202T123456", + "20060224T123456", + "20060228T123456" + }, + "20060301T120000"); + } + + @SmallTest + public void testMonthly8() throws Exception { + verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3", + "America/Los_Angeles;20060207T140000,20060307T160000,20060407T180000", + null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060205T100000", + "20060207T140000", + "20060305T100000", + "20060307T160000", + "20060405T100000", + "20060407T180000", + }); + } + + @SmallTest + public void testMonthly9() throws Exception { + verifyRecurrence("20060205T100000", null /* rrule */, + "America/Los_Angeles;20060207T140000,20060307T160000,20060407T180000", + null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060207T140000", + "20060307T160000", + "20060407T180000", + }); + } + + @SmallTest + public void testMonthly10() throws Exception { + verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3\nFREQ=WEEKLY;COUNT=2", + "America/Los_Angeles;20060207T140000,20060307T160000,20060407T180000", + null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060205T100000", + "20060207T140000", + "20060212T100000", + "20060305T100000", + "20060307T160000", + "20060405T100000", + "20060407T180000", + }); + } + + @SmallTest + public void testMonthly11() throws Exception { + verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3\nFREQ=WEEKLY;COUNT=2", + null /* rdate */, + "FREQ=MONTHLY;COUNT=2", null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060212T100000", + "20060405T100000", + }); + } + + @SmallTest + public void testMonthly12() throws Exception { + verifyRecurrence("20060205T100000", "FREQ=MONTHLY;COUNT=3\nFREQ=WEEKLY;COUNT=2", + null /* rdate */, null /* exrule */, + "20060212T180000Z,20060405T170000Z" /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060205T100000", + "20060305T100000", + }); + } + + @SmallTest + public void testMonthly13() throws Exception { + verifyRecurrence("20060101T100000", "FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13;COUNT=10", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20101231T000000", + new String[]{ + "20060101T100000", + "20060113T100000", + "20061013T100000", + "20070413T100000", + "20070713T100000", + "20080613T100000", + "20090213T100000", + "20090313T100000", + "20091113T100000", + "20100813T100000", + }); + } + + @SmallTest + public void testMonthly14() throws Exception { + verifyRecurrence("20110103T100000", "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1", + null /* rdate */, null /* exrule */, null /* exdate */, + "20110101T000000", "20110331T235959", + new String[]{ + "20110103T100000", + "20110131T100000", + "20110201T100000", + "20110228T100000", + "20110301T100000", + "20110331T100000", + }); + } + + @SmallTest + public void testMonthly15() throws Exception { + verifyRecurrence("20110703T100000", "FREQ=MONTHLY;BYDAY=SA,SU;BYSETPOS=2,-2", + null /* rdate */, null /* exrule */, null /* exdate */, + "20110701T000000", "20110931T235959", + new String[]{ + "20110703T100000", + "20110730T100000", + "20110807T100000", + "20110827T100000", + "20110904T100000", + "20110924T100000", + }); + } + + @SmallTest + public void testWeekly0() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;COUNT=3", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060222T100000", + "20060301T100000" + }); + } + + @SmallTest + public void testWeekly1() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060301T100000Z", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060222T100000" + }, "20060301T020000"); + } + + @SmallTest + public void testWeekly2() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060301T100001Z", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060222T100000" + }, "20060301T020001"); + } + + @SmallTest + public void testWeekly3() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060301T090000Z", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060222T100000" + }, "20060301T010000"); + } + + @SmallTest + public void testWeekly4() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060311T100001Z;BYDAY=TU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060221T100000", + "20060228T100000", + "20060307T100000" + }, "20060311T020001"); + } + + // until without "Z" + @SmallTest + public void testWeekly4a() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060311T100001;BYDAY=TU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060221T100000", + "20060228T100000", + "20060307T100000" + }, "20060311T100001"); + } + + @SmallTest + public void testWeekly5() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060311T100001Z;BYDAY=TH", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060216T100000", + "20060223T100000", + "20060302T100000", + "20060309T100000" + }, "20060311T020001"); + } + + @SmallTest + public void testWeekly6() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060309T100001Z;BYDAY=WE,TH", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060216T100000", + "20060222T100000", + "20060223T100000", + "20060301T100000", + "20060302T100000", + "20060308T100000" + }, "20060309T020001"); + } + + @SmallTest + public void testWeekly7() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060220T100001Z;BYDAY=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060219T100000" + }, "20060220T020001"); + } + + @SmallTest + public void testWeekly8() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;COUNT=4;WKST=SU;BYDAY=TU,TH", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060216T100000", + "20060221T100000", + "20060223T100000" + }); + } + + @SmallTest + public void testWeekly9() throws Exception { + verifyRecurrence("19970805T100000", + "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU", // uses default WKST=MO + null /* rdate */, null /* exrule */, null /* exdate */, + "19970101T000000", "19980101T000000", + new String[]{ + "19970805T100000", + "19970810T100000", + "19970819T100000", + "19970824T100000", + }); + } + + @SmallTest + public void testWeekly10() throws Exception { + verifyRecurrence("19970805T100000", + "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "19970101T000000", "19980101T000000", + new String[]{ + "19970805T100000", + "19970817T100000", + "19970819T100000", + "19970831T100000", + }); + } + + // BUG 1658567: UNTIL=date + @SmallTest + public void testWeekly11() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=20060220;BYDAY=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060219T100000" + }, "20060220T000000"); + } + + @SmallTest + public void testWeekly12() throws Exception { + try { + verifyRecurrence("20060215T100000", "FREQ=WEEKLY;UNTIL=junk;BYDAY=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060219T100000" + }, "20060220T020001"); + fail("Bad UNTIL string failed to throw exception"); + } catch (TimeFormatException e) { + // expected + } + } + + /** + * Test repeating weekly event with dtstart and dtend (only one occurrence) + * See bug #3267616 + * @throws Exception + */ + @SmallTest + public void testWeekly13() throws Exception { + verifyRecurrence("20101117T150000", + "FREQ=WEEKLY;BYDAY=WE", + null /* rdate */, null /* exrule */, null /* exdate */, + "20101117T150000", "20101117T160000", + new String[]{ "20101117T150000" }); + } + + @SmallTest + public void testWeekly14() throws Exception { + verifyRecurrence("19970805T100000", + "FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=TH", + null /* rdate */, null /* exrule */, null /* exdate */, + "19970101T000000", "19980101T000000", + new String[]{ + "19970805T100000", + "19970817T100000", + "19970819T100000", + "19970831T100000", + }); + } + + @SmallTest + public void testDaily0() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=DAILY;COUNT=3", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060216T100000", + "20060217T100000" + }); + } + + @SmallTest + public void testDaily1() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=DAILY;UNTIL=20060302T100001Z", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060216T100000", + "20060217T100000", + "20060218T100000", + "20060219T100000", + "20060220T100000", + "20060221T100000", + "20060222T100000", + "20060223T100000", + "20060224T100000", + "20060225T100000", + "20060226T100000", + "20060227T100000", + "20060228T100000", + "20060301T100000" + }, "20060302T100001Z"); + } + + @SmallTest + public void testDaily2() throws Exception { + verifyRecurrence("20060215T100000", "FREQ=DAILY;UNTIL=20060220T100001Z;BYDAY=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060215T100000", + "20060219T100000" + }, "20060220T020001"); + } + + @SmallTest + public void testDaily3() throws Exception { + verifyRecurrence("20060219T100000", + "FREQ=DAILY;UNTIL=20060225T180304Z;BYDAY=SU,MO,SA;BYHOUR=5,10,22;BYMINUTE=3,59;BYSECOND=2,5", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20080101T000000", + new String[]{ + "20060219T100000", + "20060219T100302", + "20060219T100305", + "20060219T105902", + "20060219T105905", + "20060219T220302", + "20060219T220305", + "20060219T225902", + "20060219T225905", + "20060220T050302", + "20060220T050305", + "20060220T055902", + "20060220T055905", + "20060220T100302", + "20060220T100305", + "20060220T105902", + "20060220T105905", + "20060220T220302", + "20060220T220305", + "20060220T225902", + "20060220T225905", + "20060225T050302", + "20060225T050305", + "20060225T055902", + "20060225T055905", + "20060225T100302" + }, "20060225T100304"); + } + + @MediumTest + public void testFromGoogleCalendar0() throws Exception { + // Tuesday, Thursday (10/2) + verifyRecurrence("20061002T050000", + "FREQ=WEEKLY;UNTIL=20071031T200000Z;INTERVAL=1;BYDAY=TU,TH;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061002T050000", + "20061003T050000", + "20061005T050000", + "20061010T050000", + "20061012T050000", + "20061017T050000", + "20061019T050000", + "20061024T050000", + "20061026T050000", + "20061031T050000", + "20061102T050000", + "20061107T050000", + "20061109T050000", + "20061114T050000", + "20061116T050000", + "20061121T050000", + "20061123T050000", + "20061128T050000", + "20061130T050000", + "20061205T050000", + "20061207T050000", + "20061212T050000", + "20061214T050000", + "20061219T050000", + "20061221T050000", + "20061226T050000", + "20061228T050000", + "20070102T050000", + "20070104T050000", + "20070109T050000", + "20070111T050000", + "20070116T050000", + "20070118T050000", + "20070123T050000", + "20070125T050000", + "20070130T050000", + "20070201T050000", + "20070206T050000", + "20070208T050000", + "20070213T050000", + "20070215T050000", + "20070220T050000", + "20070222T050000", + "20070227T050000", + "20070301T050000", + "20070306T050000", + "20070308T050000", + "20070313T050000", + "20070315T050000", + "20070320T050000", + "20070322T050000", + "20070327T050000", + "20070329T050000", + "20070403T050000", + "20070405T050000", + "20070410T050000", + "20070412T050000", + "20070417T050000", + "20070419T050000", + "20070424T050000", + "20070426T050000", + "20070501T050000", + "20070503T050000", + "20070508T050000", + "20070510T050000", + "20070515T050000", + "20070517T050000", + "20070522T050000", + "20070524T050000", + "20070529T050000", + "20070531T050000", + "20070605T050000", + "20070607T050000", + "20070612T050000", + "20070614T050000", + "20070619T050000", + "20070621T050000", + "20070626T050000", + "20070628T050000", + "20070703T050000", + "20070705T050000", + "20070710T050000", + "20070712T050000", + "20070717T050000", + "20070719T050000", + "20070724T050000", + "20070726T050000", + "20070731T050000", + "20070802T050000", + "20070807T050000", + "20070809T050000", + "20070814T050000", + "20070816T050000", + "20070821T050000", + "20070823T050000", + "20070828T050000", + "20070830T050000", + "20070904T050000", + "20070906T050000", + "20070911T050000", + "20070913T050000", + "20070918T050000", + "20070920T050000", + "20070925T050000", + "20070927T050000", + "20071002T050000", + "20071004T050000", + "20071009T050000", + "20071011T050000", + "20071016T050000", + "20071018T050000", + "20071023T050000", + "20071025T050000", + "20071030T050000", + }, "20071031T130000"); + } + + @MediumTest + public void testFromGoogleCalendar1() throws Exception { + // Mon Wed Fri + verifyRecurrence("20061002T030000", + "FREQ=WEEKLY;UNTIL=20071025T180000Z;INTERVAL=1;BYDAY=MO,WE,FR;", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061002T030000", + "20061004T030000", + "20061006T030000", + "20061009T030000", + "20061011T030000", + "20061013T030000", + "20061016T030000", + "20061018T030000", + "20061020T030000", + "20061023T030000", + "20061025T030000", + "20061027T030000", + "20061030T030000", + "20061101T030000", + "20061103T030000", + "20061106T030000", + "20061108T030000", + "20061110T030000", + "20061113T030000", + "20061115T030000", + "20061117T030000", + "20061120T030000", + "20061122T030000", + "20061124T030000", + "20061127T030000", + "20061129T030000", + "20061201T030000", + "20061204T030000", + "20061206T030000", + "20061208T030000", + "20061211T030000", + "20061213T030000", + "20061215T030000", + "20061218T030000", + "20061220T030000", + "20061222T030000", + "20061225T030000", + "20061227T030000", + "20061229T030000", + "20070101T030000", + "20070103T030000", + "20070105T030000", + "20070108T030000", + "20070110T030000", + "20070112T030000", + "20070115T030000", + "20070117T030000", + "20070119T030000", + "20070122T030000", + "20070124T030000", + "20070126T030000", + "20070129T030000", + "20070131T030000", + "20070202T030000", + "20070205T030000", + "20070207T030000", + "20070209T030000", + "20070212T030000", + "20070214T030000", + "20070216T030000", + "20070219T030000", + "20070221T030000", + "20070223T030000", + "20070226T030000", + "20070228T030000", + "20070302T030000", + "20070305T030000", + "20070307T030000", + "20070309T030000", + "20070312T030000", + "20070314T030000", + "20070316T030000", + "20070319T030000", + "20070321T030000", + "20070323T030000", + "20070326T030000", + "20070328T030000", + "20070330T030000", + "20070402T030000", + "20070404T030000", + "20070406T030000", + "20070409T030000", + "20070411T030000", + "20070413T030000", + "20070416T030000", + "20070418T030000", + "20070420T030000", + "20070423T030000", + "20070425T030000", + "20070427T030000", + "20070430T030000", + "20070502T030000", + "20070504T030000", + "20070507T030000", + "20070509T030000", + "20070511T030000", + "20070514T030000", + "20070516T030000", + "20070518T030000", + "20070521T030000", + "20070523T030000", + "20070525T030000", + "20070528T030000", + "20070530T030000", + "20070601T030000", + "20070604T030000", + "20070606T030000", + "20070608T030000", + "20070611T030000", + "20070613T030000", + "20070615T030000", + "20070618T030000", + "20070620T030000", + "20070622T030000", + "20070625T030000", + "20070627T030000", + "20070629T030000", + "20070702T030000", + "20070704T030000", + "20070706T030000", + "20070709T030000", + "20070711T030000", + "20070713T030000", + "20070716T030000", + "20070718T030000", + "20070720T030000", + "20070723T030000", + "20070725T030000", + "20070727T030000", + "20070730T030000", + "20070801T030000", + "20070803T030000", + "20070806T030000", + "20070808T030000", + "20070810T030000", + "20070813T030000", + "20070815T030000", + "20070817T030000", + "20070820T030000", + "20070822T030000", + "20070824T030000", + "20070827T030000", + "20070829T030000", + "20070831T030000", + "20070903T030000", + "20070905T030000", + "20070907T030000", + "20070910T030000", + "20070912T030000", + "20070914T030000", + "20070917T030000", + "20070919T030000", + "20070921T030000", + "20070924T030000", + "20070926T030000", + "20070928T030000", + "20071001T030000", + "20071003T030000", + "20071005T030000", + "20071008T030000", + "20071010T030000", + "20071012T030000", + "20071015T030000", + "20071017T030000", + "20071019T030000", + "20071022T030000", + "20071024T030000", + }, "20071025T110000"); + } + + @SmallTest + public void testFromGoogleCalendar2() throws Exception { + // Monthly on day 2 + verifyRecurrence("20061002T070000", + "FREQ=MONTHLY;INTERVAL=1;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061002T070000", + "20061102T070000", + "20061202T070000", + "20070102T070000", + "20070202T070000", + "20070302T070000", + "20070402T070000", + "20070502T070000", + "20070602T070000", + "20070702T070000", + "20070802T070000", + "20070902T070000", + "20071002T070000", + "20071102T070000", + "20071202T070000", + "20080102T070000", + "20080202T070000", + "20080302T070000", + "20080402T070000", + "20080502T070000", + "20080602T070000", + "20080702T070000", + "20080802T070000", + "20080902T070000", + "20081002T070000", + "20081102T070000", + "20081202T070000", + }, "20081202T070000"); + } + + @MediumTest + public void testFromGoogleCalendar3() throws Exception { + // Every Weekday + verifyRecurrence("20061002T100000", + "FREQ=WEEKLY;UNTIL=20070215T100000Z;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061002T100000", + "20061003T100000", + "20061004T100000", + "20061005T100000", + "20061006T100000", + "20061009T100000", + "20061010T100000", + "20061011T100000", + "20061012T100000", + "20061013T100000", + "20061016T100000", + "20061017T100000", + "20061018T100000", + "20061019T100000", + "20061020T100000", + "20061023T100000", + "20061024T100000", + "20061025T100000", + "20061026T100000", + "20061027T100000", + "20061030T100000", + "20061031T100000", + "20061101T100000", + "20061102T100000", + "20061103T100000", + "20061106T100000", + "20061107T100000", + "20061108T100000", + "20061109T100000", + "20061110T100000", + "20061113T100000", + "20061114T100000", + "20061115T100000", + "20061116T100000", + "20061117T100000", + "20061120T100000", + "20061121T100000", + "20061122T100000", + "20061123T100000", + "20061124T100000", + "20061127T100000", + "20061128T100000", + "20061129T100000", + "20061130T100000", + "20061201T100000", + "20061204T100000", + "20061205T100000", + "20061206T100000", + "20061207T100000", + "20061208T100000", + "20061211T100000", + "20061212T100000", + "20061213T100000", + "20061214T100000", + "20061215T100000", + "20061218T100000", + "20061219T100000", + "20061220T100000", + "20061221T100000", + "20061222T100000", + "20061225T100000", + "20061226T100000", + "20061227T100000", + "20061228T100000", + "20061229T100000", + "20070101T100000", + "20070102T100000", + "20070103T100000", + "20070104T100000", + "20070105T100000", + "20070108T100000", + "20070109T100000", + "20070110T100000", + "20070111T100000", + "20070112T100000", + "20070115T100000", + "20070116T100000", + "20070117T100000", + "20070118T100000", + "20070119T100000", + "20070122T100000", + "20070123T100000", + "20070124T100000", + "20070125T100000", + "20070126T100000", + "20070129T100000", + "20070130T100000", + "20070131T100000", + "20070201T100000", + "20070202T100000", + "20070205T100000", + "20070206T100000", + "20070207T100000", + "20070208T100000", + "20070209T100000", + "20070212T100000", + "20070213T100000", + "20070214T100000", + }, "20070215T020000"); + } + + @SmallTest + public void testFromGoogleCalendar4() throws Exception { + // Every 5 months on day 2 + verifyRecurrence("20061003T100000", + "FREQ=MONTHLY;INTERVAL=5;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061003T100000", + "20070303T100000", + "20070803T100000", + "20080103T100000", + "20080603T100000", + "20081103T100000", + }, "20081103T100000"); + } + + @MediumTest + public void testFromGoogleCalendar5() throws Exception { + // Tuesday, Thursday (10/3) + verifyRecurrence("20061003T040000", + "FREQ=WEEKLY;INTERVAL=1;BYDAY=TU,TH;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061003T040000", + "20061005T040000", + "20061010T040000", + "20061012T040000", + "20061017T040000", + "20061019T040000", + "20061024T040000", + "20061026T040000", + "20061031T040000", + "20061102T040000", + "20061107T040000", + "20061109T040000", + "20061114T040000", + "20061116T040000", + "20061121T040000", + "20061123T040000", + "20061128T040000", + "20061130T040000", + "20061205T040000", + "20061207T040000", + "20061212T040000", + "20061214T040000", + "20061219T040000", + "20061221T040000", + "20061226T040000", + "20061228T040000", + "20070102T040000", + "20070104T040000", + "20070109T040000", + "20070111T040000", + "20070116T040000", + "20070118T040000", + "20070123T040000", + "20070125T040000", + "20070130T040000", + "20070201T040000", + "20070206T040000", + "20070208T040000", + "20070213T040000", + "20070215T040000", + "20070220T040000", + "20070222T040000", + "20070227T040000", + "20070301T040000", + "20070306T040000", + "20070308T040000", + "20070313T040000", + "20070315T040000", + "20070320T040000", + "20070322T040000", + "20070327T040000", + "20070329T040000", + "20070403T040000", + "20070405T040000", + "20070410T040000", + "20070412T040000", + "20070417T040000", + "20070419T040000", + "20070424T040000", + "20070426T040000", + "20070501T040000", + "20070503T040000", + "20070508T040000", + "20070510T040000", + "20070515T040000", + "20070517T040000", + "20070522T040000", + "20070524T040000", + "20070529T040000", + "20070531T040000", + "20070605T040000", + "20070607T040000", + "20070612T040000", + "20070614T040000", + "20070619T040000", + "20070621T040000", + "20070626T040000", + "20070628T040000", + "20070703T040000", + "20070705T040000", + "20070710T040000", + "20070712T040000", + "20070717T040000", + "20070719T040000", + "20070724T040000", + "20070726T040000", + "20070731T040000", + "20070802T040000", + "20070807T040000", + "20070809T040000", + "20070814T040000", + "20070816T040000", + "20070821T040000", + "20070823T040000", + "20070828T040000", + "20070830T040000", + "20070904T040000", + "20070906T040000", + "20070911T040000", + "20070913T040000", + "20070918T040000", + "20070920T040000", + "20070925T040000", + "20070927T040000", + "20071002T040000", + "20071004T040000", + "20071009T040000", + "20071011T040000", + "20071016T040000", + "20071018T040000", + "20071023T040000", + "20071025T040000", + "20071030T040000", + "20071101T040000", + "20071106T040000", + "20071108T040000", + "20071113T040000", + "20071115T040000", + "20071120T040000", + "20071122T040000", + "20071127T040000", + "20071129T040000", + "20071204T040000", + "20071206T040000", + "20071211T040000", + "20071213T040000", + "20071218T040000", + "20071220T040000", + "20071225T040000", + "20071227T040000", + "20080101T040000", + "20080103T040000", + "20080108T040000", + "20080110T040000", + "20080115T040000", + "20080117T040000", + "20080122T040000", + "20080124T040000", + "20080129T040000", + "20080131T040000", + "20080205T040000", + "20080207T040000", + "20080212T040000", + "20080214T040000", + "20080219T040000", + "20080221T040000", + "20080226T040000", + "20080228T040000", + "20080304T040000", + "20080306T040000", + "20080311T040000", + "20080313T040000", + "20080318T040000", + "20080320T040000", + "20080325T040000", + "20080327T040000", + "20080401T040000", + "20080403T040000", + "20080408T040000", + "20080410T040000", + "20080415T040000", + "20080417T040000", + "20080422T040000", + "20080424T040000", + "20080429T040000", + "20080501T040000", + "20080506T040000", + "20080508T040000", + "20080513T040000", + "20080515T040000", + "20080520T040000", + "20080522T040000", + "20080527T040000", + "20080529T040000", + "20080603T040000", + "20080605T040000", + "20080610T040000", + "20080612T040000", + "20080617T040000", + "20080619T040000", + "20080624T040000", + "20080626T040000", + "20080701T040000", + "20080703T040000", + "20080708T040000", + "20080710T040000", + "20080715T040000", + "20080717T040000", + "20080722T040000", + "20080724T040000", + "20080729T040000", + "20080731T040000", + "20080805T040000", + "20080807T040000", + "20080812T040000", + "20080814T040000", + "20080819T040000", + "20080821T040000", + "20080826T040000", + "20080828T040000", + "20080902T040000", + "20080904T040000", + "20080909T040000", + "20080911T040000", + "20080916T040000", + "20080918T040000", + "20080923T040000", + "20080925T040000", + "20080930T040000", + "20081002T040000", + "20081007T040000", + "20081009T040000", + "20081014T040000", + "20081016T040000", + "20081021T040000", + "20081023T040000", + "20081028T040000", + "20081030T040000", + "20081104T040000", + "20081106T040000", + "20081111T040000", + "20081113T040000", + "20081118T040000", + "20081120T040000", + "20081125T040000", + "20081127T040000", + "20081202T040000", + "20081204T040000", + "20081209T040000", + "20081211T040000", + "20081216T040000", + "20081218T040000", + "20081223T040000", + "20081225T040000", + "20081230T040000", + }, "20081230T040000"); + } + + @MediumTest + public void testFromGoogleCalendar6() throws Exception { + // Weekly on all days + verifyRecurrence("20061003T060000", + "FREQ=WEEKLY;INTERVAL=1;BYDAY=SU,MO,TU,WE,TH,FR,SA;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20071003T060000", + new String[]{ + "20061003T060000", + "20061004T060000", + "20061005T060000", + "20061006T060000", + "20061007T060000", + "20061008T060000", + "20061009T060000", + "20061010T060000", + "20061011T060000", + "20061012T060000", + "20061013T060000", + "20061014T060000", + "20061015T060000", + "20061016T060000", + "20061017T060000", + "20061018T060000", + "20061019T060000", + "20061020T060000", + "20061021T060000", + "20061022T060000", + "20061023T060000", + "20061024T060000", + "20061025T060000", + "20061026T060000", + "20061027T060000", + "20061028T060000", + "20061029T060000", + "20061030T060000", + "20061031T060000", + "20061101T060000", + "20061102T060000", + "20061103T060000", + "20061104T060000", + "20061105T060000", + "20061106T060000", + "20061107T060000", + "20061108T060000", + "20061109T060000", + "20061110T060000", + "20061111T060000", + "20061112T060000", + "20061113T060000", + "20061114T060000", + "20061115T060000", + "20061116T060000", + "20061117T060000", + "20061118T060000", + "20061119T060000", + "20061120T060000", + "20061121T060000", + "20061122T060000", + "20061123T060000", + "20061124T060000", + "20061125T060000", + "20061126T060000", + "20061127T060000", + "20061128T060000", + "20061129T060000", + "20061130T060000", + "20061201T060000", + "20061202T060000", + "20061203T060000", + "20061204T060000", + "20061205T060000", + "20061206T060000", + "20061207T060000", + "20061208T060000", + "20061209T060000", + "20061210T060000", + "20061211T060000", + "20061212T060000", + "20061213T060000", + "20061214T060000", + "20061215T060000", + "20061216T060000", + "20061217T060000", + "20061218T060000", + "20061219T060000", + "20061220T060000", + "20061221T060000", + "20061222T060000", + "20061223T060000", + "20061224T060000", + "20061225T060000", + "20061226T060000", + "20061227T060000", + "20061228T060000", + "20061229T060000", + "20061230T060000", + "20061231T060000", + "20070101T060000", + "20070102T060000", + "20070103T060000", + "20070104T060000", + "20070105T060000", + "20070106T060000", + "20070107T060000", + "20070108T060000", + "20070109T060000", + "20070110T060000", + "20070111T060000", + "20070112T060000", + "20070113T060000", + "20070114T060000", + "20070115T060000", + "20070116T060000", + "20070117T060000", + "20070118T060000", + "20070119T060000", + "20070120T060000", + "20070121T060000", + "20070122T060000", + "20070123T060000", + "20070124T060000", + "20070125T060000", + "20070126T060000", + "20070127T060000", + "20070128T060000", + "20070129T060000", + "20070130T060000", + "20070131T060000", + "20070201T060000", + "20070202T060000", + "20070203T060000", + "20070204T060000", + "20070205T060000", + "20070206T060000", + "20070207T060000", + "20070208T060000", + "20070209T060000", + "20070210T060000", + "20070211T060000", + "20070212T060000", + "20070213T060000", + "20070214T060000", + "20070215T060000", + "20070216T060000", + "20070217T060000", + "20070218T060000", + "20070219T060000", + "20070220T060000", + "20070221T060000", + "20070222T060000", + "20070223T060000", + "20070224T060000", + "20070225T060000", + "20070226T060000", + "20070227T060000", + "20070228T060000", + "20070301T060000", + "20070302T060000", + "20070303T060000", + "20070304T060000", + "20070305T060000", + "20070306T060000", + "20070307T060000", + "20070308T060000", + "20070309T060000", + "20070310T060000", + "20070311T060000", + "20070312T060000", + "20070313T060000", + "20070314T060000", + "20070315T060000", + "20070316T060000", + "20070317T060000", + "20070318T060000", + "20070319T060000", + "20070320T060000", + "20070321T060000", + "20070322T060000", + "20070323T060000", + "20070324T060000", + "20070325T060000", + "20070326T060000", + "20070327T060000", + "20070328T060000", + "20070329T060000", + "20070330T060000", + "20070331T060000", + "20070401T060000", + "20070402T060000", + "20070403T060000", + "20070404T060000", + "20070405T060000", + "20070406T060000", + "20070407T060000", + "20070408T060000", + "20070409T060000", + "20070410T060000", + "20070411T060000", + "20070412T060000", + "20070413T060000", + "20070414T060000", + "20070415T060000", + "20070416T060000", + "20070417T060000", + "20070418T060000", + "20070419T060000", + "20070420T060000", + "20070421T060000", + "20070422T060000", + "20070423T060000", + "20070424T060000", + "20070425T060000", + "20070426T060000", + "20070427T060000", + "20070428T060000", + "20070429T060000", + "20070430T060000", + "20070501T060000", + "20070502T060000", + "20070503T060000", + "20070504T060000", + "20070505T060000", + "20070506T060000", + "20070507T060000", + "20070508T060000", + "20070509T060000", + "20070510T060000", + "20070511T060000", + "20070512T060000", + "20070513T060000", + "20070514T060000", + "20070515T060000", + "20070516T060000", + "20070517T060000", + "20070518T060000", + "20070519T060000", + "20070520T060000", + "20070521T060000", + "20070522T060000", + "20070523T060000", + "20070524T060000", + "20070525T060000", + "20070526T060000", + "20070527T060000", + "20070528T060000", + "20070529T060000", + "20070530T060000", + "20070531T060000", + "20070601T060000", + "20070602T060000", + "20070603T060000", + "20070604T060000", + "20070605T060000", + "20070606T060000", + "20070607T060000", + "20070608T060000", + "20070609T060000", + "20070610T060000", + "20070611T060000", + "20070612T060000", + "20070613T060000", + "20070614T060000", + "20070615T060000", + "20070616T060000", + "20070617T060000", + "20070618T060000", + "20070619T060000", + "20070620T060000", + "20070621T060000", + "20070622T060000", + "20070623T060000", + "20070624T060000", + "20070625T060000", + "20070626T060000", + "20070627T060000", + "20070628T060000", + "20070629T060000", + "20070630T060000", + "20070701T060000", + "20070702T060000", + "20070703T060000", + "20070704T060000", + "20070705T060000", + "20070706T060000", + "20070707T060000", + "20070708T060000", + "20070709T060000", + "20070710T060000", + "20070711T060000", + "20070712T060000", + "20070713T060000", + "20070714T060000", + "20070715T060000", + "20070716T060000", + "20070717T060000", + "20070718T060000", + "20070719T060000", + "20070720T060000", + "20070721T060000", + "20070722T060000", + "20070723T060000", + "20070724T060000", + "20070725T060000", + "20070726T060000", + "20070727T060000", + "20070728T060000", + "20070729T060000", + "20070730T060000", + "20070731T060000", + "20070801T060000", + "20070802T060000", + "20070803T060000", + "20070804T060000", + "20070805T060000", + "20070806T060000", + "20070807T060000", + "20070808T060000", + "20070809T060000", + "20070810T060000", + "20070811T060000", + "20070812T060000", + "20070813T060000", + "20070814T060000", + "20070815T060000", + "20070816T060000", + "20070817T060000", + "20070818T060000", + "20070819T060000", + "20070820T060000", + "20070821T060000", + "20070822T060000", + "20070823T060000", + "20070824T060000", + "20070825T060000", + "20070826T060000", + "20070827T060000", + "20070828T060000", + "20070829T060000", + "20070830T060000", + "20070831T060000", + "20070901T060000", + "20070902T060000", + "20070903T060000", + "20070904T060000", + "20070905T060000", + "20070906T060000", + "20070907T060000", + "20070908T060000", + "20070909T060000", + "20070910T060000", + "20070911T060000", + "20070912T060000", + "20070913T060000", + "20070914T060000", + "20070915T060000", + "20070916T060000", + "20070917T060000", + "20070918T060000", + "20070919T060000", + "20070920T060000", + "20070921T060000", + "20070922T060000", + "20070923T060000", + "20070924T060000", + "20070925T060000", + "20070926T060000", + "20070927T060000", + "20070928T060000", + "20070929T060000", + "20070930T060000", + "20071001T060000", + "20071002T060000", + }, "20071002T060000"); + } + + @MediumTest + public void testFromGoogleCalendar7() throws Exception { + // Every 3 days + verifyRecurrence("20061003T080000", + "FREQ=DAILY;INTERVAL=3;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061003T080000", + "20061006T080000", + "20061009T080000", + "20061012T080000", + "20061015T080000", + "20061018T080000", + "20061021T080000", + "20061024T080000", + "20061027T080000", + "20061030T080000", + "20061102T080000", + "20061105T080000", + "20061108T080000", + "20061111T080000", + "20061114T080000", + "20061117T080000", + "20061120T080000", + "20061123T080000", + "20061126T080000", + "20061129T080000", + "20061202T080000", + "20061205T080000", + "20061208T080000", + "20061211T080000", + "20061214T080000", + "20061217T080000", + "20061220T080000", + "20061223T080000", + "20061226T080000", + "20061229T080000", + "20070101T080000", + "20070104T080000", + "20070107T080000", + "20070110T080000", + "20070113T080000", + "20070116T080000", + "20070119T080000", + "20070122T080000", + "20070125T080000", + "20070128T080000", + "20070131T080000", + "20070203T080000", + "20070206T080000", + "20070209T080000", + "20070212T080000", + "20070215T080000", + "20070218T080000", + "20070221T080000", + "20070224T080000", + "20070227T080000", + "20070302T080000", + "20070305T080000", + "20070308T080000", + "20070311T080000", + "20070314T080000", + "20070317T080000", + "20070320T080000", + "20070323T080000", + "20070326T080000", + "20070329T080000", + "20070401T080000", + "20070404T080000", + "20070407T080000", + "20070410T080000", + "20070413T080000", + "20070416T080000", + "20070419T080000", + "20070422T080000", + "20070425T080000", + "20070428T080000", + "20070501T080000", + "20070504T080000", + "20070507T080000", + "20070510T080000", + "20070513T080000", + "20070516T080000", + "20070519T080000", + "20070522T080000", + "20070525T080000", + "20070528T080000", + "20070531T080000", + "20070603T080000", + "20070606T080000", + "20070609T080000", + "20070612T080000", + "20070615T080000", + "20070618T080000", + "20070621T080000", + "20070624T080000", + "20070627T080000", + "20070630T080000", + "20070703T080000", + "20070706T080000", + "20070709T080000", + "20070712T080000", + "20070715T080000", + "20070718T080000", + "20070721T080000", + "20070724T080000", + "20070727T080000", + "20070730T080000", + "20070802T080000", + "20070805T080000", + "20070808T080000", + "20070811T080000", + "20070814T080000", + "20070817T080000", + "20070820T080000", + "20070823T080000", + "20070826T080000", + "20070829T080000", + "20070901T080000", + "20070904T080000", + "20070907T080000", + "20070910T080000", + "20070913T080000", + "20070916T080000", + "20070919T080000", + "20070922T080000", + "20070925T080000", + "20070928T080000", + "20071001T080000", + "20071004T080000", + "20071007T080000", + "20071010T080000", + "20071013T080000", + "20071016T080000", + "20071019T080000", + "20071022T080000", + "20071025T080000", + "20071028T080000", + "20071031T080000", + "20071103T080000", + "20071106T080000", + "20071109T080000", + "20071112T080000", + "20071115T080000", + "20071118T080000", + "20071121T080000", + "20071124T080000", + "20071127T080000", + "20071130T080000", + "20071203T080000", + "20071206T080000", + "20071209T080000", + "20071212T080000", + "20071215T080000", + "20071218T080000", + "20071221T080000", + "20071224T080000", + "20071227T080000", + "20071230T080000", + "20080102T080000", + "20080105T080000", + "20080108T080000", + "20080111T080000", + "20080114T080000", + "20080117T080000", + "20080120T080000", + "20080123T080000", + "20080126T080000", + "20080129T080000", + "20080201T080000", + "20080204T080000", + "20080207T080000", + "20080210T080000", + "20080213T080000", + "20080216T080000", + "20080219T080000", + "20080222T080000", + "20080225T080000", + "20080228T080000", + "20080302T080000", + "20080305T080000", + "20080308T080000", + "20080311T080000", + "20080314T080000", + "20080317T080000", + "20080320T080000", + "20080323T080000", + "20080326T080000", + "20080329T080000", + "20080401T080000", + "20080404T080000", + "20080407T080000", + "20080410T080000", + "20080413T080000", + "20080416T080000", + "20080419T080000", + "20080422T080000", + "20080425T080000", + "20080428T080000", + "20080501T080000", + "20080504T080000", + "20080507T080000", + "20080510T080000", + "20080513T080000", + "20080516T080000", + "20080519T080000", + "20080522T080000", + "20080525T080000", + "20080528T080000", + "20080531T080000", + "20080603T080000", + "20080606T080000", + "20080609T080000", + "20080612T080000", + "20080615T080000", + "20080618T080000", + "20080621T080000", + "20080624T080000", + "20080627T080000", + "20080630T080000", + "20080703T080000", + "20080706T080000", + "20080709T080000", + "20080712T080000", + "20080715T080000", + "20080718T080000", + "20080721T080000", + "20080724T080000", + "20080727T080000", + "20080730T080000", + "20080802T080000", + "20080805T080000", + "20080808T080000", + "20080811T080000", + "20080814T080000", + "20080817T080000", + "20080820T080000", + "20080823T080000", + "20080826T080000", + "20080829T080000", + "20080901T080000", + "20080904T080000", + "20080907T080000", + "20080910T080000", + "20080913T080000", + "20080916T080000", + "20080919T080000", + "20080922T080000", + "20080925T080000", + "20080928T080000", + "20081001T080000", + "20081004T080000", + "20081007T080000", + "20081010T080000", + "20081013T080000", + "20081016T080000", + "20081019T080000", + "20081022T080000", + "20081025T080000", + "20081028T080000", + "20081031T080000", + "20081103T080000", + "20081106T080000", + "20081109T080000", + "20081112T080000", + "20081115T080000", + "20081118T080000", + "20081121T080000", + "20081124T080000", + "20081127T080000", + "20081130T080000", + "20081203T080000", + "20081206T080000", + "20081209T080000", + "20081212T080000", + "20081215T080000", + "20081218T080000", + "20081221T080000", + "20081224T080000", + "20081227T080000", + "20081230T080000", + }, "20081230T080000"); + } + + @SmallTest + public void testFromGoogleCalendar8() throws Exception { + // Annually on October 4 + verifyRecurrence("20061004T130000", + "FREQ=YEARLY;INTERVAL=1;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061004T130000", + "20071004T130000", + "20081004T130000", + }, "20081004T130000"); + } + + @MediumTest + public void testFromGoogleCalendar9() throws Exception { + // Monthly on the last Monday + verifyRecurrence("20061030T170000", + "FREQ=MONTHLY;INTERVAL=1;BYDAY=-1MO;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061030T170000", + "20061127T170000", + "20061225T170000", + "20070129T170000", + "20070226T170000", + "20070326T170000", + "20070430T170000", + "20070528T170000", + "20070625T170000", + "20070730T170000", + "20070827T170000", + "20070924T170000", + "20071029T170000", + "20071126T170000", + "20071231T170000", + "20080128T170000", + "20080225T170000", + "20080331T170000", + "20080428T170000", + "20080526T170000", + "20080630T170000", + "20080728T170000", + "20080825T170000", + "20080929T170000", + "20081027T170000", + "20081124T170000", + "20081229T170000", + }, "20081229T170000"); + } + + @SmallTest + public void testFromGoogleCalendar10() throws Exception { + // Every 7 weeks on Tuesday, Wednesday + verifyRecurrence("20061004T090000", + "FREQ=WEEKLY;UNTIL=20070223T010000Z;INTERVAL=7;BYDAY=TU,WE;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061004T090000", + "20061121T090000", + "20061122T090000", + "20070109T090000", + "20070110T090000", + }, "20070222T170000"); + } + + @SmallTest + public void testFromGoogleCalendar11() throws Exception { + // Monthly on day 31 + verifyRecurrence("20061031T160000", + "FREQ=MONTHLY;INTERVAL=1;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061031T160000", + "20061231T160000", + "20070131T160000", + "20070331T160000", + "20070531T160000", + "20070731T160000", + "20070831T160000", + "20071031T160000", + "20071231T160000", + "20080131T160000", + "20080331T160000", + "20080531T160000", + "20080731T160000", + "20080831T160000", + "20081031T160000", + "20081231T160000", + }, + "20081231T160000"); + } + + @SmallTest + public void testFromGoogleCalendar12() throws Exception { + // Every 2 months on the first Tuesday + verifyRecurrence("20061004T110000", + "FREQ=MONTHLY;INTERVAL=2;BYDAY=1TU;WKST=SU", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090101T000000", + new String[]{ + "20061004T110000", + "20061205T110000", + "20070206T110000", + "20070403T110000", + "20070605T110000", + "20070807T110000", + "20071002T110000", + "20071204T110000", + "20080205T110000", + "20080401T110000", + "20080603T110000", + "20080805T110000", + "20081007T110000", + "20081202T110000", + }, + "20081202T110000"); + } + + @SmallTest + public void testYearly0() throws Exception { + verifyRecurrence("20080101T100000", + "FREQ=YEARLY;UNTIL=20090131T090000Z;BYMONTH=1;BYDAY=SU,MO", + null /* rdate */, null /* exrule */, null /* exdate */, + "20080101T000000", "20090130T000000", + new String[]{ + "20080101T100000", + "20080106T100000", + "20080107T100000", + "20080113T100000", + "20080114T100000", + "20080120T100000", + "20080121T100000", + "20080127T100000", + "20080128T100000", + "20090104T100000", + "20090105T100000", + "20090111T100000", + "20090112T100000", + "20090118T100000", + "20090119T100000", + "20090125T100000", + "20090126T100000", + }, "20090131T010000"); + } + + /** + * This test fails because of a bug in RecurrenceProcessor.expand(). We + * don't have time to fix the bug yet but we don't want to lose track of + * this test either. The "failing" prefix on the method name prevents this + * test from being run. Remove the "failing" prefix when the bug is fixed. + * + * @throws Exception + */ + @SmallTest + public void failingTestYearly1() throws Exception { + verifyRecurrence("20060101T100000", + "FREQ=YEARLY;COUNT=10;BYYEARDAY=1,100,200", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090131T000000", + new String[]{ + "20060101T100000", + "20060409T100000", + "20060718T100000", + "20070101T100000", + "20070409T100000", + "20070718T100000", + "20080101T100000", + "20080410T100000", + "20080719T100000", + "20090101T100000", + }); + } + + /** + * This test fails because of a bug in RecurrenceProcessor.expand(). We + * don't have time to fix the bug yet but we don't want to lose track of + * this test either. The "failing" prefix on the method name prevents this + * test from being run. Remove the "failing" prefix when the bug is fixed. + * + * @throws Exception + */ + @SmallTest + public void failingTestYearly2() throws Exception { + verifyRecurrence("20060101T100000", + "FREQ=YEARLY;COUNT=5;BYWEEKNO=6;BYDAY=MO;WKST=MO", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090131T000000", + new String[]{ + "20060101T100000", + "20060206T100000", + "20070205T100000", + "20080204T100000", + "20090209T100000", + }); + } + + /** + * This test fails because of a bug in RecurrenceProcessor.expand(). We + * don't have time to fix the bug yet but we don't want to lose track of + * this test either. The "failing" prefix on the method name prevents this + * test from being run. Remove the "failing" prefix when the bug is fixed. + * + * @throws Exception + */ + @SmallTest + public void failingTestYearly3() throws Exception { + verifyRecurrence("20060101T100000", + "FREQ=YEARLY;BYMONTH=3;BYDAY=TH", + null /* rdate */, null /* exrule */, null /* exdate */, + "20060101T000000", "20090131T000000", + new String[]{ + "20060101T100000", + "20060302T100000", + "20060309T100000", + "20060316T100000", + "20060323T100000", + "20060330T100000", + "20070301T100000", + "20070308T100000", + "20070315T100000", + "20070322T100000", + "20070329T100000", + "20080306T100000", + "20080313T100000", + "20080320T100000", + "20080327T100000", + }); + } + + /** + * This test fails because of a bug in RecurrenceProcessor.expand(). We + * don't have time to fix the bug yet but we don't want to lose track of + * this test either. The "failing" prefix on the method name prevents this + * test from being run. Remove the "failing" prefix when the bug is fixed. + * + * @throws Exception + */ + @SmallTest + public void failingTestYearly4() throws Exception { + verifyRecurrence("19920101T100000", + "FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8", + null /* rdate */, null /* exrule */, null /* exdate */, + "19920101T000000", "20121231T000000", + new String[]{ + "19920101T100000", + "19921103T100000", + "19961105T100000", + "20001107T100000", + "20041102T100000", + "20081104T100000", + "20121106T100000", + }); + } + + /** + * Test repeating event from Exchange with count field. + * Time range covers the whole repetition. + * + * @throws Exception + */ + public void testCount1() throws Exception { + verifyRecurrence("20100324T153000", + "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", + null /* rdate */, null /* exrule */, null /* exdate */, + "20100301T000000", "20100630T000000", + new String[]{ + "20100324T153000", + "20100331T153000", + "20100407T153000", + "20100414T153000", + "20100421T153000", + "20100428T153000", + "20100505T153000", + "20100512T153000", + "20100519T153000", + "20100526T153000", + }); + } + + /** + * Test repeating event from Exchange with count field. + * Time range covers the first part of the repetition. + * @throws Exception + */ + public void testCount2() throws Exception { + verifyRecurrence("20100324T153000", + "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", + null /* rdate */, null /* exrule */, null /* exdate */, + "20100501T000000", "20100630T000000", + new String[]{ + "20100505T153000", + "20100512T153000", + "20100519T153000", + "20100526T153000", + }); + } + + /** + * Test repeating event from Exchange with count field. + * Time range is beyond the repetition. + * @throws Exception + */ + public void testCount3() throws Exception { + verifyRecurrence("20100324T153000", + "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", + null /* rdate */, null /* exrule */, null /* exdate */, + "20100601T000000", "20100630T000000", + new String[]{}, + "20100526T153000" /* last */); + } + + /** + * Test repeating event from Exchange with count field. + * Time range is before the repetition + * @throws Exception + */ + public void testCount4() throws Exception { + verifyRecurrence("20100324T153000", + "FREQ=WEEKLY;INTERVAL=1;COUNT=10;BYDAY=WE", + null /* rdate */, null /* exrule */, null /* exdate */, + "20100101T000000", "20100301T000000", + new String[]{}, + null /* last */); + } + + + // These recurrence rules are used in the loop that measures the performance + // of recurrence expansion. + private static final String[] performanceRrules = new String[] { + "FREQ=DAILY;COUNT=100", + "FREQ=DAILY;INTERVAL=2;UNTIL=20080101T000000Z", + "FREQ=YEARLY;UNTIL=20090131T090000Z;BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA", + "FREQ=WEEKLY;INTERVAL=2;WKST=SU", + "FREQ=WEEKLY;COUNT=100;WKST=SU;BYDAY=MO,TU,WE,TH,FR", + "FREQ=MONTHLY;COUNT=100;BYDAY=1FR", + "FREQ=MONTHLY;INTERVAL=2;COUNT=100;BYDAY=1SU,-1SU", + "FREQ=MONTHLY;BYMONTHDAY=1,15", + "FREQ=MONTHLY;INTERVAL=3;COUNT=100;BYMONTHDAY=10,11,12,13,14", + "FREQ=YEARLY;COUNT=100;BYMONTH=6,7,8", + "FREQ=YEARLY;INTERVAL=2;BYMONTH=1,2,3,6,7,8", + "FREQ=YEARLY;COUNT=100;BYYEARDAY=1,100,200", + "FREQ=YEARLY;BYDAY=2MO", + "FREQ=YEARLY;BYWEEKNO=2,3,4;BYDAY=MO", + "FREQ=YEARLY;BYMONTH=3,4,5;BYDAY=TH", + "FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13", + "FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13", + "FREQ=YEARLY;INTERVAL=2;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8", + "FREQ=WEEKLY;INTERVAL=2;COUNT=100;BYDAY=TU,SU;WKST=MO", + "FREQ=WEEKLY;INTERVAL=2;COUNT=100;BYDAY=TU,SU;WKST=SU", + }; + + /** + * This test never fails. It just runs for a while (about 10 seconds) + * in order to measure the performance of recurrence expansion. + * + * @throws Exception + */ + @LargeTest + public void performanceTextExpand() throws Exception { + String tz = "America/Los_Angeles"; + Time dtstart = new Time(tz); + Time rangeStart = new Time(tz); + Time rangeEnd = new Time(tz); + TreeSet out = new TreeSet(); + + dtstart.parse("20010101T000000"); + rangeStart.parse("20010101T000000"); + rangeEnd.parse("20090101T000000"); + long rangeStartMillis = rangeStart.toMillis(false /* use isDst */); + long rangeEndMillis = rangeEnd.toMillis(false /* use isDst */); + + long startTime = System.currentTimeMillis(); + for (int iterations = 0; iterations < 5; iterations++) { + RecurrenceProcessor rp = new RecurrenceProcessor(); + + int len = performanceRrules.length; + for (int i = 0; i < len; i++) { + String rrule = performanceRrules[i]; + //Log.i(TAG, "expanding rule: " + rrule); + RecurrenceSet recur = new RecurrenceSet(rrule, null, null, null); + + long [] dates = rp.expand(dtstart, recur, rangeStartMillis, rangeEndMillis); + //Log.i(TAG, "num instances: " + out.size()); + + // Also include the time to iterate through the expanded values + for (long date : dates) { + // Use the date so that this loop is not optimized away. + if (date == -1) { + Log.e(TAG, "unexpected date"); + break; + } + } + out.clear(); + } + } + + long endTime = System.currentTimeMillis(); + long elapsed = endTime - startTime; + Log.i(TAG, "testPerformanceExpand() expand() elapsed millis: " + elapsed); + } + + @LargeTest + public void performanceTestNormalize() throws Exception { + final int ITERATIONS = 50000; + + String tz = "America/Los_Angeles"; + Time date = new Time(tz); + date.parse("20090404T100000"); + + long startTime = System.currentTimeMillis(); + + for (int i = 0; i < ITERATIONS; i++) { + date.month += 1; + date.monthDay += 100; + date.normalize(true); + date.month -= 1; + date.monthDay -= 100; + date.normalize(true); + } + + long endTime = System.currentTimeMillis(); + long elapsed = endTime - startTime; + Log.i(TAG, "date: " + date.format2445()); + Log.i(TAG, "testPerformanceNormalize() normalize() elapsed millis: " + elapsed); + + // Time the unsafe version + date.parse("20090404T100000"); + startTime = System.currentTimeMillis(); + for (int i = 0; i < ITERATIONS; i++) { + date.month += 1; + date.monthDay += 100; + RecurrenceProcessor.unsafeNormalize(date); + date.month -= 1; + date.monthDay -= 100; + RecurrenceProcessor.unsafeNormalize(date); + } + + endTime = System.currentTimeMillis(); + elapsed = endTime - startTime; + Log.i(TAG, "date: " + date.format2445()); + Log.i(TAG, "testPerformanceNormalize() unsafeNormalize() elapsed millis: " + elapsed); + } + } diff --git a/tests/src/com/android/calendarcommon2/RecurrenceSetTest.java b/tests/src/com/android/calendarcommon2/RecurrenceSetTest.java new file mode 100644 index 0000000..f65c780 --- /dev/null +++ b/tests/src/com/android/calendarcommon2/RecurrenceSetTest.java @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.calendarcommon2; + +import com.android.calendarcommon2.ICalendar; +import com.android.calendarcommon2.RecurrenceSet; + +import android.content.ContentValues; +import android.test.suitebuilder.annotation.SmallTest; +import android.util.Log; +import android.provider.CalendarContract; +import junit.framework.TestCase; + +/** + * Test some pim.RecurrenceSet functionality. + */ +public class RecurrenceSetTest extends TestCase { + + // Test a recurrence + @SmallTest + public void testRecurrenceSet0() throws Exception { + String recurrence = "DTSTART;TZID=America/New_York:20080221T070000\n" + + "DTEND;TZID=America/New_York:20080221T190000\n" + + "RRULE:FREQ=DAILY;UNTIL=20080222T000000Z\n" + + "EXDATE:20080222T120000Z"; + verifyPopulateContentValues(recurrence, "FREQ=DAILY;UNTIL=20080222T000000Z", null, + null, "20080222T120000Z", 1203595200000L, "America/New_York", "P43200S", 0, false); + } + + // Test 1 day all-day event + @SmallTest + public void testRecurrenceSet1() throws Exception { + String recurrence = "DTSTART;VALUE=DATE:20090821\nDTEND;VALUE=DATE:20090822\n" + + "RRULE:FREQ=YEARLY;WKST=SU"; + verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU", null, + null, null, 1250812800000L, "UTC", "P1D", 1, false); + } + + // Test 2 day all-day event + @SmallTest + public void testRecurrenceSet2() throws Exception { + String recurrence = "DTSTART;VALUE=DATE:20090821\nDTEND;VALUE=DATE:20090823\n" + + "RRULE:FREQ=YEARLY;WKST=SU"; + verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU", null, + null, null, 1250812800000L, "UTC", "P2D", 1, false); + } + + // Test multi-rule RRULE. + @SmallTest + public void testRecurrenceSet3() throws Exception { + String recurrence = "DTSTART;VALUE=DATE:20090821\n" + + "RRULE:FREQ=YEARLY;WKST=SU\n" + + "RRULE:FREQ=MONTHLY;COUNT=3\n" + + "DURATION:P2H"; + verifyPopulateContentValues(recurrence, "FREQ=YEARLY;WKST=SU\nFREQ=MONTHLY;COUNT=3", null, + null, null, 1250812800000L, "UTC", "P2H", 1 /*allDay*/, false); + // allDay=1 just means the start time is 00:00:00 UTC. + } + + // Test RDATE with VALUE=DATE. + @SmallTest + public void testRecurrenceSet4() throws Exception { + String recurrence = "DTSTART;TZID=America/Los_Angeles:20090821T010203\n" + + "RDATE;TZID=America/Los_Angeles;VALUE=DATE:20110601,20110602,20110603\n" + + "DURATION:P2H"; + verifyPopulateContentValues(recurrence, null, + //"TZID=America/Los_Angeles;VALUE=DATE:20110601,20110602,20110603", + "America/Los_Angeles;20110601,20110602,20110603", // incorrect + null, null, 1250841723000L, "America/Los_Angeles", "P2H", 0 /*allDay*/, false); + // allDay=1 just means the start time is 00:00:00 UTC. + } + + // Check generation of duration from events in different time zones. + @SmallTest + public void testRecurrenceSet5() throws Exception { + String recurrence = "DTSTART;TZID=America/Los_Angeles:20090821T070000\n" + + "DTEND;TZID=America/New_York:20090821T110000\n" + + "RRULE:FREQ=YEARLY\n"; + verifyPopulateContentValues(recurrence, "FREQ=YEARLY", null, + null, null, 1250863200000L, "America/Los_Angeles", "P3600S" /*P1H*/, 0 /*allDay*/, + false); + // TODO: would like to use P1H for duration + + String recurrence2 = "DTSTART;TZID=America/New_York:20090821T100000\n" + + "DTEND;TZID=America/Los_Angeles:20090821T080000\n" + + "RRULE:FREQ=YEARLY\n"; + verifyPopulateContentValues(recurrence, "FREQ=YEARLY", null, + null, null, 1250863200000L, "America/Los_Angeles", "P3600S" /*P1H*/, 0 /*allDay*/, + false); + // TODO: should we rigorously define which tzid becomes the "event timezone"? + } + + // Test a failure to parse the recurrence data + @SmallTest + public void testRecurrenceSetBadDstart() throws Exception { + String recurrence = "DTSTART;TZID=GMT+05:30:20080221T070000\n" + + "DTEND;TZID=GMT+05:30:20080221T190000\n" + + "RRULE:FREQ=DAILY;UNTIL=20080222T000000Z\n" + + "EXDATE:20080222T120000Z"; + verifyPopulateContentValues(recurrence, "FREQ=DAILY;UNTIL=20080222T000000Z", null, + null, "20080222T120000Z", 1203595200000L, "America/New_York", "P43200S", 0, true); + } + + @SmallTest + public void testRecurrenceSetBadRrule() throws Exception { + String recurrence = "DTSTART;TZID=America/New_York:20080221T070000\n" + + "DTEND;TZID=GMT+05:30:20080221T190000\n" + + "RRULE:FREQ=NEVER;UNTIL=20080222T000000Z\n" + + "EXDATE:20080222T120000Z"; + verifyPopulateContentValues(recurrence, "FREQ=DAILY;UNTIL=20080222T000000Z", null, + null, "20080222T120000Z", 1203595200000L, "America/New_York", "P43200S", 0, true); + } + + // run populateContentValues and verify the results + private void verifyPopulateContentValues(String recurrence, String rrule, String rdate, + String exrule, String exdate, long dtstart, String tzid, String duration, int allDay, + boolean badFormat) + throws ICalendar.FormatException { + ICalendar.Component recurrenceComponent = + new ICalendar.Component("DUMMY", null /* parent */); + ICalendar.parseComponent(recurrenceComponent, recurrence); + ContentValues values = new ContentValues(); + boolean result = RecurrenceSet.populateContentValues(recurrenceComponent, values); + Log.d("KS", "values " + values); + + if (badFormat) { + assertEquals(result, !badFormat); + return; + } + assertEquals(rrule, values.get(android.provider.CalendarContract.Events.RRULE)); + assertEquals(rdate, values.get(android.provider.CalendarContract.Events.RDATE)); + assertEquals(exrule, values.get(android.provider.CalendarContract.Events.EXRULE)); + assertEquals(exdate, values.get(android.provider.CalendarContract.Events.EXDATE)); + assertEquals(dtstart, (long) values.getAsLong(CalendarContract.Events.DTSTART)); + assertEquals(tzid, values.get(android.provider.CalendarContract.Events.EVENT_TIMEZONE)); + assertEquals(duration, values.get(android.provider.CalendarContract.Events.DURATION)); + assertEquals(allDay, + (int) values.getAsInteger(android.provider.CalendarContract.Events.ALL_DAY)); + } + +} -- cgit v1.2.3