Permalink
Browse files

Convert tests to work with or without ARC.

  • Loading branch information...
1 parent d72adc2 commit 1569db021de8e76bf0350afaeef6a0c688a91bee @mbaltaks committed Aug 20, 2012
Showing with 44 additions and 27 deletions.
  1. +4 −3 testparser.m
  2. +6 −5 testunparsewithtime.m
  3. +21 −10 timetrial.m
  4. +5 −3 unparse-date.m
  5. +4 −3 unparse-ordinaldate.m
  6. +4 −3 unparse-weekdate.m
View
@@ -1,8 +1,9 @@
#import <Foundation/Foundation.h>
#import "ISO8601DateFormatter.h"
+#import "ARCMacros.h"
int main(int argc, const char **argv) {
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ SAFE_ARC_AUTORELEASE_POOL_START()
BOOL parseStrictly = NO;
if((argc > 1) && (strcmp(argv[1], "--strict") == 0)) {
@@ -12,7 +13,7 @@ int main(int argc, const char **argv) {
[NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:+0]];
- ISO8601DateFormatter *formatter = [[[ISO8601DateFormatter alloc] init] autorelease];
+ ISO8601DateFormatter *formatter = SAFE_ARC_AUTORELEASE([[ISO8601DateFormatter alloc] init]);
formatter.parsesStrictly = parseStrictly;
while(--argc) {
@@ -22,6 +23,6 @@ int main(int argc, const char **argv) {
fputs([[NSString stringWithFormat:@"%@ %C %@\n", str, 0x2192, date] UTF8String], stdout);
}
- [pool release];
+ SAFE_ARC_AUTORELEASE_POOL_END()
return 0;
}
View
@@ -1,11 +1,12 @@
#import <Foundation/Foundation.h>
#import "ISO8601DateFormatter.h"
+#import "ARCMacros.h"
static void testFormatStrings(int hour, int minute);
int main(void) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- ISO8601DateFormatter *formatter = [[[ISO8601DateFormatter alloc] init] autorelease];
+ SAFE_ARC_AUTORELEASE_POOL_START()
+ ISO8601DateFormatter *formatter = SAFE_ARC_AUTORELEASE([[ISO8601DateFormatter alloc] init]);
formatter.includeTime = YES;
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:336614400.0];
NSLog(@"2011-09-01 at 5 PM ET: %@", [formatter stringFromDate:date]);
@@ -14,7 +15,7 @@ int main(void) {
testFormatStrings(2, 6);
testFormatStrings(-2, 6);
- [pool drain];
+ SAFE_ARC_AUTORELEASE_POOL_END()
return EXIT_SUCCESS;
}
@@ -32,7 +33,7 @@ static void testFormatStrings(int hour, int minute) {
}
printf("Testing with printf:\n");
for (NSString *format in formatStrings) {
- format = [format stringByReplacingOccurrencesOfString:@"%@" withString:@"%s"];
- printf([[format stringByAppendingString:@"\n"] UTF8String], [format UTF8String], hour, minute);
+ NSString *cFormat = [format stringByReplacingOccurrencesOfString:@"%@" withString:@"%s"];
+ printf([[cFormat stringByAppendingString:@"\n"] UTF8String], [cFormat UTF8String], hour, minute);
}
}
View
@@ -1,13 +1,13 @@
#import <Foundation/Foundation.h>
#import "ISO8601DateFormatter.h"
+#import "ARCMacros.h"
-int main(void) {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- sleep(1);
-
- ISO8601DateFormatter *formatter = [[[ISO8601DateFormatter alloc] init] autorelease];
+void test_part_one(void);
+void test_part_one(void)
+{
+ SAFE_ARC_AUTORELEASE_POOL_START()
+ ISO8601DateFormatter *formatter = SAFE_ARC_AUTORELEASE([[ISO8601DateFormatter alloc] init]);
NSString *inString = @"2011-04-12T13:15:17-0800";
NSUInteger numResults = 0;
NSDate *start, *end;
@@ -26,12 +26,23 @@ int main(void) {
NSLog(@"Number of dates and strings computed: %lu each", (unsigned long)numResults);
NSLog(@"Time taken per date: %f seconds", [end timeIntervalSinceDate:start] / numReps);
- [pool drain];
- pool = [[NSAutoreleasePool alloc] init];
+ SAFE_ARC_AUTORELEASE_POOL_END()
+}
+
+int main(void) {
sleep(1);
- numResults = 0;
+ test_part_one();
+
+ SAFE_ARC_AUTORELEASE_POOL_START()
+
+ sleep(1);
+
+ NSString *inString = @"2011-04-12T13:15:17-0800";
+ NSUInteger numResults = 0;
+ NSDate *start, *end;
+ enum { numReps = 10000 };
NSLog(@"Timing C standard library parsing and unparsing");
@@ -63,6 +74,6 @@ int main(void) {
sleep(1);
- [pool drain];
+ SAFE_ARC_AUTORELEASE_POOL_END()
return EXIT_SUCCESS;
}
View
@@ -1,9 +1,11 @@
#import "ISO8601DateFormatter.h"
+#import "ARCMacros.h"
+
int main(int argc, const char **argv) {
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ SAFE_ARC_AUTORELEASE_POOL_START()
- ISO8601DateFormatter *formatter = [[[ISO8601DateFormatter alloc] init] autorelease];
+ ISO8601DateFormatter *formatter = SAFE_ARC_AUTORELEASE([[ISO8601DateFormatter alloc] init]);
formatter.format = ISO8601DateFormatCalendar;
BOOL forceUTC = NO;
@@ -28,6 +30,6 @@ int main(int argc, const char **argv) {
printf("%s\n", [[NSString stringWithFormat:@"%@:\t%@", arg, [formatter stringFromDate:date timeZone:timeZone]] UTF8String]);
}
- [pool release];
+ SAFE_ARC_AUTORELEASE_POOL_END()
return 0;
}
View
@@ -1,9 +1,10 @@
#import "ISO8601DateFormatter.h"
+#import "ARCMacros.h"
int main(int argc, const char **argv) {
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ SAFE_ARC_AUTORELEASE_POOL_START()
- ISO8601DateFormatter *formatter = [[[ISO8601DateFormatter alloc] init] autorelease];
+ ISO8601DateFormatter *formatter = SAFE_ARC_AUTORELEASE([[ISO8601DateFormatter alloc] init]);
formatter.format = ISO8601DateFormatOrdinal;
while(--argc) {
@@ -12,6 +13,6 @@ int main(int argc, const char **argv) {
printf("%s\n", [[NSString stringWithFormat:@"%@:\t%@", arg, [formatter stringFromDate:[formatter dateFromString:arg timeZone:&timeZone] timeZone:timeZone]] UTF8String]);
}
- [pool release];
+ SAFE_ARC_AUTORELEASE_POOL_END()
return 0;
}
View
@@ -1,9 +1,10 @@
#import "ISO8601DateFormatter.h"
+#import "ARCMacros.h"
int main(int argc, const char **argv) {
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ SAFE_ARC_AUTORELEASE_POOL_START()
- ISO8601DateFormatter *formatter = [[[ISO8601DateFormatter alloc] init] autorelease];
+ ISO8601DateFormatter *formatter = SAFE_ARC_AUTORELEASE([[ISO8601DateFormatter alloc] init]);
formatter.format = ISO8601DateFormatWeek;
while(--argc) {
@@ -12,6 +13,6 @@ int main(int argc, const char **argv) {
printf("%s\n", [[NSString stringWithFormat:@"%@:\t%@", arg, [formatter stringFromDate:[formatter dateFromString:arg timeZone:&timeZone] timeZone:timeZone]] UTF8String]);
}
- [pool release];
+ SAFE_ARC_AUTORELEASE_POOL_END()
return 0;
}

0 comments on commit 1569db0

Please sign in to comment.