UnitTests/TestDateAdditions.m
author Matthew Kotila
Mon, 14 Dec 2015 00:37:29 -0800
changeset 5949 334dc418b409
parent 3679 f4294bb53b0f
permissions -rw-r--r--
Transition Adium from SenTestingKit to XCTest.

In order to build on OS X 10.11, Xcode 7.2, several changes have been made that are outlined:
- Unit tests Target Build Settings modified:
* 'Wrapper Extension' set to 'xctest'
* 'Enable Modules (C and Objective-C)' set to 'Yes'
- UnitTests Target of AutoHyperlink.framework Build Settings modified:
* 'Wrapper Extension' set to 'xctest'
* 'Enable Modules (C and Objective-C)' set to 'Yes'
* 'Other Linker Flags' removed '-framework SenTestingKit'
- 'SenTestingKit.framework' removed from Adium -> Linked Frameworks -> System
- 'SenTestingKit.framework' removed from Adium -> Linked Frameworks -> AutoHyperlinks.framework.xcodeproj -> External Frameworks and Libraries -> Linked Frameworks
- Find and Replace within 'Adium/Unit tests' && 'Adium/Linked Frameworks/Others/AutoHyperlinks.framework.xcodeproj/UnitTests'
* '<SenTestingKit/SenTestingKit.h>' to '<XCTest/XCTest.h>'
* 'SenTestCase' to 'XCTestCase'
* 'STAssert' to 'XCTAssert'
* 'XCTAssertEquals(' to 'XCTAssertEqual('
* regex '(\[\[\[)([^\]]*\][^\]]*\])(\ autorelease\]);' to '[[$2;'
* regex '(\[)([^\]]*\][^\]]*)(\ autorelease\])' to '$2'
- modified AutoHyperlinks.framework.xcodeproj -> project.pbxproj
* line 331: ?productType = "com.apple.product-type.bundle.ocunit-test";' to 'productType = "com.apple.product-type.bundle.unit-test";'
- AIWebKitMessageViewController.h
* forward declare WebUIDelegate, WebFrameLoadDelegate protocols
* add WebUIDelegate, WebFrameLoadDelegate protocols to 'AIWebKitMessageViewController' class
- AIFacebookXMPPOAuthWebViewWindowController.m lines 107 && 108
* '[[domDoc getElementById:@"email"] setValue:self.autoFillUsername];' to '[domDoc getElementById:@"email"].innerHTML = self.autoFillUsername;'
* '[[domDoc getElementById:@"pass"] setValue:self.autoFillPassword];' to '[domDoc getElementById:@"pass"].innerHTML = self.autoFillPassword;'
- XCTAssertEqual for NSRanges modified to ?XCTAssertTrue(NSEqualRanges(range1, range2)), ...)' in Unit tests
3679
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     1
/* 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     2
 * Adium is the legal property of its developers, whose names are listed in the copyright file included
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     3
 * with this source distribution.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     4
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     6
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     7
 * or (at your option) any later version.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     8
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
    10
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
    11
 * Public License for more details.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
    12
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
    13
 * You should have received a copy of the GNU General Public License along with this program; if not,
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
    14
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2677
diff changeset
    15
 */
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    16
#import "TestDateAdditions.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    17
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    18
#import <AIUtilities/AIDateAdditions.h>
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    19
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    20
//2009-03-08T03:00:00.5 PDT - half a second after the start of Daylight Saving Time.
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    21
#define TEST_DATE [NSDate dateWithTimeIntervalSinceReferenceDate:258199200.5]
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    22
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    23
//We're testing converting intervals. If we use a time zone that supports DST, the DST changes screw us up. We need an invariant time zone, and UTC works well for this purpose.
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    24
#define TEST_TIME_ZONE [NSTimeZone timeZoneWithName:@"UTC"]
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    25
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    26
@implementation TestDateAdditions
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    27
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    28
- (void)testConvertIntervalToWeeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    29
{
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    30
	NSDate *now = TEST_DATE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    31
	NSDate *then;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    32
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    33
	NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    34
	NSTimeZone *tz = TEST_TIME_ZONE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    35
	gregorianCalendar.timeZone = tz;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    36
	NSDateComponents *components;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    37
2677
43d104027d33 Correct for 64-bit type mismatches for our unit tests.
Stephen Holt <sholt@adium.im>
parents: 1126
diff changeset
    38
	NSInteger weeks, days, hours, minutes;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    39
	NSTimeInterval seconds;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    40
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    41
	//Test exactly one week ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    42
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    43
	components.day = -7;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    44
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    45
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    46
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    47
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    48
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    49
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    50
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    51
	XCTAssertEqual(weeks, (NSInteger)1, @"Expected the difference between now and 7 days ago, which is %f seconds, to be 1 week; result was %iw, %id, %ih, %im, %fs", [now timeIntervalSinceDate:then], weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    52
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 7 days ago to be 1 week, 0 days; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    53
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 7 days ago to be 1 week, 0 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    54
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 7 days ago to be 1 week, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    55
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 7 days ago to be 1 week, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    56
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    57
	//Test eight days ago. [Insert obligatory Beatles reference]
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    58
	components.day = -8;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    59
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    60
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    61
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    62
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    63
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    64
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    65
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    66
	XCTAssertEqual(weeks, (NSInteger)1, @"Expected the difference between now and 8 days ago to be 1 week, 1 day; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    67
	XCTAssertEqual( days, (NSInteger)1, @"Expected the difference between now and 8 days ago to be 1 week, 1 day; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    68
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 8 days ago to be 1 week, 1 day, 0 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    69
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 8 days ago to be 1 week, 1 day, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    70
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 8 days ago to be 1 week, 1 day, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    71
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    72
	//Test six days (almost, but not quite, one week) ago. [Insert obligatory DJ Shadow reference]
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    73
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    74
	components.day = -6;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    75
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
1079
24e5c35a2178 Added a unit test for converting an interval to weeks. In this new test, we use a date that's known to cause the test to fail.
Peter Hosey
parents: 0
diff changeset
    76
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
24e5c35a2178 Added a unit test for converting an interval to weeks. In this new test, we use a date that's known to cause the test to fail.
Peter Hosey
parents: 0
diff changeset
    77
						toWeeks:&weeks
24e5c35a2178 Added a unit test for converting an interval to weeks. In this new test, we use a date that's known to cause the test to fail.
Peter Hosey
parents: 0
diff changeset
    78
						   days:&days
24e5c35a2178 Added a unit test for converting an interval to weeks. In this new test, we use a date that's known to cause the test to fail.
Peter Hosey
parents: 0
diff changeset
    79
						  hours:&hours
24e5c35a2178 Added a unit test for converting an interval to weeks. In this new test, we use a date that's known to cause the test to fail.
Peter Hosey
parents: 0
diff changeset
    80
						minutes:&minutes
24e5c35a2178 Added a unit test for converting an interval to weeks. In this new test, we use a date that's known to cause the test to fail.
Peter Hosey
parents: 0
diff changeset
    81
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    82
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 6 days ago to be 0 weeks, 6 days; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    83
	XCTAssertEqual( days, (NSInteger)6, @"Expected the difference between now and 6 days ago to be 6 days; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    84
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 6 days ago to be 6 days, 0 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    85
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 6 days ago to be 6 days, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    86
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 6 days ago to be 6 days, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
1079
24e5c35a2178 Added a unit test for converting an interval to weeks. In this new test, we use a date that's known to cause the test to fail.
Peter Hosey
parents: 0
diff changeset
    87
}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    88
- (void)testConvertIntervalToDays
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    89
{
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    90
	NSDate *now = TEST_DATE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    91
	NSDate *then;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    92
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
    93
	NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    94
	NSTimeZone *tz = TEST_TIME_ZONE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    95
	gregorianCalendar.timeZone = tz;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
    96
	NSDateComponents *components;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    97
2677
43d104027d33 Correct for 64-bit type mismatches for our unit tests.
Stephen Holt <sholt@adium.im>
parents: 1126
diff changeset
    98
	NSInteger weeks, days, hours, minutes;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    99
	NSTimeInterval seconds;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   100
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   101
	//Test one day ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   102
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   103
	components.day = -1;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   104
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   105
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   106
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   107
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   108
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   109
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   110
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   111
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 1 day ago to be 0 weeks, 1 day; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   112
	XCTAssertEqual( days, (NSInteger)1, @"Expected the difference between now and 1 day ago to be 1 day; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   113
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 1 day ago to be 1 day, 0 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   114
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 1 day ago to be 1 day, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   115
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 1 day ago to be 1 day, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   116
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   117
	//Test one day ago, expressed as hours.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   118
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   119
	components.hour = -24;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   120
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   121
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   122
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   123
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   124
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   125
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   126
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   127
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 1 day ago to be 0 weeks, 1 day; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   128
	XCTAssertEqual( days, (NSInteger)1, @"Expected the difference between now and 1 day ago to be 1 day; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   129
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 1 day ago to be 1 day, 0 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   130
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 1 day ago to be 1 day, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   131
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 1 day ago to be 1 day, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   132
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   133
	//Test 23 hours (almost, but not quite, one day) ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   134
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   135
	components.hour = -23;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   136
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   137
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   138
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   139
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   140
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   141
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   142
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   143
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 23 hours ago to be 0 weeks, 23 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   144
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 23 hours ago to be 0 days, 23 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   145
	XCTAssertEqual(hours, (NSInteger)23, @"Expected the difference between now and 23 hours ago to be 23 hours; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   146
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 23 hours ago to be 23 hours, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   147
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 23 hours ago to be 23 hours, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   148
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   149
- (void)testConvertIntervalToHours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   150
{
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   151
	NSDate *now = TEST_DATE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   152
	NSDate *then;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   153
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   154
	NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   155
	NSTimeZone *tz = TEST_TIME_ZONE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   156
	gregorianCalendar.timeZone = tz;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   157
	NSDateComponents *components;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   158
2677
43d104027d33 Correct for 64-bit type mismatches for our unit tests.
Stephen Holt <sholt@adium.im>
parents: 1126
diff changeset
   159
	NSInteger weeks, days, hours, minutes;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   160
	NSTimeInterval seconds;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   161
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   162
	//Test one hour ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   163
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   164
	components.hour = -1;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   165
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   166
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   167
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   168
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   169
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   170
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   171
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   172
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 1 hour ago to be 0 weeks, 1 hour; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   173
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 1 hour ago to be 0 days, 1 hour; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   174
	XCTAssertEqual(hours, (NSInteger)1, @"Expected the difference between now and 1 hour ago to be 1 hour; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   175
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 1 hour ago to be 1 hour, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   176
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 1 hour ago to be 1 hour, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   177
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   178
	//Test one hour ago, expressed as minutes.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   179
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   180
	components.minute = -60;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   181
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   182
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   183
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   184
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   185
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   186
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   187
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   188
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 1 hour ago to be 0 weeks, 1 hour; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   189
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 1 hour ago to be 0 days, 1 hour; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   190
	XCTAssertEqual(hours, (NSInteger)1, @"Expected the difference between now and 1 hour ago to be 1 hour; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   191
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 1 hour ago to be 1 hour, 0 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   192
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 1 hour ago to be 1 hour, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   193
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   194
	//Test 59 minutes (almost, but not quite, one hour) ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   195
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   196
	components.minute = -59;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   197
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   198
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   199
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   200
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   201
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   202
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   203
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   204
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 59 minutes ago to be 0 weeks, 59 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   205
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 59 minutes ago to be 0 days, 59 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   206
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 59 minutes ago to be 0 hours, 59 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   207
	XCTAssertEqual(minutes, (NSInteger)59, @"Expected the difference between now and 59 minutes ago to be 59 minutes; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   208
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 59 minutes ago to be 59 minutes, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   209
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   210
- (void)testConvertIntervalToMinutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   211
{
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   212
	NSDate *now = TEST_DATE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   213
	NSDate *then;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   214
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   215
	NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   216
	NSTimeZone *tz = TEST_TIME_ZONE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   217
	gregorianCalendar.timeZone = tz;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   218
	NSDateComponents *components;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   219
2677
43d104027d33 Correct for 64-bit type mismatches for our unit tests.
Stephen Holt <sholt@adium.im>
parents: 1126
diff changeset
   220
	NSInteger weeks, days, hours, minutes;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   221
	NSTimeInterval seconds;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   222
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   223
	//Test one minute ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   224
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   225
	components.minute = -1;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   226
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   227
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   228
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   229
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   230
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   231
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   232
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   233
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 1 minute ago to be 0 weeks, 1 minute; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   234
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 1 minute ago to be 0 days, 1 minute; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   235
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 1 minute ago to be 0 hours, 1 minute; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   236
	XCTAssertEqual(minutes, (NSInteger)1, @"Expected the difference between now and 1 minute ago to be 1 minute; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   237
	XCTAssertEqual(seconds, 0.0, @"Expected the difference between now and 1 minute ago to be 1 minute, 0 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   238
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   239
	//Test 59 seconds (almost, but not quite, one minute) ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   240
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   241
	components.second = -59;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   242
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   243
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   244
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   245
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   246
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   247
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   248
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   249
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 59 seconds ago to be 0 weeks, 59 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   250
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 59 seconds ago to be 0 days, 59 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   251
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 59 seconds ago to be 0 hours, 59 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   252
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 59 seconds ago to be 0 minutes, 59 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   253
	XCTAssertEqual(seconds, 59.0, @"Expected the difference between now and 59 seconds ago to be 59 seconds; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   254
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   255
- (void)testConvertIntervalToSeconds
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   256
{
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   257
	NSDate *now = TEST_DATE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   258
	NSDate *then;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   259
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   260
	NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   261
	NSTimeZone *tz = TEST_TIME_ZONE;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   262
	gregorianCalendar.timeZone = tz;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   263
	NSDateComponents *components;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   264
2677
43d104027d33 Correct for 64-bit type mismatches for our unit tests.
Stephen Holt <sholt@adium.im>
parents: 1126
diff changeset
   265
	NSInteger weeks, days, hours, minutes;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   266
	NSTimeInterval seconds;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   267
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   268
	//Test one second ago.
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   269
	components = [[NSDateComponents alloc] init];
1125
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   270
	components.second = -1;
7a84ec70ec2b Significant changes to the NSDate additions unit tests:
Peter Hosey
parents: 1124
diff changeset
   271
	then = [gregorianCalendar dateByAddingComponents:components toDate:now options:0UL];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   272
	[NSDate convertTimeInterval:[now timeIntervalSinceDate:then]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   273
						toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   274
						   days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   275
						  hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   276
						minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   277
						seconds:&seconds];
5949
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   278
	XCTAssertEqual(weeks, (NSInteger)0, @"Expected the difference between now and 1 second ago to be 0 weeks, 1 second; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   279
	XCTAssertEqual( days, (NSInteger)0, @"Expected the difference between now and 1 second ago to be 0 days, 1 second; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   280
	XCTAssertEqual(hours, (NSInteger)0, @"Expected the difference between now and 1 second ago to be 0 hours, 1 second; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   281
	XCTAssertEqual(minutes, (NSInteger)0, @"Expected the difference between now and 1 second ago to be 0 minutes, 1 second; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
334dc418b409 Transition Adium from SenTestingKit to XCTest.
Matthew Kotila
parents: 3679
diff changeset
   282
	XCTAssertEqual(seconds, 1.0, @"Expected the difference between now and 1 second ago to be 1 second; result was %iw, %id, %ih, %im, %fs", weeks, days, hours, minutes, seconds);
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   283
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   284
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   285
@end