From a8259394596eda7aed2b9edfdb30ff03c34acb66 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Mon, 1 Feb 2010 16:44:16 -0800 Subject: [PATCH] Handle upsync of multiple BYDAY values; add some unit tests Change-Id: If3be28df41ed88cb83edca2f6ea6ca1f734f506f --- .../exchange/utility/CalendarUtilities.java | 22 ++++++++++++++----- .../utility/CalendarUtilitiesTests.java | 17 ++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/com/android/exchange/utility/CalendarUtilities.java b/src/com/android/exchange/utility/CalendarUtilities.java index 40733260d..3eccdaf35 100644 --- a/src/com/android/exchange/utility/CalendarUtilities.java +++ b/src/com/android/exchange/utility/CalendarUtilities.java @@ -14,6 +14,12 @@ * limitations under the License. */ +/** + * Tests of EAS Calendar Utilities + * You can run this entire test case with: + * runtest -c com.android.exchange.utility.CalendarUtilitiesTests email + */ + package com.android.exchange.utility; import com.android.exchange.Eas; @@ -396,16 +402,22 @@ public class CalendarUtilities { rrule.append(";BYMONTHDAY=" + dom); } + /** + * Generate the String version of the EAS integer for a given BYDAY value in an rrule + * @param dow the BYDAY value of the rrule + * @return the String version of the EAS value of these days + */ static String generateEasDayOfWeek(String dow) { + int bits = 0; int bit = 1; for (String token: sDayTokens) { - if (dow.equals(token)) { - break; - } else { - bit <<= 1; + // If we can find the day in the dow String, add the bit to our bits value + if (dow.indexOf(token) >= 0) { + bits |= bit; } + bit <<= 1; } - return Integer.toString(bit); + return Integer.toString(bits); } static String tokenFromRrule(String rrule, String token) { diff --git a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java index 524b72f02..379c40259 100644 --- a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java +++ b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java @@ -64,6 +64,23 @@ public class CalendarUtilitiesTests extends AndroidTestCase { assertEquals("Israel Standard Time", tz.getDisplayName()); } + public void testGenerateEasDayOfWeek() { + String byDay = "TU;WE;SA"; + assertEquals("76", CalendarUtilities.generateEasDayOfWeek(byDay)); + byDay = "MO;TU;WE;TH;FR"; + assertEquals("62", CalendarUtilities.generateEasDayOfWeek(byDay)); + byDay = "SU"; + assertEquals("1", CalendarUtilities.generateEasDayOfWeek(byDay)); + } + + public void testTokenFromRrule() { + String rrule = "FREQ=DAILY;INTERVAL=1;BYDAY=WE,TH,SA;BYMONTHDAY=17"; + assertEquals("DAILY", CalendarUtilities.tokenFromRrule(rrule, "FREQ=")); + assertEquals("1", CalendarUtilities.tokenFromRrule(rrule, "INTERVAL=")); + assertEquals("17", CalendarUtilities.tokenFromRrule(rrule, "BYMONTHDAY=")); + assertNull(CalendarUtilities.tokenFromRrule(rrule, "UNTIL=")); + } + // TODO In progress // public void testParseTimeZone() { // GregorianCalendar cal = getTestCalendar(parsedTimeZone, dstStart);