Ben Copsey

Update GHUnit iPhone (Still won't build for device as Xcode has a hissy fit)

Give up trying to protect url, and make it public setable to fix error
@@ -407,7 +407,7 @@ extern NSString* const NetworkRequestErrorDomain; @@ -407,7 +407,7 @@ extern NSString* const NetworkRequestErrorDomain;
407 @property (retain) NSString *password; 407 @property (retain) NSString *password;
408 @property (retain) NSString *domain; 408 @property (retain) NSString *domain;
409 409
410 -@property (retain,readonly) NSURL *url; 410 +@property (retain,setter=setURL:) NSURL *url;
411 @property (assign) id delegate; 411 @property (assign) id delegate;
412 @property (assign) id queue; 412 @property (assign) id queue;
413 @property (assign) id uploadProgressDelegate; 413 @property (assign) id uploadProgressDelegate;
@@ -46,7 +46,6 @@ static NSError *ASITooMuchRedirectionError; @@ -46,7 +46,6 @@ static NSError *ASITooMuchRedirectionError;
46 46
47 // Private stuff 47 // Private stuff
48 @interface ASIHTTPRequest () 48 @interface ASIHTTPRequest ()
49 - @property (retain,setter=setURL:) NSURL *url;  
50 @property (assign) BOOL complete; 49 @property (assign) BOOL complete;
51 @property (retain) NSDictionary *responseHeaders; 50 @property (retain) NSDictionary *responseHeaders;
52 @property (retain) NSArray *responseCookies; 51 @property (retain) NSArray *responseCookies;
@@ -13,7 +13,6 @@ static NSDateFormatter *dateFormatter = nil; @@ -13,7 +13,6 @@ static NSDateFormatter *dateFormatter = nil;
13 13
14 // Private stuff 14 // Private stuff
15 @interface ASIS3ListRequest () 15 @interface ASIS3ListRequest ()
16 - @property (retain,setter=setURL:) NSURL *url;  
17 @property (retain, nonatomic) NSString *currentContent; 16 @property (retain, nonatomic) NSString *currentContent;
18 @property (retain, nonatomic) NSString *currentElement; 17 @property (retain, nonatomic) NSString *currentElement;
19 @property (retain, nonatomic) ASIS3BucketObject *currentObject; 18 @property (retain, nonatomic) ASIS3BucketObject *currentObject;
@@ -133,5 +132,4 @@ static NSDateFormatter *dateFormatter = nil; @@ -133,5 +132,4 @@ static NSDateFormatter *dateFormatter = nil;
133 @synthesize marker; 132 @synthesize marker;
134 @synthesize maxResultCount; 133 @synthesize maxResultCount;
135 @synthesize delimiter; 134 @synthesize delimiter;
136 -@synthesize url;  
137 @end 135 @end
@@ -50,7 +50,7 @@ enum { @@ -50,7 +50,7 @@ enum {
50 // Do asynchronous task here 50 // Do asynchronous task here
51 [self performSelector:@selector(_succeed) withObject:nil afterDelay:0.1]; 51 [self performSelector:@selector(_succeed) withObject:nil afterDelay:0.1];
52 52
53 - [self waitFor:kGHUnitWaitStatusSuccess timeout:1.0]; 53 + [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0];
54 } 54 }
55 55
56 - (void)_succeed { 56 - (void)_succeed {
@@ -65,14 +65,14 @@ enum { @@ -65,14 +65,14 @@ enum {
65 NSInteger waitForStatus_; 65 NSInteger waitForStatus_;
66 NSInteger notifiedStatus_; 66 NSInteger notifiedStatus_;
67 67
68 - BOOL prepared_; // Whether prepared was called before waitFor:timeout: 68 + BOOL prepared_; // Whether prepared was called before waitForStatus:timeout:
69 NSRecursiveLock *lock_; // Lock to synchronize on 69 NSRecursiveLock *lock_; // Lock to synchronize on
70 SEL waitSelector_; // The selector we are waiting on 70 SEL waitSelector_; // The selector we are waiting on
71 71
72 NSArray *_runLoopModes; // Run loop modes to run while waiting; Defaults to NSDefaultRunLoopMode, NSRunLoopCommonModes, NSConnectionReplyMode 72 NSArray *_runLoopModes; // Run loop modes to run while waiting; Defaults to NSDefaultRunLoopMode, NSRunLoopCommonModes, NSConnectionReplyMode
73 } 73 }
74 74
75 -@property (retain) NSArray *runLoopModes; 75 +@property (retain, nonatomic) NSArray *runLoopModes;
76 76
77 /*! 77 /*!
78 Prepare before calling the asynchronous method. 78 Prepare before calling the asynchronous method.
@@ -96,13 +96,16 @@ enum { @@ -96,13 +96,16 @@ enum {
96 - (void)testFoo { 96 - (void)testFoo {
97 [self prepare]; 97 [self prepare];
98 // Do asynchronous task here 98 // Do asynchronous task here
99 - [self waitFor:kGHUnitWaitStatusSuccess timeout:1.0]; 99 + [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0];
100 } 100 }
101 @endcode 101 @endcode
102 102
103 @param status kGHUnitWaitStatusSuccess, kGHUnitWaitStatusFailure or custom status 103 @param status kGHUnitWaitStatusSuccess, kGHUnitWaitStatusFailure or custom status
104 @param timeout Timeout in seconds 104 @param timeout Timeout in seconds
105 */ 105 */
  106 +- (void)waitForStatus:(NSInteger)status timeout:(NSTimeInterval)timeout;
  107 +
  108 +// Deprecated
106 - (void)waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout; 109 - (void)waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout;
107 110
108 /*! 111 /*!
@@ -113,11 +116,17 @@ enum { @@ -113,11 +116,17 @@ enum {
113 - (void)waitForTimeout:(NSTimeInterval)timeout; 116 - (void)waitForTimeout:(NSTimeInterval)timeout;
114 117
115 /*! 118 /*!
116 - Notify of status for test selector. 119 + Notify waiting of status for test selector.
117 - @param status For example, kGHUnitWaitStatusSuccess 120 + @param status Status, for example, kGHUnitWaitStatusSuccess
118 @param selector If not NULL, then will verify this selector is where we are waiting. 121 @param selector If not NULL, then will verify this selector is where we are waiting.
119 This prevents stray asynchronous callbacks to fail a later test 122 This prevents stray asynchronous callbacks to fail a later test
120 */ 123 */
121 - (void)notify:(NSInteger)status forSelector:(SEL)selector; 124 - (void)notify:(NSInteger)status forSelector:(SEL)selector;
122 125
  126 +/*!
  127 + Notify waiting of status for any selector.
  128 + @param status Status, for example, kGHUnitWaitStatusSuccess
  129 + */
  130 +- (void)notify:(NSInteger)status;
  131 +
123 @end 132 @end
1 -//  
2 -// GHMockNSHTTPURLResponse.h  
3 -// GHUnit  
4 -//  
5 -// Created by Gabriel Handford on 4/9/09.  
6 -// Copyright 2009. All rights reserved.  
7 -//  
8 -// Permission is hereby granted, free of charge, to any person  
9 -// obtaining a copy of this software and associated documentation  
10 -// files (the "Software"), to deal in the Software without  
11 -// restriction, including without limitation the rights to use,  
12 -// copy, modify, merge, publish, distribute, sublicense, and/or sell  
13 -// copies of the Software, and to permit persons to whom the  
14 -// Software is furnished to do so, subject to the following  
15 -// conditions:  
16 -//  
17 -// The above copyright notice and this permission notice shall be  
18 -// included in all copies or substantial portions of the Software.  
19 -//  
20 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  
21 -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES  
22 -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  
23 -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  
24 -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
25 -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  
26 -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR  
27 -// OTHER DEALINGS IN THE SOFTWARE.  
28 -//  
29 -  
30 -#import <Foundation/Foundation.h>  
31 -  
32 -/*!  
33 - NSHTTPURLResponse for use with mocking.  
34 - Allows us to manually set the status code and headers in the response.  
35 - */  
36 -@interface GHMockNSHTTPURLResponse : NSHTTPURLResponse {  
37 - NSInteger statusCode_;  
38 - NSDictionary *headers_;  
39 -}  
40 -  
41 -- (id)initWithStatusCode:(NSInteger)statusCode headers:(NSDictionary *)headers;  
42 -  
43 -- (void)setStatusCode:(NSInteger)code;  
44 -- (void)setHeaders:(NSDictionary *)headers;  
45 -  
46 -@end  
1 -//  
2 -// GHMockNSURLConnection.h  
3 -// GHUnit  
4 -//  
5 -// Created by Gabriel Handford on 4/9/09.  
6 -// Copyright 2009. All rights reserved.  
7 -//  
8 -// Permission is hereby granted, free of charge, to any person  
9 -// obtaining a copy of this software and associated documentation  
10 -// files (the "Software"), to deal in the Software without  
11 -// restriction, including without limitation the rights to use,  
12 -// copy, modify, merge, publish, distribute, sublicense, and/or sell  
13 -// copies of the Software, and to permit persons to whom the  
14 -// Software is furnished to do so, subject to the following  
15 -// conditions:  
16 -//  
17 -// The above copyright notice and this permission notice shall be  
18 -// included in all copies or substantial portions of the Software.  
19 -//  
20 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  
21 -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES  
22 -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  
23 -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  
24 -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
25 -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  
26 -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR  
27 -// OTHER DEALINGS IN THE SOFTWARE.  
28 -//  
29 -  
30 -#import <Foundation/Foundation.h>  
31 -  
32 -extern NSString *const GHMockNSURLConnectionException;  
33 -  
34 -/*!  
35 - NSURLConnection for mocking.  
36 -  
37 - Use with GHAsyncTestCase to mock out connections.  
38 -  
39 - @code  
40 -  
41 - @interface GHNSURLConnectionMockTest : GHAsyncTestCase {}  
42 - @end  
43 -  
44 - @implementation GHNSURLConnectionMockTest  
45 -  
46 - - (void)testMock {  
47 - [self prepare];  
48 - GHMockNSURLConnection *connection = [[GHMockNSURLConnection alloc] initWithRequest:nil delegate:self];  
49 - [connection receiveHTTPResponseWithStatusCode:204 headers:testHeaders_ afterDelay:0.1];  
50 - [connection receiveData:testData_ afterDelay:0.2];  
51 - [connection finishAfterDelay:0.3];  
52 - [self waitFor:kGHUnitWaitStatusSuccess timeout:1.0];  
53 - }  
54 -  
55 - - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {  
56 - GHAssertEquals([(NSHTTPURLResponse *)response statusCode], 204, nil);  
57 - GHAssertEqualObjects([(NSHTTPURLResponse *)response allHeaderFields], testHeaders_, nil);  
58 - }  
59 -  
60 - - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {  
61 - GHAssertEqualObjects(data, testData_, nil);  
62 - }  
63 -  
64 - - (void)connectionDidFinishLoading:(NSURLConnection *)connection {  
65 - [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testMock)];  
66 - }  
67 - @end  
68 -  
69 - @endcode  
70 - */  
71 -@interface GHMockNSURLConnection : NSObject {  
72 - NSURLRequest *request_;  
73 - id delegate_; // weak  
74 -  
75 - BOOL cancelled_;  
76 - BOOL started_;  
77 -}  
78 -  
79 -@property (readonly, nonatomic, getter=isStarted) BOOL started;  
80 -@property (readonly, nonatomic, getter=isCancelled) BOOL cancelled;  
81 -  
82 -// Mocked version of NSURLConnection#initWithRequest:delegate:  
83 -- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate;  
84 -  
85 -// Mocked version of NSURLConnection#initWithRequest:delegate:startImmediately:  
86 -- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)startImmediately;  
87 -  
88 -// Mocked version of NSURLConnection#scheduleInRunLoop:forMode: (NOOP)  
89 -- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;  
90 -  
91 -// Mocked version of NSURLConnection#start (NOOP)  
92 -- (void)start;  
93 -  
94 -/*!  
95 - Send generic response to delegate after delay.  
96 - (For asynchronous requests)  
97 - @param delay Delay in seconds (if < 0, there is no delay)  
98 - */  
99 -- (void)receiveResponse:(NSURLResponse *)response afterDelay:(NSTimeInterval)delay;  
100 -  
101 -/*!  
102 - Send HTTP response to delegate with status code, headers, after delay.  
103 - This is only the HTTP response (and not data or finished).  
104 - (For asynchronous requests)  
105 - @param statusCode HTTP status code  
106 - @param headers Headers  
107 - @param delay Delay in seconds (if < 0, there is no delay)  
108 - */  
109 -- (void)receiveHTTPResponseWithStatusCode:(int)statusCode headers:(NSDictionary *)headers afterDelay:(NSTimeInterval)delay;  
110 -  
111 -/*!  
112 - Send data to connection delegate after delay.  
113 - @param data Data to send  
114 - @param delay Delay in seconds  
115 - */  
116 -- (void)receiveData:(NSData *)data afterDelay:(NSTimeInterval)delay;  
117 -  
118 -/*!  
119 - Send data (from file in bundle resource) to connection delegate after delay.  
120 - (For asynchronous requests)  
121 - @param path Path to file  
122 - @param delay Delay in seconds  
123 - */  
124 -- (void)receiveDataFromPath:(NSString *)path afterDelay:(NSTimeInterval)delay;  
125 -  
126 -/*!  
127 - Calls connectionDidFinish: delegate after delay.  
128 - (For asynchronous requests)  
129 - @param delay Delay in seconds (if < 0, there is no delay)  
130 - */  
131 -- (void)finishAfterDelay:(NSTimeInterval)delay;  
132 -  
133 -/*!  
134 - Sends mock response, sends data, and then calls finish.  
135 - (For asynchronous requests)  
136 - @param path Data to load path from. File should be available in Test target (bundle)  
137 - @param statusCode Status code for response  
138 - @param MIMEType Content type for response header  
139 - @param afterDelay Delay before responding (if < 0, there is no delay)  
140 - */  
141 -- (void)receiveFromPath:(NSString *)path statusCode:(NSInteger)statusCode MIMEType:(NSString *)MIMEType afterDelay:(NSTimeInterval)delay;  
142 -  
143 -@end  
1 -//  
2 -// GHMockNSLocale.h  
3 -// GHUnitIPhone  
4 -//  
5 -// Created by Gabriel Handford on 4/13/09.  
6 -// Copyright 2009. All rights reserved.  
7 -//  
8 -// Permission is hereby granted, free of charge, to any person  
9 -// obtaining a copy of this software and associated documentation  
10 -// files (the "Software"), to deal in the Software without  
11 -// restriction, including without limitation the rights to use,  
12 -// copy, modify, merge, publish, distribute, sublicense, and/or sell  
13 -// copies of the Software, and to permit persons to whom the  
14 -// Software is furnished to do so, subject to the following  
15 -// conditions:  
16 -//  
17 -// The above copyright notice and this permission notice shall be  
18 -// included in all copies or substantial portions of the Software.  
19 -//  
20 -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  
21 -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES  
22 -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  
23 -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  
24 -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,  
25 -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  
26 -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR  
27 -// OTHER DEALINGS IN THE SOFTWARE.  
28 -//  
29 -  
30 -/*!  
31 - Category for overriding the current locale at runtime.  
32 -  
33 - @code  
34 - #import "GHNSLocale+Mock.h"  
35 - // This aliases the currentLocale method and with the specified locale identifier  
36 - [NSLocale gh_setLocaleIdentifier:@"en_GB"];  
37 -  
38 - [[NSLocale currentLocale] localeIdentifier] == "en_GB"  
39 - @endcode  
40 - */  
41 -@interface NSLocale (GHMock)  
42 -  
43 -+ (void)gh_setLocaleIdentifier:(NSString *)localeIdentifier;  
44 -  
45 -/*!  
46 - Aliases to currentLocale with locale set from gh_setLocaleIdentifier.  
47 - If not set, defaults to NSLocale with identifier en_US.  
48 - */  
49 -+ (NSLocale *)gh_currentLocale;  
50 -  
51 -+ (void)gh_setPreferredLanguages:(NSArray *)preferredLanguages;  
52 -  
53 -/*!  
54 - Aliases to preferredLanguages set from gh_setPreferredLanguages.  
55 - If not set, defaults to [@"en"].  
56 - */  
57 -+ (NSArray *)gh_preferredLanguages;  
58 -  
59 -@end  
@@ -31,34 +31,41 @@ @@ -31,34 +31,41 @@
31 Test status. 31 Test status.
32 */ 32 */
33 typedef enum { 33 typedef enum {
34 - GHTestStatusNone = 0, 34 + GHTestStatusNone = 0,
35 - GHTestStatusRunning, 35 + GHTestStatusRunning, // Test is running
36 - GHTestStatusFinished, 36 + GHTestStatusCancelling, // Test is being cancelled
37 - GHTestStatusIgnored 37 + GHTestStatusCancelled, // Test was cancelled
  38 + GHTestStatusSucceeded, // Test finished and succeeded
  39 + GHTestStatusErrored, // Test finished and errored
38 } GHTestStatus; 40 } GHTestStatus;
39 41
40 /*! 42 /*!
41 Generate string from GHTestStatus 43 Generate string from GHTestStatus
42 @param status 44 @param status
43 */ 45 */
44 -NSString* NSStringFromGHTestStatus(GHTestStatus status); 46 +extern NSString* NSStringFromGHTestStatus(GHTestStatus status);
  47 +
  48 +extern BOOL GHTestStatusIsRunning(GHTestStatus status);
  49 +extern BOOL GHTestStatusEnded(GHTestStatus status);
45 50
46 /*! 51 /*!
47 Test stats. 52 Test stats.
48 */ 53 */
49 typedef struct { 54 typedef struct {
50 - NSInteger runCount; 55 + NSInteger succeedCount; // Number of succeeded tests
51 - NSInteger failureCount; 56 + NSInteger failureCount; // Number of failed tests
52 - NSInteger ignoreCount; 57 + NSInteger cancelCount; // Number of aborted tests
53 - NSInteger testCount; 58 + NSInteger testCount; // Total number of tests
54 } GHTestStats; 59 } GHTestStats;
55 60
56 /*! 61 /*!
57 Create GHTestStats. 62 Create GHTestStats.
58 */ 63 */
59 -GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSInteger ignoreCount, NSInteger testCount); 64 +extern GHTestStats GHTestStatsMake(NSInteger succeedCount, NSInteger failureCount, NSInteger cancelCount, NSInteger testCount);
  65 +
  66 +const GHTestStats GHTestStatsEmpty;
60 67
61 -#define NSStringFromGHTestStats(stats) [NSString stringWithFormat:@"%d/%d/%d", stats.runCount, stats.testCount, stats.failureCount] 68 +extern NSString *NSStringFromGHTestStats(GHTestStats stats);
62 69
63 @protocol GHTestDelegate; 70 @protocol GHTestDelegate;
64 71
@@ -80,11 +87,16 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege @@ -80,11 +87,16 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege
80 - (void)setDelegate:(id<GHTestDelegate>)delegate; 87 - (void)setDelegate:(id<GHTestDelegate>)delegate;
81 88
82 - (NSException *)exception; 89 - (NSException *)exception;
  90 +- (void)setException:(NSException *)exception;
83 91
84 - (NSArray *)log; 92 - (NSArray *)log;
85 93
86 -- (BOOL)ignore; 94 +- (void)reset;
87 -- (void)setIgnore:(BOOL)ignore; 95 +- (void)cancel;
  96 +
  97 +- (void)setDisabled:(BOOL)disabled;
  98 +- (BOOL)isDisabled;
  99 +- (NSInteger)disabledCount;
88 100
89 @end 101 @end
90 102
@@ -92,29 +104,34 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege @@ -92,29 +104,34 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege
92 Test delegate for notification when a test starts and ends. 104 Test delegate for notification when a test starts and ends.
93 */ 105 */
94 @protocol GHTestDelegate <NSObject> 106 @protocol GHTestDelegate <NSObject>
95 -- (void)testDidStart:(id<GHTest>)test; 107 +- (void)testDidStart:(id<GHTest>)test source:(id<GHTest>)source;
96 -- (void)testDidFinish:(id<GHTest>)test; 108 +- (void)testDidUpdate:(id<GHTest>)test source:(id<GHTest>)source;
97 -- (void)test:(id<GHTest>)test didLog:(NSString *)message; 109 +- (void)testDidEnd:(id<GHTest>)test source:(id<GHTest>)source;
98 -- (void)testDidIgnore:(id<GHTest>)test; 110 +- (void)test:(id<GHTest>)test didLog:(NSString *)message source:(id<GHTest>)source;
99 @end 111 @end
100 112
101 /*! 113 /*!
102 Delegate which is notified of log messages from inside GHTestCase. 114 Delegate which is notified of log messages from inside GHTestCase.
103 */ 115 */
104 -@protocol GHTestCaseLogDelegate <NSObject> 116 +@protocol GHTestCaseLogWriter <NSObject>
105 -- (void)testCase:(id)testCase didLog:(NSString *)message; 117 +- (void)log:(NSString *)message testCase:(id)testCase;
  118 +@end
  119 +
  120 +@interface GHTestOperation : NSOperation {
  121 + id<GHTest> test_;
  122 +}
106 @end 123 @end
107 124
108 /*! 125 /*!
109 - Default test implementation target with a target/selector pair. 126 + Default test implementation with a target/selector pair.
110 - Consists of a target/selector 127 - Consists of a target/selector
111 - Notifies a test delegate 128 - Notifies a test delegate
112 - Keeps track of status, running time and failures 129 - Keeps track of status, running time and failures
113 - Stores any test specific logging 130 - Stores any test specific logging
114 */ 131 */
115 -@interface GHTest : NSObject <GHTest, GHTestCaseLogDelegate> { 132 +@interface GHTest : NSObject <GHTest, GHTestCaseLogWriter> {
116 133
117 - id<GHTestDelegate> delegate_; // weak 134 + NSObject<GHTestDelegate> *delegate_; // weak
118 135
119 id target_; 136 id target_;
120 SEL selector_; 137 SEL selector_;
@@ -123,16 +140,24 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege @@ -123,16 +140,24 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege
123 NSString *name_; 140 NSString *name_;
124 GHTestStatus status_; 141 GHTestStatus status_;
125 NSTimeInterval interval_; 142 NSTimeInterval interval_;
126 - BOOL failed_; 143 + BOOL disabled_;
127 NSException *exception_; // If failed 144 NSException *exception_; // If failed
128 -  
129 - GHTestStats stats_;  
130 145
131 NSMutableArray *log_; 146 NSMutableArray *log_;
132 -  
133 - BOOL ignore_;  
134 } 147 }
135 148
  149 +@property (readonly, nonatomic) id target;
  150 +@property (readonly, nonatomic) SEL selector;
  151 +@property (readonly, nonatomic) NSString *identifier; // Unique identifier for test
  152 +@property (readonly, nonatomic) NSString *name;
  153 +@property (readonly, nonatomic) NSTimeInterval interval;
  154 +@property (retain, nonatomic) NSException *exception;
  155 +@property (readonly, nonatomic) GHTestStatus status;
  156 +@property (assign, nonatomic, getter=isDisabled) BOOL disabled;
  157 +@property (readonly, nonatomic) NSArray *log;
  158 +
  159 +@property (assign, nonatomic) NSObject<GHTestDelegate> *delegate;
  160 +
136 /*! 161 /*!
137 Create test with target/selector. 162 Create test with target/selector.
138 @param target Target (usually a test case) 163 @param target Target (usually a test case)
@@ -147,25 +172,4 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege @@ -147,25 +172,4 @@ GHTestStats GHTestStatsMake(NSInteger runCount, NSInteger failureCount, NSIntege
147 */ 172 */
148 + (id)testWithTarget:(id)target selector:(SEL)selector; 173 + (id)testWithTarget:(id)target selector:(SEL)selector;
149 174
150 -@property (readonly, nonatomic) id target;  
151 -@property (readonly, nonatomic) SEL selector;  
152 -@property (readonly, nonatomic) NSString *identifier; // Unique identifier for test  
153 -@property (readonly, nonatomic) NSString *name;  
154 -@property (readonly, nonatomic) NSTimeInterval interval;  
155 -@property (readonly, nonatomic) NSException *exception;  
156 -@property (readonly, nonatomic) GHTestStatus status;  
157 -@property (readonly, nonatomic) BOOL failed;  
158 -@property (readonly, nonatomic) GHTestStats stats;  
159 -@property (readonly, nonatomic) NSArray *log;  
160 -  
161 -@property (assign, nonatomic) id<GHTestDelegate> delegate;  
162 -@property (assign, nonatomic) BOOL ignore;  
163 -  
164 -/*!  
165 - Run the test.  
166 - After running, the interval and exception properties may be set.  
167 - @result YES if passed, NO otherwise  
168 - */  
169 -- (void)run;  
170 -  
171 @end 175 @end
@@ -54,8 +54,8 @@ @@ -54,8 +54,8 @@
54 #define GHTestLog(...) [self log:[NSString stringWithFormat:__VA_ARGS__, nil]] 54 #define GHTestLog(...) [self log:[NSString stringWithFormat:__VA_ARGS__, nil]]
55 55
56 /*! 56 /*!
57 - @brief The base class for a test case. 57 + The base class for a test case.
58 - 58 +
59 @code 59 @code
60 @interface MyTest : GHTestCase {} 60 @interface MyTest : GHTestCase {}
61 @end 61 @end
@@ -90,14 +90,14 @@ @@ -90,14 +90,14 @@
90 90
91 */ 91 */
92 @interface GHTestCase : NSObject { 92 @interface GHTestCase : NSObject {
93 - id<GHTestCaseLogDelegate> logDelegate_; // weak 93 + id<GHTestCaseLogWriter> logWriter_; // weak
94 94
95 SEL currentSelector_; 95 SEL currentSelector_;
96 } 96 }
97 97
98 //! The current test selector 98 //! The current test selector
99 @property (assign, nonatomic) SEL currentSelector; 99 @property (assign, nonatomic) SEL currentSelector;
100 -@property (assign, nonatomic) id<GHTestCaseLogDelegate> logDelegate; 100 +@property (assign, nonatomic) id<GHTestCaseLogWriter> logWriter;
101 101
102 // GTM_BEGIN 102 // GTM_BEGIN
103 //! Run before each test method 103 //! Run before each test method
@@ -120,6 +120,14 @@ @@ -120,6 +120,14 @@
120 //! Run after the tests (once per test case) 120 //! Run after the tests (once per test case)
121 - (void)tearDownClass; 121 - (void)tearDownClass;
122 122
  123 +/*!
  124 + Whether to run the tests on a separate thread. Override this method in your
  125 + test case to override the default.
  126 + Default is NO, tests are run on a separate thread by default.
  127 + @result If YES runs on the main thread
  128 + */
  129 +- (BOOL)shouldRunOnMainThread;
  130 +
123 //! Any special handling of exceptions after they are thrown; By default logs stack trace to standard out. 131 //! Any special handling of exceptions after they are thrown; By default logs stack trace to standard out.
124 - (void)handleException:(NSException *)exception; 132 - (void)handleException:(NSException *)exception;
125 133
@@ -81,7 +81,7 @@ @@ -81,7 +81,7 @@
81 */ 81 */
82 @interface GHTestGroup : NSObject <GHTestDelegate, GHTestGroup> { 82 @interface GHTestGroup : NSObject <GHTestDelegate, GHTestGroup> {
83 83
84 - id<GHTestDelegate> delegate_; // weak 84 + NSObject<GHTestDelegate> *delegate_; // weak
85 id<GHTestGroup> parent_; // weak 85 id<GHTestGroup> parent_; // weak
86 86
87 NSMutableArray *children_; // of id<GHTest> 87 NSMutableArray *children_; // of id<GHTest>
@@ -91,16 +91,17 @@ @@ -91,16 +91,17 @@
91 GHTestStatus status_; // Current status of the group (current status of running or completed child tests) 91 GHTestStatus status_; // Current status of the group (current status of running or completed child tests)
92 GHTestStats stats_; // Current stats for the group (aggregate of child test stats) 92 GHTestStats stats_; // Current stats for the group (aggregate of child test stats)
93 93
94 - id testCase_; // Is set if test is created from initWithTestCase:delegate: 94 + BOOL didSetUpClass_;
95 - id<GHTest> currentTest_; // weak  
96 95
97 - NSException *exception_; // If exception happens in group setUpClass/tearDownClass 96 + // Set if test is created from initWithTestCase:delegate:
  97 + // Allows use to perform setUpClass and tearDownClass (once per test case run)
  98 + id testCase_;
98 99
99 - BOOL ignore_; 100 + NSException *exception_; // If exception happens in group setUpClass/tearDownClass
100 } 101 }
101 102
102 -@property (readonly, nonatomic) NSArray *children; 103 +@property (readonly, nonatomic) NSArray */*of id<GHTest>*/children;
103 -@property (assign, nonatomic) id<GHTestDelegate> delegate; 104 +@property (assign, nonatomic) NSObject<GHTestDelegate> *delegate;
104 @property (assign, nonatomic) id<GHTestGroup> parent; 105 @property (assign, nonatomic) id<GHTestGroup> parent;
105 @property (readonly, nonatomic) id testCase; 106 @property (readonly, nonatomic) id testCase;
106 107
@@ -110,8 +111,7 @@ @@ -110,8 +111,7 @@
110 111
111 @property (readonly, nonatomic) NSTimeInterval interval; 112 @property (readonly, nonatomic) NSTimeInterval interval;
112 @property (readonly, nonatomic) GHTestStats stats; 113 @property (readonly, nonatomic) GHTestStats stats;
113 - 114 +@property (readonly, nonatomic) NSException *exception;
114 -@property (assign, nonatomic) BOOL ignore;  
115 115
116 /*! 116 /*!
117 Create an empty test group. 117 Create an empty test group.
@@ -134,7 +134,7 @@ @@ -134,7 +134,7 @@
134 /*! 134 /*!
135 Create test group from a single test. 135 Create test group from a single test.
136 @param testCase 136 @param testCase
137 - @param selector Test to run 137 + @param selector Test to run
138 @param delegate 138 @param delegate
139 */ 139 */
140 - (id)initWithTestCase:(id)testCase selector:(SEL)selector delegate:(id<GHTestDelegate>)delegate; 140 - (id)initWithTestCase:(id)testCase selector:(SEL)selector delegate:(id<GHTestDelegate>)delegate;
@@ -155,10 +155,13 @@ @@ -155,10 +155,13 @@
155 155
156 - (void)addTestGroup:(GHTestGroup *)testGroup; 156 - (void)addTestGroup:(GHTestGroup *)testGroup;
157 157
  158 +- (BOOL)shouldRunOnMainThread;
  159 +
158 /*! 160 /*!
159 - Run the test group. 161 + Run in operation queue.
160 - Will notify delegate as tests are run. 162 + Tests from the group are added and will block until they have completed.
  163 + @param operationQueue If nil, then runs as is
161 */ 164 */
162 -- (void)run; 165 +- (void)runInOperationQueue:(NSOperationQueue *)operationQueue;
163 166
164 @end 167 @end
@@ -54,12 +54,14 @@ @@ -54,12 +54,14 @@
54 @protocol GHTestRunnerDelegate <NSObject> 54 @protocol GHTestRunnerDelegate <NSObject>
55 @optional 55 @optional
56 - (void)testRunnerDidStart:(GHTestRunner *)runner; 56 - (void)testRunnerDidStart:(GHTestRunner *)runner;
57 -- (void)testRunner:(GHTestRunner *)runner didStartTest:(id<GHTest>)test; 57 +- (void)testRunner:(GHTestRunner *)runner didStartTest:(id<GHTest>)test; // Test started
58 -- (void)testRunner:(GHTestRunner *)runner didFinishTest:(id<GHTest>)test; 58 +- (void)testRunner:(GHTestRunner *)runner didUpdateTest:(id<GHTest>)test; // Test changed
59 -- (void)testRunnerDidFinish:(GHTestRunner *)runner; 59 +- (void)testRunner:(GHTestRunner *)runner didEndTest:(id<GHTest>)test; // Test finished
60 - 60 +- (void)testRunnerDidCancel:(GHTestRunner *)runner;
61 -- (void)testRunner:(GHTestRunner *)runner didLog:(NSString *)message; 61 +- (void)testRunnerDidEnd:(GHTestRunner *)runner;
62 -- (void)testRunner:(GHTestRunner *)runner test:(id<GHTest>)test didLog:(NSString *)message; 62 +
  63 +- (void)testRunner:(GHTestRunner *)runner didLog:(NSString *)message; // Runner logged message
  64 +- (void)testRunner:(GHTestRunner *)runner test:(id<GHTest>)test didLog:(NSString *)message; // Test logged message
63 @end 65 @end
64 66
65 /*! 67 /*!
@@ -71,22 +73,24 @@ @@ -71,22 +73,24 @@
71 73
72 id<GHTest> test_; // The test to run; Could be a GHTestGroup (suite), GHTestGroup (test case), or GHTest (target/selector) 74 id<GHTest> test_; // The test to run; Could be a GHTestGroup (suite), GHTestGroup (test case), or GHTest (target/selector)
73 75
74 - id<GHTestRunnerDelegate> delegate_; // weak 76 + NSObject<GHTestRunnerDelegate> *delegate_; // weak
75 77
76 // If YES, will allow exceptions to be raised (so you can trigger the debugger) 78 // If YES, will allow exceptions to be raised (so you can trigger the debugger)
77 - BOOL raiseExceptions_; 79 + BOOL raiseExceptions_;
78 80
79 - // If yes, delegate calls will occur on the main thread 81 + BOOL running_;
80 - // Defaults to YES. 82 + BOOL cancelling_;
81 - BOOL delegateOnMainThread_; 83 +
82 - 84 + NSOperationQueue *operationQueue_; //! If running a suite in operation queue
83 } 85 }
84 86
85 @property (retain) id<GHTest> test; 87 @property (retain) id<GHTest> test;
86 -@property (assign) id<GHTestRunnerDelegate> delegate; 88 +@property (assign) NSObject<GHTestRunnerDelegate> *delegate;
87 @property (assign) BOOL raiseExceptions; 89 @property (assign) BOOL raiseExceptions;
88 -@property (assign) BOOL delegateOnMainThread;  
89 @property (readonly) GHTestStats stats; 90 @property (readonly) GHTestStats stats;
  91 +@property (readonly, getter=isRunning) BOOL running;
  92 +@property (readonly, getter=isCancelling) BOOL cancelling;
  93 +@property (retain, nonatomic) NSOperationQueue *operationQueue;
90 94
91 /*! 95 /*!
92 Create runner for test. 96 Create runner for test.
@@ -109,6 +113,14 @@ @@ -109,6 +113,14 @@
109 + (GHTestRunner *)runnerForSuite:(GHTestSuite *)suite; 113 + (GHTestRunner *)runnerForSuite:(GHTestSuite *)suite;
110 114
111 /*! 115 /*!
  116 + Create runner for class and method.
  117 + @param testClassName
  118 + @param methodName
  119 + @result Runner
  120 + */
  121 ++ (GHTestRunner *)runnerForTestClassName:(NSString *)testClassName methodName:(NSString *)methodName;
  122 +
  123 +/*!
112 Get the runner from the environment. 124 Get the runner from the environment.
113 If the TEST env is set, then we will only run that test case or test method. 125 If the TEST env is set, then we will only run that test case or test method.
114 */ 126 */
@@ -117,14 +129,19 @@ @@ -117,14 +129,19 @@
117 /*! 129 /*!
118 Run the test runner. Usually called from the test main. 130 Run the test runner. Usually called from the test main.
119 Reads the TEST environment variable and filters on that; or all tests are run. 131 Reads the TEST environment variable and filters on that; or all tests are run.
120 - @result Return value, 0 is success, otherwise the failure count 132 + @result 0 is success, otherwise the failure count
121 */ 133 */
122 + (int)run; 134 + (int)run;
123 135
  136 +- (void)runInBackground;
  137 +
124 /*! 138 /*!
125 Start the test runner. 139 Start the test runner.
  140 + @result 0 is success, otherwise the failure count
126 */ 141 */
127 -- (void)run; 142 +- (int)runTests;
  143 +
  144 +- (void)cancel;
128 145
129 @end 146 @end
130 147
@@ -30,6 +30,12 @@ @@ -30,6 +30,12 @@
30 #import "GHTestGroup.h" 30 #import "GHTestGroup.h"
31 31
32 /*! 32 /*!
  33 + If set, will run it as a "test filter" like the env variable TEST.
  34 + */
  35 +extern NSString *GHUnitTest;
  36 +
  37 +
  38 +/*!
33 Test suite is an alias for test group. 39 Test suite is an alias for test group.
34 40
35 A test case is an instance of a test case class with test methods. 41 A test case is an instance of a test case class with test methods.
@@ -48,9 +54,7 @@ @@ -48,9 +54,7 @@
48 - (void)testB2; (GHTest with target GHTestCase2 + testB2) 54 - (void)testB2; (GHTest with target GHTestCase2 + testB2)
49 55
50 */ 56 */
51 -@interface GHTestSuite : GHTestGroup { 57 +@interface GHTestSuite : GHTestGroup { }
52 -  
53 -}  
54 58
55 /*! 59 /*!
56 Create test suite with test cases. 60 Create test suite with test cases.
@@ -63,6 +67,7 @@ @@ -63,6 +67,7 @@
63 /*! 67 /*!
64 Creates a suite of all tests. 68 Creates a suite of all tests.
65 Will load all classes that subclass from GHTestCase, SenTestCase or GTMTestCase (or register test case class). 69 Will load all classes that subclass from GHTestCase, SenTestCase or GTMTestCase (or register test case class).
  70 + @result Suite
66 */ 71 */
67 + (GHTestSuite *)allTests; 72 + (GHTestSuite *)allTests;
68 73
@@ -80,6 +85,14 @@ @@ -80,6 +85,14 @@
80 + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilter; 85 + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilter;
81 86
82 /*! 87 /*!
  88 + Suite for a single test/method.
  89 + @param testCaseClass
  90 + @param method
  91 + @result Suite
  92 + */
  93 ++ (GHTestSuite *)suiteWithTestCaseClass:(Class)testCaseClass method:(SEL)method;
  94 +
  95 +/*!
83 Return test suite based on environment (TEST=TestFoo/foo) 96 Return test suite based on environment (TEST=TestFoo/foo)
84 @result Suite 97 @result Suite
85 */ 98 */
@@ -67,7 +67,7 @@ BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass); @@ -67,7 +67,7 @@ BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass);
67 67
68 /*! 68 /*!
69 Load all test classes that we can "see". 69 Load all test classes that we can "see".
70 - @return Array of initialized (and autoreleased) test case classes in an autoreleased array. 70 + @result Array of initialized (and autoreleased) test case classes in an autoreleased array.
71 */ 71 */
72 - (NSArray *)loadAllTestCases; 72 - (NSArray *)loadAllTestCases;
73 73
@@ -98,7 +98,7 @@ BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass); @@ -98,7 +98,7 @@ BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass);
98 Run test. 98 Run test.
99 Exception if set is retained and should be released by the caller. 99 Exception if set is retained and should be released by the caller.
100 */ 100 */
101 -- (BOOL)runTest:(id)target selector:(SEL)selector exception:(NSException **)exception interval:(NSTimeInterval *)interval; 101 ++ (BOOL)runTest:(id)target selector:(SEL)selector withObject:(id)obj exception:(NSException **)exception interval:(NSTimeInterval *)interval;
102 102
103 @end 103 @end
104 104
@@ -32,3 +32,9 @@ @@ -32,3 +32,9 @@
32 #import "GHTestSuite.h" 32 #import "GHTestSuite.h"
33 #import "GHTestMacros.h" 33 #import "GHTestMacros.h"
34 #import "GHTestRunner.h" 34 #import "GHTestRunner.h"
  35 +
  36 +#ifdef DEBUG
  37 +#define GHUDebug(fmt, ...) NSLog(fmt, ##__VA_ARGS__)
  38 +#else
  39 +#define GHUDebug(fmt, ...) do {} while(0)
  40 +#endif
