Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Converting to ARC. Fixing build issues.

  • Loading branch information...
commit 0530b1a286021b46890e97b195bee54124c01216 1 parent eab2894
Gabriel Handford gabriel authored
Showing with 1,416 additions and 3,034 deletions.
  1. +17 −42 Classes-MacOSX/GHUnitTestMain.m
  2. +2 −5 Classes-MacOSX/UI/GHTestApp.m
  3. +1 −1  Classes-MacOSX/UI/GHTestOutlineViewModel.h
  4. +1 −2  Classes-MacOSX/UI/GHTestOutlineViewModel.m
  5. +4 −4 Classes-MacOSX/UI/GHTestViewController.h
  6. +3 −9 Classes-MacOSX/UI/GHTestViewController.m
  7. +1 −1  Classes-MacOSX/UI/GHTestWindowController.h
  8. +0 −4 Classes-MacOSX/UI/GHTestWindowController.m
  9. +0 −5 Classes-iOS/GHImageDiffView.m
  10. +12 −22 Classes/Mock/GHUNSObject+Swizzle.h → Classes-iOS/GHUIImageViewControl.h
  11. +37 −34 Classes/Mock/GHNSLocale+Mock.h → Classes-iOS/GHUIImageViewControl.m
  12. +5 −8 Classes-iOS/GHUnitIOSAppDelegate.m
  13. +1 −1  Classes-iOS/GHUnitIOSTableViewDataSource.m
  14. +5 −5 Classes-iOS/GHUnitIOSTestView.h
  15. +2 −5 Classes-iOS/GHUnitIOSTestView.m
  16. +1 −10 Classes-iOS/GHUnitIOSTestViewController.m
  17. +0 −6 Classes-iOS/GHUnitIOSView.m
  18. +1 −1  Classes-iOS/GHUnitIOSViewController.h
  19. +0 −8 Classes-iOS/GHUnitIOSViewController.m
  20. +1 −1  Classes/GHAsyncTestCase.h
  21. +21 −26 Classes/GHAsyncTestCase.m
  22. +2 −4 Classes/GHTest/GHTest.h
  23. +10 −19 Classes/GHTest/GHTest.m
  24. +4 −5 Classes/GHTest/GHTestGroup.h
  25. +8 −18 Classes/GHTest/GHTestGroup.m
  26. +5 −10 Classes/GHTest/GHTestOperation.m
  27. +4 −4 Classes/GHTest/GHTestRunner.h
  28. +38 −31 Classes/GHTest/GHTestRunner.m
  29. +11 −9 Classes/GHTest/GHTestSuite.m
  30. +0 −5 Classes/GHTest/GHTesting.h
  31. +137 −64 Classes/GHTest/GHTesting.m
  32. +8 −8 Classes/GHTest/NSException+GHTestFailureExceptions.m
  33. +2 −2 Classes/GHTestCase.h
  34. +0 −1  Classes/GHTestCase.m
  35. +1 −8 Classes/Mock/GHMockNSHTTPURLResponse.m
  36. +16 −15 Classes/Mock/GHMockNSURLConnection.m
  37. +0 −85 Classes/Mock/GHNSLocale+Mock.m
  38. +0 −131 Classes/Mock/GHUNSObject+Swizzle.m
  39. +5 −5 Classes/SharedUI/GHTestViewModel.h
  40. +12 −32 Classes/SharedUI/GHTestViewModel.m
  41. +0 −132 Libraries/GHKit/GHNSInvocation+Utils.h
  42. +0 −124 Libraries/GHKit/GHNSInvocation+Utils.m
  43. +0 −135 Libraries/GHKit/GHNSInvocationProxy.h
  44. +0 −123 Libraries/GHKit/GHNSInvocationProxy.m
  45. +0 −100 Libraries/GHKit/GHNSObject+Invocation.h
  46. +0 −128 Libraries/GHKit/GHNSObject+Invocation.m
  47. +0 −72 Libraries/GTM/Foundation/GTMGarbageCollection.h
  48. +3 −4 Libraries/GTM/Foundation/GTMNSString+XML.m
  49. +0 −106 Libraries/GTM/Foundation/GTMStackTrace.h
  50. +0 −358 Libraries/GTM/Foundation/GTMStackTrace.m
  51. +1 −2  Libraries/README.md
  52. +0 −20 Libraries/YelpKit/YKUIImageViewControl.h
  53. +0 −52 Libraries/YelpKit/YKUIImageViewControl.m
  54. +0 −24 Libraries/update
  55. +10 −67 Project-MacOSX/GHUnitMacOSX.xcodeproj/project.pbxproj
  56. +24 −108 Project-iOS/GHUnitIOS.xcodeproj/project.pbxproj
  57. +1 −0  Scripts/iOSFramework.sh
  58. +5 −10 Tests/GHAsyncTestCaseTest.m
  59. +1 −5 Tests/GHKVObserveTest.m
  60. +2 −7 Tests/GHMockNSURLConnectionTest.m
  61. +0 −23 Tests/GHNSLocaleMockTest.m
  62. +3 −3 Tests/GHNSURLConnectionTest.m
  63. +4 −4 Tests/GHUnitIOSTestMain.m
  64. +767 −680 Tests/GTM/GTMSenTestCase.h
  65. +216 −90 Tests/GTM/GTMSenTestCase.m
  66. +1 −1  XcodeConfig/Shared.xcconfig
