1
1
/* The simplest of tests for the NSNotification and NSNotificationCenter
2
classes. These tests should be expanded.
2
classes. These tests should be expanded.
4
(The Tcp*Port classes, however, do test the notification mechanism
4
(The Tcp*Port classes, however, do test the notification mechanism
7
7
#include <Foundation/Foundation.h>
31
id o1 = [NSObject new];
32
id observer1 = [Observer new];
35
35
arp = [NSAutoreleasePool new];
37
[[NSNotificationCenter defaultCenter]
38
addObserver: observer1
39
selector: @selector(gotNotificationFoo:)
43
[[NSNotificationCenter defaultCenter]
44
addObserver: observer1
45
selector: @selector(gotNotificationFooNoObject:)
50
/* This will cause two messages to be printed, one for each request above. */
51
[[NSNotificationCenter defaultCenter]
52
postNotificationName: foo
55
/* This will cause one message to be printed. */
56
[[NSNotificationCenter defaultCenter]
57
postNotificationName: foo
36
NSLog(@"Make string object");
38
NSLog(@"Make Observer object");
39
observer1 = [Observer new];
41
NSLog(@"Add observer to process centre");
43
[[NSNotificationCenter defaultCenter]
44
addObserver: observer1
45
selector: @selector(gotNotificationFoo:)
49
NSLog(@"Add observer to distributed centre");
50
[[NSDistributedNotificationCenter defaultCenter]
51
addObserver: observer1
52
selector: @selector(gotNotificationFoo:)
56
NSLog(@"Add observer to process centre");
57
[[NSNotificationCenter defaultCenter]
58
addObserver: observer1
59
selector: @selector(gotNotificationFooNoObject:)
63
NSLog(@"Add observer to distributed centre");
64
[[NSDistributedNotificationCenter defaultCenter]
65
addObserver: observer1
66
selector: @selector(gotNotificationFooNoObject:)
71
NSLog(@"Post to process centre");
72
/* This will cause two messages to be printed, one for each request above. */
73
[[NSNotificationCenter defaultCenter]
74
postNotificationName: foo
77
NSLog(@"Post to distributed centre");
78
/* This will cause two messages to be printed, one for each request above. */
79
[[NSDistributedNotificationCenter defaultCenter]
80
postNotificationName: foo
83
NSLog(@"Post to process centre");
84
/* This will cause one message to be printed. */
85
[[NSNotificationCenter defaultCenter]
86
postNotificationName: foo
89
NSLog(@"Post to distributed centre");
90
/* This will cause one message to be printed. */
91
[[NSDistributedNotificationCenter defaultCenter]
92
postNotificationName: foo
96
NSLog(@"Remove observer from process centre");
61
97
[[NSNotificationCenter defaultCenter]
62
98
removeObserver: observer1