Files
cappuccino/Tests/Foundation/CPNotificationCenterTest.j
T
Alexander Ljungberg bb0972ba49 Fixed: notifications were sent to removed observers.
If one observer of a notification centre notification removed another observer, that other observer would still be notified even that it was no longer observing.

Now the code agrees with its comments.
2011-12-01 18:18:15 +00:00

33 lines
980 B
Plaintext

@import <Foundation/CPNotificationCenter.j>
@implementation CPNotificationCenterTest : OJTestCase
{
int notificationCount;
}
- (void)testRemoveObserversDuringNotification
{
var center = [CPNotificationCenter defaultCenter],
TestNotification = @"TestNotification";
notificationCount = 0;
[center addObserver:self selector:@selector(receiveNotification:) name:TestNotification object:nil];
[center addObserver:self selector:@selector(receiveNotification:) name:TestNotification object:nil];
[center addObserver:self selector:@selector(receiveNotification:) name:TestNotification object:nil];
[center postNotificationName:TestNotification object:self];
[self assert:1 equals:notificationCount message:@"receiveFirstNotification s.b. called once"];
}
- (void)receiveNotification:(CPNotification)aNotification
{
notificationCount += 1;
var center = [CPNotificationCenter defaultCenter];
[center removeObserver:self];
}
@end