Merge "Handle upsync of multiple BYDAY values; add some unit tests"
This commit is contained in:
commit
cfbbb99c67
@ -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 {
|
||||
// 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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user