Handle upsync of multiple BYDAY values; add some unit tests

Change-Id: If3be28df41ed88cb83edca2f6ea6ca1f734f506f
This commit is contained in:
Marc Blank 2010-02-01 16:44:16 -08:00
parent 31ac14aa51
commit a825939459
2 changed files with 34 additions and 5 deletions

View File

@ -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) {

View File

@ -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);