<commit_before>@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
<commit_msg>More extensive Notification Center tests.<commit_after>@import <Foundation/CPNotificationCenter.j>

var TestNotification = @"TestNotification";

@implementation CPNotificationCenterTest : OJTestCase
{
    int notificationCount;
}

/*!
    Test various filter parameters.
*/
- (void)testNotify
{
    var center = [CPNotificationCenter defaultCenter];

    notificationCount = 0;

    [center addObserver:self selector:@selector(countNotification:) name:TestNotification object:2];
    [center addObserver:self selector:@selector(countNotification:) name:TestNotification object:25];
    [center postNotificationName:TestNotification object:self];
    [self assert:0 equals:notificationCount message:@"observer should only be notified for object '2'"];

    [center postNotificationName:TestNotification object:2];
    [self assert:1 equals:notificationCount message:@"observer should be notified for object '2'"];

    [center addObserver:self selector:@selector(countNotification:) name:TestNotification object:nil];
    [center postNotificationName:TestNotification object:2];
    [self assert:3 equals:notificationCount message:@"observer should be notified for object '2' and for any object"];

    [center removeObserver:self name:TestNotification object:2];
    [center postNotificationName:TestNotification object:2];
    [self assert:4 equals:notificationCount message:@"observer should be notified only for any object"];

    // At this point we have TestNofication:nil observer and a TestNotification:25 observer.
    [center addObserver:self selector:@selector(countNotification:) name:nil object:2];
    [center postNotificationName:TestNotification object:2];
    [self assert:6 equals:notificationCount message:@"observer should be notified for TestNofication and for object '2' (TestNotification)"];
    [center postNotificationName:@"RandomNotification" object:2];
    [self assert:7 equals:notificationCount message:@"observer should be notified for object '2' (RandomNotification)"];

    [center removeObserver:self name:TestNotification object:nil];
    [center postNotificationName:TestNotification object:nil];
    [center postNotificationName:TestNotification object:2];
    [center postNotificationName:TestNotification object:25];
    [self assert:8 equals:notificationCount message:@"observer should be notified only for object '2'"];

    [center removeObserver:self];
    [center postNotificationName:TestNotification object:nil];
    [center postNotificationName:TestNotification object:2];
    [center postNotificationName:TestNotification object:25];
    [self assert:8 equals:notificationCount message:@"observer should not be notified"];
}

- (void)testAddObserversDuringNotification
{
    var center = [CPNotificationCenter defaultCenter];

    notificationCount = 0;

    [center addObserver:self selector:@selector(addObserversNotification:) name:TestNotification object:nil];

    [center postNotificationName:TestNotification object:self];

    [self assert:1 equals:notificationCount message:@"the new observers in addObserversNotification: should not be notified"];

    [center postNotificationName:TestNotification object:self];

    [self assert:5 equals:notificationCount message:@"the new observers from the first addObserversNotification should now be active"];
}

- (void)testRemoveObserversDuringNotification
{
    var center = [CPNotificationCenter defaultCenter];

    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];
}

- (void)addObserversNotification:(CPNotification)aNotification
{
    notificationCount += 1;

    var center = [CPNotificationCenter defaultCenter];
    // These should not be notified.
    [center addObserver:self selector:@selector(countNotification:) name:TestNotification object:nil];
    [center addObserver:self selector:@selector(countNotification:) name:TestNotification object:nil];
    [center addObserver:self selector:@selector(countNotification:) name:TestNotification object:nil];
}

- (void)countNotification:(CPNotification)aNotification
{
    notificationCount += 1;
}

@end

{'fraction_non_alphanumeric': 0.09517966695880806, 'fraction_numerical': 0.007712532865907099, 'mean_word_length': 6.597869507323568, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2355978', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1360, 'n_words': 359}