Handle upsync of multiple BYDAY values; add some unit tests
Change-Id: If3be28df41ed88cb83edca2f6ea6ca1f734f506f
diff --git a/src/com/android/exchange/utility/CalendarUtilities.java b/src/com/android/exchange/utility/CalendarUtilities.java
index 4073326..3eccdaf 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 @@
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 524b72f..379c402 100644
--- a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
+++ b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
@@ -64,6 +64,23 @@
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);