~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Testing/nsnotification.m

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
3
3
 
4
 
   (The Tcp*Port classes, however, do test the notification mechanism 
 
4
   (The Tcp*Port classes, however, do test the notification mechanism
5
5
    further.) */
6
6
 
7
7
#include <Foundation/Foundation.h>
28
28
 
29
29
int main ()
30
30
{
31
 
  id o1 = [NSObject new];
32
 
  id observer1 = [Observer new];
 
31
  id o1;
 
32
  id observer1;
33
33
  id arp;
34
34
 
35
35
  arp = [NSAutoreleasePool new];
36
 
 
37
 
  [[NSNotificationCenter defaultCenter]
38
 
    addObserver: observer1
39
 
    selector: @selector(gotNotificationFoo:)
40
 
    name: foo
41
 
    object: o1];
42
 
 
43
 
  [[NSNotificationCenter defaultCenter]
44
 
    addObserver: observer1
45
 
    selector: @selector(gotNotificationFooNoObject:)
46
 
    name: foo
47
 
    object: nil];
48
 
 
49
 
 
50
 
  /* This will cause two messages to be printed, one for each request above. */
51
 
  [[NSNotificationCenter defaultCenter]
52
 
    postNotificationName: foo
53
 
    object: o1];
54
 
 
55
 
  /* This will cause one message to be printed. */
56
 
  [[NSNotificationCenter defaultCenter]
57
 
    postNotificationName: foo
58
 
    object: nil];
59
 
 
60
 
  
 
36
NSLog(@"Make string object");
 
37
  o1 = [NSString new];
 
38
NSLog(@"Make Observer object");
 
39
  observer1 = [Observer new];
 
40
 
 
41
NSLog(@"Add observer to process centre");
 
42
 
 
43
  [[NSNotificationCenter defaultCenter]
 
44
    addObserver: observer1
 
45
    selector: @selector(gotNotificationFoo:)
 
46
    name: foo
 
47
    object: o1];
 
48
 
 
49
NSLog(@"Add observer to distributed centre");
 
50
  [[NSDistributedNotificationCenter defaultCenter]
 
51
    addObserver: observer1
 
52
    selector: @selector(gotNotificationFoo:)
 
53
    name: foo
 
54
    object: o1];
 
55
 
 
56
NSLog(@"Add observer to process centre");
 
57
  [[NSNotificationCenter defaultCenter]
 
58
    addObserver: observer1
 
59
    selector: @selector(gotNotificationFooNoObject:)
 
60
    name: foo
 
61
    object: nil];
 
62
 
 
63
NSLog(@"Add observer to distributed centre");
 
64
  [[NSDistributedNotificationCenter defaultCenter]
 
65
    addObserver: observer1
 
66
    selector: @selector(gotNotificationFooNoObject:)
 
67
    name: foo
 
68
    object: nil];
 
69
 
 
70
 
 
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
 
75
    object: o1];
 
76
 
 
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
 
81
    object: o1];
 
82
 
 
83
NSLog(@"Post to process centre");
 
84
  /* This will cause one message to be printed. */
 
85
  [[NSNotificationCenter defaultCenter]
 
86
    postNotificationName: foo
 
87
    object: nil];
 
88
 
 
89
NSLog(@"Post to distributed centre");
 
90
  /* This will cause one message to be printed. */
 
91
  [[NSDistributedNotificationCenter defaultCenter]
 
92
    postNotificationName: foo
 
93
    object: nil];
 
94
 
 
95
 
 
96
NSLog(@"Remove observer from process centre");
61
97
  [[NSNotificationCenter defaultCenter]
62
98
    removeObserver: observer1
63
99
    name: nil