mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-07 19:27:12 +00:00
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.
33 lines
980 B
Plaintext
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
|