add calendar tests

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36390 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-03-20 17:08:00 +00:00
parent eff2f31f06
commit deaa8b820e

View file

@ -0,0 +1,56 @@
#import "Testing.h"
#import "ObjectTesting.h"
#import <Foundation/NSCalendar.h>
#import <Foundation/NSTimeZone.h>
#import <Foundation/NSLocale.h>
#include <stdio.h>
#if defined(GS_USE_ICU)
#define NSCALENDAR_SUPPORTED GS_USE_ICU
#else
#define NSCALENDAR_SUPPORTED 1 /* Assume Apple support */
#endif
int main()
{
NSDateComponents *comps;
NSCalendar *cal;
NSDate *date;
NSDate *date2;
START_SET("NSCalendar 10.7 features")
if (!NSCALENDAR_SUPPORTED)
SKIP("NSCalendar not supported\nThe ICU library was not available when GNUstep-base was built")
cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
date = [NSDate dateWithString: @"2012-12-31 13:57:00 +0100"];
comps = [cal components: NSYearForWeekOfYearCalendarUnit
| NSWeekOfYearCalendarUnit | NSWeekOfMonthCalendarUnit
fromDate: date];
PASS([comps weekOfMonth] == 5, "-weekOfMonth returns the correct week");
PASS([comps weekOfYear] == 1, "-weekOfYear returns the correct week");
PASS([comps yearForWeekOfYear] == 2013,
"-yearForWeekOfYear returns the correct year");
comps = [[NSDateComponents alloc] init];
[comps setCalendar: cal];
[comps setTimeZone: [NSTimeZone timeZoneForSecondsFromGMT: 3600]];
[comps setHour: 13];
[comps setMinute: 57];
[comps setDay: 31];
[comps setMonth: 12];
[comps setYear: 2012];
date2 = [comps date];
PASS_EQUAL(date, date2, "-[NSDateComponents date] returns the correct date");
RELEASE(comps);
RELEASE(cal);
END_SET("NSCalendar 10.7 features")
return 0;
}