1/* Test/example program for the base library
2
3   Copyright (C) 2005 Free Software Foundation, Inc.
4
5  Copying and distribution of this file, with or without modification,
6  are permitted in any medium without royalty provided the copyright
7  notice and this notice are preserved.
8
9   This file is part of the GNUstep Base Library.
10*/
11
12#include	<Foundation/Foundation.h>
13
14id	myServer;
15
16@interface	Tester : NSObject
17{
18}
19+ (void) connectWithPorts: (NSArray*)portArray;
20+ (void) setServer: (id)anObject;
21+ (void) startup;
22- (int) doIt;
23- (void) testPerform: (id)anObject;
24@end
25
26@implementation	Tester
27+ (void) connectWithPorts: (NSArray*)portArray
28{
29  NSAutoreleasePool	*pool;
30  NSConnection		*serverConnection;
31  Tester		*serverObject;
32
33  pool = [[NSAutoreleasePool alloc] init];
34
35  serverConnection = [NSConnection
36	  connectionWithReceivePort: [portArray objectAtIndex: 0]
37			   sendPort: [portArray objectAtIndex: 1]];
38
39  serverObject = [[self alloc] init];
40  [serverObject performSelectorOnMainThread: @selector(testPerform:)
41				 withObject: @"84"
42			      waitUntilDone: NO];
43
44  [(id)[serverConnection rootProxy] setServer: serverObject];
45  [serverObject release];
46
47  [[NSRunLoop currentRunLoop] run];
48  [pool release];
49  [NSThread exit];
50
51  return;
52}
53
54+ (void) setServer: (id)anObject
55{
56  myServer = [anObject retain];
57  NSLog(@"Got %d", [myServer doIt]);
58  exit(0);
59}
60
61+ (void) startup
62{
63  NSPort	*port1;
64  NSPort	*port2;
65  NSArray	*portArray;
66  NSConnection	*conn;
67
68  port1 = [NSPort port];
69  port2 = [NSPort port];
70
71  conn = [[NSConnection alloc] initWithReceivePort: port1 sendPort: port2];
72  [conn setRootObject: self];
73
74  /* Ports switched here. */
75  portArray = [NSArray arrayWithObjects: port2, port1, nil];
76
77  [NSThread detachNewThreadSelector: @selector(connectWithPorts:)
78			   toTarget: self
79			 withObject: portArray];
80
81  return;
82}
83
84- (int) doIt
85{
86  return 42;
87}
88
89- (void) testPerform: (id)anObject
90{
91  NSLog(@"Test perform: %@", anObject);
92}
93
94@end
95
96int
97main(int argc, char *argv[], char **env)
98{
99  NSAutoreleasePool	*pool;
100
101#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
102   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
103#endif
104  pool = [[NSAutoreleasePool alloc] init];
105
106  [NSConnection setDebug: YES];
107  [Tester startup];
108  [[NSRunLoop currentRunLoop] run];
109  [pool release];
110  return 0;
111}
112