Simple NSConnection client/server test tools

This commit is contained in:
Richard Frith-Macdonald 2021-05-31 13:08:40 +01:00
parent c54a673f79
commit 802c82cf33
3 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,42 @@
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSTLS.h>
@interface TestServer : NSObject
{
}
- (int) doIt;
@end
int
main()
{
ENTER_POOL
NSSocketPortNameServer *ns = [NSSocketPortNameServer sharedInstance];
NSString *name = @"TestServer";
NSConnection *conn;
NSDistantObject *proxy;
TestServer *test;
int result;
[NSSocketPort setOptionsForTLS: [NSDictionary dictionaryWithObjectsAndKeys:
@"9", GSTLSDebug,
nil]];
conn = [NSConnection connectionWithRegisteredName: name
host: @""
usingNameServer: ns];
proxy = [conn rootProxy];
test = (TestServer*)proxy;
result = [test doIt];
printf("Result is %d\n", result);
LEAVE_POOL
exit(0);
}
@implementation TestServer
- (int) doIt
{
return 42;
}
@end

View file

@ -2,6 +2,13 @@ include $(GNUSTEP_MAKEFILES)/common.make
BUNDLE_NAME=TestConnection
TestConnection_NEEDS_GUI = NO
TestConnection_OBJC_FILES=Connection.m
TEST_TOOL_NAME=Client Server
Client_NEEDS_GUI = NO
Client_OBJC_FILES=Client.m
Server_NEEDS_GUI = NO
Server_OBJC_FILES=Server.m
include $(GNUSTEP_MAKEFILES)/bundle.make
include $(GNUSTEP_MAKEFILES)/test-tool.make

View file

@ -0,0 +1,48 @@
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSTLS.h>
@interface TestServer : NSObject
{
}
- (int) doIt;
@end
int
main()
{
ENTER_POOL
NSSocketPortNameServer *ns = [NSSocketPortNameServer sharedInstance];
NSString *name = @"TestServer";
NSConnection *conn;
NSPort *port;
TestServer *test = AUTORELEASE([TestServer new]);
port = [NSSocketPort port];
[(NSSocketPort*)port setOptionsForTLS:
[NSDictionary dictionaryWithObjectsAndKeys:
@"9", GSTLSDebug,
nil]];
conn = [[NSConnection alloc] initWithReceivePort: port
sendPort: nil];
[conn setRootObject: test];
if ([conn registerName: name withNameServer: ns] == NO)
{
NSPort *p = [ns portForName: name onHost: @""];
DESTROY(conn);
NSLog(@"There is already a process: %@, on %@", name, p);
return NO;
}
[[NSRunLoop currentRunLoop] run];
LEAVE_POOL
exit(0);
}
@implementation TestServer
- (int) doIt
{
return 42;
}
@end