59 Classes-MacOSX/GHUnitTestMain.m
View
@@ -32,52 +32,27 @@
#import <GHUnit/GHUnit.h>
#import <GHUnit/GHTestApp.h>
-// Default exception handler
-void exceptionHandler(NSException *exception) {
- NSLog(@"%@\n%@", [exception reason], GHUStackTraceFromException(exception));
-}
-
int main(int argc, char *argv[]) {
-
- /*!
- Default: Set to:
- NSDebugEnabled NO "YES"
- NSZombieEnabled NO "YES"
- NSDeallocateZombies NO "YES"
- NSHangOnUncaughtException NO "YES"
-
- NSEnableAutoreleasePool YES "NO"
- NSAutoreleaseFreedObjectCheckEnabled NO "YES"
- NSAutoreleaseHighWaterMark 0 non-negative integer
- NSAutoreleaseHighWaterResolution 0 non-negative integer
-
- For info on these varaiables see NSDebug.h; http://theshadow.uw.hu/iPhoneSDKdoc/Foundation.framework/NSDebug.h.html
-
- For malloc debugging see: http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html
- */
- NSSetUncaughtExceptionHandler(&exceptionHandler);
-
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ @autoreleasepool {
// Register any special test case classes
//[[GHTesting sharedInstance] registerClassName:@"GHSpecialTestCase"];
- int retVal = 0;
- // If GHUNIT_CLI is set we are using the command line interface and run the tests
- // Otherwise load the GUI app
- if (getenv("GHUNIT_CLI")) {
- retVal = [GHTestRunner run];
- } else {
- // To run all tests (from ENV)
- GHTestApp *app = [[GHTestApp alloc] init];
- // To run a different test suite:
- //GHTestSuite *suite = [GHTestSuite suiteWithTestFilter:@"GHSlowTest,GHAsyncTestCaseTest"];
- //GHTestApp *app = [[GHTestApp alloc] initWithSuite:suite];
- // Or set global:
- //GHUnitTest = @"GHSlowTest";
- [NSApp run];
- [app release];
+ int retVal = 0;
+ // If GHUNIT_CLI is set we are using the command line interface and run the tests
+ // Otherwise load the GUI app
+ if (getenv("GHUNIT_CLI")) {
+ retVal = [GHTestRunner run];
+ } else {
+ // To run all tests (from ENV)
+ GHTestApp *app = [[GHTestApp alloc] init];
+ // To run a different test suite:
+ //GHTestSuite *suite = [GHTestSuite suiteWithTestFilter:@"GHSlowTest,GHAsyncTestCaseTest"];
+ //GHTestApp *app = [[GHTestApp alloc] initWithSuite:suite];
+ // Or set global:
+ //GHUnitTest = @"GHSlowTest";
+ [NSApp run];
+ }
+ return retVal;
}
- [pool release];
- return retVal;
}
7 Classes-MacOSX/UI/GHTestApp.m
View
@@ -16,14 +16,14 @@ - (id)init {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
topLevelObjects_ = [[NSMutableArray alloc] init];
NSDictionary *externalNameTable = [NSDictionary dictionaryWithObjectsAndKeys:self, @"NSOwner", topLevelObjects_, @"NSTopLevelObjects", nil];
- [bundle loadNibFile:@"GHTestApp" externalNameTable:externalNameTable withZone:[self zone]];
+ [bundle loadNibFile:@"GHTestApp" externalNameTable:externalNameTable withZone:nil];
}
return self;
}
- (id)initWithSuite:(GHTestSuite *)suite {
// Since init loads XIB we need to set suite early; For backwards compat.
- suite_ = [suite retain];
+ suite_ = suite;
if ((self = [self init])) { }
return self;
}
@@ -37,9 +37,6 @@ - (void)awakeFromNib {
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [suite_ release];
- [topLevelObjects_ release];
- [super dealloc];
}
- (void)runTests {
2  Classes-MacOSX/UI/GHTestOutlineViewModel.h
View
@@ -28,6 +28,6 @@
NSButtonCell *editCell_;
}
-@property (assign, nonatomic) id<GHTestOutlineViewModelDelegate> delegate;
+@property ( nonatomic) id<GHTestOutlineViewModelDelegate> delegate;
@end
3  Classes-MacOSX/UI/GHTestOutlineViewModel.m
View
@@ -70,7 +70,6 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTab
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:[item name] attributes:attributes];
[cell setAttributedTitle:attributedString];
- [attributedString release];
} else {
[cell setTitle:[item name]];
[cell setTextColor:textColor];
@@ -101,7 +100,7 @@ - (NSCell *)outlineView:(NSOutlineView *)outlineView dataCellForTableColumn:(NST
if ([[tableColumn identifier] isEqual:@"name"] && self.isEditing) {
// TODO(gabe): Doesn't work if you try to re-use cells so making a new one;
// Need help with this; This might explode if you have a lot of tests
- NSButtonCell *cell = [[[NSButtonCell alloc] init] autorelease];
+ NSButtonCell *cell = [[NSButtonCell alloc] init];
[cell setControlSize:NSSmallControlSize];
[cell setFont:[NSFont fontWithName:@"Lucida Grande" size:11]];
[cell setButtonType:NSSwitchButton];
8 Classes-MacOSX/UI/GHTestViewController.h
View
@@ -63,14 +63,14 @@
@property (readonly, nonatomic) id<GHTest> selectedTest;
@property (readonly, nonatomic) GHTestOutlineViewModel *dataSource;
-@property (retain, nonatomic) NSString *status;
+@property ( nonatomic) NSString *status;
@property (assign, nonatomic) double statusProgress;
-@property (retain, nonatomic) NSString *runLabel;
+@property ( nonatomic) NSString *runLabel;
-@property (retain, nonatomic) GHTestSuite *suite;
+@property ( nonatomic) GHTestSuite *suite;
@property (assign, nonatomic, getter=isRunning) BOOL running;
-@property (retain, nonatomic) NSString *exceptionFilename;
+@property ( nonatomic) NSString *exceptionFilename;
@property (assign, nonatomic) NSInteger exceptionLineNumber;
@property (assign, nonatomic) BOOL reraiseExceptions;
12 Classes-MacOSX/UI/GHTestViewController.m
View
@@ -46,9 +46,9 @@ @implementation GHTestViewController
- (id)init {
if ((self = [super initWithNibName:@"GHTestView" bundle:[NSBundle bundleForClass:[GHTestViewController class]]])) {
- suite_ = [[GHTestSuite suiteFromEnv] retain];
+ suite_ = [GHTestSuite suiteFromEnv];
- NSString *identifier = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"] retain];
+ NSString *identifier = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
if (!identifier) identifier = @"Tests";
GHUDebug(@"Using identifier: %@", identifier);
@@ -62,18 +62,13 @@ - (id)init {
- (void)dealloc {
dataSource_.delegate = nil;
- [dataSource_ release];
- [suite_ release];
- [status_ release];
- [_detailsView release];
- [super dealloc];
}
- (void)awakeFromNib {
_outlineView.delegate = dataSource_;
_outlineView.dataSource = dataSource_;
- [_detailsView retain]; // If we remove from superview, need to keep it retained
+ // If we remove from superview, need to keep it retained
[_textView setTextColor:[NSColor whiteColor]];
[_textView setFont:[NSFont fontWithName:@"Monaco" size:10.0]];
@@ -209,7 +204,6 @@ - (IBAction)rerunTest:(id)sender {
[self _updateDetailForTest:nil prefix:@"Re-running test."];
[test run:GHTestOptionForceSetUpTearDownClass];
[self _updateDetailForTest:test prefix:@"Re-ran test. (This feature is experimental.)"];
- [test release];
}
- (BOOL)isShowingDetails {
2  Classes-MacOSX/UI/GHTestWindowController.h
View
@@ -33,7 +33,7 @@
GHTestViewController *viewController_;
}
-@property (retain, nonatomic) IBOutlet GHTestViewController *viewController;
+@property ( nonatomic) IBOutlet GHTestViewController *viewController;
- (IBAction)runTests:(id)sender;
- (IBAction)copy:(id)sender;
4 Classes-MacOSX/UI/GHTestWindowController.m
View
@@ -57,10 +57,6 @@ - (IBAction)copy:(id)sender {
[viewController_ copy:sender];
}
-- (void)dealloc {
- [viewController_ release];
- [super dealloc];
-}
- (void)windowWillClose:(NSNotification *)notification {
[[NSApplication sharedApplication] terminate:self];
5 Classes-iOS/GHImageDiffView.m
View
@@ -37,7 +37,6 @@ - (id)initWithFrame:(CGRect)frame {
scrollView_.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
scrollView_.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
[self addSubview:scrollView_];
- [scrollView_ release];
segmentedControl_ = [[UISegmentedControl alloc] initWithFrame:CGRectZero];
[segmentedControl_ insertSegmentWithTitle:@"Original" atIndex:0 animated:NO];
@@ -45,19 +44,15 @@ - (id)initWithFrame:(CGRect)frame {
[segmentedControl_ insertSegmentWithTitle:@"Diff" atIndex:2 animated:NO];
[segmentedControl_ addTarget:self action:@selector(segmentedControlDidChange:) forControlEvents:UIControlEventValueChanged];
[self addSubview:segmentedControl_];
- [segmentedControl_ release];
originalImageView_ = [[UIImageView alloc] initWithFrame:CGRectZero];
[scrollView_ addSubview:originalImageView_];
- [originalImageView_ release];
newImageView_ = [[UIImageView alloc] initWithFrame:CGRectZero];
[scrollView_ addSubview:newImageView_];
- [newImageView_ release];
diffImageView_ = [[UIImageView alloc] initWithFrame:CGRectZero];
[scrollView_ addSubview:diffImageView_];
- [diffImageView_ release];
}
return self;
}
34 Classes/Mock/GHUNSObject+Swizzle.h → Classes-iOS/GHUIImageViewControl.h
View
@@ -1,9 +1,9 @@
//
-// GHNSObject+Swizzle.h
-// GHUnit
+// GHUIImageViewControl.h
+// GHUnitIOS
//
-// Created by Gabriel Handford on 4/13/09.
-// Copyright 2009. All rights reserved.
+// Created by Gabriel Handford on 4/1/11.
+// Copyright 2011. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -27,25 +27,15 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
-/*!
- Method swizzling.
- */
-@interface NSObject(GHUSwizzle)
+@interface GHUIImageViewControl : UIControl {
+ UIImageView *_imageView;
+}
-/*!
- Swizzle instance method.
- @param original Original method
- @param withMethod New method
- */
-+ (void)ghu_swizzleMethod:(SEL)original withMethod:(SEL)withMethod;
+@property (readonly, nonatomic) UIImageView *imageView;
+@property (nonatomic) UIImage *image;
-/*!
- Swizzle class method.
- @param original Original method
- @param withClassMethod New method
- */
-+ (void)ghu_swizzleClassMethod:(SEL)original withClassMethod:(SEL)withClassMethod;
+- (id)initWithFrame:(CGRect)frame image:(UIImage *)image highlightedImage:(UIImage *)highlightedImage;
-@end
+@end
71 Classes/Mock/GHNSLocale+Mock.h → Classes-iOS/GHUIImageViewControl.m
View
@@ -1,9 +1,9 @@
//
-// GHNSLocale+Mock.h
-// GHUnit
+// GHUIImageViewControl.m
+// GHUnitIOS
//
-// Created by Gabriel Handford on 4/13/09.
-// Copyright 2009. All rights reserved.
+// Created by Gabriel Handford on 4/1/11.
+// Copyright 2011. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@@ -27,42 +27,45 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-#import <Foundation/Foundation.h>
+#import "GHUIImageViewControl.h"
-/*!
- Category for overriding the current locale at runtime.
- #import "GHNSLocale+Mock.h"
- // This aliases the currentLocale method and with the specified locale identifier
- [NSLocale gh_setLocaleIdentifier:@"en_GB"];
-
- [[NSLocale currentLocale] localeIdentifier] == "en_GB"
+@implementation GHUIImageViewControl
- */
-@interface NSLocale(GHMock)
+@synthesize imageView=_imageView;
-/*!
- Set locale.
- @param localeIdentifier Locale identifier, e.g. "en_US"
- */
-+ (void)gh_setLocaleIdentifier:(NSString *)localeIdentifier;
+- (id)initWithFrame:(CGRect)frame {
+ if ((self = [super initWithFrame:frame])) {
+ _imageView = [[UIImageView alloc] init];
+ [self addSubview:_imageView];
+ }
+ return self;
+}
-/*!
- Aliases to currentLocale with locale set from gh_setLocaleIdentifier.
- If not set, defaults to NSLocale with identifier en_US.
- */
-+ (NSLocale *)gh_currentLocale;
+- (id)initWithFrame:(CGRect)frame image:(UIImage *)image highlightedImage:(UIImage *)highlightedImage {
+ if ((self = [super initWithFrame:frame])) {
+ _imageView = [[UIImageView alloc] initWithImage:image highlightedImage:highlightedImage];
+ [self addSubview:_imageView];
+ }
+ return self;
+}
-/*!
- Set preferred languages. To reset, set to nil.
- @param preferredLanguages Preferred languages to set
- */
-+ (void)gh_setPreferredLanguages:(NSArray *)preferredLanguages;
+- (void)layoutSubviews {
+ [super layoutSubviews];
+ _imageView.frame = self.bounds;
+}
-/*!
- Aliases to preferredLanguages set from gh_setPreferredLanguages.
- If not set, defaults to [@"en"].
- */
-+ (NSArray *)gh_preferredLanguages;
+- (void)setHighlighted:(BOOL)highlighted {
+ [super setHighlighted:highlighted];
+ _imageView.highlighted = highlighted;
+}
+
+- (UIImage *)image {
+ return _imageView.image;
+}
+
+- (void)setImage:(UIImage *)image {
+ _imageView.image = image;
+}
@end
13 Classes-iOS/GHUnitIOSAppDelegate.m
View
@@ -31,14 +31,17 @@
#import "GHUnitIOSViewController.h"
#import "GHUnit.h"
+@interface GHUnitIOSAppDelegate (Terminate)
+- (void)_terminateWithStatus:(int)status;
+@end
+
@implementation GHUnitIOSAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
if (getenv("GHUNIT_CLI")) {
int exitStatus = [GHTestRunner run];
if ([application respondsToSelector:@selector(_terminateWithStatus:)]) {
- [application performSelector:@selector(_terminateWithStatus:)
- withObject:(id)exitStatus];
+ [(id)application _terminateWithStatus:exitStatus];
} else {
exit(exitStatus);
}
@@ -46,7 +49,6 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
GHUnitIOSViewController *viewController = [[GHUnitIOSViewController alloc] init];
[viewController loadDefaults];
navigationController_ = [[UINavigationController alloc] initWithRootViewController:viewController];
- [viewController release];
CGSize size = [[UIScreen mainScreen] bounds].size;
window_ = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
[window_ addSubview:navigationController_.view];
@@ -63,10 +65,5 @@ - (void)applicationWillTerminate:(UIApplication *)application {
[[[navigationController_ viewControllers] objectAtIndex:0] saveDefaults];
}
-- (void)dealloc {
- [navigationController_ release];
- [window_ release];
- [super dealloc];
-}
@end
2  Classes-iOS/GHUnitIOSTableViewDataSource.m
View
@@ -70,7 +70,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
static NSString *CellIdentifier = @"ReviewFeedViewItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if (editing_) {
cell.textLabel.text = node.name;
10 Classes-iOS/GHUnitIOSTestView.h
View
@@ -28,7 +28,7 @@
//
#import <UIKit/UIKit.h>
-#import "YKUIImageViewControl.h"
+#import "GHUIImageViewControl.h"
@class GHUnitIOSTestView;
@@ -39,18 +39,18 @@
@end
@interface GHUnitIOSTestView : UIScrollView {
- id<GHUnitIOSTestViewDelegate> controlDelegate_;
+ id<GHUnitIOSTestViewDelegate> __unsafe_unretained controlDelegate_;
// TODO(johnb): Perhaps hold a scrollview here as subclassing UIViews can be weird.
- YKUIImageViewControl *originalImageView_;
- YKUIImageViewControl *newImageView_;
+ GHUIImageViewControl *originalImageView_;
+ GHUIImageViewControl *newImageView_;
UIButton *approveButton_;
UILabel *textLabel_;
}
-@property(assign, nonatomic) id<GHUnitIOSTestViewDelegate> controlDelegate;
+@property(unsafe_unretained, nonatomic) id<GHUnitIOSTestViewDelegate> controlDelegate;
- (void)setOriginalImage:(UIImage *)originalImage newImage:(UIImage *)newImage text:(NSString *)text;
7 Classes-iOS/GHUnitIOSTestView.m
View
@@ -43,23 +43,20 @@ - (id)initWithFrame:(CGRect)frame {
textLabel_.textColor = [UIColor blackColor];
textLabel_.numberOfLines = 0;
[self addSubview:textLabel_];
- [textLabel_ release];
- originalImageView_ = [[YKUIImageViewControl alloc] initWithFrame:CGRectMake(10, 10, 145, 100)];
+ originalImageView_ = [[GHUIImageViewControl alloc] initWithFrame:CGRectMake(10, 10, 145, 100)];
[originalImageView_ addTarget:self action:@selector(_selectOriginalImage) forControlEvents:UIControlEventTouchUpInside];
[originalImageView_.layer setBorderWidth:2.0f];
[originalImageView_.layer setBorderColor:[UIColor blackColor].CGColor];
originalImageView_.hidden = YES;
[self addSubview:originalImageView_];
- [originalImageView_ release];
- newImageView_ = [[YKUIImageViewControl alloc] initWithFrame:CGRectMake(165, 10, 145, 100)];
+ newImageView_ = [[GHUIImageViewControl alloc] initWithFrame:CGRectMake(165, 10, 145, 100)];
[newImageView_ addTarget:self action:@selector(_selectNewImage) forControlEvents:UIControlEventTouchUpInside];
[newImageView_.layer setBorderWidth:2.0f];
[newImageView_.layer setBorderColor:[UIColor blackColor].CGColor];
newImageView_.hidden = YES;
[self addSubview:newImageView_];
- [newImageView_ release];
approveButton_ = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[approveButton_ addTarget:self action:@selector(_approveChange) forControlEvents:UIControlEventTouchUpInside];
11 Classes-iOS/GHUnitIOSTestViewController.m
View
@@ -37,21 +37,15 @@ - (id)init {
UIBarButtonItem *runButton = [[UIBarButtonItem alloc] initWithTitle:@"Re-run" style:UIBarButtonItemStyleDone
target:self action:@selector(_runTest)];
self.navigationItem.rightBarButtonItem = runButton;
- [runButton release];
}
return self;
}
-- (void)dealloc {
- [testNode_ release];
- [super dealloc];
-}
- (void)loadView {
testView_ = [[GHUnitIOSTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
testView_.controlDelegate = self;
self.view = testView_;
- [testView_ release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
@@ -64,7 +58,6 @@ - (void)_runTest {
[testView_ setText:@"Running..."];
[test run:GHTestOptionForceSetUpTearDownClass];
[self setTest:test];
- [test release];
}
- (void)_showImageDiff {
@@ -76,7 +69,6 @@ - (void)_showImageDiff {
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view = imageDiffView_;
[self.navigationController pushViewController:viewController animated:YES];
- [viewController release];
}
- (NSString *)updateTestView {
@@ -105,8 +97,7 @@ - (void)setTest:(id<GHTest>)test {
[self view];
self.title = [test name];
- [testNode_ release];
- testNode_ = [[GHTestNode nodeWithTest:test children:nil source:nil] retain];
+ testNode_ = [GHTestNode nodeWithTest:test children:nil source:nil];
NSString *text = [self updateTestView];
NSLog(@"%@", text);
}
6 Classes-iOS/GHUnitIOSView.m
View
@@ -42,13 +42,11 @@ - (id)initWithFrame:(CGRect)frame {
searchBar_.showsCancelButton = NO;
searchBar_.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self addSubview:searchBar_];
- [searchBar_ release];
// Table view
tableView_ = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
tableView_.sectionIndexMinimumDisplayRowCount = 5;
[self addSubview:tableView_];
- [tableView_ release];
footerView_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 36)];
footerView_.backgroundColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
@@ -61,10 +59,8 @@ - (id)initWithFrame:(CGRect)frame {
statusLabel_.numberOfLines = 2;
statusLabel_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[footerView_ addSubview:statusLabel_];
- [statusLabel_ release];
[self addSubview:footerView_];
- [footerView_ release];
runToolbar_ = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 36)];
filterControl_ = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"All", @"Failed", nil]];
@@ -72,9 +68,7 @@ - (id)initWithFrame:(CGRect)frame {
filterControl_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
filterControl_.segmentedControlStyle = UISegmentedControlStyleBar;
[runToolbar_ addSubview:filterControl_];
- [filterControl_ release];
[self addSubview:runToolbar_];
- [runToolbar_ release];
}
return self;
}
2  Classes-iOS/GHUnitIOSViewController.h
View
@@ -49,7 +49,7 @@
}
-@property (retain, nonatomic) GHTestSuite *suite;
+@property (strong, nonatomic) GHTestSuite *suite;
- (void)reloadTest:(id<GHTest>)test;
8 Classes-iOS/GHUnitIOSViewController.m
View
@@ -51,13 +51,8 @@ - (id)init {
}
- (void)dealloc {
- [dataSource_ release];
- [suite_ release];
- [runButton_ release];
view_.tableView.delegate = nil;
view_.searchBar.delegate = nil;
- [view_ release];
- [super dealloc];
}
- (void)loadDefaults { }
@@ -69,7 +64,6 @@ - (void)saveDefaults {
- (void)loadView {
[super loadView];
- [runButton_ release];
runButton_ = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStyleDone
target:self action:@selector(_toggleTestsRunning)];
self.navigationItem.rightBarButtonItem = runButton_;
@@ -77,7 +71,6 @@ - (void)loadView {
// Clear view
view_.tableView.delegate = nil;
view_.searchBar.delegate = nil;
- [view_ release];
view_ = [[GHUnitIOSView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
view_.searchBar.delegate = self;
@@ -206,7 +199,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
GHUnitIOSTestViewController *testViewController = [[GHUnitIOSTestViewController alloc] init];
[testViewController setTest:testNode.test];
[self.navigationController pushViewController:testViewController animated:YES];
- [testViewController release];
}
}
2  Classes/GHAsyncTestCase.h
View
@@ -89,7 +89,7 @@ enum {
Run loop modes to run while waiting;
Defaults to NSDefaultRunLoopMode, NSRunLoopCommonModes, NSConnectionReplyMode
*/
-@property (retain, nonatomic) NSArray *runLoopModes;
+@property (strong, nonatomic) NSArray *runLoopModes;
/*!
Prepare before calling the asynchronous method.
47 Classes/GHAsyncTestCase.m
View
@@ -41,10 +41,6 @@ @implementation GHAsyncTestCase
@synthesize runLoopModes=_runLoopModes;
-- (void)dealloc {
- [_runLoopModes release];
- [super dealloc];
-}
// Internal GHUnit setUp
- (void)_setUp {
@@ -57,7 +53,6 @@ - (void)_setUp {
- (void)_tearDown {
waitSelector_ = NULL;
if (prepared_) [lock_ unlock]; // If we prepared but never waited we need to unlock
- [lock_ release];
lock_ = nil;
}
@@ -81,7 +76,7 @@ - (GHUnitAsyncError)_waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout {
waitForStatus_ = status;
if (!_runLoopModes)
- _runLoopModes = [[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSRunLoopCommonModes, nil] retain];
+ _runLoopModes = [NSArray arrayWithObjects:NSDefaultRunLoopMode, NSRunLoopCommonModes, nil];
NSTimeInterval checkEveryInterval = 0.05;
NSDate *runUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeout];
@@ -91,11 +86,11 @@ - (GHUnitAsyncError)_waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout {
NSString *mode = [_runLoopModes objectAtIndex:(runIndex++ % [_runLoopModes count])];
[lock_ unlock];
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- if (!mode || ![[NSRunLoop currentRunLoop] runMode:mode beforeDate:[NSDate dateWithTimeIntervalSinceNow:checkEveryInterval]])
- // If there were no run loop sources or timers then we should sleep for the interval
- [NSThread sleepForTimeInterval:checkEveryInterval];
- [pool release];
+ @autoreleasepool {
+ if (!mode || ![[NSRunLoop currentRunLoop] runMode:mode beforeDate:[NSDate dateWithTimeIntervalSinceNow:checkEveryInterval]])
+ // If there were no run loop sources or timers then we should sleep for the interval
+ [NSThread sleepForTimeInterval:checkEveryInterval];
+ }
[lock_ lock];
// If current date is after the run until date
@@ -144,7 +139,7 @@ - (void)runForInterval:(NSTimeInterval)interval {
NSDate *runUntilDate = [NSDate dateWithTimeIntervalSinceNow:interval];
if (!_runLoopModes)
- _runLoopModes = [[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSRunLoopCommonModes, nil] retain];
+ _runLoopModes = [NSArray arrayWithObjects:NSDefaultRunLoopMode, NSRunLoopCommonModes, nil];
NSInteger runIndex = 0;
@@ -152,11 +147,11 @@ - (void)runForInterval:(NSTimeInterval)interval {
NSString *mode = [_runLoopModes objectAtIndex:(runIndex++ % [_runLoopModes count])];
[lock_ unlock];
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- if (!mode || ![[NSRunLoop currentRunLoop] runMode:mode beforeDate:[NSDate dateWithTimeIntervalSinceNow:checkEveryInterval]])
- // If there were no run loop sources or timers then we should sleep for the interval
- [NSThread sleepForTimeInterval:checkEveryInterval];
- [pool release];
+ @autoreleasepool {
+ if (!mode || ![[NSRunLoop currentRunLoop] runMode:mode beforeDate:[NSDate dateWithTimeIntervalSinceNow:checkEveryInterval]])
+ // If there were no run loop sources or timers then we should sleep for the interval
+ [NSThread sleepForTimeInterval:checkEveryInterval];
+ }
[lock_ lock];
}
}
@@ -167,18 +162,18 @@ - (void)notify:(NSInteger)status {
- (void)notify:(NSInteger)status forSelector:(SEL)selector {
// Note: If this is called from a stray thread or delayed call, we may not be in an autorelease pool
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ @autoreleasepool {
// Make sure the notify is for the currently waiting test
- if (selector != NULL && !sel_isEqual(waitSelector_, selector)) {
- NSLog(@"Warning: Notified from %@ but we were waiting for %@", NSStringFromSelector(selector), NSStringFromSelector(waitSelector_));
- } else {
- [lock_ lock];
- notifiedStatus_ = status;
- [lock_ unlock];
- }
+ if (selector != NULL && !sel_isEqual(waitSelector_, selector)) {
+ NSLog(@"Warning: Notified from %@ but we were waiting for %@", NSStringFromSelector(selector), NSStringFromSelector(waitSelector_));
+ } else {
+ [lock_ lock];
+ notifiedStatus_ = status;
+ [lock_ unlock];
+ }
- [pool release];
+ }
}
@end
6 Classes/GHTest/GHTest.h
View
@@ -229,8 +229,6 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);
*/
@interface GHTest : NSObject <GHTest, GHTestCaseLogWriter> {
- NSObject<GHTestDelegate> *delegate_; // weak
-
id target_;
SEL selector_;
@@ -246,9 +244,9 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);
}
-@property (readonly, nonatomic) id target;
+@property (readonly, strong, nonatomic) id target;
@property (readonly, nonatomic) SEL selector;
-@property (readonly, nonatomic) NSArray *log;
+@property (readonly, strong, nonatomic) NSArray *log;
/*!
Create test with identifier, name.
29 Classes/GHTest/GHTest.m
View
@@ -85,8 +85,8 @@ @implementation GHTest
- (id)initWithIdentifier:(NSString *)identifier name:(NSString *)name {
if ((self = [self init])) {
- identifier_ = [identifier retain];
- name_ = [name retain];
+ identifier_ = identifier;
+ name_ = name;
interval_ = -1;
status_ = GHTestStatusNone;
}
@@ -97,24 +97,16 @@ - (id)initWithTarget:(id)target selector:(SEL)selector {
NSString *name = NSStringFromSelector(selector);
NSString *identifier = [NSString stringWithFormat:@"%@/%@", NSStringFromClass([target class]), name];
if ((self = [self initWithIdentifier:identifier name:name])) {
- target_ = [target retain];
+ target_ = target;
selector_ = selector;
}
return self;
}
+ (id)testWithTarget:(id)target selector:(SEL)selector {
- return [[[self alloc] initWithTarget:target selector:selector] autorelease];
+ return [[self alloc] initWithTarget:target selector:selector];
}
-- (void)dealloc {
- [identifier_ release];
- [name_ release];
- [target_ release];
- [exception_ release];
- [log_ release];
- [super dealloc];
-}
- (BOOL)isEqual:(id)test {
return ((test == self) ||
@@ -139,7 +131,6 @@ - (GHTestStats)stats {
- (void)reset {
status_ = GHTestStatusNone;
interval_ = 0;
- [exception_ release];
exception_ = nil;
[delegate_ testDidUpdate:self source:self];
}
@@ -169,8 +160,6 @@ - (NSInteger)disabledCount {
}
- (void)setException:(NSException *)exception {
- [exception retain];
- [exception_ release];
exception_ = exception;
status_ = GHTestStatusErrored;
[delegate_ testDidUpdate:self source:self];
@@ -184,7 +173,7 @@ - (void)setUpClass {
}
} @catch(NSException *exception) {
// If we fail in the setUpClass, then we will cancel all the child tests (below)
- exception_ = [exception retain];
+ exception_ = exception;
status_ = GHTestStatusErrored;
}
}
@@ -195,7 +184,7 @@ - (void)tearDownClass {
if ([target_ respondsToSelector:@selector(tearDownClass)])
[target_ tearDownClass];
} @catch(NSException *exception) {
- exception_ = [exception retain];
+ exception_ = exception;
status_ = GHTestStatusErrored;
}
}
@@ -215,7 +204,9 @@ - (void)run:(GHTestOptions)options {
[self _setLogWriter:self];
BOOL reraiseExceptions = ((options & GHTestOptionReraiseExceptions) == GHTestOptionReraiseExceptions);
- [GHTesting runTestWithTarget:target_ selector:selector_ exception:&exception_ interval:&interval_ reraiseExceptions:reraiseExceptions];
+ NSException *exception = nil;
+ [GHTesting runTestWithTarget:target_ selector:selector_ exception:&exception interval:&interval_ reraiseExceptions:reraiseExceptions];
+ exception_ = exception;
[self _setLogWriter:nil];
@@ -236,7 +227,7 @@ - (void)run:(GHTestOptions)options {
}
- (void)log:(NSString *)message testCase:(id)testCase {
- if (!log_) log_ = [[NSMutableArray array] retain];
+ if (!log_) log_ = [NSMutableArray array];
[log_ addObject:message];
[delegate_ test:self didLog:message source:self];
}
9 Classes/GHTest/GHTestGroup.h
View
@@ -75,8 +75,7 @@
*/
@interface GHTestGroup : NSObject <GHTestDelegate, GHTestGroup> {
- NSObject<GHTestDelegate> *delegate_; // weak
- id<GHTestGroup> parent_; // weak
+ id<GHTestGroup> __unsafe_unretained parent_; // weak
NSMutableArray */*of id<GHTest>*/children_;
@@ -96,9 +95,9 @@
NSException *exception_; // If exception happens in group setUpClass/tearDownClass
}
-@property (readonly, nonatomic) NSArray */*of id<GHTest>*/children;
-@property (assign, nonatomic) id<GHTestGroup> parent;
-@property (readonly, nonatomic) id testCase;
+@property (readonly, strong, nonatomic) NSArray */*of id<GHTest>*/children;
+@property (unsafe_unretained, nonatomic) id<GHTestGroup> parent;
+@property (readonly, strong, nonatomic) id testCase;
@property (assign, nonatomic) GHTestOptions options;
/*!
26 Classes/GHTest/GHTestGroup.m
View
@@ -33,7 +33,6 @@
#import "GHTestOperation.h"
#import "GHTesting.h"
-#import "GTMStackTrace.h"
#import "GHTestGroup+JUnitXML.h"
@@ -49,8 +48,8 @@ @implementation GHTestGroup
- (id)initWithName:(NSString *)name delegate:(id<GHTestDelegate>)delegate {
if ((self = [super init])) {
- name_ = [name retain];
- children_ = [[NSMutableArray array] retain];
+ name_ = name;
+ children_ = [NSMutableArray array];
delegate_ = delegate;
}
return self;
@@ -58,7 +57,7 @@ - (id)initWithName:(NSString *)name delegate:(id<GHTestDelegate>)delegate {
- (id)initWithTestCase:(id)testCase delegate:(id<GHTestDelegate>)delegate {
if ([self initWithName:NSStringFromClass([testCase class]) delegate:delegate]) {
- testCase_ = [testCase retain];
+ testCase_ = testCase;
[self _addTestsFromTestCase:testCase];
}
return self;
@@ -66,23 +65,19 @@ - (id)initWithTestCase:(id)testCase delegate:(id<GHTestDelegate>)delegate {
- (id)initWithTestCase:(id)testCase selector:(SEL)selector delegate:(id<GHTestDelegate>)delegate {
if ([self initWithName:NSStringFromClass([testCase class]) delegate:delegate]) {
- testCase_ = [testCase retain];
+ testCase_ = testCase;
[self addTest:[GHTest testWithTarget:testCase selector:selector]];
}
return self;
}
+ (GHTestGroup *)testGroupFromTestCase:(id)testCase delegate:(id<GHTestDelegate>)delegate {
- return [[[GHTestGroup alloc] initWithTestCase:testCase delegate:delegate] autorelease];
+ return [[GHTestGroup alloc] initWithTestCase:testCase delegate:delegate];
}
- (void)dealloc {
for(id<GHTest> test in children_)
[test setDelegate:nil];
- [name_ release];
- [children_ release];
- [testCase_ release];
- [super dealloc];
}
- (NSString *)description {
@@ -102,7 +97,6 @@ - (void)_addTestsFromTestCase:(id)testCase {
- (void)addTestCase:(id)testCase {
GHTestGroup *testCaseGroup = [[GHTestGroup alloc] initWithTestCase:testCase delegate:self];
[self addTestGroup:testCaseGroup];
- [testCaseGroup release];
}
- (void)addTestGroup:(GHTestGroup *)testGroup {
@@ -147,7 +141,6 @@ - (void)_reset {
status_ = GHTestStatusNone;
stats_ = GHTestStatsMake(0, 0, 0, stats_.testCount);
interval_ = 0;
- [exception_ release];
exception_ = nil;
}
@@ -166,8 +159,6 @@ - (void)_failedTests:(NSMutableArray *)tests testGroup:(id<GHTestGroup>)testGrou
}
- (void)setException:(NSException *)exception {
- [exception retain];
- [exception_ release];
exception_ = exception;
status_ = GHTestStatusErrored;
[delegate_ testDidUpdate:self source:self];
@@ -227,7 +218,7 @@ - (void)setUpClass {
[testCase_ setUpClass];
} @catch(NSException *exception) {
// If we fail in the setUpClass, then we will cancel all the child tests (below)
- exception_ = [exception retain];
+ exception_ = exception;
status_ = GHTestStatusErrored;
for(id<GHTest> test in children_) {
if (![test isDisabled]) {
@@ -245,7 +236,7 @@ - (void)tearDownClass {
if ([testCase_ respondsToSelector:@selector(tearDownClass)])
[testCase_ tearDownClass];
} @catch(NSException *exception) {
- exception_ = [exception retain];
+ exception_ = exception;
status_ = GHTestStatusErrored;
// We need to reverse any successes in the test run above
// and set the error on all the child tests
@@ -287,7 +278,7 @@ - (void)_run:(NSOperationQueue *)operationQueue {
[test setException:exception_];
} else {
if (operationQueue) {
- [operationQueue addOperation:[[[GHTestOperation alloc] initWithTest:test options:options_] autorelease]];
+ [operationQueue addOperation:[[GHTestOperation alloc] initWithTest:test options:options_]];
} else {
if (![test isDisabled])
[self setUpClass];
@@ -386,7 +377,6 @@ - (id)copyWithZone:(NSZone *)zone {
for(id<GHTest> test in children_) {
id<GHTest> testCopy = [test copyWithZone:zone];
[tests addObject:testCopy];
- [testCopy release];
}
GHTestGroup *testGroup = [[GHTestGroup alloc] initWithName:name_ delegate:nil];
[testGroup addTests:tests];
15 Classes/GHTest/GHTestOperation.m
View
@@ -35,27 +35,22 @@ @implementation GHTestOperation
- (id)initWithTest:(id<GHTest>)test options:(GHTestOptions)options {
if ((self = [super init])) {
- test_ = [test retain];
+ test_ = test;
options_ = options;
}
return self;
}
-- (void)dealloc {
- [test_ release];
- [super dealloc];
-}
-
- (void)cancel {
[super cancel];
[test_ cancel];
}
- (void)main {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- if (!self.isCancelled)
- [test_ run:options_];
- [pool release];
+ @autoreleasepool {
+ if (!self.isCancelled)
+ [test_ run:options_];
+ }
}
@end
8 Classes/GHTest/GHTestRunner.h
View
@@ -130,7 +130,7 @@
id<GHTest> test_; // The test to run; Could be a GHTestGroup (suite), GHTestGroup (test case), or GHTest (target/selector)
- NSObject<GHTestRunnerDelegate> *delegate_; // weak
+ NSObject<GHTestRunnerDelegate> *__unsafe_unretained delegate_; // weak
GHTestOptions options_;
@@ -142,14 +142,14 @@
NSOperationQueue *operationQueue_; //! If running a suite in operation queue
}
-@property (retain) id<GHTest> test;
-@property (assign) NSObject<GHTestRunnerDelegate> *delegate;
+@property (strong) id<GHTest> test;
+@property (unsafe_unretained) NSObject<GHTestRunnerDelegate> *delegate;
@property (assign) GHTestOptions options;
@property (readonly) GHTestStats stats;
@property (readonly, getter=isRunning) BOOL running;
@property (readonly, getter=isCancelling) BOOL cancelling;
@property (readonly) NSTimeInterval interval;
-@property (retain, nonatomic) NSOperationQueue *operationQueue;
+@property (strong, nonatomic) NSOperationQueue *operationQueue;
@property (assign, nonatomic, getter=isInParallel) BOOL inParallel;
/*!
69 Classes/GHTest/GHTestRunner.m
View
@@ -46,8 +46,6 @@
// the License.
//
-#import "GHNSObject+Invocation.h"
-
#import "GHTestRunner.h"
#import "GHTestSuite.h"
#import "GHTesting.h"
@@ -63,24 +61,17 @@ - (void)_log:(NSString *)message;
@implementation GHTestRunner
-#define kGHTestRunnerDelegateProxyWait YES
-
@synthesize test=test_, options=options_, delegate=delegate_, running=running_, cancelling=cancelling_,
operationQueue=operationQueue_;
- (id)initWithTest:(id<GHTest>)test {
if ((self = [self init])) {
- test_ = [test retain];
+ test_ = test;
test_.delegate = self;
}
return self;
}
-- (void)dealloc {
- [test_ release];
- [operationQueue_ release];
- [super dealloc];
-}
+ (GHTestRunner *)runnerForAllTests {
GHTestSuite *suite = [GHTestSuite allTests];
@@ -89,7 +80,7 @@ + (GHTestRunner *)runnerForAllTests {
+ (GHTestRunner *)runnerForSuite:(GHTestSuite *)suite {
GHTestRunner *runner = [[GHTestRunner alloc] initWithTest:suite];
- return [runner autorelease];
+ return runner;
}
+ (GHTestRunner *)runnerForTestClassName:(NSString *)testClassName methodName:(NSString *)methodName {
@@ -112,7 +103,7 @@ + (int)run {
- (void)setInParallel:(BOOL)inParallel {
if (inParallel) {
- NSOperationQueue *operationQueue = [[[NSOperationQueue alloc] init] autorelease];
+ NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
operationQueue.maxConcurrentOperationCount = NSOperationQueueDefaultMaxConcurrentOperationCount;
self.operationQueue = operationQueue;
} else {
@@ -155,9 +146,9 @@ - (void)runInBackground {
}
- (void)_runInBackground {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [self runTests];
- [pool release];
+ @autoreleasepool {
+ [self runTests];
+ }
}
- (GHTestStats)stats {
@@ -174,8 +165,10 @@ - (void)_log:(NSString *)message {
fputs("\n", stdout);
fflush(stdout);
- if ([delegate_ respondsToSelector:@selector(testRunner:didLog:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunner:self didLog:message];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunner:didLog:)])
+ [delegate_ testRunner:self didLog:message];
+ });
}
#pragma mark Delegates (GHTest)
@@ -185,13 +178,17 @@ - (void)testDidStart:(id<GHTest>)test source:(id<GHTest>)source {
[self log:[NSString stringWithFormat:@"Starting %@\n", [source identifier]]];
}
- if ([delegate_ respondsToSelector:@selector(testRunner:didStartTest:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunner:self didStartTest:source];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunner:didStartTest:)])
+ [delegate_ testRunner:self didStartTest:source];
+ });
}
- (void)testDidUpdate:(id<GHTest>)test source:(id<GHTest>)source {
- if ([delegate_ respondsToSelector:@selector(testRunner:didUpdateTest:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunner:self didUpdateTest:source];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunner:didUpdateTest:)])
+ [delegate_ testRunner:self didUpdateTest:source];
+ });
}
- (void)testDidEnd:(id<GHTest>)test source:(id<GHTest>)source {
@@ -203,8 +200,10 @@ - (void)testDidEnd:(id<GHTest>)test source:(id<GHTest>)source {
[self log:message];
}
- if ([delegate_ respondsToSelector:@selector(testRunner:didEndTest:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunner:self didEndTest:source];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunner:didEndTest:)])
+ [delegate_ testRunner:self didEndTest:source];
+ });
} else {
[self log:[NSString stringWithFormat:@"Cancelled\n", [source identifier]]];
@@ -220,8 +219,10 @@ - (void)testDidEnd:(id<GHTest>)test source:(id<GHTest>)source {
- (void)test:(id<GHTest>)test didLog:(NSString *)message source:(id<GHTest>)source {
[self _log:[NSString stringWithFormat:@"%@: %@", source, message]];
- if ([delegate_ respondsToSelector:@selector(testRunner:test:didLog:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunner:self test:source didLog:message];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunner:test:didLog:)])
+ [delegate_ testRunner:self test:source didLog:message];
+ });
}
#pragma mark Notifications (Private)
@@ -230,8 +231,10 @@ - (void)_notifyStart {
NSString *message = [NSString stringWithFormat:@"Test Suite '%@' started.\n", [test_ name]];
[self log:message];
- if ([delegate_ respondsToSelector:@selector(testRunnerDidStart:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunnerDidStart:self];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunnerDidStart:)])
+ [delegate_ testRunnerDidStart:self];
+ });
}
- (void)_notifyCancelled {
@@ -241,8 +244,10 @@ - (void)_notifyCancelled {
cancelling_ = NO;
running_ = NO;
- if ([delegate_ respondsToSelector:@selector(testRunnerDidCancel:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunnerDidCancel:self];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunnerDidCancel:)])
+ [delegate_ testRunnerDidCancel:self];
+ });
}
- (void)_notifyFinished {
@@ -282,8 +287,10 @@ - (void)_notifyFinished {
cancelling_ = NO;
running_ = NO;
- if ([delegate_ respondsToSelector:@selector(testRunnerDidEnd:)])
- [[delegate_ ghu_proxyOnMainThread:kGHTestRunnerDelegateProxyWait] testRunnerDidEnd:self];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([delegate_ respondsToSelector:@selector(testRunnerDidEnd:)])
+ [delegate_ testRunnerDidEnd:self];
+ });
}
@end
20 Classes/GHTest/GHTestSuite.m
View
@@ -36,6 +36,10 @@
NSString *GHUnitTest = NULL;
+@interface GHTestSuite (CLIDisabled)
+- (BOOL)isCLIDisabled;
+@end
+
@implementation GHTestSuite
- (id)initWithName:(NSString *)name testCases:(NSArray *)testCases delegate:(id<GHTestDelegate>)delegate {
@@ -54,20 +58,19 @@ + (GHTestSuite *)allTests {
// Ignore test cases that can't be run at the command line
if (!([testCase respondsToSelector:@selector(isCLIDisabled)] && [testCase isCLIDisabled] && getenv("GHUNIT_CLI"))) [allTests addTestCase:testCase];
}
- return [allTests autorelease];
+ return allTests;
}
+ (GHTestSuite *)suiteWithTestCaseClass:(Class)testCaseClass method:(SEL)method {
NSString *name = [NSString stringWithFormat:@"%@/%@", NSStringFromClass(testCaseClass), NSStringFromSelector(method)];
- GHTestSuite *testSuite = [[[GHTestSuite alloc] initWithName:name testCases:nil delegate:nil] autorelease];
- id testCase = [[[testCaseClass alloc] init] autorelease];
+ GHTestSuite *testSuite = [[GHTestSuite alloc] initWithName:name testCases:nil delegate:nil];
+ id testCase = [[testCaseClass alloc] init];
if (!testCase) {
NSLog(@"Couldn't instantiate test: %@", NSStringFromClass(testCaseClass));
return nil;
}
GHTestGroup *group = [[GHTestGroup alloc] initWithTestCase:testCase selector:method delegate:nil];
[testSuite addTestGroup:group];
- [group release];
return testSuite;
}
@@ -82,7 +85,7 @@ + (GHTestSuite *)suiteWithPrefix:(NSString *)prefix options:(NSStringCompareOpti
if ([className compare:prefix options:options range:NSMakeRange(0, [prefix length])] == NSOrderedSame)
[testSuite addTestCase:testCase];
}
- return [testSuite autorelease];
+ return testSuite;
}
@@ -95,7 +98,7 @@ + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilterString {
if ([components count] == 2) {
NSString *testCaseClassName = [components objectAtIndex:0];
Class testCaseClass = NSClassFromString(testCaseClassName);
- id testCase = [[[testCaseClass alloc] init] autorelease];
+ id testCase = [[testCaseClass alloc] init];
if (!testCase) {
NSLog(@"Couldn't find test: %@", testCaseClassName);
continue;
@@ -103,10 +106,9 @@ + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilterString {
NSString *methodName = [components objectAtIndex:1];
GHTestGroup *group = [[GHTestGroup alloc] initWithTestCase:testCase selector:NSSelectorFromString(methodName) delegate:nil];
[testSuite addTestGroup:group];
- [group release];
} else {
Class testCaseClass = NSClassFromString(testFilter);
- id testCase = [[[testCaseClass alloc] init] autorelease];
+ id testCase = [[testCaseClass alloc] init];
if (!testCase) {
NSLog(@"Couldn't find test: %@", testFilter);
continue;
@@ -115,7 +117,7 @@ + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilterString {
}
}
- return [testSuite autorelease];
+ return testSuite;
}
+ (GHTestSuite *)suiteFromEnv {
5 Classes/GHTest/GHTesting.h
View
@@ -51,11 +51,6 @@
#import <Foundation/Foundation.h>
#import "GHUnit.h"
-#ifdef __cplusplus
-extern "C" NSString *GHUStackTraceFromException(NSException *e);
-#else
-extern NSString *GHUStackTraceFromException(NSException *e);
-#endif
// GTM_BEGIN
BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass);
201 Classes/GHTest/GHTesting.m
View
@@ -51,14 +51,9 @@
#import "GHTesting.h"
#import "GHTest.h"
#import "GHTestCase.h"
-#import "GTMStackTrace.h"
#import <objc/runtime.h>
-NSString *GHUStackTraceFromException(NSException *e) {
- return GHU_GTMStackTraceFromException(e);
-}
-
NSInteger ClassSort(id a, id b, void *context) {
const char *nameA = class_getName([a class]);
const char *nameB = class_getName([b class]);
@@ -67,11 +62,21 @@ NSInteger ClassSort(id a, id b, void *context) {
// GTM_BEGIN
// Used for sorting methods below
+static int MethodSort(id a, id b, void *context) {
+ NSInvocation *invocationA = a;
+ NSInvocation *invocationB = b;
+ const char *nameA = sel_getName([invocationA selector]);
+ const char *nameB = sel_getName([invocationB selector]);
+ return strcmp(nameA, nameB);
+}
+
+/*
static int MethodSort(const void *a, const void *b) {
const char *nameA = sel_getName(method_getName(*(Method*)a));
const char *nameB = sel_getName(method_getName(*(Method*)b));
return strcmp(nameA, nameB);
}
+ */
BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass) {
if (testCaseClass == NULL) return NO;
@@ -100,11 +105,11 @@ + (GHTesting *)sharedInstance {
- (id)init {
if ((self = [super init])) {
// Default test cases
- testCaseClassNames_ = [[NSMutableArray arrayWithObjects:
+ testCaseClassNames_ = [NSMutableArray arrayWithObjects:
@"GHTestCase",
@"SenTestCase",
@"GTMTestCase",
- nil] retain];
+ nil];
}
return self;
}
@@ -135,7 +140,7 @@ + (NSString *)descriptionForException:(NSException *)exception {
filenameDescription,
lineDescription,
[exception reason],
- GHU_GTMStackTraceFromException(exception)];
+ [exception callStackSymbols]];
}
+ (NSString *)exceptionFilenameForTest:(id<GHTest>)test {
@@ -167,7 +172,6 @@ - (NSArray *)loadAllTestCases {
}
[testCases addObject:testcase];
- [testcase release];
}
return [testCases sortedArrayUsingFunction:ClassSort context:NULL];
@@ -175,6 +179,7 @@ - (NSArray *)loadAllTestCases {
// GTM_BEGIN
+/*
- (NSArray *)loadTestsFromTarget:(id)target {
NSMutableArray *tests = [NSMutableArray array];
@@ -219,6 +224,68 @@ - (NSArray *)loadTestsFromTarget:(id)target {
return tests;
}
+*/
+- (NSArray *)loadTestsFromTarget:(id)target {
+ NSMutableArray *invocations = nil;
+ // Need to walk all the way up the parent classes collecting methods (in case
+ // a test is a subclass of another test).
+ for (Class currentClass = [target class];
+ currentClass && (currentClass != [NSObject class]);
+ currentClass = class_getSuperclass(currentClass)) {
+ unsigned int methodCount;
+ Method *methods = class_copyMethodList(currentClass, &methodCount);
+ if (methods) {
+ // This handles disposing of methods for us even if an exception should fly.
+ [NSData dataWithBytes:methods
+ length:sizeof(Method) * methodCount];
+ if (!invocations) {
+ invocations = [NSMutableArray arrayWithCapacity:methodCount];
+ }
+ for (size_t i = 0; i < methodCount; ++i) {
+ Method currMethod = methods[i];
+ SEL sel = method_getName(currMethod);
+ const char *name = sel_getName(sel);
+ char *returnType = NULL;
+ // If it starts with test, takes 2 args (target and sel) and returns
+ // void run it.
+ if (strstr(name, "test") == name) {
+ returnType = method_copyReturnType(currMethod);
+ if (returnType) {
+ // This handles disposing of returnType for us even if an
+ // exception should fly. Length +1 for the terminator, not that
+ // the length really matters here, as we never reference inside
+ // the data block.
+ [NSData dataWithBytes:returnType
+ length:strlen(returnType) + 1];
+ }
+ }
+ // TODO: If a test class is a subclass of another, and they reuse the
+ // same selector name (ie-subclass overrides it), this current loop
+ // and test here will cause cause it to get invoked twice. To fix this
+ // the selector would have to be checked against all the ones already
+ // added, so it only gets done once.
+ if (returnType // True if name starts with "test"
+ && strcmp(returnType, @encode(void)) == 0
+ && method_getNumberOfArguments(currMethod) == 2) {
+ NSMethodSignature *sig = [[target class] instanceMethodSignatureForSelector:sel];
+ NSInvocation *invocation
+ = [NSInvocation invocationWithMethodSignature:sig];
+ [invocation setSelector:sel];
+ [invocations addObject:invocation];
+ }
+ }
+ }
+ }
+ // Match SenTestKit and run everything in alphbetical order.
+ [invocations sortUsingFunction:MethodSort context:nil];
+
+ NSMutableArray *tests = [[NSMutableArray alloc] initWithCapacity:[invocations count]];
+ for (NSInvocation *invocation in invocations) {
+ GHTest *test = [GHTest testWithTarget:target selector:invocation.selector];
+ [tests addObject:test];
+ }
+ return tests;
+}
+ (BOOL)runTestWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception interval:(NSTimeInterval *)interval
reraiseExceptions:(BOOL)reraiseExceptions {
@@ -233,47 +300,50 @@ + (BOOL)runTestWithTarget:(id)target selector:(SEL)selector exception:(NSExcepti
// Wrap things in autorelease pools because they may
// have an STMacro in their dealloc which may get called
// when the pool is cleaned up
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ @autoreleasepool {
// We don't log exceptions here, instead we let the person that called
// this log the exception. This ensures they are only logged once but the
// outer layers get the exceptions to report counts, etc.
- @try {
- // Private setUp internal to GHUnit (in case subclasses fail to call super)
- if ([target respondsToSelector:@selector(_setUp)])
- [target performSelector:@selector(_setUp)];
-
- if ([target respondsToSelector:@selector(setUp)])
- [target performSelector:@selector(setUp)];
- @try {
+ @try {
+ // Private setUp internal to GHUnit (in case subclasses fail to call super)
+ if ([target respondsToSelector:@selector(_setUp)])
+ [target performSelector:@selector(_setUp)];
+
+ if ([target respondsToSelector:@selector(setUp)])
+ [target performSelector:@selector(setUp)];
+ @try {
+ if ([target respondsToSelector:@selector(setCurrentSelector:)])
+ [target setCurrentSelector:selector];
+
+ // If this isn't set SenTest macros don't raise
+ if ([target respondsToSelector:@selector(raiseAfterFailure)])
+ [target raiseAfterFailure];
+
+ // Runs the test
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+ [target performSelector:selector];
+#pragma clang diagnostic pop
+
+ } @catch (NSException *exception) {
+ if (!testException) testException = exception;
+ }
if ([target respondsToSelector:@selector(setCurrentSelector:)])
- [target setCurrentSelector:selector];
+ [target setCurrentSelector:NULL];
- // If this isn't set SenTest macros don't raise
- if ([target respondsToSelector:@selector(raiseAfterFailure)])
- [target raiseAfterFailure];
-
- // Runs the test
- [target performSelector:selector];
+ if ([target respondsToSelector:@selector(tearDown)])
+ [target performSelector:@selector(tearDown)];
+ // Private tearDown internal to GHUnit (in case subclasses fail to call super)
+ if ([target respondsToSelector:@selector(_tearDown)])
+ [target performSelector:@selector(_tearDown)];
+
} @catch (NSException *exception) {
- if (!testException) testException = [exception retain];
+ if (!testException) testException = exception;
}
- if ([target respondsToSelector:@selector(setCurrentSelector:)])
- [target setCurrentSelector:NULL];
-
- if ([target respondsToSelector:@selector(tearDown)])
- [target performSelector:@selector(tearDown)];
-
- // Private tearDown internal to GHUnit (in case subclasses fail to call super)
- if ([target respondsToSelector:@selector(_tearDown)])
- [target performSelector:@selector(_tearDown)];
-
- } @catch (NSException *exception) {
- if (!testException) testException = [exception retain];
}
- [pool release];
} @catch (NSException *exception) {
- if (!testException) testException = [exception retain];
+ if (!testException) testException = exception;
}
if (interval) *interval = [[NSDate date] timeIntervalSinceDate:startDate];
@@ -291,36 +361,39 @@ + (BOOL)runTestOrRaiseWithTarget:(id)target selector:(SEL)selector exception:(NS
NSDate *startDate = [NSDate date];
NSException *testException = nil;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- if ([target respondsToSelector:@selector(_setUp)])
- [target performSelector:@selector(_setUp)];
-
- if ([target respondsToSelector:@selector(setUp)])
- [target performSelector:@selector(setUp)];
+ @autoreleasepool {
- if ([target respondsToSelector:@selector(setCurrentSelector:)])
- [target setCurrentSelector:selector];
+ if ([target respondsToSelector:@selector(_setUp)])
+ [target performSelector:@selector(_setUp)];
- // If this isn't set SenTest macros don't raise
- if ([target respondsToSelector:@selector(raiseAfterFailure)])
- [target raiseAfterFailure];
+ if ([target respondsToSelector:@selector(setUp)])
+ [target performSelector:@selector(setUp)];
+
+ if ([target respondsToSelector:@selector(setCurrentSelector:)])
+ [target setCurrentSelector:selector];
+
+ // If this isn't set SenTest macros don't raise
+ if ([target respondsToSelector:@selector(raiseAfterFailure)])
+ [target raiseAfterFailure];
+
+ // Runs the test
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
+ [target performSelector:selector];
+#pragma clang diagnostic pop
+
+ if ([target respondsToSelector:@selector(setCurrentSelector:)])
+ [target setCurrentSelector:NULL];
- // Runs the test
- [target performSelector:selector];
+ if ([target respondsToSelector:@selector(tearDown)])
+ [target performSelector:@selector(tearDown)];
- if ([target respondsToSelector:@selector(setCurrentSelector:)])
- [target setCurrentSelector:NULL];
-
- if ([target respondsToSelector:@selector(tearDown)])
- [target performSelector:@selector(tearDown)];
-
- // Private tearDown internal to GHUnit (in case subclasses fail to call super)
- if ([target respondsToSelector:@selector(_tearDown)])
- [target performSelector:@selector(_tearDown)];
+ // Private tearDown internal to GHUnit (in case subclasses fail to call super)
+ if ([target respondsToSelector:@selector(_tearDown)])
+ [target performSelector:@selector(_tearDown)];
- [pool release];
+ }
if (interval) *interval = [[NSDate date] timeIntervalSinceDate:startDate];
if (exception) *exception = testException;
16 Classes/GHTest/NSException+GHTestFailureExceptions.m
View
@@ -92,7 +92,7 @@ + (NSException *)ghu_failureInFile:(NSString *)filename
va_list vl;
va_start(vl, formatString);
testDescription =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
@@ -112,7 +112,7 @@ + (NSException *)ghu_failureInCondition:(NSString *)condition
va_list vl;
va_start(vl, formatString);
testDescription =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
@@ -133,7 +133,7 @@ + (NSException *)ghu_failureInEqualityBetweenObject:(id)left
va_list vl;
va_start(vl, formatString);
testDescription =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
@@ -155,7 +155,7 @@ + (NSException *)ghu_failureInInequalityBetweenObject:(id)left
va_list vl;
va_start(vl, formatString);
testDescription =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
@@ -178,7 +178,7 @@ + (NSException *)ghu_failureInEqualityBetweenValue:(NSValue *)left
va_list vl;
va_start(vl, formatString);
testDescription =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
@@ -206,7 +206,7 @@ + (NSException *)ghu_failureInRaise:(NSString *)expression
va_list vl;
va_start(vl, formatString);
testDescription =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
@@ -227,7 +227,7 @@ + (NSException *)ghu_failureInRaise:(NSString *)expression
va_list vl;
va_start(vl, formatString);
testDescription =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
@@ -267,7 +267,7 @@ + (NSException *)ghu_failureWithName:(NSString *)name
va_list vl;
va_start(vl, formatString);
reason =
- [[[NSString alloc] initWithFormat:formatString arguments:vl] autorelease];
+ [[NSString alloc] initWithFormat:formatString arguments:vl];
va_end(vl);
}
return reason;
4 Classes/GHTestCase.h
View
@@ -92,14 +92,14 @@
*/
@interface GHTestCase : NSObject {
- id<GHTestCaseLogWriter> logWriter_; // weak
+ id<GHTestCaseLogWriter> __unsafe_unretained logWriter_; // weak
SEL currentSelector_;
}
//! The current test selector
@property (assign, nonatomic) SEL currentSelector;
-@property (assign, nonatomic) id<GHTestCaseLogWriter> logWriter;
+@property (unsafe_unretained, nonatomic) id<GHTestCaseLogWriter> logWriter;
// GTM_BEGIN
//! Run before each test method
1  Classes/GHTestCase.m
View
@@ -28,7 +28,6 @@
//
#import "GHTestCase.h"
-#import "GTMStackTrace.h"
#import "GHTesting.h"
@implementation GHTestCase
9 Classes/Mock/GHMockNSHTTPURLResponse.m
View
@@ -41,11 +41,6 @@ - (id)initWithStatusCode:(NSInteger)statusCode headers:(NSDictionary *)headers {
return self;
}
-- (void)dealloc {
- [headers_ release];
- [super dealloc];
-}
-
- (void)setStatusCode:(NSInteger)code {
statusCode_ = code;
}
@@ -55,13 +50,11 @@ - (NSInteger)statusCode {
}
- (void)setHeaders:(NSDictionary *)headers {
- [headers retain];
- [headers_ release];
headers_ = headers;
}
- (NSDictionary *)allHeaderFields {
- return headers_ ? [[headers_ copy] autorelease] : [super allHeaderFields];
+ return headers_ ? [headers_ copy] : [super allHeaderFields];
}
@end
31 Classes/Mock/GHMockNSURLConnection.m
View
@@ -31,7 +31,6 @@
#import "GHMockNSURLConnection.h"
#import "GHMockNSHTTPURLResponse.h"
-#import "GHNSObject+Invocation.h"
NSString *const GHMockNSURLConnectionException = @"GHMockNSURLConnectionException";
@@ -41,7 +40,7 @@ @implementation GHMockNSURLConnection
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate {
if ((self = [super init])) {
- request_ = [request retain];
+ request_ = request;
delegate_ = delegate;
}
return self;
@@ -51,12 +50,6 @@ - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmedia
return [self initWithRequest:request delegate:delegate];
}
-- (void)dealloc {
- [request_ release];
- delegate_ = nil;
- [super dealloc];
-}
-
- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode { }
- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode { }
@@ -74,7 +67,9 @@ - (void)cancel {
#pragma mark -
- (void)receiveData:(NSData *)data afterDelay:(NSTimeInterval)delay {
- [delegate_ ghu_performSelector:@selector(connection:didReceiveData:) afterDelay:delay withObjects:[NSNull null], data, nil];
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
+ [delegate_ connection:nil didReceiveData:data];
+ });
}
- (NSData *)loadDataFromPath:(NSString *)path {
@@ -98,10 +93,10 @@ - (void)receiveFromPath:(NSString *)path statusCode:(NSInteger)statusCode MIMETy
}
- (void)receiveData:(NSData *)data statusCode:(NSInteger)statusCode MIMEType:(NSString *)MIMEType afterDelay:(NSTimeInterval)delay {
- GHMockNSHTTPURLResponse *response = [[[GHMockNSHTTPURLResponse alloc] initWithURL:[request_ URL]
+ GHMockNSHTTPURLResponse *response = [[GHMockNSHTTPURLResponse alloc] initWithURL:[request_ URL]
MIMEType:MIMEType
expectedContentLength:[data length]
- textEncodingName:nil] autorelease];
+ textEncodingName:nil];
[response setStatusCode:statusCode];
[self receiveResponse:response afterDelay:delay];
[self receiveData:data afterDelay:delay];
@@ -109,19 +104,25 @@ - (void)receiveData:(NSData *)data statusCode:(NSInteger)statusCode MIMEType:(NS
}
- (void)receiveHTTPResponseWithStatusCode:(int)statusCode headers:(NSDictionary *)headers afterDelay:(NSTimeInterval)delay {
- [self receiveResponse:[[[GHMockNSHTTPURLResponse alloc] initWithStatusCode:statusCode headers:headers] autorelease] afterDelay:delay];
+ [self receiveResponse:[[GHMockNSHTTPURLResponse alloc] initWithStatusCode:statusCode headers:headers] afterDelay:delay];
}
- (void)receiveResponse:(NSURLResponse *)response afterDelay:(NSTimeInterval)delay {
- [delegate_ ghu_performSelector:@selector(connection:didReceiveResponse:) afterDelay:delay withObjects:self, response, nil];
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
+ [delegate_ connection:(NSURLConnection *)self didReceiveResponse:response];
+ });
}
- (void)finishAfterDelay:(NSTimeInterval)delay {
- [delegate_ ghu_performSelector:@selector(connectionDidFinishLoading:) afterDelay:delay withObjects:self, nil];
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
+ [delegate_ connectionDidFinishLoading:(NSURLConnection *)self];
+ });
}
- (void)failWithError:(NSError *)error afterDelay:(NSTimeInterval)delay {
- [delegate_ ghu_performSelector:@selector(connection:didFailWithError:) afterDelay:delay withObjects:self, error, nil];
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
+ [delegate_ connection:(NSURLConnection *)self didFailWithError:error];
+ });
}
@end
85 Classes/Mock/GHNSLocale+Mock.m
View
@@ -1,85 +0,0 @@
-//
-// GHNSLocale+Mock.h
-// GHUnit
-//
-// Created by Gabriel Handford on 4/13/09.
-// Copyright 2009. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//! @cond DEV
-
-#import "GHNSLocale+Mock.h"
-
-#import "GHUNSObject+Swizzle.h"
-
-// Allows us to override the current locale for testing
-@implementation NSLocale(GHMock)
-
-static NSString *gGHUNSLocaleLocaleIdentifier = NULL;
-static NSArray *gGHUNSLocalePreferredLanguages = NULL;
-static BOOL gGHUNSLocaleMockSetup = NO;
-
-+ (void)_gh_setUpMock {
- @synchronized([NSLocale class]) {
- if (!gGHUNSLocaleMockSetup) {
- // TODO(gabe): Check and handle swizzle errors
- [NSLocale ghu_swizzleClassMethod:@selector(currentLocale) withClassMethod:@selector(gh_currentLocale)];
- [NSLocale ghu_swizzleClassMethod:@selector(preferredLanguages) withClassMethod:@selector(gh_preferredLanguages)];
- gGHUNSLocaleMockSetup = YES;
- }
- }
-}
-
-+ (void)gh_setLocaleIdentifier:(NSString *)localeIdentifier {
- [self _gh_setUpMock];
- [gGHUNSLocaleLocaleIdentifier release];
- gGHUNSLocaleLocaleIdentifier = [localeIdentifier copy];
-}
-
-+ (void)gh_setPreferredLanguages:(NSArray *)preferredLanguages {
- [self _gh_setUpMock];
- [preferredLanguages retain];
- [gGHUNSLocalePreferredLanguages release];
- gGHUNSLocalePreferredLanguages = preferredLanguages;
-}
-
-+ (NSLocale *)gh_currentLocale {
- if (gGHUNSLocaleLocaleIdentifier != NULL) {
- return [[[NSLocale alloc] initWithLocaleIdentifier:gGHUNSLocaleLocaleIdentifier] autorelease];
- } else {
- return [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
- }
-}
-
-+ (NSArray *)gh_preferredLanguages {
- if (gGHUNSLocalePreferredLanguages != NULL) {
- return gGHUNSLocalePreferredLanguages;
- } else {
- return [NSArray arrayWithObject:@"en"];
- }
-}
-
-@end
-
-//! @endcond
131 Classes/Mock/GHUNSObject+Swizzle.m
View
@@ -1,131 +0,0 @@
-//
-// GHUNSObject+Swizzle.m
-// GHUnit
-//
-// Created by Gabriel Handford on 4/13/09.
-// Copyright 2009. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-//! @cond DEV
-
-#import "GHUNSObject+Swizzle.h"
-
-#import <objc/runtime.h>
-
-BOOL GHU_PerformSwizzle(Class klass, SEL origSel, SEL altSel, BOOL forInstance);
-
-@implementation NSObject(GHUSwizzle)
-
-+ (void)ghu_swizzleMethod:(SEL)original withMethod:(SEL)alternate {
- GHU_PerformSwizzle([self class], original, alternate, YES);
-}
-
-+ (void)ghu_swizzleClassMethod:(SEL)original withClassMethod:(SEL)alternate {
- GHU_PerformSwizzle([self class], original, alternate, NO);
-}
-
-@end
-
-// @see http://www.cocoadev.com/index.pl?MethodSwizzling
-BOOL GHU_PerformSwizzle(Class klass, SEL origSel, SEL altSel, BOOL forInstance) {
-
- // Make sure the class isn't nil
- if (klass == nil)
- return NO;
-
- // Look for the methods in the implementation of the immediate class
- Class iterKlass = (forInstance ? klass : klass->isa);
- Method origMethod = NULL, altMethod = NULL;
- unsigned int methodCount = 0;
- Method *mlist = class_copyMethodList(iterKlass, &methodCount);
- if ( mlist != NULL ) {
- int i;
- for (i = 0; i < methodCount; ++i) {
- if ( method_getName(mlist[i]) == origSel )
- origMethod = mlist[i];
- if (method_getName(mlist[i]) == altSel)
- altMethod = mlist[i];
- }
- }
-
- // if origMethod was not found, that means it is not in the immediate class
- // try searching the entire class hierarchy with class_getInstanceMethod
- // if not found or not added, bail out
- if ( origMethod == NULL ) {
- origMethod = class_getInstanceMethod(iterKlass, origSel);
- if ( origMethod == NULL )
- return NO;
- if ( class_addMethod(iterKlass, method_getName(origMethod), method_getImplementation(origMethod), method_getTypeEncoding(origMethod)) == NO )
- return NO;
- }
-
- // same thing with altMethod
- if ( altMethod == NULL ) {
- altMethod = class_getInstanceMethod(iterKlass, altSel);
- if ( altMethod == NULL )
- return NO;
- if ( class_addMethod(iterKlass, method_getName(altMethod), method_getImplementation(altMethod), method_getTypeEncoding(altMethod)) == NO )
- return NO;
- }
-
- //clean up
- free(mlist);
-
- // we now have to look up again for the methods in case they were not in the class implementation,
- //but in one of the superclasses. In the latter, that means we added the method to the class,
- //but the Leopard APIs is only 'class_addMethod', in which case we need to have the pointer
- //to the Method objects actually stored in the Class structure (in the Tiger implementation,
- //a new mlist was explicitely created with the added methods and directly added to the class;
- //thus we were able to add a new Method AND get the pointer to it)
-
- // for simplicity, just use the same code as in the first step
- origMethod = NULL;
- altMethod = NULL;
- methodCount = 0;
- mlist = class_copyMethodList(iterKlass, &methodCount);
- if ( mlist != NULL ) {
- int i;
- for (i = 0; i < methodCount; ++i) {
- if ( method_getName(mlist[i]) == origSel )
- origMethod = mlist[i];
- if (method_getName(mlist[i]) == altSel)
- altMethod = mlist[i];
- }
- }
-
- // bail if one of the methods doesn't exist anywhere
- // with all we did, this should not happen, though
- if (origMethod == NULL || altMethod == NULL)
- return NO;
-
- // now swizzle
- method_exchangeImplementations(origMethod, altMethod);
-
- //clean up