mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Get test/examples working again
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28361 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c02ac14584
commit
745ca3f62b
6 changed files with 231 additions and 12 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#define STRICT_OPENSTEP 1
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
id myServer;
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include <stdio.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
#include <Foundation/NSPort.h>
|
||||
#include <Foundation/NSPortNameServer.h>
|
||||
#include <Foundation/NSDistantObject.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
@ -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");
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*/
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
#include <Foundation/NSPort.h>
|
||||
#include <Foundation/NSPortNameServer.h>
|
||||
#include <Foundation/NSDistantObject.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
|
@ -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
|
||||
|
|
126
Examples/server.h
Normal file
126
Examples/server.h
Normal file
|
@ -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 <Foundation/NSConnection.h>
|
||||
|
||||
@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<ClientProtocol>)client;
|
||||
- (oneway void) unregisterClient: (id<ClientProtocol>)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 <ServerProtocol,privateServer>
|
||||
{
|
||||
id the_array;
|
||||
id<ClientProtocol> registered_client;
|
||||
}
|
||||
@end
|
||||
#else
|
||||
@interface Server : NSObject <ServerProtocol>
|
||||
{
|
||||
id the_array;
|
||||
id<ClientProtocol> registered_client;
|
||||
}
|
||||
@end
|
||||
#endif
|
||||
|
||||
#endif /* _server_h */
|
74
Examples/wgetopt.h
Normal file
74
Examples/wgetopt.h
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue