mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
For example the method ’initWithName:’ will return different abbreviation depending on the order CPDictionary returns keys from the method ’keyEnumerator’. As this is undefined the answer can vary. Test cases now handle all cases.
345 lines
14 KiB
Plaintext
345 lines
14 KiB
Plaintext
/* CPTimeZoneTest.j
|
|
* Foundation
|
|
*
|
|
* Created by Alexandre Wilhelm
|
|
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
@import <Foundation/Foundation.j>
|
|
@import <OJUnit/OJTestCase.j>
|
|
|
|
@implementation CPTimeZoneTest : OJTestCase
|
|
{
|
|
CPLocale _locale;
|
|
CPData _data;
|
|
CPDate _date;
|
|
}
|
|
|
|
- (void)setUp
|
|
{
|
|
_locale = [[CPLocale alloc] initWithLocaleIdentifier:@"en_US"];
|
|
_data = [CPData dataWithRawString:@"Data with string"];
|
|
_date = [[CPDate alloc] initWithString:@"2011-10-05 16:34:38 +0900"];
|
|
}
|
|
|
|
- (void)tearDown
|
|
{
|
|
|
|
}
|
|
|
|
- (void)testTimeZoneWithAbbreviation
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithAbbreviation:@"PDT"];
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PDT"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
|
|
}
|
|
|
|
- (void)testTimeZoneWithWrongAbbreviation
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithAbbreviation:@"PDTezdez"];
|
|
[self assert:timeZone equals:nil];
|
|
}
|
|
|
|
- (void)testTimeZoneWithName
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angeles"];
|
|
|
|
// The current implementation can return daylight saving time or standard time depending on the current implmentation on CPDictionary
|
|
if ([timeZone abbreviation] === @"PDT") {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PDT"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
|
|
} else {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PST"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-480 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PST) offset -28800"];
|
|
}
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
|
|
}
|
|
|
|
- (void)testTimeZoneWithWrongName
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angelesezdez"];
|
|
[self assert:timeZone equals:nil];
|
|
}
|
|
|
|
- (void)testexceptionTimeZoneWithNilName
|
|
{
|
|
try
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithName:nil];
|
|
[self fail:"Invalid value provided for tzName"];
|
|
}
|
|
catch (e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
- (void)testTimeZoneWithNameWithData
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angeles" data:_data];
|
|
|
|
// The current implementation can return daylight saving time or standard time depending on the current implmentation on CPDictionary
|
|
if ([timeZone abbreviation] === @"PDT") {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PDT"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
|
|
} else {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PST"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-480 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PST) offset -28800"];
|
|
}
|
|
[self assert:[timeZone data] equals:_data];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
|
|
}
|
|
|
|
- (void)testTimeZoneWithWrongNameWithData
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angelesezdez" data:_data];
|
|
[self assert:timeZone equals:nil];
|
|
}
|
|
|
|
- (void)testexceptionTimeZoneWithNilNameWithData
|
|
{
|
|
try
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneWithName:nil data:_data];
|
|
[self fail:"Invalid value provided for tzName"];
|
|
}
|
|
catch (e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
- (void)testTimeZoneWithSecondsFromGMT
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneForSecondsFromGMT:(-600 * 60)];
|
|
[self assert:[timeZone name] equals:@"Pacific/Honolulu"];
|
|
[self assert:[timeZone abbreviation] equals:@"HST"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-600 * 60)];
|
|
[self assert:[timeZone description] equals:@"Pacific/Honolulu (HST) offset -36000"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Hawaii-Aleutian Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"HST"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Hawaii-Aleutian Daylight Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"HDT"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Hawaii-Aleutian Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"HST"];
|
|
}
|
|
|
|
- (void)testTimeZoneWithWrongSecondsFromGMT
|
|
{
|
|
var timeZone = [CPTimeZone timeZoneForSecondsFromGMT:(-421 * 60)];
|
|
[self assert:timeZone equals:nil];
|
|
}
|
|
|
|
- (void)testInitTimeZoneWithName
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
|
|
|
|
// The current implementation can return daylight saving time or standard time depending on the current implmentation on CPDictionary
|
|
if ([timeZone abbreviation] === @"PDT") {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PDT"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
|
|
} else {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PST"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-480 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PST) offset -28800"];
|
|
}
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
|
|
}
|
|
|
|
- (void)testInitTimeZoneWithWrongName
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angelesezdez"];
|
|
[self assert:timeZone equals:nil];
|
|
}
|
|
|
|
- (void)testexceptionInitTimeZoneWithNilName
|
|
{
|
|
try
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:nil];
|
|
[self fail:"Invalid value provided for tzName"];
|
|
}
|
|
catch (e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
- (void)testInitTimeZoneWithNameWithData
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles" data:_data];
|
|
|
|
// The current implementation can return daylight saving time or standard time depending on the current implmentation on CPDictionary
|
|
if ([timeZone abbreviation] === @"PDT") {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PDT"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
|
|
} else {
|
|
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
|
|
[self assert:[timeZone abbreviation] equals:@"PST"];
|
|
[self assert:[timeZone secondsFromGMT] equals:(-480 * 60)];
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PST) offset -28800"];
|
|
}
|
|
[self assert:[timeZone data] equals:_data];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
|
|
}
|
|
|
|
- (void)testInitTimeZoneWithWrongNameWithData
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angelesezdez" data:_data];
|
|
[self assert:timeZone equals:nil];
|
|
}
|
|
|
|
- (void)testexceptionInitTimeZoneWithNilNameWithData
|
|
{
|
|
try
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:nil data:_data];
|
|
[self fail:"Invalid value provided for tzName"];
|
|
}
|
|
catch (e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
- (void)testAbbreviationWithDate
|
|
{
|
|
var timeZone = [CPTimeZone localTimeZone],
|
|
abbreviation = [timeZone abbreviationForDate:_date];
|
|
|
|
[self assert:abbreviation equals:String(String(_date).split("(")[1]).split(")")[0]];
|
|
}
|
|
|
|
- (void)testAbbreviationWithNilDate
|
|
{
|
|
var timeZone = [CPTimeZone localTimeZone],
|
|
abbreviation = [timeZone abbreviationForDate:nil];
|
|
|
|
[self assert:abbreviation equals:nil];
|
|
}
|
|
|
|
|
|
- (void)testSecondsFromGMTForDate
|
|
{
|
|
var timeZone = [CPTimeZone localTimeZone],
|
|
seconds = [timeZone secondsFromGMTForDate:_date];
|
|
|
|
[self assert:seconds equals:(_date.getTimezoneOffset() * -60)];
|
|
}
|
|
|
|
- (void)testSecondsFromGMTForDateWithNilDate
|
|
{
|
|
var timeZone = [CPTimeZone localTimeZone],
|
|
seconds = [timeZone secondsFromGMTForDate:nil];
|
|
|
|
[self assert:seconds equals:nil];
|
|
}
|
|
|
|
- (void)testSecondsFromGMT
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
|
|
|
|
// The current implementation can return daylight saving time or standard time depending on the current implmentation on CPDictionary
|
|
if ([timeZone abbreviation] === @"PDT") {
|
|
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
|
|
} else {
|
|
[self assert:[timeZone secondsFromGMT] equals:(-480 * 60)];
|
|
}
|
|
}
|
|
|
|
- (void)testDescription
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
|
|
|
|
// The current implementation can return daylight saving time or standard time depending on the current implmentation on CPDictionary
|
|
if ([timeZone abbreviation] === @"PDT") {
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
|
|
} else {
|
|
[self assert:[timeZone description] equals:@"America/Los_Angeles (PST) offset -28800"];
|
|
}
|
|
}
|
|
|
|
- (void)testLocalizedName
|
|
{
|
|
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
|
|
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
|
|
}
|
|
|
|
- (void)testEqualTrueToTimeZone
|
|
{
|
|
var timeZone1 = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"],
|
|
timeZone2 = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
|
|
|
|
[self assert:[timeZone1 isEqualToTimeZone:timeZone2] equals:YES];
|
|
}
|
|
|
|
- (void)testEqualFalseToTimeZone
|
|
{
|
|
var timeZone1 = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"],
|
|
timeZone2 = [[CPTimeZone alloc] initWithName:@"Pacific/Honolulu"];
|
|
|
|
[self assert:[timeZone1 isEqualToTimeZone:timeZone2] equals:NO];
|
|
}
|
|
|
|
@end
|