PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/NSObjectBlocksKitTest.m

http://github.com/zwaldowski/BlocksKit
Objective C | 57 lines | 45 code | 8 blank | 4 comment | 0 complexity | dafb7c7120fa051a5e9fc0f43c9422dd MD5 | raw file
 1//
 2//  NSObjectBlocksKitTest.m
 3//  BlocksKit Unit Tests
 4//
 5
 6#import "NSObjectBlocksKitTest.h"
 7
 8@implementation NSObjectBlocksKitTest {
 9	NSMutableString *_subject;	
10}
11
12- (void)setUp {
13	_subject = [[NSMutableString alloc] initWithString:@"Hello "];
14}
15
16- (void)tearDown {
17	[_subject release];
18}  
19
20- (void)testPerformBlockAfterDelay {
21	BKSenderBlock senderBlock = ^(NSObjectBlocksKitTest *sender) {
22		[_subject appendString:@"BlocksKit"];
23		[sender notify:kGHUnitWaitStatusSuccess forSelector:@selector(testPerformBlockAfterDelay)];
24	};
25	[self prepare];
26	id block = [self performBlock:senderBlock afterDelay:0.5];
27	GHAssertNotNil(block,@"block is nil");
28	[self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0];
29	GHAssertEqualStrings(_subject,@"Hello BlocksKit",@"subject string is %@",_subject);
30}
31
32- (void)testClassPerformBlockAfterDelay {
33	__block NSObjectBlocksKitTest *test = self;
34	__block NSMutableString *subject = [NSMutableString stringWithString:@"Hello "];
35	[self prepare];
36	id blk = [NSObject performBlock:^{
37		[subject appendString:@"BlocksKit"];
38		[test notify:kGHUnitWaitStatusSuccess forSelector:@selector(testClassPerformBlockAfterDelay)];
39	} afterDelay:0.5];
40	GHAssertNotNil(blk,@"block is nil");
41	[self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0];
42	GHAssertEqualStrings(subject,@"Hello BlocksKit",@"subject string is %@",subject);
43}
44
45- (void)testCancel {
46	[self prepare];
47	id block = [self performBlock:^(NSObjectBlocksKitTest * sender) {
48		[_subject appendString:@"BlocksKit"];
49		[sender notify:kGHUnitWaitStatusSuccess forSelector:@selector(testCancel)];
50	} afterDelay:0.1];
51	GHAssertNotNil(block,@"block is nil");
52	[NSObject cancelBlock:block];
53	[self waitForTimeout:0.5];
54	GHAssertEqualStrings(_subject,@"Hello ",@"subject string is %@",_subject);
55}
56
57@end