PageRenderTime 71ms CodeModel.GetById 60ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/NSObjectAssociatedObjectTest.m

http://github.com/zwaldowski/BlocksKit
Objective C | 56 lines | 38 code | 11 blank | 7 comment | 0 complexity | ce78bb8133c5461550c053a284e97237 MD5 | raw file
 1//
 2//  NSObjectAssociatedObjectTest.m
 3//  BlocksKit Unit Tests
 4//
 5
 6#import "NSObjectAssociatedObjectTest.h"
 7
 8static char kAssociationKey;
 9static char kNotFoundKey;
10
11@implementation NSObjectAssociatedObjectTest
12
13- (void)tearDown {
14	[self removeAllAssociatedObjects];
15}
16
17- (void)testAssociatedRetainValue {
18	NSMutableString *subject = [[NSMutableString alloc] initWithString:@"Hello"];
19	[self associateValue:subject withKey:&kAssociationKey];
20	[subject appendString:@" BlocksKit"];
21	[subject release];
22
23	// Value is retained
24	NSString *associated = [self associatedValueForKey:&kAssociationKey];
25	GHAssertEqualStrings(associated,@"Hello BlocksKit",@"associated value is %@",associated);
26}
27
28- (void)testAssociatedCopyValue {
29	NSMutableString *subject = [[NSMutableString alloc] initWithString:@"Hello"];
30	[self associateCopyOfValue:subject withKey:&kAssociationKey];
31	[subject appendString:@" BlocksKit"];
32	[subject release];
33
34	// Value is copied
35	NSString *associated = [self associatedValueForKey:&kAssociationKey];
36	GHAssertEqualStrings(associated,@"Hello",@"associated value is %@",associated);
37}
38
39- (void)testAssociatedAssignValue {
40	NSString *subject = [[NSString alloc] initWithString:@"Hello BlocksKit"];
41	[self weaklyAssociateValue:subject withKey:&kAssociationKey];
42	[subject release];
43	subject = nil;
44#if BK_HAS_APPKIT
45	//zeroing weak reference is not available for iOS
46	NSString *associated = [self associatedValueForKey:&kAssociationKey];
47	GHAssertNil(associated,@"associated value is nil");
48#endif
49}
50
51- (void)testAssociatedNotFound {
52	NSString *associated = [self associatedValueForKey:&kNotFoundKey];
53	GHAssertNil(associated,@"associated value is not found for kNotFoundKey");
54}
55
56@end