@@ -7,10 +7,20 @@ @@ -7,10 +7,20 @@
7 // 7 //
8 8
9 #import <UIKit/UIKit.h> 9 #import <UIKit/UIKit.h>
  10 +
10 #import "GHUnit.h" 11 #import "GHUnit.h"
11 12
  13 +extern BOOL NSDebugEnabled;
  14 +extern BOOL NSZombieEnabled;
  15 +extern BOOL NSDeallocateZombies;
  16 +extern BOOL NSHangOnUncaughtException;
  17 +
12 int main(int argc, char *argv[]) { 18 int main(int argc, char *argv[]) {
13 - setenv("NSAutoreleaseFreedObjectCheckEnabled", "1", 1); 19 +
  20 + NSDebugEnabled = YES;
  21 + NSZombieEnabled = YES;
  22 + NSDeallocateZombies = NO;
  23 + NSHangOnUncaughtException = YES;
14 24
15 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 25 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
16 26
@@ -7,6 +7,17 @@ fi @@ -7,6 +7,17 @@ fi
7 7
8 export DYLD_ROOT_PATH="$SDKROOT" 8 export DYLD_ROOT_PATH="$SDKROOT"
9 export DYLD_FRAMEWORK_PATH="$CONFIGURATION_BUILD_DIR" 9 export DYLD_FRAMEWORK_PATH="$CONFIGURATION_BUILD_DIR"
  10 +export IPHONE_SIMULATOR_ROOT="$SDKROOT"
  11 +
  12 +export MallocScribble=YES
  13 +export MallocPreScribble=YES
  14 +export MallocGuardEdges=YES
  15 +export MallocStackLogging=YES
  16 +export MallocStackLoggingNoCompact=YES
  17 +export NSAutoreleaseFreedObjectCheckEnabled=YES
  18 +
  19 +export CFZombieLevel=3
  20 +export NSZombieEnabled=YES
10 21
11 "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents 22 "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents
12 RETVAL=$? 23 RETVAL=$?
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 <key>CFBundleExecutable</key> 7 <key>CFBundleExecutable</key>
8 <string>${EXECUTABLE_NAME}</string> 8 <string>${EXECUTABLE_NAME}</string>
9 <key>CFBundleIdentifier</key> 9 <key>CFBundleIdentifier</key>
10 - <string>com.yourcompany.${PRODUCT_NAME:identifier}</string> 10 + <string>com.allseeinginteractive.trailsnetwork.tests</string>
11 <key>CFBundleInfoDictionaryVersion</key> 11 <key>CFBundleInfoDictionaryVersion</key>
12 <string>6.0</string> 12 <string>6.0</string>
13 <key>CFBundlePackageType</key> 13 <key>CFBundlePackageType</key>
This diff was suppressed by a .gitattributes entry.