From 745ca3f62b34c8110dce823330ba4d9a170b1253 Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 19 Jun 2009 15:51:11 +0000 Subject: [PATCH] Get test/examples working again git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28361 72102866-910b-0410-8b05-ffd578937521 --- Examples/GNUmakefile | 9 ++- Examples/nsconnection.m | 2 +- Examples/nsconnection_client.m | 17 +++-- Examples/nsconnection_server.m | 15 ++-- Examples/server.h | 126 +++++++++++++++++++++++++++++++++ Examples/wgetopt.h | 74 +++++++++++++++++++ 6 files changed, 231 insertions(+), 12 deletions(-) create mode 100644 Examples/server.h create mode 100644 Examples/wgetopt.h diff --git a/Examples/GNUmakefile b/Examples/GNUmakefile index a6adaf370..510492988 100644 --- a/Examples/GNUmakefile +++ b/Examples/GNUmakefile @@ -47,10 +47,17 @@ include $(GNUSTEP_MAKEFILES)/common.make # The tools to be created TEST_TOOL_NAME = \ - dictionary + dictionary \ + nsconnection \ + nsconnection_client \ + nsconnection_server \ + # The Objective-C source files to be compiled to create each tool dictionary_OBJC_FILES = dictionary.m +nsconnection_OBJC_FILES = nsconnection.m +nsconnection_client_OBJC_FILES = nsconnection_client.m +nsconnection_server_OBJC_FILES = nsconnection_server.m include Makefile.preamble diff --git a/Examples/nsconnection.m b/Examples/nsconnection.m index 591a6afde..96016fbc9 100644 --- a/Examples/nsconnection.m +++ b/Examples/nsconnection.m @@ -8,7 +8,7 @@ This file is part of the GNUstep Base Library. */ -#define STRICT_OPENSTEP 1 + #include id myServer; diff --git a/Examples/nsconnection_client.m b/Examples/nsconnection_client.m index 110e3f850..b8554e71a 100644 --- a/Examples/nsconnection_client.m +++ b/Examples/nsconnection_client.m @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include @@ -91,8 +93,6 @@ int con_data (id prx) id obj; small_struct small = {12}; foo ffoo = {'Z', 1234.5678, 99, "cow", 9876543}; - int a3[3] = {66,77,88}; - struct myarray ma = {{55,66,77}}; printf("Testing data sending\n"); @@ -502,6 +502,7 @@ int main (int argc, char *argv[], char **env) id cobj, prx; unsigned connect_attempts; NSAutoreleasePool *arp; + NSPortNameServer *ns; Auth *auth; #ifndef __MINGW32__ extern int optind; @@ -517,7 +518,7 @@ int main (int argc, char *argv[], char **env) debug = 0; type_test = 0; stats = 0; - while ((c = getopt(argc, argv, "hdtbmslocr")) != EOF) + while ((c = wgetopt(argc, argv, "hdtbmslocr")) != EOF) switch (c) { case 'd': @@ -573,6 +574,7 @@ int main (int argc, char *argv[], char **env) [NSObject enableDoubleReleaseCheck: YES]; } + ns = [NSSocketPortNameServer sharedInstance]; while (connect_attempts-- > 0) { if (optind < argc) @@ -580,15 +582,18 @@ int main (int argc, char *argv[], char **env) if (optind+1 < argc) prx = [NSConnection rootProxyForConnectionWithRegisteredName: [NSString stringWithCString: argv[optind+1]] - host: [NSString stringWithCString:argv[optind]]]; + host: [NSString stringWithCString:argv[optind]] + usingNameServer: ns]; else prx = [NSConnection rootProxyForConnectionWithRegisteredName: @"test2server" - host:[NSString stringWithCString:argv[optind]]]; + host:[NSString stringWithCString:argv[optind]] + usingNameServer: ns]; } else prx = [NSConnection rootProxyForConnectionWithRegisteredName: - @"test2server" host: @""]; + @"test2server" host: @"" + usingNameServer: ns]; if (prx == nil) { printf("ERROR: Failed to connect to server\n"); diff --git a/Examples/nsconnection_server.m b/Examples/nsconnection_server.m index e4e04f778..8d95fa194 100644 --- a/Examples/nsconnection_server.m +++ b/Examples/nsconnection_server.m @@ -10,6 +10,8 @@ */ #include #include +#include +#include #include #include #include @@ -475,6 +477,8 @@ int main(int argc, char *argv[], char **env) id l; id o = [[NSObject alloc] init]; NSConnection *c; + NSPortNameServer *ns; + NSPort *port; NSAutoreleasePool *arp = [NSAutoreleasePool new]; #ifndef __MINGW32__ extern int optind; @@ -487,7 +491,7 @@ int main(int argc, char *argv[], char **env) [NSProcessInfo initializeWithArguments: argv count: argc environment: env]; debug = 0; timeout = 0; - while ((i = getopt(argc, argv, "hdt:")) != EOF) + while ((i = wgetopt(argc, argv, "hdt:")) != EOF) switch (i) { case 'd': @@ -518,13 +522,16 @@ int main(int argc, char *argv[], char **env) [NSConnection setDebug: debug]; [NSObject enableDoubleReleaseCheck: YES]; } - c = [NSConnection defaultConnection]; + ns = [NSSocketPortNameServer sharedInstance]; + port = [NSSocketPort port]; + c = [NSConnection connectionWithReceivePort: port sendPort: port]; [c setRootObject: l]; if (optind < argc) - [c registerName: [NSString stringWithUTF8String: argv[optind]]]; + [c registerName: [NSString stringWithUTF8String: argv[optind]] + withNameServer: ns]; else - [c registerName: @"test2server"]; + [c registerName: @"test2server" withNameServer: ns]; [[NSNotificationCenter defaultCenter] addObserver: s diff --git a/Examples/server.h b/Examples/server.h new file mode 100644 index 000000000..90b832402 --- /dev/null +++ b/Examples/server.h @@ -0,0 +1,126 @@ +/* Test/example program for the base library + + Copyright (C) 2005 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. + + This file is part of the GNUstep Base Library. +*/ +#ifndef _server_h +#define _server_h + +#include + +@interface NSConnection (Debug) ++ (void) setDebug: (BOOL)aFlag; +@end +@interface NSDistantObject (Debug) ++ (void) setDebug: (BOOL)aFlag; +@end + +typedef struct _small_struct { + unsigned char z; +} small_struct; + +typedef struct _foo { + char c; + double d; + int i; + char *s; + unsigned long l; +} foo; + +struct myarray { + int a[3]; +}; + +#define ADD_CONST 47 + +@protocol ClientProtocol +- (BOOL) callback; +@end + +@protocol ServerProtocol +- (void) addObject: (id)o; +- (BOOL) sendBoolean: (BOOL)b; +- (void) getBoolean: (BOOL*)bp; +- (unsigned char) sendUChar: (unsigned char)uc; +- (void) getUChar: (unsigned char *)ucp; +- (char) sendChar: (char)uc; +- (void) getChar: (char *)ucp; +- (short) sendShort: (short)num; +- (void) getShort: (short *)num; +- (int) sendInt: (int)num; +- (void) getInt: (int *)num; +- (long) sendLong: (long)num; +- (void) getLong: (long *)num; +- (float) sendFloat: (float)num; +- (void) getFloat: (float *)num; +- (double) sendDouble: (double)num; +- (void) getDouble: (double *)num; +- sendDouble: (double)dbl andFloat: (float)flt; + +- (small_struct) sendSmallStruct: (small_struct)str; +- (void) getSmallStruct: (small_struct *)str; +- (foo) sendStruct: (foo)str; +- (void) getStruct: (foo *)str; +- (id) sendObject: (id)str; +- (void) getObject: (id *)str; +- (char *) sendString: (char *)str; +- (void) getString: (char **)str; + +- print: (const char *)str; + +- objectAt: (unsigned)i; +- (unsigned) count; +- echoObject: obj; + +- (oneway void) shout; +- bounce: sender count: (int)c; +- (oneway void) outputStats:obj; + +- sendArray: (int[3])a; +- sendStructArray: (struct myarray)ma; + +- sendBycopy: (bycopy id)o; +#ifdef _F_BYREF +- sendByref: (byref id)o; +- modifyByref: (byref NSMutableString *)o; +#endif +- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6 +: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12; +- (int) exceptionTest1; +- (void) exceptionTest2; +- (oneway void) exceptionTest3; + +- (oneway void) registerClient: (id)client; +- (oneway void) unregisterClient: (id)client; +- (BOOL) tryClientCallback; +@end + +#ifdef IN_SERVER +/* + * We don't want the client to know about some methods, so we can + * check that they work when it doesn't know them. + */ +@protocol privateServer +- quietBycopy: (bycopy id)o; +@end +@interface Server : NSObject +{ + id the_array; + id registered_client; +} +@end +#else +@interface Server : NSObject +{ + id the_array; + id registered_client; +} +@end +#endif + +#endif /* _server_h */ diff --git a/Examples/wgetopt.h b/Examples/wgetopt.h new file mode 100644 index 000000000..792e6c446 --- /dev/null +++ b/Examples/wgetopt.h @@ -0,0 +1,74 @@ +/* Test/example program for the base library + + Copyright (C) 2005 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. + + This file is part of the GNUstep Base Library. +*/ + +/* A simple implementation of getopt() */ +static int +indexof(char c, char *string) +{ + int i; + + for (i = 0; i < strlen(string); i++) + { + if (string[i] == c) + { + return i; + } + } + return -1; +} + +static char *optarg; +static int optind; +static char +wgetopt(int argc, char **argv, char *options) +{ + static char *arg; + int index; + char retval = '\0'; + + optarg = NULL; + if (optind == 0) + { + optind = 1; + } + while (optind < argc) + { + arg = argv[optind]; + if (strlen(arg) == 2) + { + if (arg[0] == '-') + { + if ((index = indexof(arg[1], options)) != -1) + { + retval = arg[1]; + if (index < strlen(options)) + { + if (options[index+1] == ':') + { + if (optind < argc-1) + { + optind++; + optarg = argv[optind]; + } + else + { + return -1; /* ':' given, but argv exhausted */ + } + } + } + } + } + } + optind++; + return retval; + } + return -1; +}