propagate from branch 'ca.inverse.sogo.1_3_15' (head f44990050ab038029a3fa83c4918912da401bd4b)
to branch 'ca.inverse.sogo' (head 74637b0d30612389db5f908c078f94c96d2f4a04) Monotone-Parent: 74637b0d30612389db5f908c078f94c96d2f4a04 Monotone-Parent: f44990050ab038029a3fa83c4918912da401bd4b Monotone-Revision: 94d7b980dccff8cbae9bff2eaee5dbefc75a7dfd Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-04-23T19:16:50 Monotone-Branch: ca.inverse.sogomaint-2.0.2
commit
952d74e7be
|
@ -34,10 +34,10 @@
|
||||||
|
|
||||||
#import "SOGoTest.h"
|
#import "SOGoTest.h"
|
||||||
|
|
||||||
@interface TestiCalRecurrenceCalculator : SOGoTest
|
@interface TestiCalWeeklyRecurrenceCalculator : SOGoTest
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation TestiCalRecurrenceCalculator
|
@implementation TestiCalWeeklyRecurrenceCalculator
|
||||||
|
|
||||||
- (void) test_recurrenceRangesWithinCalendarDateRange_
|
- (void) test_recurrenceRangesWithinCalendarDateRange_
|
||||||
{
|
{
|
||||||
|
@ -72,6 +72,70 @@
|
||||||
@"19971212T090000Z",
|
@"19971212T090000Z",
|
||||||
@"19971222T090000Z",
|
@"19971222T090000Z",
|
||||||
nil],
|
nil],
|
||||||
|
nil];
|
||||||
|
|
||||||
|
NSString *dateFormat = @"%a %Y-%m-%d %H:%M";
|
||||||
|
NSString *error;
|
||||||
|
NGCalendarDateRange *firRange, *range;
|
||||||
|
NSEnumerator *rulesList;
|
||||||
|
NSArray *currentRule, *occurrences;
|
||||||
|
int i, j;
|
||||||
|
NSCalendarDate *startDate, *endDate, *currentOccurrence;
|
||||||
|
iCalRecurrenceRule *recurrenceRule;
|
||||||
|
iCalRecurrenceCalculator *calculator;
|
||||||
|
|
||||||
|
rulesList = [rules objectEnumerator];
|
||||||
|
while ((currentRule = [rulesList nextObject]))
|
||||||
|
{
|
||||||
|
startDate = [[currentRule objectAtIndex: 0] asCalendarDate];
|
||||||
|
endDate = [startDate dateByAddingYears: 0 months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
|
||||||
|
recurrenceRule = [iCalRecurrenceRule recurrenceRuleWithICalRepresentation: [currentRule objectAtIndex: 1]];
|
||||||
|
// NSLog(@"%@: %@", startDate, recurrenceRule);
|
||||||
|
|
||||||
|
firRange = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
|
||||||
|
endDate: endDate];
|
||||||
|
calculator = [iCalRecurrenceCalculator recurrenceCalculatorForRecurrenceRule: recurrenceRule
|
||||||
|
withFirstInstanceCalendarDateRange: firRange];
|
||||||
|
range = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
|
||||||
|
endDate: [NSCalendarDate distantFuture]];
|
||||||
|
occurrences = [calculator recurrenceRangesWithinCalendarDateRange: range];
|
||||||
|
for (i = 2, j = 0; i < [currentRule count] && j < [occurrences count]; i++, j++)
|
||||||
|
{
|
||||||
|
currentOccurrence = [[currentRule objectAtIndex: i] asCalendarDate];
|
||||||
|
error = [NSString stringWithFormat: @"Invalid occurrence for recurrence rule %@: %@ (expected date was %@)",
|
||||||
|
[currentRule objectAtIndex: 1],
|
||||||
|
[[[occurrences objectAtIndex: j] startDate] descriptionWithCalendarFormat: dateFormat],
|
||||||
|
[currentOccurrence descriptionWithCalendarFormat: dateFormat]];
|
||||||
|
testWithMessage([currentOccurrence isDateOnSameDay: [[occurrences objectAtIndex: j] startDate]], error);
|
||||||
|
// if ([currentOccurrence compare: [[occurrences objectAtIndex: j] startDate]] != NSOrderedSame)
|
||||||
|
// NSLog(@"Expected: %@ Obtained: %@", [currentOccurrence descriptionWithCalendarFormat: dateFormat],
|
||||||
|
// [[[occurrences objectAtIndex: j] startDate] descriptionWithCalendarFormat: dateFormat]);
|
||||||
|
// else
|
||||||
|
// NSLog(@" %@ Matched: %@", [currentOccurrence descriptionWithCalendarFormat: dateFormat],
|
||||||
|
// [[[occurrences objectAtIndex: j] startDate] descriptionWithCalendarFormat: dateFormat]);
|
||||||
|
}
|
||||||
|
error = [NSString stringWithFormat: @"Unexpected number of occurrences for recurrence rule %@ (found %i, expected %i)",
|
||||||
|
[currentRule objectAtIndex: 1],
|
||||||
|
[occurrences count],
|
||||||
|
[currentRule count] - 2];
|
||||||
|
testWithMessage([currentRule count] - [occurrences count] == 2, error);
|
||||||
|
// for (; i < [currentRule count]; i++)
|
||||||
|
// NSLog(@"Expected additional date : %@", [[currentRule objectAtIndex: i] asCalendarDate]);
|
||||||
|
// for (; j < [occurrences count]; j++)
|
||||||
|
// NSLog(@"Found additional date : %@", [[occurrences objectAtIndex: j] startDate]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface TestiCalMonthlyRecurrenceCalculator : SOGoTest
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation TestiCalMonthlyRecurrenceCalculator
|
||||||
|
|
||||||
|
- (void) test_recurrenceRangesWithinCalendarDateRange_
|
||||||
|
{
|
||||||
|
NSArray *rules = [NSArray arrayWithObjects:
|
||||||
// Monthly on the 1st Friday for ten occurrences
|
// Monthly on the 1st Friday for ten occurrences
|
||||||
[NSArray arrayWithObjects: @"19970905T090000Z",
|
[NSArray arrayWithObjects: @"19970905T090000Z",
|
||||||
@"FREQ=MONTHLY;COUNT=10;BYDAY=1FR",
|
@"FREQ=MONTHLY;COUNT=10;BYDAY=1FR",
|
||||||
|
@ -105,6 +169,70 @@
|
||||||
@"19980129T090000Z",
|
@"19980129T090000Z",
|
||||||
@"19980226T090000Z",
|
@"19980226T090000Z",
|
||||||
nil],
|
nil],
|
||||||
|
nil];
|
||||||
|
|
||||||
|
NSString *dateFormat = @"%a %Y-%m-%d %H:%M";
|
||||||
|
NSString *error;
|
||||||
|
NGCalendarDateRange *firRange, *range;
|
||||||
|
NSEnumerator *rulesList;
|
||||||
|
NSArray *currentRule, *occurrences;
|
||||||
|
int i, j;
|
||||||
|
NSCalendarDate *startDate, *endDate, *currentOccurrence;
|
||||||
|
iCalRecurrenceRule *recurrenceRule;
|
||||||
|
iCalRecurrenceCalculator *calculator;
|
||||||
|
|
||||||
|
rulesList = [rules objectEnumerator];
|
||||||
|
while ((currentRule = [rulesList nextObject]))
|
||||||
|
{
|
||||||
|
startDate = [[currentRule objectAtIndex: 0] asCalendarDate];
|
||||||
|
endDate = [startDate dateByAddingYears: 0 months: 0 days: 0 hours: 1 minutes: 0 seconds: 0];
|
||||||
|
recurrenceRule = [iCalRecurrenceRule recurrenceRuleWithICalRepresentation: [currentRule objectAtIndex: 1]];
|
||||||
|
// NSLog(@"%@: %@", startDate, recurrenceRule);
|
||||||
|
|
||||||
|
firRange = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
|
||||||
|
endDate: endDate];
|
||||||
|
calculator = [iCalRecurrenceCalculator recurrenceCalculatorForRecurrenceRule: recurrenceRule
|
||||||
|
withFirstInstanceCalendarDateRange: firRange];
|
||||||
|
range = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
|
||||||
|
endDate: [NSCalendarDate distantFuture]];
|
||||||
|
occurrences = [calculator recurrenceRangesWithinCalendarDateRange: range];
|
||||||
|
for (i = 2, j = 0; i < [currentRule count] && j < [occurrences count]; i++, j++)
|
||||||
|
{
|
||||||
|
currentOccurrence = [[currentRule objectAtIndex: i] asCalendarDate];
|
||||||
|
error = [NSString stringWithFormat: @"Invalid occurrence for recurrence rule %@: %@ (expected date was %@)",
|
||||||
|
[currentRule objectAtIndex: 1],
|
||||||
|
[[[occurrences objectAtIndex: j] startDate] descriptionWithCalendarFormat: dateFormat],
|
||||||
|
[currentOccurrence descriptionWithCalendarFormat: dateFormat]];
|
||||||
|
testWithMessage([currentOccurrence isDateOnSameDay: [[occurrences objectAtIndex: j] startDate]], error);
|
||||||
|
// if ([currentOccurrence compare: [[occurrences objectAtIndex: j] startDate]] != NSOrderedSame)
|
||||||
|
// NSLog(@"Expected: %@ Obtained: %@", [currentOccurrence descriptionWithCalendarFormat: dateFormat],
|
||||||
|
// [[[occurrences objectAtIndex: j] startDate] descriptionWithCalendarFormat: dateFormat]);
|
||||||
|
// else
|
||||||
|
// NSLog(@" %@ Matched: %@", [currentOccurrence descriptionWithCalendarFormat: dateFormat],
|
||||||
|
// [[[occurrences objectAtIndex: j] startDate] descriptionWithCalendarFormat: dateFormat]);
|
||||||
|
}
|
||||||
|
error = [NSString stringWithFormat: @"Unexpected number of occurrences for recurrence rule %@ (found %i, expected %i)",
|
||||||
|
[currentRule objectAtIndex: 1],
|
||||||
|
[occurrences count],
|
||||||
|
[currentRule count] - 2];
|
||||||
|
testWithMessage([currentRule count] - [occurrences count] == 2, error);
|
||||||
|
// for (; i < [currentRule count]; i++)
|
||||||
|
// NSLog(@"Expected additional date : %@", [[currentRule objectAtIndex: i] asCalendarDate]);
|
||||||
|
// for (; j < [occurrences count]; j++)
|
||||||
|
// NSLog(@"Found additional date : %@", [[occurrences objectAtIndex: j] startDate]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface TestiCalYearlyRecurrenceCalculator : SOGoTest
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation TestiCalYearlyRecurrenceCalculator
|
||||||
|
|
||||||
|
- (void) test_recurrenceRangesWithinCalendarDateRange_
|
||||||
|
{
|
||||||
|
NSArray *rules = [NSArray arrayWithObjects:
|
||||||
// Every other year on January, February, and March for 10 occurrences
|
// Every other year on January, February, and March for 10 occurrences
|
||||||
[NSArray arrayWithObjects: @"19970310T090000Z",
|
[NSArray arrayWithObjects: @"19970310T090000Z",
|
||||||
@"FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3",
|
@"FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3",
|
||||||
|
|
Loading…
Reference in New Issue