Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Nov 15, 2010
1 parent 84c24cf commit 0fd0a7d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 40 deletions.
10 changes: 9 additions & 1 deletion Project-IPhone/GHUnitIPhone.xcodeproj/project.pbxproj
Expand Up @@ -143,6 +143,8 @@
00803E79128DEAE60033DA60 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00803E78128DEAE60033DA60 /* CoreGraphics.framework */; };
00803E7B128DEAE60033DA60 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00803E7A128DEAE60033DA60 /* Foundation.framework */; };
00803E7D128DEAE60033DA60 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00803E7C128DEAE60033DA60 /* UIKit.framework */; };
0080411A1290B1B60033DA60 /* GHNSURLConnectionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008041191290B1B60033DA60 /* GHNSURLConnectionTest.m */; };
008041261290B1ED0033DA60 /* GHKVObserveTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 008041251290B1ED0033DA60 /* GHKVObserveTest.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -298,6 +300,8 @@
00803E78128DEAE60033DA60 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
00803E7A128DEAE60033DA60 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
00803E7C128DEAE60033DA60 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
008041191290B1B60033DA60 /* GHNSURLConnectionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHNSURLConnectionTest.m; sourceTree = "<group>"; };
008041251290B1ED0033DA60 /* GHKVObserveTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHKVObserveTest.m; sourceTree = "<group>"; };
008F39E11174300C001A35C4 /* GHUnitIPhoneView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHUnitIPhoneView.h; sourceTree = "<group>"; };
008F39E21174300C001A35C4 /* GHUnitIPhoneView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHUnitIPhoneView.m; sourceTree = "<group>"; };
00A230BD1022586400337F7B /* GHTestMacrosTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHTestMacrosTest.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -549,7 +553,6 @@
00DCB8780FA4F9E10022DA5A /* IPhone */,
000203F40F8EA86000EC31BA /* Data */,
00080FB80F4FC7CB0034DF4C /* GTM */,
007730230F8D8DF400586577 /* GHAsyncTestCaseTest.m */,
007730240F8D8DF400586577 /* GHRegisterTestCaseClassTest.m */,
0016AF0C1012A4A8009F4F8F /* GHTestOnMainThread.m */,
0016AF0E1012A4A8009F4F8F /* GHTestFail.m */,
Expand All @@ -563,6 +566,9 @@
00A230BD1022586400337F7B /* GHTestMacrosTest.m */,
00A230BF1022587F00337F7B /* GHTestLogTest.m */,
00F09A65108D5040000E5AB5 /* GHTestEmpty.m */,
007730230F8D8DF400586577 /* GHAsyncTestCaseTest.m */,
008041191290B1B60033DA60 /* GHNSURLConnectionTest.m */,
008041251290B1ED0033DA60 /* GHKVObserveTest.m */,
);
name = Tests;
path = ../Tests;
Expand Down Expand Up @@ -880,6 +886,8 @@
0051315A11C6EDA300A46E09 /* GHNSLocale+Mock.m in Sources */,
0051316311C6EDB400A46E09 /* GHUNSObject+Swizzle.m in Sources */,
004810C6122E257500E3B69F /* GHUnitIOSTestMain.m in Sources */,
0080411A1290B1B60033DA60 /* GHNSURLConnectionTest.m in Sources */,
008041261290B1ED0033DA60 /* GHKVObserveTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
39 changes: 0 additions & 39 deletions Tests/GHAsyncTestCaseTest.m
Expand Up @@ -81,42 +81,3 @@ - (void)_testWaitNoSelectorCheck {
@end


@interface GHAsyncConnectionTestCaseTest : GHAsyncTestCase { }
@end

@implementation GHAsyncConnectionTestCaseTest

- (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

59 changes: 59 additions & 0 deletions Tests/GHKVObserveTest.m
@@ -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
48 changes: 48 additions & 0 deletions Tests/GHNSURLConnectionTest.m
@@ -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

0 comments on commit 0fd0a7d

Please sign in to comment.