mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 18:21:04 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32187 72102866-910b-0410-8b05-ffd578937521
56 lines
1.3 KiB
Objective-C
56 lines
1.3 KiB
Objective-C
#import <Foundation/Foundation.h>
|
|
#import "ObjectTesting.h"
|
|
|
|
@interface MyClass : NSObject
|
|
+ (unsigned) finalisationCounter;
|
|
+ (unsigned) notificationCounter;
|
|
- (void) notified: (NSNotification*)n;
|
|
@end
|
|
|
|
@implementation MyClass
|
|
static unsigned notificationCounter = 0;
|
|
static unsigned finalisationCounter = 0;
|
|
+ (unsigned) finalisationCounter
|
|
{
|
|
return finalisationCounter;
|
|
}
|
|
+ (unsigned) notificationCounter
|
|
{
|
|
return notificationCounter;
|
|
}
|
|
- (void) finalize
|
|
{
|
|
finalisationCounter++;
|
|
}
|
|
- (void) notified: (NSNotification*)n
|
|
{
|
|
notificationCounter++;
|
|
}
|
|
@end
|
|
|
|
int
|
|
main()
|
|
{
|
|
NSGarbageCollector *collector = [NSGarbageCollector defaultCollector];
|
|
NSNotificationCenter *center;
|
|
MyClass *object;
|
|
|
|
if (collector == nil) return 0; // No garbage collection.
|
|
|
|
center = [NSNotificationCenter defaultCenter];
|
|
object = [MyClass new];
|
|
[center addObserver: object
|
|
selector: @selector(notified:)
|
|
name: @"Notification"
|
|
object: nil];
|
|
|
|
[center postNotificationName: @"Notification" object: nil];
|
|
PASS([MyClass notificationCounter] == 1, "simple notification works");
|
|
object = nil;
|
|
[collector collectExhaustively];
|
|
PASS([MyClass finalisationCounter] == 1, "finalisation done");
|
|
[center postNotificationName: @"Notification" object: nil];
|
|
PASS([MyClass notificationCounter] == 1, "automatic removal works");
|
|
|
|
return 0;
|
|
}
|