2005-07-01 21:00:04 +00:00
|
|
|
/* Test/example program for the base library
|
|
|
|
|
|
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
|
|
|
|
2005-07-15 22:51:23 +00:00
|
|
|
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.
|
|
|
|
|
2005-07-01 21:00:04 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
*/
|
2000-08-07 22:00:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <Foundation/NSObject.h>
|
|
|
|
#include <Foundation/NSConnection.h>
|
2009-06-19 15:51:11 +00:00
|
|
|
#include <Foundation/NSPort.h>
|
|
|
|
#include <Foundation/NSPortNameServer.h>
|
2000-08-07 22:00:31 +00:00
|
|
|
#include <Foundation/NSDistantObject.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSRunLoop.h>
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
#include <Foundation/NSDate.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
2001-09-20 10:22:09 +00:00
|
|
|
#include <Foundation/NSException.h>
|
2002-03-20 22:37:22 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
2000-08-07 22:00:31 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include "server.h"
|
|
|
|
|
2000-09-22 04:20:52 +00:00
|
|
|
#include "wgetopt.h"
|
|
|
|
|
2003-07-04 09:33:53 +00:00
|
|
|
/*
|
|
|
|
* Dummy declaration with different bycopy/byref info from the one
|
|
|
|
* in the server ... we expect the info from the server to be used.
|
|
|
|
*/
|
|
|
|
@interface Dummy : NSObject
|
2005-11-21 13:15:39 +00:00
|
|
|
- (id) quietBycopy: (byref id)a;
|
2003-07-04 09:33:53 +00:00
|
|
|
@end
|
|
|
|
|
2003-10-21 14:28:34 +00:00
|
|
|
@interface CallbackClient : NSObject <ClientProtocol>
|
|
|
|
- (BOOL) callback;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CallbackClient
|
|
|
|
- (BOOL) callback
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
@interface Auth : NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Auth
|
|
|
|
- (BOOL) authenticateComponents: (NSMutableArray*)components
|
|
|
|
withData: (NSData*)authData
|
|
|
|
{
|
|
|
|
unsigned count = [components count];
|
|
|
|
|
|
|
|
while (count-- > 0)
|
|
|
|
{
|
|
|
|
id obj = [components objectAtIndex: count];
|
|
|
|
|
|
|
|
if ([obj isKindOfClass: [NSData class]] == YES)
|
|
|
|
{
|
|
|
|
NSMutableData *d = [obj mutableCopy];
|
|
|
|
unsigned l = [d length];
|
|
|
|
char *p = (char*)[d mutableBytes];
|
|
|
|
|
|
|
|
while (l-- > 0)
|
|
|
|
p[l] ^= 42;
|
|
|
|
[components replaceObjectAtIndex: count withObject: d];
|
|
|
|
RELEASE(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int con_data (id prx)
|
|
|
|
{
|
2003-04-10 16:28:07 +00:00
|
|
|
id pool;
|
2000-08-07 22:00:31 +00:00
|
|
|
BOOL b, br;
|
|
|
|
unsigned char uc, ucr;
|
|
|
|
char c, cr;
|
|
|
|
short s, sr;
|
|
|
|
int i, ir;
|
|
|
|
long l, lr;
|
|
|
|
float flt, fltr;
|
|
|
|
double dbl, dblr;
|
|
|
|
char *str;
|
|
|
|
id obj;
|
2009-10-04 19:16:32 +00:00
|
|
|
small_struct ss = {12};
|
2003-04-10 16:28:07 +00:00
|
|
|
foo ffoo = {'Z', 1234.5678, 99, "cow", 9876543};
|
2009-10-04 09:53:19 +00:00
|
|
|
foo bck;
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
printf("Testing data sending\n");
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("Boolean:\n");
|
|
|
|
b = YES;
|
|
|
|
printf(" sending %d", b);
|
|
|
|
br = [prx sendBoolean: b];
|
|
|
|
printf(" got %d", br);
|
|
|
|
if (b == !br)
|
|
|
|
printf(" ...ok\n");
|
|
|
|
else
|
|
|
|
printf(" *** ERROR ***\n");
|
|
|
|
br = b = YES;
|
|
|
|
printf(" sending ptr to %d", br);
|
|
|
|
[prx getBoolean: &br];
|
|
|
|
printf(" got %d", br);
|
|
|
|
if (b == !br)
|
|
|
|
printf(" ...ok\n");
|
|
|
|
else
|
|
|
|
printf(" *** ERROR ***\n");
|
2000-12-22 21:46:47 +00:00
|
|
|
printf(" error is ok (due to incorrect encoding by gcc)\n");
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
#define TEST_CALL(test, send, got, sendp, var, varr, val, msg1, msg2) \
|
2003-04-10 16:28:07 +00:00
|
|
|
pool = [NSAutoreleasePool new]; \
|
2000-08-07 22:00:31 +00:00
|
|
|
printf(test); \
|
|
|
|
var = val; \
|
|
|
|
printf(send, var); \
|
|
|
|
varr = [prx msg1 var]; \
|
|
|
|
printf(got, varr); \
|
2000-12-08 19:06:00 +00:00
|
|
|
if (varr != (var+ADD_CONST)) \
|
2000-08-07 22:00:31 +00:00
|
|
|
printf(" *** ERROR ***\n"); \
|
|
|
|
else \
|
|
|
|
printf(" ...ok\n"); \
|
|
|
|
varr = var = val+1; \
|
|
|
|
printf(sendp, varr); \
|
|
|
|
[prx msg2 &varr]; \
|
|
|
|
printf(got, varr); \
|
2000-12-08 19:06:00 +00:00
|
|
|
if (varr != (var+ADD_CONST)) \
|
2000-08-07 22:00:31 +00:00
|
|
|
printf(" *** ERROR ***\n"); \
|
|
|
|
else \
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" ...ok\n"); \
|
|
|
|
[pool release];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
#define TEST_FCALL(test, send, got, sendp, var, varr, val, msg1, msg2) \
|
2003-04-10 16:28:07 +00:00
|
|
|
pool = [NSAutoreleasePool new]; \
|
2000-12-08 19:06:00 +00:00
|
|
|
printf(test); \
|
|
|
|
var = val; \
|
|
|
|
printf(send, var); \
|
|
|
|
varr = [prx msg1 var]; \
|
|
|
|
printf(got, varr); \
|
|
|
|
if (varr - (var+ADD_CONST) > 1e-3) \
|
|
|
|
printf(" *** ERROR ***\n"); \
|
|
|
|
else \
|
|
|
|
printf(" ...ok\n"); \
|
|
|
|
varr = var = val+1; \
|
|
|
|
printf(sendp, varr); \
|
|
|
|
[prx msg2 &varr]; \
|
|
|
|
printf(got, varr); \
|
|
|
|
if (varr - (var+ADD_CONST) > 1e-3) \
|
|
|
|
printf(" *** ERROR ***\n"); \
|
|
|
|
else \
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" ...ok\n"); \
|
|
|
|
[pool release];
|
2000-12-08 19:06:00 +00:00
|
|
|
|
|
|
|
TEST_CALL("UChar:\n", " sending %d", " got %d", " sending ptr to %d",
|
2000-08-07 22:00:31 +00:00
|
|
|
uc, ucr, 23, sendUChar:, getUChar:)
|
2000-12-22 21:46:47 +00:00
|
|
|
printf(" error is ok (due to incorrect encoding by gcc)\n");
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
TEST_CALL("Char:\n", " sending %d", " got %d", " sending ptr to %d",
|
2000-08-07 22:00:31 +00:00
|
|
|
c, cr, 23, sendChar:, getChar:)
|
2000-12-22 21:46:47 +00:00
|
|
|
printf(" error is ok (due to incorrect encoding by gcc)\n");
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
TEST_CALL("Short:\n", " sending %hd", " got %hd", " sending ptr to %hd",
|
2000-08-07 22:00:31 +00:00
|
|
|
s, sr, 23, sendShort:, getShort:)
|
|
|
|
|
|
|
|
TEST_CALL("Int:\n", " sending %d", " got %d", " sending ptr to %d",
|
|
|
|
i, ir, 23, sendInt:, getInt:)
|
|
|
|
|
|
|
|
TEST_CALL("Long:\n", " sending %ld", " got %ld", " sending ptr to %ld",
|
|
|
|
l, lr, 23, sendLong:, getLong:)
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
TEST_FCALL("Float:\n", " sending %f", " got %f", " sending ptr to %f",
|
2000-08-07 22:00:31 +00:00
|
|
|
flt, fltr, 23.2, sendFloat:, getFloat:)
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
TEST_FCALL("Double:\n", " sending %g", " got %g", " sending ptr to %g",
|
2000-08-07 22:00:31 +00:00
|
|
|
dbl, dblr, 23.2, sendDouble:, getDouble:)
|
|
|
|
|
|
|
|
flt = 2.718;
|
|
|
|
dbl = 3.14159265358979323846264338327;
|
|
|
|
printf(" sending double %f, float %f\n", dbl, flt);
|
|
|
|
[prx sendDouble:dbl andFloat:flt];
|
|
|
|
|
|
|
|
|
2003-04-10 16:28:07 +00:00
|
|
|
pool = [NSAutoreleasePool new];
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("String:\n");
|
|
|
|
str = "My String 1";
|
|
|
|
printf(" sending (%s)", str);
|
|
|
|
str = [prx sendString: str];
|
|
|
|
printf(" got (%s)\n", str);
|
2003-04-10 16:28:07 +00:00
|
|
|
[pool release];
|
|
|
|
|
|
|
|
pool = [NSAutoreleasePool new];
|
2000-08-07 22:00:31 +00:00
|
|
|
str = "My String 3";
|
|
|
|
printf(" sending ptr to (%s)", str);
|
|
|
|
[prx getString: &str];
|
|
|
|
printf(" got (%s)\n", str);
|
2003-04-10 16:28:07 +00:00
|
|
|
[pool release];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2003-04-10 16:28:07 +00:00
|
|
|
pool = [NSAutoreleasePool new];
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("Small Struct:\n");
|
2009-10-04 19:16:32 +00:00
|
|
|
//printf(" sending %x", ss.z);
|
|
|
|
//ss = [prx sendSmallStruct: ss];
|
|
|
|
//printf(" got %x\n", ss.z);
|
|
|
|
printf(" sending ptr to %x", ss.z);
|
|
|
|
[prx getSmallStruct: &ss];
|
|
|
|
printf(" got %x\n", ss.z);
|
2003-04-10 16:28:07 +00:00
|
|
|
[pool release];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2010-03-19 12:10:11 +00:00
|
|
|
#if 1 || !defined(__MINGW__)
|
2003-04-10 16:28:07 +00:00
|
|
|
pool = [NSAutoreleasePool new];
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("Struct:\n");
|
2009-10-04 09:53:19 +00:00
|
|
|
memcpy(&bck, &ffoo, sizeof(bck));
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" sending c='%c',d=%g,i=%d,s=%s,l=%ld",
|
|
|
|
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
2000-08-07 22:00:31 +00:00
|
|
|
ffoo = [prx sendStruct: ffoo];
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" got c='%c',d=%g,i=%d,s=%s,l=%ld\n",
|
|
|
|
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
2009-10-04 09:53:19 +00:00
|
|
|
memcpy(&ffoo, &bck, sizeof(bck));
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" sending ptr to c='%c',d=%g,i=%d,s=%s,l=%ld",
|
|
|
|
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
2000-08-07 22:00:31 +00:00
|
|
|
[prx getStruct: &ffoo];
|
2003-04-10 16:28:07 +00:00
|
|
|
printf(" got c='%c',d=%g,i=%d,s=%s,l=%ld\n",
|
|
|
|
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
|
|
|
[pool release];
|
2005-11-11 10:07:03 +00:00
|
|
|
#endif
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2003-04-10 16:28:07 +00:00
|
|
|
pool = [NSAutoreleasePool new];
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("Object:\n");
|
|
|
|
obj = [NSObject new];
|
|
|
|
[prx addObject: obj]; // FIXME: Why is this needed?
|
|
|
|
printf(" sending %s", [[obj description] cString]);
|
|
|
|
obj = [prx sendObject: obj];
|
|
|
|
printf(" got %s\n", [[obj description] cString]);
|
|
|
|
printf(" sending ptr to %s", [[obj description] cString]);
|
|
|
|
[prx getObject: &obj];
|
|
|
|
printf(" got %s\n", [[obj description] cString]);
|
2003-04-10 16:28:07 +00:00
|
|
|
[pool release];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
printf("Many Arguments:\n");
|
|
|
|
[prx manyArgs:1 :2 :3 :4 :5 :6 :7 :8 :9 :10 :11 :12];
|
|
|
|
|
2002-04-24 03:12:55 +00:00
|
|
|
printf("Done\n");
|
2000-08-07 22:00:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
con_messages (id prx)
|
|
|
|
{
|
|
|
|
id obj;
|
2004-04-19 19:29:15 +00:00
|
|
|
Protocol *pc = @protocol(ClientProtocol);
|
|
|
|
Protocol *ps = @protocol(ServerProtocol);
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
obj = [NSObject new];
|
|
|
|
|
2004-04-19 19:29:15 +00:00
|
|
|
printf("Conforms to protocol (remote) should be 1: %d\n",
|
|
|
|
[prx conformsToProtocol: ps]);
|
|
|
|
printf("Conforms to protocol (remote) should be 0: %d\n",
|
|
|
|
[prx conformsToProtocol: pc]);
|
|
|
|
|
|
|
|
[prx setProtocolForProxy: ps];
|
|
|
|
|
|
|
|
printf("Conforms to protocol (local) should be 1: %d\n",
|
|
|
|
[prx conformsToProtocol: ps]);
|
|
|
|
printf("Conforms to protocol (local) should be 0: %d\n",
|
|
|
|
[prx conformsToProtocol: pc]);
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("Oneway Void message:\n");
|
|
|
|
[prx shout];
|
|
|
|
printf(" ok\n");
|
|
|
|
|
2001-09-20 10:22:09 +00:00
|
|
|
printf("Testing exception in method with return value:\n");
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
[prx exceptionTest1];
|
|
|
|
printf(" ERROR\n");
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
printf(" ok ... %s\n", [[localException description] cString]);
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
printf("Testing exception in method with void return:\n");
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
[prx exceptionTest2];
|
|
|
|
printf(" ERROR\n");
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
printf(" ok ... %s\n", [[localException description] cString]);
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
printf("Testing exception in oneway void method:\n");
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
[prx exceptionTest3];
|
|
|
|
printf(" ok\n");
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
printf(" ERROR ... %s\n", [[localException description] cString]);
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
/* this next line doesn't actually test callbacks, it tests
|
|
|
|
sending the same object twice in the same message. */
|
|
|
|
printf("Send same object twice in message\n");
|
|
|
|
[prx sendObject: prx];
|
|
|
|
printf(" ok\n");
|
|
|
|
|
|
|
|
printf("performSelector:\n");
|
2008-12-01 18:38:58 +00:00
|
|
|
if (prx != [prx performSelector: GSSelectorFromName("self")])
|
2000-08-07 22:00:31 +00:00
|
|
|
printf(" ERROR\n");
|
|
|
|
else
|
|
|
|
printf(" ok\n");
|
|
|
|
|
|
|
|
printf("Testing bycopy/byref:\n");
|
|
|
|
[prx sendBycopy: obj];
|
2003-07-04 09:33:53 +00:00
|
|
|
[prx quietBycopy: obj];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
#ifdef _F_BYREF
|
|
|
|
[prx sendByref: obj];
|
2002-03-20 06:11:36 +00:00
|
|
|
[prx sendByref: @"hello"];
|
|
|
|
[prx sendByref: [NSDate date]];
|
|
|
|
{
|
|
|
|
NSMutableString *str = [NSMutableString string];
|
|
|
|
|
|
|
|
[prx modifyByref: str];
|
|
|
|
printf(" Modified '%s'\n", [str lossyCString]);
|
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
#endif
|
|
|
|
printf(" ok\n");
|
2001-09-20 10:22:09 +00:00
|
|
|
|
2002-04-24 03:12:55 +00:00
|
|
|
printf("Done\n");
|
2000-08-07 22:00:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
con_benchmark (id prx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NSDate *d = [NSDate date];
|
|
|
|
NSMutableData *sen = [NSMutableData data];
|
|
|
|
id localObj;
|
|
|
|
id rep;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
printf("Benchmarking\n");
|
|
|
|
[sen setLength: 100000];
|
|
|
|
rep = [prx sendObject: sen];
|
|
|
|
printf(" Sent: 0x%p, Reply: 0x%p, Length: %d\n", sen, rep, [rep length]);
|
|
|
|
|
|
|
|
localObj = [[NSObject alloc] init];
|
|
|
|
[prx addObject: localObj]; // FIXME: Why is this needed?
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
k = [prx count];
|
|
|
|
for (j = 0; j < k; j++)
|
|
|
|
{
|
|
|
|
id remote_peer_obj = [prx objectAt: j];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
[prx echoObject: localObj];
|
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
printf(" Delay is %f\n", [d timeIntervalSinceNow]);
|
2002-04-24 03:12:55 +00:00
|
|
|
printf("Done\n");
|
2000-08-07 22:00:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
con_statistics (id prx)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
id localObj, cobj, a, o;
|
|
|
|
|
|
|
|
printf("------------------------------------------------------------\n");
|
|
|
|
printf("Printing Statistics\n");
|
|
|
|
localObj = [[NSObject alloc] init];
|
|
|
|
[prx outputStats: localObj];
|
|
|
|
printf(" >>list proxy's hash is 0x%d\n", [prx hash]);
|
|
|
|
printf(" >>list proxy's self is 0x%p = 0x%p\n", [prx self], prx);
|
2002-09-19 19:24:01 +00:00
|
|
|
printf(" >>proxy's description is (%s)\n", [[prx description] lossyCString]);
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
cobj = [prx connectionForProxy];
|
|
|
|
o = [cobj statistics];
|
|
|
|
a = [o allKeys];
|
|
|
|
|
|
|
|
for (j = 0; j < [a count]; j++)
|
|
|
|
{
|
|
|
|
id k = [a objectAtIndex:j];
|
|
|
|
id v = [o objectForKey:k];
|
|
|
|
|
|
|
|
printf(" %s - %s\n", [k cString], [[v description] cString]);
|
|
|
|
}
|
|
|
|
printf("------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
con_loop (id prx)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *arp;
|
|
|
|
id cobj;
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
2002-12-12 15:14:13 +00:00
|
|
|
[prx addObject: [NSObject new]]; // So loss of this connection is logged.
|
2000-08-07 22:00:31 +00:00
|
|
|
cobj = [prx connectionForProxy];
|
|
|
|
printf("%d\n", [cobj retainCount]);
|
|
|
|
printf("%s\n", [[[cobj statistics] description] cString]);
|
|
|
|
//printf("%s\n", GSDebugAllocationList(YES));
|
|
|
|
|
2002-12-12 15:14:13 +00:00
|
|
|
printf("loop left running idle for 30 seconds\n");
|
2002-02-26 10:38:50 +00:00
|
|
|
[[NSRunLoop currentRunLoop] runUntilDate:
|
2002-12-12 15:14:13 +00:00
|
|
|
[NSDate dateWithTimeIntervalSinceNow: 30]];
|
2000-08-07 22:00:31 +00:00
|
|
|
[cobj invalidate];
|
|
|
|
[arp release];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
con_objects (id prx)
|
|
|
|
{
|
|
|
|
int j, k;
|
|
|
|
id localObj;
|
|
|
|
|
|
|
|
localObj = [NSObject new];
|
|
|
|
[prx addObject:localObj];
|
|
|
|
k = [prx count];
|
|
|
|
for (j = 0; j < k; j++)
|
|
|
|
{
|
|
|
|
id remote_peer_obj = [prx objectAt:j];
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("triangle %d object proxy's hash is 0x%x\n",
|
2000-08-07 22:00:31 +00:00
|
|
|
j, (unsigned)[remote_peer_obj hash]);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* xxx look at this again after we use release/retain everywhere */
|
|
|
|
if ([remote_peer_obj isProxy])
|
|
|
|
[remote_peer_obj release];
|
|
|
|
#endif
|
|
|
|
remote_peer_obj = [prx objectAt:j];
|
2005-02-22 11:22:44 +00:00
|
|
|
printf("repeated triangle %d object proxy's hash is 0x%x\n",
|
2000-08-07 22:00:31 +00:00
|
|
|
j, (unsigned)[remote_peer_obj hash]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-21 14:28:34 +00:00
|
|
|
int
|
|
|
|
con_callback (id prx)
|
|
|
|
{
|
|
|
|
int j, k;
|
|
|
|
id localObj;
|
|
|
|
|
|
|
|
localObj = [CallbackClient new];
|
|
|
|
[prx registerClient: localObj];
|
2003-10-27 13:41:01 +00:00
|
|
|
k = 1000;
|
2003-10-21 14:28:34 +00:00
|
|
|
for (j = 0; j < k; j++)
|
|
|
|
{
|
2003-10-27 13:41:01 +00:00
|
|
|
CREATE_AUTORELEASE_POOL(arp);
|
2003-10-21 14:28:34 +00:00
|
|
|
[prx unregisterClient: localObj];
|
|
|
|
[prx registerClient: localObj];
|
|
|
|
[prx tryClientCallback];
|
|
|
|
if (j < 10 || j %10 == 0)
|
|
|
|
printf("repeated client registration and callback %d\n", j);
|
2003-10-27 13:41:01 +00:00
|
|
|
RELEASE(arp);
|
2003-10-21 14:28:34 +00:00
|
|
|
}
|
|
|
|
printf("repeated client registration and callback %d\n", j);
|
|
|
|
RELEASE(localObj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
void
|
|
|
|
usage(const char *program)
|
|
|
|
{
|
|
|
|
printf("Usage: %s [-ds] [t|b|m|l|o] [host] [server]\n", program);
|
|
|
|
printf(" -d - Debug connection\n");
|
|
|
|
printf(" -s - Print Statistics\n");
|
|
|
|
printf(" -t - Data type test [default]\n");
|
|
|
|
printf(" -b - Benchmark test\n");
|
|
|
|
printf(" -m - Messaging test\n");
|
|
|
|
printf(" -l - Loop test\n");
|
|
|
|
printf(" -o - Objects test\n");
|
2000-11-10 03:01:45 +00:00
|
|
|
printf(" -c - Connect test\n");
|
2003-10-21 14:28:34 +00:00
|
|
|
printf(" -r - Registration and callback test\n");
|
2000-08-07 22:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
NO_TEST, TYPE_TEST, BENCHMARK_TEST, MESSAGE_TEST,
|
2003-10-21 14:28:34 +00:00
|
|
|
LOOP_TEST, OBJECT_TEST, CONNECT_TEST, CALLBACK_TEST
|
2000-08-07 22:00:31 +00:00
|
|
|
} test_t;
|
|
|
|
|
|
|
|
int main (int argc, char *argv[], char **env)
|
|
|
|
{
|
|
|
|
int c, debug, stats;
|
|
|
|
test_t type_test;
|
|
|
|
id cobj, prx;
|
2000-11-10 03:01:45 +00:00
|
|
|
unsigned connect_attempts;
|
2000-08-07 22:00:31 +00:00
|
|
|
NSAutoreleasePool *arp;
|
2009-06-19 15:51:11 +00:00
|
|
|
NSPortNameServer *ns;
|
2000-08-07 22:00:31 +00:00
|
|
|
Auth *auth;
|
2010-03-19 12:10:11 +00:00
|
|
|
#if !defined(__MINGW__)
|
2000-08-07 22:00:31 +00:00
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
2000-09-22 04:20:52 +00:00
|
|
|
#endif
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
auth = [Auth new];
|
|
|
|
GSDebugAllocationActive(YES);
|
|
|
|
|
2005-11-11 10:07:03 +00:00
|
|
|
setvbuf(stdout, 0, _IONBF, 0);
|
2000-08-07 22:00:31 +00:00
|
|
|
debug = 0;
|
|
|
|
type_test = 0;
|
|
|
|
stats = 0;
|
2009-06-19 15:51:11 +00:00
|
|
|
while ((c = wgetopt(argc, argv, "hdtbmslocr")) != EOF)
|
2005-02-22 11:22:44 +00:00
|
|
|
switch (c)
|
2000-08-07 22:00:31 +00:00
|
|
|
{
|
|
|
|
case 'd':
|
2003-10-27 13:41:01 +00:00
|
|
|
debug++;
|
2000-08-07 22:00:31 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
type_test = TYPE_TEST;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
type_test = BENCHMARK_TEST;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
type_test = MESSAGE_TEST;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
stats = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
type_test = LOOP_TEST;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
type_test = OBJECT_TEST;
|
|
|
|
break;
|
2000-11-10 03:01:45 +00:00
|
|
|
case 'c':
|
|
|
|
type_test = CONNECT_TEST;
|
|
|
|
break;
|
2003-10-21 14:28:34 +00:00
|
|
|
case 'r':
|
|
|
|
type_test = CALLBACK_TEST;
|
|
|
|
break;
|
2000-08-07 22:00:31 +00:00
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
default:
|
2002-03-20 17:09:03 +00:00
|
|
|
#if 0
|
2000-08-07 22:00:31 +00:00
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
2002-03-20 17:09:03 +00:00
|
|
|
#endif
|
2000-08-07 22:00:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (type_test == NO_TEST)
|
|
|
|
type_test = TYPE_TEST;
|
|
|
|
|
2000-11-10 03:01:45 +00:00
|
|
|
if (type_test == CONNECT_TEST)
|
|
|
|
connect_attempts = 100000;
|
2000-08-07 22:00:31 +00:00
|
|
|
else
|
2000-11-10 03:01:45 +00:00
|
|
|
connect_attempts = 1;
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2003-10-27 13:41:01 +00:00
|
|
|
if (debug > 0)
|
|
|
|
{
|
|
|
|
[NSConnection setDebug: debug];
|
|
|
|
[NSDistantObject setDebug: debug];
|
|
|
|
[NSObject enableDoubleReleaseCheck: YES];
|
|
|
|
}
|
|
|
|
|
2009-06-19 15:51:11 +00:00
|
|
|
ns = [NSSocketPortNameServer sharedInstance];
|
2000-11-10 03:01:45 +00:00
|
|
|
while (connect_attempts-- > 0)
|
2000-08-07 22:00:31 +00:00
|
|
|
{
|
2000-11-10 03:01:45 +00:00
|
|
|
if (optind < argc)
|
|
|
|
{
|
|
|
|
if (optind+1 < argc)
|
2005-02-22 11:22:44 +00:00
|
|
|
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
|
2000-11-10 03:01:45 +00:00
|
|
|
[NSString stringWithCString: argv[optind+1]]
|
2009-06-19 15:51:11 +00:00
|
|
|
host: [NSString stringWithCString:argv[optind]]
|
|
|
|
usingNameServer: ns];
|
2000-11-10 03:01:45 +00:00
|
|
|
else
|
|
|
|
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
|
|
|
|
@"test2server"
|
2009-06-19 15:51:11 +00:00
|
|
|
host:[NSString stringWithCString:argv[optind]]
|
|
|
|
usingNameServer: ns];
|
2000-11-10 03:01:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
|
2009-06-19 15:51:11 +00:00
|
|
|
@"test2server" host: @""
|
|
|
|
usingNameServer: ns];
|
2000-11-10 03:01:45 +00:00
|
|
|
if (prx == nil)
|
|
|
|
{
|
|
|
|
printf("ERROR: Failed to connect to server\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (type_test == CONNECT_TEST)
|
|
|
|
{
|
|
|
|
NSLog(@"Made connection\n");
|
|
|
|
if (connect_attempts > 0)
|
|
|
|
{
|
|
|
|
RELEASE(arp);
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
}
|
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 15:35:40 +00:00
|
|
|
#if 1
|
2009-08-05 08:03:37 +00:00
|
|
|
/* Check that we can retain the connection, release the proxy,
|
|
|
|
* and then regain the proxy from the connection.
|
|
|
|
*/
|
|
|
|
cobj = RETAIN([prx connectionForProxy]);
|
|
|
|
RELEASE(arp);
|
|
|
|
arp = [NSAutoreleasePool new];
|
2009-10-03 15:35:40 +00:00
|
|
|
prx = [cobj rootProxy];
|
2009-08-05 08:03:37 +00:00
|
|
|
AUTORELEASE(cobj);
|
|
|
|
#else
|
2000-08-07 22:00:31 +00:00
|
|
|
cobj = [prx connectionForProxy];
|
2009-08-05 08:03:37 +00:00
|
|
|
#endif
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
[cobj setDelegate:auth];
|
|
|
|
[cobj setRequestTimeout:180.0];
|
|
|
|
[cobj setReplyTimeout:180.0];
|
|
|
|
|
|
|
|
[prx print: "This is a message from the client. Starting Tests!"];
|
|
|
|
|
|
|
|
switch (type_test)
|
|
|
|
{
|
|
|
|
case TYPE_TEST:
|
|
|
|
con_data (prx);
|
|
|
|
break;
|
|
|
|
case BENCHMARK_TEST:
|
|
|
|
con_benchmark (prx);
|
|
|
|
break;
|
|
|
|
case MESSAGE_TEST:
|
|
|
|
con_messages (prx);
|
|
|
|
break;
|
|
|
|
case LOOP_TEST:
|
|
|
|
con_loop (prx);
|
|
|
|
break;
|
|
|
|
case OBJECT_TEST:
|
|
|
|
con_objects (prx);
|
|
|
|
break;
|
2003-10-21 14:28:34 +00:00
|
|
|
case CALLBACK_TEST:
|
|
|
|
con_callback (prx);
|
|
|
|
break;
|
2000-08-07 22:00:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stats)
|
|
|
|
con_statistics (prx);
|
|
|
|
|
2005-11-21 13:15:39 +00:00
|
|
|
[cobj invalidate];
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
[arp release];
|
|
|
|
return 0;
|
|
|
|
}
|