forked from gh-unit/gh-unit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// GHKVObserveTest.m | ||
// GHUnitIPhone | ||
// | ||
// Created by Gabriel Handford on 11/14/10. | ||
// Copyright 2010 Yelp. All rights reserved. | ||
// | ||
|
||
|
||
#import "GHAsyncTestCase.h" | ||
|
||
@interface GHKVObserve : NSObject { | ||
NSString *_text; | ||
} | ||
|
||
@property (retain, nonatomic) NSString *text; | ||
|
||
- (void)updateText; | ||
|
||
@end | ||
|
||
|
||
@interface GHKVObserveTest : GHAsyncTestCase { } | ||
@end | ||
|
||
|
||
@implementation GHKVObserveTest | ||
|
||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | ||
[self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testObserve)]; | ||
} | ||
|
||
- (void)testObserve { | ||
GHKVObserve *observe = [[GHKVObserve alloc] init]; | ||
[self prepare]; | ||
[observe addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:nil]; | ||
[observe updateText]; | ||
[self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0]; | ||
GHAssertEqualStrings(observe.text, @"Test", nil); | ||
} | ||
|
||
@end | ||
|
||
#pragma mark - | ||
|
||
@implementation GHKVObserve | ||
|
||
@synthesize text=_text; | ||
|
||
- (void)dealloc { | ||
[_text release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)updateText { | ||
[self performSelector:@selector(setText:) withObject:@"Test" afterDelay:0.1]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// GHNSURLConnectionTest.m | ||
// GHUnitIPhone | ||
// | ||
// Created by Gabriel Handford on 11/14/10. | ||
// Copyright 2010. All rights reserved. | ||
// | ||
|
||
#import "GHAsyncTestCase.h" | ||
|
||
@interface GHNSURLConnectionTest : GHAsyncTestCase { } | ||
@end | ||
|
||
@implementation GHNSURLConnectionTest | ||
|
||
- (void)testURLConnection { | ||
|
||
// Call prepare to setup the asynchronous action. | ||
// This helps in cases where the action is synchronous and the | ||
// action occurs before the wait is actually called. | ||
[self prepare]; | ||
|
||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]; | ||
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; | ||
|
||
// Wait until notify called for timeout (seconds); If notify is not called with kGHUnitWaitStatusSuccess then | ||
// we will throw an error. | ||
[self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; | ||
|
||
[connection release]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { | ||
GHTestLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]); | ||
} | ||
|
||
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { | ||
// Notify of success, specifying the method where wait is called. | ||
// This prevents stray notifies from affecting other tests. | ||
[self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testURLConnection)]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { | ||
// Notify of connection failure | ||
[self notify:kGHUnitWaitStatusFailure forSelector:@selector(testURLConnection)]; | ||
} | ||
|
||
@end |