Skip to content

Commit

Permalink
Update the tests slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
alco committed Feb 24, 2012
1 parent 8b84d1c commit c522148
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
8 changes: 7 additions & 1 deletion test/TastyKVOTest/TastyKVOTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
6EECC57814E15698003A5349 /* NSObject+TastyKVO.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFB288E14DD2A440024E766 /* NSObject+TastyKVO.m */; settings = {COMPILER_FLAGS = "-DTASTYKVO_ENABLE_AUTOREMOVE -DTASTYKVO_ENABLE_AUTOUNREGISTER"; }; };
6E5FCA9514F7F971006E3150 /* TastyKVOExtensionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFB289D14DD59DB0024E766 /* TastyKVOExtensionTests.m */; };
6E5FCA9814F7F974006E3150 /* TastyKVODeallocationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFB28A414DD5AB10024E766 /* TastyKVODeallocationTests.m */; };
6EECC57814E15698003A5349 /* NSObject+TastyKVO.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFB288E14DD2A440024E766 /* NSObject+TastyKVO.m */; settings = {COMPILER_FLAGS = "-DTASTYKVO_ENABLE_AUTOREMOVE -DTASTYKVO_ENABLE_AUTOUNREGISTER -DTASTYKVO_USE_SWIZZLING"; }; };
6EECC57B14E15698003A5349 /* Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFB28A714DD5AED0024E766 /* Helpers.m */; };
6EECC57C14E15698003A5349 /* TastyKVOAutoRemovalTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EECC57314E1538E003A5349 /* TastyKVOAutoRemovalTests.m */; };
6EECC57E14E15698003A5349 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EFB287114DD29E00024E766 /* Cocoa.framework */; };
Expand Down Expand Up @@ -248,6 +250,8 @@
6EECC57814E15698003A5349 /* NSObject+TastyKVO.m in Sources */,
6EECC57B14E15698003A5349 /* Helpers.m in Sources */,
6EECC57C14E15698003A5349 /* TastyKVOAutoRemovalTests.m in Sources */,
6E5FCA9514F7F971006E3150 /* TastyKVOExtensionTests.m in Sources */,
6E5FCA9814F7F974006E3150 /* TastyKVODeallocationTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -328,12 +332,14 @@
6EFB286714DD29C50024E766 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_ENABLE_OBJC_GC = unsupported;
};
name = Debug;
};
6EFB286814DD29C50024E766 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_ENABLE_OBJC_GC = unsupported;
};
name = Release;
};
Expand Down
22 changes: 16 additions & 6 deletions test/TastyKVOTest/TastyKVOTests/TastyKVOAutoRemovalTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
static int targetDeallocFlag;
static int observerDeallocFlag;

@implementation TargetObject(AugmentedDealloc)
@interface CustomTargetObject: TargetObject
@end
@implementation CustomTargetObject
- (void)dealloc
{
++targetDeallocFlag;
[_message release];
[super dealloc];
}
@end

@implementation ObserverObject(AugmentedDealloc)
@interface CustomObserverObject: ObserverObject
@end
@implementation CustomObserverObject
- (void)dealloc
{
++observerDeallocFlag;
Expand Down Expand Up @@ -69,7 +72,9 @@ - (void)testOneTarget
STAssertNil(objc_getAssociatedObject(observer, kAssociatedTargetKey), @"The observer was not automatically removed");
STAssertNil(objc_getAssociatedObject(secondObserver, kAssociatedTargetKey), @"The secondObserver was not automatically removed");

[observer stopObservingAllTargets]; // mustn't crash
[observer release];
[secondObserver stopObservingAllTargets]; // mustn't crash
[secondObserver release];
}

Expand All @@ -92,18 +97,21 @@ - (void)testOneObserver
[target1 release];
[target2 release];

STAssertNil(objc_getAssociatedObject(observer, kAssociatedTargetKey), @"The observer was not automatically removed");
STAssertNil(objc_getAssociatedObject(observer, kAssociatedTargetKey), @"The observer was not automatically removed");
[observer stopObservingAllTargets]; // mustn't crash
[observer release];
}

- (void)testOwnDealloc
{
ObserverObject *observer = [[ObserverObject alloc] init];
TargetObject *target = [[TargetObject alloc] init];
TargetObject *target = [[CustomTargetObject alloc] init];
[target addTastyObserver:observer forKeyPath:@"intVar" withSelector:@selector(increment)];
[target release];
STAssertEquals(targetDeallocFlag, 1, @"Target's own dealloc was not called");
STAssertNil(objc_getAssociatedObject(observer, kAssociatedTargetKey), @"The observer was not automatically removed");
// Check that we don't crash
[observer stopObservingAllTargets];
[observer release];
}

Expand All @@ -113,12 +121,14 @@ - (void)testObserverEarlyRelease
TargetObject *target = [[TargetObject alloc] init];
[target addTastyObserver:observer forKeyPath:@"intVar" withSelector:@selector(increment)];
[observer release];
// Check that we don't crash
target.intVar = 10;
[target release];
}

- (void)testObserverAndTargetInOneObject
{
ObserverObject *obj = [[ObserverObject alloc] init];
ObserverObject *obj = [[CustomObserverObject alloc] init];
ObserverObject *observer = [[ObserverObject alloc] init];
TargetObject *target = [[TargetObject alloc] init];

Expand Down

0 comments on commit c522148

Please sign in to comment.